|
15 | 15 | #include <ArborX_Point.hpp>
|
16 | 16 | #include <misc/ArborX_Exception.hpp>
|
17 | 17 |
|
| 18 | +#include <fstream> |
18 | 19 | #include <iostream>
|
19 | 20 | #include <random>
|
20 | 21 | #include <vector>
|
21 | 22 |
|
| 23 | +#include "parameters.hpp" |
| 24 | + |
22 | 25 | using ArborX::Point;
|
23 | 26 |
|
24 | 27 | template <int DIM>
|
@@ -51,6 +54,33 @@ std::vector<Point<DIM>> sampleData(std::vector<Point<DIM>> const &data,
|
51 | 54 | return sampled_data;
|
52 | 55 | }
|
53 | 56 |
|
| 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 | + |
54 | 84 | template <int DIM>
|
55 | 85 | std::vector<Point<DIM>> loadData(std::string const &filename,
|
56 | 86 | bool binary = true, int max_num_points = -1,
|
@@ -298,4 +328,41 @@ std::vector<Point<DIM>> GanTao(int n, bool variable_density = false,
|
298 | 328 | return points;
|
299 | 329 | }
|
300 | 330 |
|
| 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 ¶ms) |
| 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 | + |
301 | 368 | #endif
|
0 commit comments