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