| 1 |
#include "kernel_simple_radial_jtjnjtr_direct.h" |
| 2 |
#include "memops.cuh" |
| 3 |
#include <cooperative_groups.h> |
| 4 |
#include <cooperative_groups/details/partitioning.h> |
| 5 |
#include <cooperative_groups/memcpy_async.h> |
| 6 |
#include <cooperative_groups/reduce.h> |
| 7 |
#include <cuda_runtime.h> |
| 8 |
|
| 9 |
namespace cg = cooperative_groups; |
| 10 |
|
| 11 |
namespace caspar { |
| 12 |
|
| 13 |
__global__ void __launch_bounds__(1024, 1) |
| 14 |
SimpleRadialJtjnjtrDirectKernel(float* pose_njtr, |
| 15 |
unsigned int pose_njtr_num_alloc, |
| 16 |
SharedIndex* pose_njtr_indices, |
| 17 |
float* pose_jac, |
| 18 |
unsigned int pose_jac_num_alloc, |
| 19 |
float* calib_njtr, |
| 20 |
unsigned int calib_njtr_num_alloc, |
| 21 |
SharedIndex* calib_njtr_indices, |
| 22 |
float* calib_jac, |
| 23 |
unsigned int calib_jac_num_alloc, |
| 24 |
float* point_njtr, |
| 25 |
unsigned int point_njtr_num_alloc, |
| 26 |
SharedIndex* point_njtr_indices, |
| 27 |
float* point_jac, |
| 28 |
unsigned int point_jac_num_alloc, |
| 29 |
float* const out_pose_njtr, |
| 30 |
unsigned int out_pose_njtr_num_alloc, |
| 31 |
float* const out_calib_njtr, |
| 32 |
unsigned int out_calib_njtr_num_alloc, |
| 33 |
float* const out_point_njtr, |
| 34 |
unsigned int out_point_njtr_num_alloc, |
| 35 |
size_t problem_size) { |
| 36 |
const int global_thread_idx = blockIdx.x * blockDim.x + threadIdx.x; |
| 37 |
__shared__ uint8_t inout_shared[16384]; |
| 38 |
|
| 39 |
__shared__ SharedIndex pose_njtr_indices_loc[1024]; |
| 40 |
pose_njtr_indices_loc[threadIdx.x] = |
| 41 |
(global_thread_idx < problem_size |
| 42 |
? pose_njtr_indices[global_thread_idx] |
| 43 |
: SharedIndex{0xffffffff, 0xffff, 0xffff}); |
| 44 |
|
| 45 |
__shared__ SharedIndex calib_njtr_indices_loc[1024]; |
| 46 |
calib_njtr_indices_loc[threadIdx.x] = |
| 47 |
(global_thread_idx < problem_size |
| 48 |
? calib_njtr_indices[global_thread_idx] |
| 49 |
: SharedIndex{0xffffffff, 0xffff, 0xffff}); |
| 50 |
|
| 51 |
__shared__ SharedIndex point_njtr_indices_loc[1024]; |
| 52 |
point_njtr_indices_loc[threadIdx.x] = |
| 53 |
(global_thread_idx < problem_size |
| 54 |
? point_njtr_indices[global_thread_idx] |
| 55 |
: SharedIndex{0xffffffff, 0xffff, 0xffff}); |
| 56 |
|
| 57 |
float r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, |
| 58 |
r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, r26, r27, r28, r29, r30; |
| 59 |
|
| 60 |
if (global_thread_idx < problem_size) { |
| 61 |
ReadIdx4<1024, float, float, float4>( |
| 62 |
pose_jac, 0 * pose_jac_num_alloc, global_thread_idx, r0, r1, r2, r3); |
| 63 |
}; |
| 64 |
LoadShared<4, float, float>(calib_njtr, |
| 65 |
0 * calib_njtr_num_alloc, |
| 66 |
calib_njtr_indices_loc, |
| 67 |
(float*)inout_shared); |
| 68 |
if (global_thread_idx < problem_size) { |
| 69 |
ReadShared4<float>((float*)inout_shared, |
| 70 |
calib_njtr_indices_loc[threadIdx.x].target, |
| 71 |
r4, |
| 72 |
r5, |
| 73 |
r6, |
| 74 |
r7); |
| 75 |
}; |
| 76 |
__syncthreads(); |
| 77 |
if (global_thread_idx < problem_size) { |
| 78 |
ReadIdx4<1024, float, float, float4>(calib_jac, |
| 79 |
0 * calib_jac_num_alloc, |
| 80 |
global_thread_idx, |
| 81 |
r8, |
| 82 |
r9, |
| 83 |
r10, |
| 84 |
r11); |
| 85 |
r6 = fmaf(r4, r8, r6); |
| 86 |
r6 = fmaf(r5, r10, r6); |
| 87 |
}; |
| 88 |
LoadShared<3, float, float>(point_njtr, |
| 89 |
0 * point_njtr_num_alloc, |
| 90 |
point_njtr_indices_loc, |
| 91 |
(float*)inout_shared); |
| 92 |
if (global_thread_idx < problem_size) { |
| 93 |
ReadShared3<float>((float*)inout_shared, |
| 94 |
point_njtr_indices_loc[threadIdx.x].target, |
| 95 |
r12, |
| 96 |
r13, |
| 97 |
r14); |
| 98 |
}; |
| 99 |
__syncthreads(); |
| 100 |
if (global_thread_idx < problem_size) { |
| 101 |
ReadIdx2<1024, float, float, float2>( |
| 102 |
point_jac, 4 * point_jac_num_alloc, global_thread_idx, r15, r16); |
| 103 |
ReadIdx4<1024, float, float, float4>(point_jac, |
| 104 |
0 * point_jac_num_alloc, |
| 105 |
global_thread_idx, |
| 106 |
r17, |
| 107 |
r18, |
| 108 |
r19, |
| 109 |
r20); |
| 110 |
r21 = fmaf(r13, r19, r14 * r15); |
| 111 |
r21 = fmaf(r12, r17, r21); |
| 112 |
r22 = r6 + r21; |
| 113 |
r4 = fmaf(r4, r9, r7); |
| 114 |
r4 = fmaf(r5, r11, r4); |
| 115 |
r13 = fmaf(r13, r20, r14 * r16); |
| 116 |
r13 = fmaf(r12, r18, r13); |
| 117 |
r12 = r4 + r13; |
| 118 |
r14 = fmaf(r1, r12, r0 * r22); |
| 119 |
r5 = fmaf(r3, r12, r2 * r22); |
| 120 |
ReadIdx4<1024, float, float, float4>( |
| 121 |
pose_jac, 4 * pose_jac_num_alloc, global_thread_idx, r7, r23, r24, r25); |
| 122 |
r26 = fmaf(r23, r12, r7 * r22); |
| 123 |
r27 = fmaf(r25, r12, r24 * r22); |
| 124 |
WriteSum4<float, float>((float*)inout_shared, r14, r5, r26, r27); |
| 125 |
}; |
| 126 |
FlushSumShared<4, float>(out_pose_njtr, |
| 127 |
0 * out_pose_njtr_num_alloc, |
| 128 |
pose_njtr_indices_loc, |
| 129 |
(float*)inout_shared); |
| 130 |
if (global_thread_idx < problem_size) { |
| 131 |
ReadIdx4<1024, float, float, float4>( |
| 132 |
pose_jac, 8 * pose_jac_num_alloc, global_thread_idx, r27, r26, r5, r14); |
| 133 |
r28 = fmaf(r26, r12, r27 * r22); |
| 134 |
r22 = fmaf(r5, r22, r14 * r12); |
| 135 |
WriteSum2<float, float>((float*)inout_shared, r28, r22); |
| 136 |
}; |
| 137 |
FlushSumShared<2, float>(out_pose_njtr, |
| 138 |
4 * out_pose_njtr_num_alloc, |
| 139 |
pose_njtr_indices_loc, |
| 140 |
(float*)inout_shared); |
| 141 |
LoadShared<2, float, float>(pose_njtr, |
| 142 |
4 * pose_njtr_num_alloc, |
| 143 |
pose_njtr_indices_loc, |
| 144 |
(float*)inout_shared); |
| 145 |
if (global_thread_idx < problem_size) { |
| 146 |
ReadShared2<float>((float*)inout_shared, |
| 147 |
pose_njtr_indices_loc[threadIdx.x].target, |
| 148 |
r22, |
| 149 |
r28); |
| 150 |
}; |
| 151 |
__syncthreads(); |
| 152 |
if (global_thread_idx < problem_size) { |
| 153 |
r27 = fmaf(r22, r27, r28 * r5); |
| 154 |
}; |
| 155 |
LoadShared<4, float, float>(pose_njtr, |
| 156 |
0 * pose_njtr_num_alloc, |
| 157 |
pose_njtr_indices_loc, |
| 158 |
(float*)inout_shared); |
| 159 |
if (global_thread_idx < problem_size) { |
| 160 |
ReadShared4<float>((float*)inout_shared, |
| 161 |
pose_njtr_indices_loc[threadIdx.x].target, |
| 162 |
r5, |
| 163 |
r12, |
| 164 |
r29, |
| 165 |
r30); |
| 166 |
}; |
| 167 |
__syncthreads(); |
| 168 |
if (global_thread_idx < problem_size) { |
| 169 |
r27 = fmaf(r29, r7, r27); |
| 170 |
r27 = fmaf(r30, r24, r27); |
| 171 |
r27 = fmaf(r5, r0, r27); |
| 172 |
r27 = fmaf(r12, r2, r27); |
| 173 |
r21 = r27 + r21; |
| 174 |
r25 = fmaf(r30, r25, r28 * r14); |
| 175 |
r25 = fmaf(r29, r23, r25); |
| 176 |
r25 = fmaf(r5, r1, r25); |
| 177 |
r25 = fmaf(r12, r3, r25); |
| 178 |
r25 = fmaf(r22, r26, r25); |
| 179 |
r13 = r25 + r13; |
| 180 |
r9 = fmaf(r9, r13, r8 * r21); |
| 181 |
r11 = fmaf(r11, r13, r10 * r21); |
| 182 |
WriteSum4<float, float>((float*)inout_shared, r9, r11, r21, r13); |
| 183 |
}; |
| 184 |
FlushSumShared<4, float>(out_calib_njtr, |
| 185 |
0 * out_calib_njtr_num_alloc, |
| 186 |
calib_njtr_indices_loc, |
| 187 |
(float*)inout_shared); |
| 188 |
if (global_thread_idx < problem_size) { |
| 189 |
r6 = r27 + r6; |
| 190 |
r4 = r25 + r4; |
| 191 |
r18 = fmaf(r18, r4, r17 * r6); |
| 192 |
r20 = fmaf(r20, r4, r19 * r6); |
| 193 |
r4 = fmaf(r16, r4, r15 * r6); |
| 194 |
WriteSum3<float, float>((float*)inout_shared, r18, r20, r4); |
| 195 |
}; |
| 196 |
FlushSumShared<3, float>(out_point_njtr, |
| 197 |
0 * out_point_njtr_num_alloc, |
| 198 |
point_njtr_indices_loc, |
| 199 |
(float*)inout_shared); |
| 200 |
} |
| 201 |
|
| 202 |
void SimpleRadialJtjnjtrDirect(float* pose_njtr, |
| 203 |
unsigned int pose_njtr_num_alloc, |
| 204 |
SharedIndex* pose_njtr_indices, |
| 205 |
float* pose_jac, |
| 206 |
unsigned int pose_jac_num_alloc, |
| 207 |
float* calib_njtr, |
| 208 |
unsigned int calib_njtr_num_alloc, |
| 209 |
SharedIndex* calib_njtr_indices, |
| 210 |
float* calib_jac, |
| 211 |
unsigned int calib_jac_num_alloc, |
| 212 |
float* point_njtr, |
| 213 |
unsigned int point_njtr_num_alloc, |
| 214 |
SharedIndex* point_njtr_indices, |
| 215 |
float* point_jac, |
| 216 |
unsigned int point_jac_num_alloc, |
| 217 |
float* const out_pose_njtr, |
| 218 |
unsigned int out_pose_njtr_num_alloc, |
| 219 |
float* const out_calib_njtr, |
| 220 |
unsigned int out_calib_njtr_num_alloc, |
| 221 |
float* const out_point_njtr, |
| 222 |
unsigned int out_point_njtr_num_alloc, |
| 223 |
size_t problem_size) { |
| 224 |
if (problem_size == 0) { |
| 225 |
return; |
| 226 |
} |
| 227 |
|
| 228 |
const int n_blocks = (problem_size + 1024 - 1) / 1024; |
| 229 |
SimpleRadialJtjnjtrDirectKernel<<<n_blocks, 1024>>>(pose_njtr, |
| 230 |
pose_njtr_num_alloc, |
| 231 |
pose_njtr_indices, |
| 232 |
pose_jac, |
| 233 |
pose_jac_num_alloc, |
| 234 |
calib_njtr, |
| 235 |
calib_njtr_num_alloc, |
| 236 |
calib_njtr_indices, |
| 237 |
calib_jac, |
| 238 |
calib_jac_num_alloc, |
| 239 |
point_njtr, |
| 240 |
point_njtr_num_alloc, |
| 241 |
point_njtr_indices, |
| 242 |
point_jac, |
| 243 |
point_jac_num_alloc, |
| 244 |
out_pose_njtr, |
| 245 |
out_pose_njtr_num_alloc, |
| 246 |
out_calib_njtr, |
| 247 |
out_calib_njtr_num_alloc, |
| 248 |
out_point_njtr, |
| 249 |
out_point_njtr_num_alloc, |
| 250 |
problem_size); |
| 251 |
} |
| 252 |
|
| 253 |
} // namespace caspar |