| 1 |
#include "kernel_pinhole_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 |
PinholeJtjnjtrDirectKernel(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; |
| 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<3, float, float>(point_njtr, |
| 65 |
0 * point_njtr_num_alloc, |
| 66 |
point_njtr_indices_loc, |
| 67 |
(float*)inout_shared); |
| 68 |
if (global_thread_idx < problem_size) { |
| 69 |
ReadShared3<float>((float*)inout_shared, |
| 70 |
point_njtr_indices_loc[threadIdx.x].target, |
| 71 |
r4, |
| 72 |
r5, |
| 73 |
r6); |
| 74 |
}; |
| 75 |
__syncthreads(); |
| 76 |
if (global_thread_idx < problem_size) { |
| 77 |
ReadIdx2<1024, float, float, float2>( |
| 78 |
point_jac, 4 * point_jac_num_alloc, global_thread_idx, r7, r8); |
| 79 |
ReadIdx4<1024, float, float, float4>(point_jac, |
| 80 |
0 * point_jac_num_alloc, |
| 81 |
global_thread_idx, |
| 82 |
r9, |
| 83 |
r10, |
| 84 |
r11, |
| 85 |
r12); |
| 86 |
r13 = fmaf(r5, r11, r6 * r7); |
| 87 |
r13 = fmaf(r4, r9, r13); |
| 88 |
}; |
| 89 |
LoadShared<4, float, float>(calib_njtr, |
| 90 |
0 * calib_njtr_num_alloc, |
| 91 |
calib_njtr_indices_loc, |
| 92 |
(float*)inout_shared); |
| 93 |
if (global_thread_idx < problem_size) { |
| 94 |
ReadShared4<float>((float*)inout_shared, |
| 95 |
calib_njtr_indices_loc[threadIdx.x].target, |
| 96 |
r14, |
| 97 |
r15, |
| 98 |
r16, |
| 99 |
r17); |
| 100 |
}; |
| 101 |
__syncthreads(); |
| 102 |
if (global_thread_idx < problem_size) { |
| 103 |
ReadIdx2<1024, float, float, float2>( |
| 104 |
calib_jac, 0 * calib_jac_num_alloc, global_thread_idx, r18, r19); |
| 105 |
r14 = fmaf(r14, r18, r16); |
| 106 |
r16 = r13 + r14; |
| 107 |
r5 = fmaf(r5, r12, r6 * r8); |
| 108 |
r5 = fmaf(r4, r10, r5); |
| 109 |
r15 = fmaf(r15, r19, r17); |
| 110 |
r17 = r5 + r15; |
| 111 |
r4 = fmaf(r1, r17, r0 * r16); |
| 112 |
r6 = fmaf(r3, r17, r2 * r16); |
| 113 |
ReadIdx4<1024, float, float, float4>(pose_jac, |
| 114 |
4 * pose_jac_num_alloc, |
| 115 |
global_thread_idx, |
| 116 |
r20, |
| 117 |
r21, |
| 118 |
r22, |
| 119 |
r23); |
| 120 |
r24 = fmaf(r21, r17, r20 * r16); |
| 121 |
r25 = fmaf(r23, r17, r22 * r16); |
| 122 |
WriteSum4<float, float>((float*)inout_shared, r4, r6, r24, r25); |
| 123 |
}; |
| 124 |
FlushSumShared<4, float>(out_pose_njtr, |
| 125 |
0 * out_pose_njtr_num_alloc, |
| 126 |
pose_njtr_indices_loc, |
| 127 |
(float*)inout_shared); |
| 128 |
if (global_thread_idx < problem_size) { |
| 129 |
ReadIdx4<1024, float, float, float4>( |
| 130 |
pose_jac, 8 * pose_jac_num_alloc, global_thread_idx, r25, r24, r6, r4); |
| 131 |
r26 = fmaf(r24, r17, r25 * r16); |
| 132 |
r16 = fmaf(r6, r16, r4 * r17); |
| 133 |
WriteSum2<float, float>((float*)inout_shared, r26, r16); |
| 134 |
}; |
| 135 |
FlushSumShared<2, float>(out_pose_njtr, |
| 136 |
4 * out_pose_njtr_num_alloc, |
| 137 |
pose_njtr_indices_loc, |
| 138 |
(float*)inout_shared); |
| 139 |
LoadShared<2, float, float>(pose_njtr, |
| 140 |
4 * pose_njtr_num_alloc, |
| 141 |
pose_njtr_indices_loc, |
| 142 |
(float*)inout_shared); |
| 143 |
if (global_thread_idx < problem_size) { |
| 144 |
ReadShared2<float>((float*)inout_shared, |
| 145 |
pose_njtr_indices_loc[threadIdx.x].target, |
| 146 |
r16, |
| 147 |
r26); |
| 148 |
}; |
| 149 |
__syncthreads(); |
| 150 |
if (global_thread_idx < problem_size) { |
| 151 |
r25 = fmaf(r16, r25, r26 * r6); |
| 152 |
}; |
| 153 |
LoadShared<4, float, float>(pose_njtr, |
| 154 |
0 * pose_njtr_num_alloc, |
| 155 |
pose_njtr_indices_loc, |
| 156 |
(float*)inout_shared); |
| 157 |
if (global_thread_idx < problem_size) { |
| 158 |
ReadShared4<float>((float*)inout_shared, |
| 159 |
pose_njtr_indices_loc[threadIdx.x].target, |
| 160 |
r6, |
| 161 |
r17, |
| 162 |
r27, |
| 163 |
r28); |
| 164 |
}; |
| 165 |
__syncthreads(); |
| 166 |
if (global_thread_idx < problem_size) { |
| 167 |
r25 = fmaf(r27, r20, r25); |
| 168 |
r25 = fmaf(r28, r22, r25); |
| 169 |
r25 = fmaf(r6, r0, r25); |
| 170 |
r25 = fmaf(r17, r2, r25); |
| 171 |
r13 = r25 + r13; |
| 172 |
r18 = r18 * r13; |
| 173 |
r23 = fmaf(r28, r23, r26 * r4); |
| 174 |
r23 = fmaf(r27, r21, r23); |
| 175 |
r23 = fmaf(r6, r1, r23); |
| 176 |
r23 = fmaf(r17, r3, r23); |
| 177 |
r23 = fmaf(r16, r24, r23); |
| 178 |
r5 = r23 + r5; |
| 179 |
r19 = r19 * r5; |
| 180 |
WriteSum4<float, float>((float*)inout_shared, r18, r19, r13, r5); |
| 181 |
}; |
| 182 |
FlushSumShared<4, float>(out_calib_njtr, |
| 183 |
0 * out_calib_njtr_num_alloc, |
| 184 |
calib_njtr_indices_loc, |
| 185 |
(float*)inout_shared); |
| 186 |
if (global_thread_idx < problem_size) { |
| 187 |
r14 = r25 + r14; |
| 188 |
r15 = r23 + r15; |
| 189 |
r10 = fmaf(r10, r15, r9 * r14); |
| 190 |
r12 = fmaf(r12, r15, r11 * r14); |
| 191 |
r15 = fmaf(r8, r15, r7 * r14); |
| 192 |
WriteSum3<float, float>((float*)inout_shared, r10, r12, r15); |
| 193 |
}; |
| 194 |
FlushSumShared<3, float>(out_point_njtr, |
| 195 |
0 * out_point_njtr_num_alloc, |
| 196 |
point_njtr_indices_loc, |
| 197 |
(float*)inout_shared); |
| 198 |
} |
| 199 |
|
| 200 |
void PinholeJtjnjtrDirect(float* pose_njtr, |
| 201 |
unsigned int pose_njtr_num_alloc, |
| 202 |
SharedIndex* pose_njtr_indices, |
| 203 |
float* pose_jac, |
| 204 |
unsigned int pose_jac_num_alloc, |
| 205 |
float* calib_njtr, |
| 206 |
unsigned int calib_njtr_num_alloc, |
| 207 |
SharedIndex* calib_njtr_indices, |
| 208 |
float* calib_jac, |
| 209 |
unsigned int calib_jac_num_alloc, |
| 210 |
float* point_njtr, |
| 211 |
unsigned int point_njtr_num_alloc, |
| 212 |
SharedIndex* point_njtr_indices, |
| 213 |
float* point_jac, |
| 214 |
unsigned int point_jac_num_alloc, |
| 215 |
float* const out_pose_njtr, |
| 216 |
unsigned int out_pose_njtr_num_alloc, |
| 217 |
float* const out_calib_njtr, |
| 218 |
unsigned int out_calib_njtr_num_alloc, |
| 219 |
float* const out_point_njtr, |
| 220 |
unsigned int out_point_njtr_num_alloc, |
| 221 |
size_t problem_size) { |
| 222 |
if (problem_size == 0) { |
| 223 |
return; |
| 224 |
} |
| 225 |
|
| 226 |
const int n_blocks = (problem_size + 1024 - 1) / 1024; |
| 227 |
PinholeJtjnjtrDirectKernel<<<n_blocks, 1024>>>(pose_njtr, |
| 228 |
pose_njtr_num_alloc, |
| 229 |
pose_njtr_indices, |
| 230 |
pose_jac, |
| 231 |
pose_jac_num_alloc, |
| 232 |
calib_njtr, |
| 233 |
calib_njtr_num_alloc, |
| 234 |
calib_njtr_indices, |
| 235 |
calib_jac, |
| 236 |
calib_jac_num_alloc, |
| 237 |
point_njtr, |
| 238 |
point_njtr_num_alloc, |
| 239 |
point_njtr_indices, |
| 240 |
point_jac, |
| 241 |
point_jac_num_alloc, |
| 242 |
out_pose_njtr, |
| 243 |
out_pose_njtr_num_alloc, |
| 244 |
out_calib_njtr, |
| 245 |
out_calib_njtr_num_alloc, |
| 246 |
out_point_njtr, |
| 247 |
out_point_njtr_num_alloc, |
| 248 |
problem_size); |
| 249 |
} |
| 250 |
|
| 251 |
} // namespace caspar |