| 1 |
#include "kernel_Point_update_r.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 |
PointUpdateRKernel(float* Point_r_k, |
| 15 |
unsigned int Point_r_k_num_alloc, |
| 16 |
float* Point_w, |
| 17 |
unsigned int Point_w_num_alloc, |
| 18 |
const float* const negalpha, |
| 19 |
float* out_Point_r_kp1, |
| 20 |
unsigned int out_Point_r_kp1_num_alloc, |
| 21 |
float* const out_Point_r_kp1_norm2_tot, |
| 22 |
size_t problem_size) { |
| 23 |
const int global_thread_idx = blockIdx.x * blockDim.x + threadIdx.x; |
| 24 |
__shared__ uint8_t inout_shared[4096]; |
| 25 |
|
| 26 |
__shared__ float out_Point_r_kp1_norm2_tot_local[1]; |
| 27 |
|
| 28 |
float r0, r1, r2, r3, r4, r5, r6; |
| 29 |
|
| 30 |
if (global_thread_idx < problem_size) { |
| 31 |
ReadIdx3<1024, float, float, float4>( |
| 32 |
Point_r_k, 0 * Point_r_k_num_alloc, global_thread_idx, r0, r1, r2); |
| 33 |
ReadIdx3<1024, float, float, float4>( |
| 34 |
Point_w, 0 * Point_w_num_alloc, global_thread_idx, r3, r4, r5); |
| 35 |
}; |
| 36 |
LoadUnique<1, float, float>(negalpha, 0, (float*)inout_shared); |
| 37 |
if (global_thread_idx < problem_size) { |
| 38 |
ReadShared1<float>((float*)inout_shared, 0, r6); |
| 39 |
}; |
| 40 |
__syncthreads(); |
| 41 |
if (global_thread_idx < problem_size) { |
| 42 |
r3 = fmaf(r3, r6, r0); |
| 43 |
r4 = fmaf(r4, r6, r1); |
| 44 |
r6 = fmaf(r5, r6, r2); |
| 45 |
WriteIdx3<1024, float, float, float4>(out_Point_r_kp1, |
| 46 |
0 * out_Point_r_kp1_num_alloc, |
| 47 |
global_thread_idx, |
| 48 |
r3, |
| 49 |
r4, |
| 50 |
r6); |
| 51 |
r3 = fmaf(r3, r3, r6 * r6); |
| 52 |
r3 = fmaf(r4, r4, r3); |
| 53 |
}; |
| 54 |
SumStore<float>(out_Point_r_kp1_norm2_tot_local, |
| 55 |
(float*)inout_shared, |
| 56 |
0, |
| 57 |
global_thread_idx < problem_size, |
| 58 |
r3); |
| 59 |
SumFlushFinal<float>( |
| 60 |
out_Point_r_kp1_norm2_tot_local, out_Point_r_kp1_norm2_tot, 1); |
| 61 |
} |
| 62 |
|
| 63 |
void PointUpdateR(float* Point_r_k, |
| 64 |
unsigned int Point_r_k_num_alloc, |
| 65 |
float* Point_w, |
| 66 |
unsigned int Point_w_num_alloc, |
| 67 |
const float* const negalpha, |
| 68 |
float* out_Point_r_kp1, |
| 69 |
unsigned int out_Point_r_kp1_num_alloc, |
| 70 |
float* const out_Point_r_kp1_norm2_tot, |
| 71 |
size_t problem_size) { |
| 72 |
if (problem_size == 0) { |
| 73 |
return; |
| 74 |
} |
| 75 |
|
| 76 |
const int n_blocks = (problem_size + 1024 - 1) / 1024; |
| 77 |
PointUpdateRKernel<<<n_blocks, 1024>>>(Point_r_k, |
| 78 |
Point_r_k_num_alloc, |
| 79 |
Point_w, |
| 80 |
Point_w_num_alloc, |
| 81 |
negalpha, |
| 82 |
out_Point_r_kp1, |
| 83 |
out_Point_r_kp1_num_alloc, |
| 84 |
out_Point_r_kp1_norm2_tot, |
| 85 |
problem_size); |
| 86 |
} |
| 87 |
|
| 88 |
} // namespace caspar |