52 const float*
const unknown,
53 const float*
const known,
56 if (b <= 0 || n <= 0)
return;
57 const size_t wg = kThreeNNWGSize;
59 queue.submit([&](sycl::handler& cgh) {
62 sycl::local_accessor<double, 1> local_best(3 * wg, cgh);
63 sycl::local_accessor<int, 1> local_besti(3 * wg, cgh);
67 sycl::range<1>(
static_cast<size_t>(b) * n * wg),
70 [=](sycl::nd_item<1> item) [[intel::kernel_args_restrict]] {
71 const size_t group_id = item.get_group(0);
72 const int bs_idx =
static_cast<int>(group_id / n);
73 const int pt_idx =
static_cast<int>(group_id % n);
74 const size_t lid = item.get_local_id(0);
75 auto group = item.get_group();
77 const float*
const u =
78 unknown + bs_idx * n * 3 + pt_idx * 3;
79 const float*
const kn = known + bs_idx * m * 3;
81 const float ux = u[0];
82 const float uy = u[1];
83 const float uz = u[2];
85 double best1 = 1e40, best2 = 1e40, best3 = 1e40;
86 int besti1 = 0, besti2 = 0, besti3 = 0;
87 for (
int k =
static_cast<int>(lid); k < m;
88 k +=
static_cast<int>(wg)) {
89 const float x = kn[k * 3 + 0];
90 const float y = kn[k * 3 + 1];
91 const float z = kn[k * 3 + 2];
92 const double d = double((ux -
x) * (ux -
x) +
102 }
else if (d < best2) {
107 }
else if (d < best3) {
113 local_best[3 * lid + 0] = best1;
114 local_best[3 * lid + 1] = best2;
115 local_best[3 * lid + 2] = best3;
116 local_besti[3 * lid + 0] = besti1;
117 local_besti[3 * lid + 1] = besti2;
118 local_besti[3 * lid + 2] = besti3;
119 sycl::group_barrier(group);
121 if (lid != 0)
return;
128 float*
const d2_out = dist2 + bs_idx * n * 3 + pt_idx * 3;
129 int*
const idx_out = idx + bs_idx * n * 3 + pt_idx * 3;
131 double mbest1 = 1e40, mbest2 = 1e40, mbest3 = 1e40;
132 int mbesti1 = 0, mbesti2 = 0, mbesti3 = 0;
133 for (
size_t c = 0; c < 3 * wg; ++c) {
134 const double d = local_best[c];
135 const int di = local_besti[c];
143 }
else if (d < mbest2) {
148 }
else if (d < mbest3) {
153 d2_out[0] =
static_cast<float>(mbest1);
154 d2_out[1] =
static_cast<float>(mbest2);
155 d2_out[2] =
static_cast<float>(mbest3);
156 idx_out[0] = mbesti1;
157 idx_out[1] = mbesti2;
158 idx_out[2] = mbesti3;
161 queue.wait_and_throw();
176 const float*
const points,
177 const int*
const idx,
178 const float*
const weight,
180 if (b <= 0 || c <= 0 || n <= 0)
return;
183 queue,
static_cast<int64_t
>(b) * c * n, [=](int64_t idx64) {
184 const int bs_idx =
static_cast<int>(idx64 / (c * n));
185 const int rem =
static_cast<int>(idx64 % (c * n));
186 const int c_idx = rem / n;
187 const int pt_idx = rem % n;
189 const float*
const w =
weight + bs_idx * n * 3 + pt_idx * 3;
190 const float*
const pts =
points + bs_idx * c * m + c_idx * m;
191 const int*
const id = idx + bs_idx * n * 3 + pt_idx * 3;
192 float*
const o = out + bs_idx * c * n + c_idx * n;
194 o[pt_idx] = w[0] * pts[
id[0]] + w[1] * pts[
id[1]] +
208 const float*
const grad_out,
209 const int*
const idx,
210 const float*
const weight,
211 float*
const grad_points) {
212 if (b <= 0 || c <= 0 || n <= 0)
return;
215 queue,
static_cast<int64_t
>(b) * c * n, [=](int64_t idx64) {
216 const int bs_idx =
static_cast<int>(idx64 / (c * n));
217 const int rem =
static_cast<int>(idx64 % (c * n));
218 const int c_idx = rem / n;
219 const int pt_idx = rem % n;
221 const float g = grad_out[bs_idx * c * n + c_idx * n + pt_idx];
222 const float*
const w =
weight + bs_idx * n * 3 + pt_idx * 3;
223 const int*
const id = idx + bs_idx * n * 3 + pt_idx * 3;
224 float*
const gp = grad_points + bs_idx * c * m + c_idx * m;
226 for (
int l = 0; l < 3; ++l) {
227 sycl::atomic_ref<float, sycl::memory_order::relaxed,
228 sycl::memory_scope::device,
229 sycl::access::address_space::global_space>
231 ref.fetch_add(g * w[l]);
sycl::queue queue
Definition SYCLContext.cpp:88
void ThreeInterpolateGradSYCL(sycl::queue &queue, int b, int c, int n, int m, const float *const grad_out, const int *const idx, const float *const weight, float *const grad_points)
Definition InterpolatePointsSYCL.h:203
void ThreeInterpolateSYCL(sycl::queue &queue, int b, int c, int m, int n, const float *const points, const int *const idx, const float *const weight, float *const out)
Definition InterpolatePointsSYCL.h:171
void ThreeNNSYCL(sycl::queue &queue, int b, int n, int m, const float *const unknown, const float *const known, float *const dist2, int *const idx)
Definition InterpolatePointsSYCL.h:48