38 const float*
const coords,
39 const float*
const feat,
43 if (b <= 0 || n <= 0)
return;
46 const int batch_index =
static_cast<int>(idx / n);
47 const int i =
static_cast<int>(idx % n);
49 const float*
const crd = coords + batch_index * n * 3;
50 int*
const ind = inds + batch_index * n * 8;
51 float*
const wgt = wgts + batch_index * n * 8;
52 const float*
const ft = feat + batch_index * c * r3;
53 float*
const out = outs + batch_index * c * n;
55 const float x = crd[i];
56 const float y = crd[i + n];
57 const float z = crd[i + n + n];
58 const float x_lo_f = sycl::floor(
x);
59 const float y_lo_f = sycl::floor(
y);
60 const float z_lo_f = sycl::floor(
z);
62 const float x_d_1 =
x - x_lo_f;
63 const float y_d_1 =
y - y_lo_f;
64 const float z_d_1 =
z - z_lo_f;
65 const float x_d_0 = 1.0f - x_d_1;
66 const float y_d_0 = 1.0f - y_d_1;
67 const float z_d_0 = 1.0f - z_d_1;
69 const float wgt000 = x_d_0 * y_d_0 * z_d_0;
70 const float wgt001 = x_d_0 * y_d_0 * z_d_1;
71 const float wgt010 = x_d_0 * y_d_1 * z_d_0;
72 const float wgt011 = x_d_0 * y_d_1 * z_d_1;
73 const float wgt100 = x_d_1 * y_d_0 * z_d_0;
74 const float wgt101 = x_d_1 * y_d_0 * z_d_1;
75 const float wgt110 = x_d_1 * y_d_1 * z_d_0;
76 const float wgt111 = x_d_1 * y_d_1 * z_d_1;
78 const int x_lo =
static_cast<int>(x_lo_f);
79 const int y_lo =
static_cast<int>(y_lo_f);
80 const int z_lo =
static_cast<int>(z_lo_f);
81 const int x_hi = (x_d_1 > 0) ? -1 : 0;
82 const int y_hi = (y_d_1 > 0) ? -1 : 0;
83 const int z_hi = (z_d_1 > 0) ? 1 : 0;
85 const int idx000 = x_lo * r2 + y_lo * r + z_lo;
86 const int idx001 = idx000 + z_hi;
87 const int idx010 = idx000 + (y_hi & r);
88 const int idx011 = idx010 + z_hi;
89 const int idx100 = idx000 + (x_hi & r2);
90 const int idx101 = idx100 + z_hi;
91 const int idx110 = idx100 + (y_hi & r);
92 const int idx111 = idx110 + z_hi;
97 wgt[i + n * 2] = wgt010;
98 wgt[i + n * 3] = wgt011;
99 wgt[i + n * 4] = wgt100;
100 wgt[i + n * 5] = wgt101;
101 wgt[i + n * 6] = wgt110;
102 wgt[i + n * 7] = wgt111;
105 ind[i + n * 2] = idx010;
106 ind[i + n * 3] = idx011;
107 ind[i + n * 4] = idx100;
108 ind[i + n * 5] = idx101;
109 ind[i + n * 6] = idx110;
110 ind[i + n * 7] = idx111;
113 for (
int j = 0; j < c; ++j) {
114 const int jr3 = j * r3;
116 wgt000 * ft[jr3 + idx000] + wgt001 * ft[jr3 + idx001] +
117 wgt010 * ft[jr3 + idx010] + wgt011 * ft[jr3 + idx011] +
118 wgt100 * ft[jr3 + idx100] + wgt101 * ft[jr3 + idx101] +
119 wgt110 * ft[jr3 + idx110] + wgt111 * ft[jr3 + idx111];
131 const int*
const inds,
132 const float*
const wgts,
133 const float*
const grad_y,
134 float*
const grad_x) {
135 if (b <= 0 || n <= 0)
return;
138 const int batch_index =
static_cast<int>(idx64 / n);
139 const int i =
static_cast<int>(idx64 % n);
141 const int*
const ind = inds + batch_index * n * 8;
142 const float*
const wgt = wgts + batch_index * n * 8;
143 float*
const gx = grad_x + batch_index * c * r3;
144 const float*
const gy = grad_y + batch_index * c * n;
146 const int idx[8] = {ind[i], ind[i + n], ind[i + n * 2],
147 ind[i + n * 3], ind[i + n * 4], ind[i + n * 5],
148 ind[i + n * 6], ind[i + n * 7]};
149 const float w[8] = {wgt[i], wgt[i + n], wgt[i + n * 2],
150 wgt[i + n * 3], wgt[i + n * 4], wgt[i + n * 5],
151 wgt[i + n * 6], wgt[i + n * 7]};
153 for (
int j = 0; j < c; ++j) {
154 const int jr3 = j * r3;
155 const float g = gy[j * n + i];
156 for (
int l = 0; l < 8; ++l) {
157 sycl::atomic_ref<float, sycl::memory_order::relaxed,
158 sycl::memory_scope::device,
159 sycl::access::address_space::global_space>
160 ref(gx[jr3 + idx[l]]);
161 ref.fetch_add(w[l] * g);
sycl::queue queue
Definition SYCLContext.cpp:88
void TrilinearDevoxelizeGradSYCL(sycl::queue &queue, int b, int c, int n, int r3, const int *const inds, const float *const wgts, const float *const grad_y, float *const grad_x)
Definition TrilinearDevoxelizeSYCL.h:126
void TrilinearDevoxelizeSYCL(sycl::queue &queue, int b, int c, int n, int r, int r2, int r3, bool is_training, const float *const coords, const float *const feat, int *const inds, float *const wgts, float *const outs)
Definition TrilinearDevoxelizeSYCL.h:30