Skip to content

Commit

Permalink
Reorganize benchmarks/dbscan\
Browse files Browse the repository at this point in the history
* Rename benchmarks/{dbscan => clustering}

* Reorganize clustering benchmarks

* Remove data converter

* Instantiate data loader only once

* benchmarks/clustering => benchmarks/cluster

* Add missing copyright header

* Maybe fix?

* Address review comments

* Fix else-after-return check
  • Loading branch information
aprokop authored Feb 26, 2025
1 parent c3ebac5 commit 0ff7c67
Show file tree
Hide file tree
Showing 18 changed files with 746 additions and 961 deletions.
2 changes: 1 addition & 1 deletion benchmarks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ else()
ENDIF()

add_subdirectory(brute_force_vs_bvh)
add_subdirectory(dbscan)
add_subdirectory(cluster)
add_subdirectory(execution_space_instances)
if(NOT WIN32)
# FIXME: for now, skip the benchmarks using Google benchmark
Expand Down
23 changes: 23 additions & 0 deletions benchmarks/cluster/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
add_library(cluster_benchmark_helpers
data.cpp
print_timers.cpp
)
target_link_libraries(cluster_benchmark_helpers PRIVATE ArborX::ArborX)

set(input_file "input.txt")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/${input_file} ${CMAKE_CURRENT_BINARY_DIR}/${input_file} COPYONLY)

add_executable(ArborX_Benchmark_DBSCAN.exe dbscan.cpp)
target_include_directories(ArborX_Benchmark_DBSCAN.exe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(ArborX_Benchmark_DBSCAN.exe ArborX::ArborX Boost::program_options cluster_benchmark_helpers)
add_test(NAME ArborX_Benchmark_DBSCAN COMMAND ArborX_Benchmark_DBSCAN.exe --filename=${input_file} --eps=1.4 --verify)

add_executable(ArborX_Benchmark_MST.exe mst.cpp)
target_include_directories(ArborX_Benchmark_MST.exe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(ArborX_Benchmark_MST.exe ArborX::ArborX Boost::program_options cluster_benchmark_helpers)
add_test(NAME ArborX_Benchmark_HDBSCAN COMMAND ArborX_Benchmark_HDBSCAN.exe --filename=${input_file})

add_executable(ArborX_Benchmark_HDBSCAN.exe hdbscan.cpp)
target_include_directories(ArborX_Benchmark_HDBSCAN.exe PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(ArborX_Benchmark_HDBSCAN.exe ArborX::ArborX Boost::program_options cluster_benchmark_helpers)
add_test(NAME ArborX_Benchmark_MST COMMAND ArborX_Benchmark_MST.exe --filename=${input_file})
File renamed without changes.
62 changes: 62 additions & 0 deletions benchmarks/cluster/data.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/****************************************************************************
* Copyright (c) 2025, ArborX authors *
* All rights reserved. *
* *
* This file is part of the ArborX library. ArborX is *
* distributed under a BSD 3-clause license. For the licensing terms see *
* the LICENSE file in the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/
#include "data.hpp"

#include <Kokkos_Core.hpp>

#include <fstream>
#include <string>

#include "data_timpl.hpp"

namespace ArborXBenchmark
{

// Explicit instantiations
using MemorySpace = typename Kokkos::DefaultExecutionSpace::memory_space;
#define INSTANTIATE_LOADER(DIM) \
template Kokkos::View<ArborX::Point<DIM> *, MemorySpace> \
loadData<DIM, MemorySpace>(ArborXBenchmark::Parameters const &);
INSTANTIATE_LOADER(2)
INSTANTIATE_LOADER(3)
INSTANTIATE_LOADER(4)
INSTANTIATE_LOADER(5)
INSTANTIATE_LOADER(6)
#undef INSTANTIATE_LOADER

int getDataDimension(std::string const &filename, bool binary)
{
std::ifstream input;
if (!binary)
input.open(filename);
else
input.open(filename, std::ifstream::binary);
if (!input.good())
throw std::runtime_error("Error reading file \"" + filename + "\"");

int num_points;
int dim;
if (!binary)
{
input >> num_points;
input >> dim;
}
else
{
input.read(reinterpret_cast<char *>(&num_points), sizeof(int));
input.read(reinterpret_cast<char *>(&dim), sizeof(int));
}
input.close();

return dim;
}

} // namespace ArborXBenchmark
31 changes: 31 additions & 0 deletions benchmarks/cluster/data.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/****************************************************************************
* Copyright (c) 2025, ArborX authors *
* All rights reserved. *
* *
* This file is part of the ArborX library. ArborX is *
* distributed under a BSD 3-clause license. For the licensing terms see *
* the LICENSE file in the top-level directory. *
* *
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/
#ifndef ARBORX_BENCHMARK_DATA_HPP
#define ARBORX_BENCHMARK_DATA_HPP

#include <ArborX_Point.hpp>

#include <Kokkos_Core.hpp>

#include "parameters.hpp"

namespace ArborXBenchmark
{

int getDataDimension(std::string const &filename, bool binary);

template <int DIM, typename MemorySpace>
Kokkos::View<ArborX::Point<DIM> *, MemorySpace>
loadData(ArborXBenchmark::Parameters const &params);

} // namespace ArborXBenchmark

#endif
53 changes: 51 additions & 2 deletions benchmarks/dbscan/data.hpp → benchmarks/cluster/data_timpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,27 @@
* SPDX-License-Identifier: BSD-3-Clause *
****************************************************************************/

#ifndef DATA_HPP
#define DATA_HPP
#ifndef ARBORX_BENCHMARK_DATA_TIMPL_HPP
#define ARBORX_BENCHMARK_DATA_TIMPL_HPP

#include <ArborX_Point.hpp>
#include <misc/ArborX_Exception.hpp>

#include <Kokkos_Core.hpp>

#include <cassert>
#include <fstream>
#include <iostream>
#include <iterator>
#include <random>
#include <vector>

#include "data.hpp"
#include "parameters.hpp"

namespace ArborXBenchmark
{

using ArborX::Point;

template <int DIM>
Expand Down Expand Up @@ -298,4 +309,42 @@ std::vector<Point<DIM>> GanTao(int n, bool variable_density = false,
return points;
}

template <typename... P, typename T>
auto vec2view(std::vector<T> const &in, std::string const &label = "")
{
Kokkos::View<T *, P...> out(
Kokkos::view_alloc(label, Kokkos::WithoutInitializing), in.size());
Kokkos::deep_copy(out, Kokkos::View<T const *, Kokkos::HostSpace,
Kokkos::MemoryTraits<Kokkos::Unmanaged>>{
in.data(), in.size()});
return out;
}

template <int DIM, typename MemorySpace>
Kokkos::View<ArborX::Point<DIM> *, MemorySpace>
loadData(ArborXBenchmark::Parameters const &params)
{
if (!params.filename.empty())
{
// Read in data
printf("filename : %s [%s, max_pts = %d]\n",
params.filename.c_str(), (params.binary ? "binary" : "text"),
params.max_num_points);
printf("samples : %d\n", params.num_samples);
return vec2view<MemorySpace>(loadData<DIM>(params.filename, params.binary,
params.max_num_points,
params.num_samples),
"Benchmark::primitives");
}

// Generate data
int dim = params.dim;
printf("generator : n = %d, dim = %d, density = %s\n", params.n, dim,
(params.variable_density ? "variable" : "constant"));
return vec2view<MemorySpace>(GanTao<DIM>(params.n, params.variable_density),
"Benchmark::primitives");
}

} // namespace ArborXBenchmark

#endif
Loading

0 comments on commit 0ff7c67

Please sign in to comment.