| 1 |
#include "kernel_pinhole_fixed_point_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 |
PinholeFixedPointJtjnjtrDirectKernel(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* const out_pose_njtr, |
| 25 |
unsigned int out_pose_njtr_num_alloc, |
| 26 |
float* const out_calib_njtr, |
| 27 |
unsigned int out_calib_njtr_num_alloc, |
| 28 |
size_t problem_size) { |
| 29 |
const int global_thread_idx = blockIdx.x * blockDim.x + threadIdx.x; |
| 30 |
__shared__ uint8_t inout_shared[16384]; |
| 31 |
|
| 32 |
__shared__ SharedIndex pose_njtr_indices_loc[1024]; |
| 33 |
pose_njtr_indices_loc[threadIdx.x] = |
| 34 |
(global_thread_idx < problem_size |
| 35 |
? pose_njtr_indices[global_thread_idx] |
| 36 |
: SharedIndex{0xffffffff, 0xffff, 0xffff}); |
| 37 |
|
| 38 |
__shared__ SharedIndex calib_njtr_indices_loc[1024]; |
| 39 |
calib_njtr_indices_loc[threadIdx.x] = |
| 40 |
(global_thread_idx < problem_size |
| 41 |
? calib_njtr_indices[global_thread_idx] |
| 42 |
: SharedIndex{0xffffffff, 0xffff, 0xffff}); |
| 43 |
|
| 44 |
float r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11, r12, r13, r14, r15, |
| 45 |
r16, r17, r18; |
| 46 |
|
| 47 |
if (global_thread_idx < problem_size) { |
| 48 |
ReadIdx4<1024, float, float, float4>( |
| 49 |
pose_jac, 0 * pose_jac_num_alloc, global_thread_idx, r0, r1, r2, r3); |
| 50 |
}; |
| 51 |
LoadShared<4, float, float>(calib_njtr, |
| 52 |
0 * calib_njtr_num_alloc, |
| 53 |
calib_njtr_indices_loc, |
| 54 |
(float*)inout_shared); |
| 55 |
if (global_thread_idx < problem_size) { |
| 56 |
ReadShared4<float>((float*)inout_shared, |
| 57 |
calib_njtr_indices_loc[threadIdx.x].target, |
| 58 |
r4, |
| 59 |
r5, |
| 60 |
r6, |
| 61 |
r7); |
| 62 |
}; |
| 63 |
__syncthreads(); |
| 64 |
if (global_thread_idx < problem_size) { |
| 65 |
ReadIdx2<1024, float, float, float2>( |
| 66 |
calib_jac, 0 * calib_jac_num_alloc, global_thread_idx, r8, r9); |
| 67 |
r4 = fmaf(r4, r8, r6); |
| 68 |
r5 = fmaf(r5, r9, r7); |
| 69 |
r7 = fmaf(r1, r5, r0 * r4); |
| 70 |
r6 = fmaf(r3, r5, r2 * r4); |
| 71 |
ReadIdx4<1024, float, float, float4>(pose_jac, |
| 72 |
4 * pose_jac_num_alloc, |
| 73 |
global_thread_idx, |
| 74 |
r10, |
| 75 |
r11, |
| 76 |
r12, |
| 77 |
r13); |
| 78 |
r14 = fmaf(r11, r5, r10 * r4); |
| 79 |
r15 = fmaf(r13, r5, r12 * r4); |
| 80 |
WriteSum4<float, float>((float*)inout_shared, r7, r6, r14, r15); |
| 81 |
}; |
| 82 |
FlushSumShared<4, float>(out_pose_njtr, |
| 83 |
0 * out_pose_njtr_num_alloc, |
| 84 |
pose_njtr_indices_loc, |
| 85 |
(float*)inout_shared); |
| 86 |
if (global_thread_idx < problem_size) { |
| 87 |
ReadIdx4<1024, float, float, float4>( |
| 88 |
pose_jac, 8 * pose_jac_num_alloc, global_thread_idx, r15, r14, r6, r7); |
| 89 |
r16 = fmaf(r14, r5, r15 * r4); |
| 90 |
r4 = fmaf(r6, r4, r7 * r5); |
| 91 |
WriteSum2<float, float>((float*)inout_shared, r16, r4); |
| 92 |
}; |
| 93 |
FlushSumShared<2, float>(out_pose_njtr, |
| 94 |
4 * out_pose_njtr_num_alloc, |
| 95 |
pose_njtr_indices_loc, |
| 96 |
(float*)inout_shared); |
| 97 |
LoadShared<2, float, float>(pose_njtr, |
| 98 |
4 * pose_njtr_num_alloc, |
| 99 |
pose_njtr_indices_loc, |
| 100 |
(float*)inout_shared); |
| 101 |
if (global_thread_idx < problem_size) { |
| 102 |
ReadShared2<float>((float*)inout_shared, |
| 103 |
pose_njtr_indices_loc[threadIdx.x].target, |
| 104 |
r4, |
| 105 |
r16); |
| 106 |
}; |
| 107 |
__syncthreads(); |
| 108 |
if (global_thread_idx < problem_size) { |
| 109 |
r15 = fmaf(r4, r15, r16 * r6); |
| 110 |
}; |
| 111 |
LoadShared<4, float, float>(pose_njtr, |
| 112 |
0 * pose_njtr_num_alloc, |
| 113 |
pose_njtr_indices_loc, |
| 114 |
(float*)inout_shared); |
| 115 |
if (global_thread_idx < problem_size) { |
| 116 |
ReadShared4<float>((float*)inout_shared, |
| 117 |
pose_njtr_indices_loc[threadIdx.x].target, |
| 118 |
r6, |
| 119 |
r5, |
| 120 |
r17, |
| 121 |
r18); |
| 122 |
}; |
| 123 |
__syncthreads(); |
| 124 |
if (global_thread_idx < problem_size) { |
| 125 |
r15 = fmaf(r17, r10, r15); |
| 126 |
r15 = fmaf(r18, r12, r15); |
| 127 |
r15 = fmaf(r6, r0, r15); |
| 128 |
r15 = fmaf(r5, r2, r15); |
| 129 |
r8 = r8 * r15; |
| 130 |
r13 = fmaf(r18, r13, r16 * r7); |
| 131 |
r13 = fmaf(r17, r11, r13); |
| 132 |
r13 = fmaf(r6, r1, r13); |
| 133 |
r13 = fmaf(r5, r3, r13); |
| 134 |
r13 = fmaf(r4, r14, r13); |
| 135 |
r9 = r9 * r13; |
| 136 |
WriteSum4<float, float>((float*)inout_shared, r8, r9, r15, r13); |
| 137 |
}; |
| 138 |
FlushSumShared<4, float>(out_calib_njtr, |
| 139 |
0 * out_calib_njtr_num_alloc, |
| 140 |
calib_njtr_indices_loc, |
| 141 |
(float*)inout_shared); |
| 142 |
} |
| 143 |
|
| 144 |
void PinholeFixedPointJtjnjtrDirect(float* pose_njtr, |
| 145 |
unsigned int pose_njtr_num_alloc, |
| 146 |
SharedIndex* pose_njtr_indices, |
| 147 |
float* pose_jac, |
| 148 |
unsigned int pose_jac_num_alloc, |
| 149 |
float* calib_njtr, |
| 150 |
unsigned int calib_njtr_num_alloc, |
| 151 |
SharedIndex* calib_njtr_indices, |
| 152 |
float* calib_jac, |
| 153 |
unsigned int calib_jac_num_alloc, |
| 154 |
float* const out_pose_njtr, |
| 155 |
unsigned int out_pose_njtr_num_alloc, |
| 156 |
float* const out_calib_njtr, |
| 157 |
unsigned int out_calib_njtr_num_alloc, |
| 158 |
size_t problem_size) { |
| 159 |
if (problem_size == 0) { |
| 160 |
return; |
| 161 |
} |
| 162 |
|
| 163 |
const int n_blocks = (problem_size + 1024 - 1) / 1024; |
| 164 |
PinholeFixedPointJtjnjtrDirectKernel<<<n_blocks, 1024>>>( |
| 165 |
pose_njtr, |
| 166 |
pose_njtr_num_alloc, |
| 167 |
pose_njtr_indices, |
| 168 |
pose_jac, |
| 169 |
pose_jac_num_alloc, |
| 170 |
calib_njtr, |
| 171 |
calib_njtr_num_alloc, |
| 172 |
calib_njtr_indices, |
| 173 |
calib_jac, |
| 174 |
calib_jac_num_alloc, |
| 175 |
out_pose_njtr, |
| 176 |
out_pose_njtr_num_alloc, |
| 177 |
out_calib_njtr, |
| 178 |
out_calib_njtr_num_alloc, |
| 179 |
problem_size); |
| 180 |
} |
| 181 |
|
| 182 |
} // namespace caspar |