Skip to content

Commit 10478a7

Browse files
committed
Reorganize clustering benchmarks
1 parent 3be019d commit 10478a7

File tree

7 files changed

+643
-457
lines changed

7 files changed

+643
-457
lines changed

benchmarks/clustering/CMakeLists.txt

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
1-
set(EXPLICIT_INSTANTIATION_SOURCE_FILES)
2-
set(TEMPLATE_PARAMETERS 2 3 4 5 6)
3-
foreach(DIM ${TEMPLATE_PARAMETERS})
4-
set(filename ${CMAKE_CURRENT_BINARY_DIR}/dbscan_${DIM}.cpp)
5-
file(WRITE ${filename}
6-
"#include \"${CMAKE_CURRENT_SOURCE_DIR}/dbscan_timpl.hpp\"\n"
7-
"template bool ArborXBenchmark::run<${DIM}>(ArborXBenchmark::Parameters const&);\n"
8-
)
9-
list(APPEND EXPLICIT_INSTANTIATION_SOURCE_FILES ${filename})
10-
endforeach()
11-
12-
add_executable(ArborX_Benchmark_DBSCAN.exe
13-
${EXPLICIT_INSTANTIATION_SOURCE_FILES}
1+
add_library(cluster_benchmark_helpers
142
print_timers.cpp
15-
dbscan.cpp
163
)
4+
target_compile_features(cluster_benchmark_helpers PRIVATE cxx_std_17)
5+
target_link_libraries(cluster_benchmark_helpers PRIVATE Kokkos::kokkos)
6+
7+
set(input_file "input.txt")
8+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${input_file} ${CMAKE_CURRENT_BINARY_DIR}/${input_file} COPYONLY)
9+
10+
add_executable(ArborX_Benchmark_DBSCAN.exe dbscan.cpp)
1711
target_include_directories(ArborX_Benchmark_DBSCAN.exe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
18-
target_link_libraries(ArborX_Benchmark_DBSCAN.exe ArborX::ArborX Boost::program_options)
12+
target_link_libraries(ArborX_Benchmark_DBSCAN.exe ArborX::ArborX Boost::program_options cluster_benchmark_helpers)
13+
add_test(NAME ArborX_Benchmark_DBSCAN COMMAND ArborX_Benchmark_DBSCAN.exe --filename=${input_file} --eps=1.4 --verify)
14+
15+
add_executable(ArborX_Benchmark_MST.exe mst.cpp)
16+
target_include_directories(ArborX_Benchmark_MST.exe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
17+
target_link_libraries(ArborX_Benchmark_MST.exe ArborX::ArborX Boost::program_options cluster_benchmark_helpers)
18+
add_test(NAME ArborX_Benchmark_HDBSCAN COMMAND ArborX_Benchmark_HDBSCAN.exe --filename=${input_file})
19+
20+
add_executable(ArborX_Benchmark_HDBSCAN.exe hdbscan.cpp)
21+
target_include_directories(ArborX_Benchmark_HDBSCAN.exe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
22+
target_link_libraries(ArborX_Benchmark_HDBSCAN.exe ArborX::ArborX Boost::program_options cluster_benchmark_helpers)
23+
add_test(NAME ArborX_Benchmark_MST COMMAND ArborX_Benchmark_MST.exe --filename=${input_file})
1924

2025
add_executable(ArborX_DataConverter.exe converter.cpp)
2126
target_compile_features(ArborX_DataConverter.exe PRIVATE cxx_std_17)
2227
target_link_libraries(ArborX_DataConverter.exe Boost::program_options)
23-
24-
set(input_file "input.txt")
25-
add_test(NAME ArborX_Benchmark_DBSCAN COMMAND ArborX_Benchmark_DBSCAN.exe --filename=${input_file} --eps=1.4 --verify)
26-
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${input_file} ${CMAKE_CURRENT_BINARY_DIR}/${input_file} COPYONLY)

benchmarks/clustering/data.hpp

+67
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,13 @@
1515
#include <ArborX_Point.hpp>
1616
#include <misc/ArborX_Exception.hpp>
1717

18+
#include <fstream>
1819
#include <iostream>
1920
#include <random>
2021
#include <vector>
2122

23+
#include "parameters.hpp"
24+
2225
using ArborX::Point;
2326

2427
template <int DIM>
@@ -51,6 +54,33 @@ std::vector<Point<DIM>> sampleData(std::vector<Point<DIM>> const &data,
5154
return sampled_data;
5255
}
5356

57+
static int getDataDimension(std::string const &filename, bool binary)
58+
{
59+
std::ifstream input;
60+
if (!binary)
61+
input.open(filename);
62+
else
63+
input.open(filename, std::ifstream::binary);
64+
if (!input.good())
65+
throw std::runtime_error("Error reading file \"" + filename + "\"");
66+
67+
int num_points;
68+
int dim;
69+
if (!binary)
70+
{
71+
input >> num_points;
72+
input >> dim;
73+
}
74+
else
75+
{
76+
input.read(reinterpret_cast<char *>(&num_points), sizeof(int));
77+
input.read(reinterpret_cast<char *>(&dim), sizeof(int));
78+
}
79+
input.close();
80+
81+
return dim;
82+
}
83+
5484
template <int DIM>
5585
std::vector<Point<DIM>> loadData(std::string const &filename,
5686
bool binary = true, int max_num_points = -1,
@@ -298,4 +328,41 @@ std::vector<Point<DIM>> GanTao(int n, bool variable_density = false,
298328
return points;
299329
}
300330

331+
template <typename... P, typename T>
332+
auto vec2view(std::vector<T> const &in, std::string const &label = "")
333+
{
334+
Kokkos::View<T *, P...> out(
335+
Kokkos::view_alloc(label, Kokkos::WithoutInitializing), in.size());
336+
Kokkos::deep_copy(out, Kokkos::View<T const *, Kokkos::HostSpace,
337+
Kokkos::MemoryTraits<Kokkos::Unmanaged>>{
338+
in.data(), in.size()});
339+
return out;
340+
}
341+
342+
template <int DIM, typename MemorySpace>
343+
auto loadData(ArborXBenchmark::Parameters const &params)
344+
{
345+
if (!params.filename.empty())
346+
{
347+
// Read in data
348+
printf("filename : %s [%s, max_pts = %d]\n",
349+
params.filename.c_str(), (params.binary ? "binary" : "text"),
350+
params.max_num_points);
351+
printf("samples : %d\n", params.num_samples);
352+
return vec2view<MemorySpace>(loadData<DIM>(params.filename, params.binary,
353+
params.max_num_points,
354+
params.num_samples),
355+
"Benchmark::primitives");
356+
}
357+
else
358+
{
359+
// Generate data
360+
int dim = params.dim;
361+
printf("generator : n = %d, dim = %d, density = %s\n", params.n,
362+
dim, (params.variable_density ? "variable" : "constant"));
363+
return vec2view<MemorySpace>(GanTao<DIM>(params.n, params.variable_density),
364+
"Benchmark::primitives");
365+
}
366+
}
367+
301368
#endif

0 commit comments

Comments
 (0)