16int main(
int argc,
char** argv) {
17 Kokkos::initialize(argc, argv);
21 std::vector<double> cx, cy, cz, r;
22 std::ifstream f(
"/home/frankp/Codes/suite/core/tests/data/rcp_pack_seed3_unit.txt");
24 while (std::getline(f, line)) {
25 if (line.empty() || line[0] ==
'#')
27 std::istringstream is(line);
29 if (is >> x >> y >> z >> rr) {
36 SphereBedQuery q(cx, cy, cz, r, Vec<3>{0, 0, 0}, Vec<3>{1, 1, 1},
true);
39 const int n = q.sphereUnion().n;
40 auto mkview = [](
const char* nm,
const double* src, std::size_t cnt) {
41 Kokkos::View<double*> v(nm, cnt);
42 auto h = Kokkos::create_mirror_view(v);
43 for (std::size_t i = 0; i < cnt; ++i)
45 Kokkos::deep_copy(v, h);
48 auto dcx = mkview(
"cx", q.sphereUnion().cx, n), dcy = mkview(
"cy", q.sphereUnion().cy, n),
49 dcz = mkview(
"cz", q.sphereUnion().cz, n), dr = mkview(
"r", q.sphereUnion().r, n);
50 const auto& gh = q.grid();
51 const long nbins = (long)gh.nx * gh.ny * gh.nz;
52 Kokkos::View<int*> doff(
"off", nbins + 1), ditems(
"items", gh.offsets[nbins]);
54 auto h1 = Kokkos::create_mirror_view(doff);
55 for (
long i = 0; i <= nbins; ++i)
56 h1(i) = gh.offsets[i];
57 Kokkos::deep_copy(doff, h1);
58 auto h2 = Kokkos::create_mirror_view(ditems);
59 for (
int i = 0; i < gh.offsets[nbins]; ++i)
61 Kokkos::deep_copy(ditems, h2);
63 SphereUnionView<double> du = q.sphereUnion();
68 CandidateGridView<double> dg = gh;
69 dg.offsets = doff.data();
70 dg.items = ditems.data();
73 const int NP = 200000;
74 Kokkos::View<double* [3]> pts(
"pts", NP);
75 auto hp = Kokkos::create_mirror_view(pts);
76 std::uint64_t st = 0x9E3779B97F4A7C15ull;
81 return (
double)((st >> 11) & ((1ull << 53) - 1)) / (double)(1ull << 53);
83 for (
int i = 0; i < NP; ++i) {
85 const int s = (int)(u01() * n);
86 const double th = 6.283185307179586 * u01(), uz = 2 * u01() - 1,
87 sr = std::sqrt(1 - uz * uz), eps = (u01() - 0.5) * 4e-3;
88 hp(i, 0) = cx[s] + (r[s] + eps) * sr * std::cos(th);
89 hp(i, 1) = cy[s] + (r[s] + eps) * sr * std::sin(th);
90 hp(i, 2) = cz[s] + (r[s] + eps) * uz;
92 hp(i, 0) = 1.6 * u01() - 0.3;
93 hp(i, 1) = 1.6 * u01() - 0.3;
94 hp(i, 2) = 1.6 * u01() - 0.3;
97 Kokkos::deep_copy(pts, hp);
99 Kokkos::View<double*> out(
"out", NP);
100 evalSphereUnionPoints(Kokkos::DefaultExecutionSpace{}, du, q.box(), dg, pts, out);
102 auto ho = Kokkos::create_mirror_view_and_copy(Kokkos::HostSpace{}, out);
105 for (
int i = 0; i < NP; ++i) {
106 const double ref = q(Vec<3>{hp(i, 0), hp(i, 1), hp(i, 2)});
108 std::memcpy(&a, &ref, 8);
109 const double v = ho(i);
110 std::memcpy(&b, &v, 8);
113 std::printf(
" mismatch %d: dev %.17g host %.17g\n", i, v, ref);
117 std::printf(
" batched device vs host query: %d/%d bit mismatches\n", nbit, NP);
122 std::printf(bad ?
"BATCH FAIL\n" :
"BATCH OK\n");