fix regressions in cuda ldpc

This commit is contained in:
laurent
2023-11-28 09:37:37 +01:00
committed by Raymond Knopp
parent 697a7871d0
commit 10d7fe9cc6
@@ -31,10 +31,10 @@
#include "bgs/BG2_I5" #include "bgs/BG2_I5"
#include "bgs/BG2_I6" #include "bgs/BG2_I6"
#include "bgs/BG2_I7" #include "bgs/BG2_I7"
#define MAX_ITERATION 2 #define MAX_ITERATION 2
#define MC 1 #define MC 1
typedef void decode_abort_t;
#define cudaCheck(ans) { cudaAssert((ans), __FILE__, __LINE__); } #define cudaCheck(ans) { cudaAssert((ans), __FILE__, __LINE__); }
inline void cudaAssert(cudaError_t code, const char *file, int line) inline void cudaAssert(cudaError_t code, const char *file, int line)
{ {
@@ -66,34 +66,16 @@ __device__ h_element dev_h_compact2[68*30]; // used in kernel 2
// __device__ __constant__ h_element dev_h_compact2[68*30]; // used in kernel 2 // __device__ __constant__ h_element dev_h_compact2[68*30]; // used in kernel 2
// row and col element count // row and col element count
__device__ __constant__ char h_ele_row_bg1_count[46] = { __device__ __constant__ char h_ele_row_bg1_count[46] = {19, 19, 19, 19, 3, 8, 9, 7, 10, 9, 7, 8, 7, 6, 7, 7, 6, 6, 6, 6, 6, 6, 5,
19, 19, 19, 19, 3, 8, 9, 7, 10, 9, 5, 6, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 4, 5, 5, 4, 5, 4, 5, 5, 4};
7, 8, 7, 6, 7, 7, 6, 6, 6, 6,
6, 6, 5, 5, 6, 5, 5, 4, 5, 5,
5, 5, 5, 5, 5, 5, 5, 4, 5, 5,
4, 5, 4, 5, 5, 4};
__device__ __constant__ char h_ele_col_bg1_count[68] = { __device__ __constant__ char h_ele_col_bg1_count[68] = {
30, 28, 7, 11, 9, 4, 8, 12, 8, 7, 30, 28, 7, 11, 9, 4, 8, 12, 8, 7, 12, 10, 12, 11, 10, 7, 10, 10, 13, 7, 8, 11, 12, 5, 6, 6, 1, 1, 1, 1, 1, 1, 1, 1,
12, 10, 12, 11, 10, 7, 10, 10, 13, 7, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
8, 11, 12, 5, 6, 6, 1, 1, 1, 1, __device__ __constant__ char h_ele_row_bg2_count[42] = {8, 10, 8, 10, 4, 6, 6, 6, 4, 5, 5, 5, 4, 5, 5, 4, 5, 5, 4, 4, 4,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 3, 4, 4, 3, 5, 3, 4, 3, 5, 3, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4};
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, __device__ __constant__ char h_ele_col_bg2_count[52] = {22, 23, 10, 5, 5, 14, 7, 13, 6, 8, 9, 16, 9, 12, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1}; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
__device__ __constant__ char h_ele_row_bg2_count[42] = {
8, 10, 8, 10, 4, 6, 6, 6, 4, 5,
5, 5, 4, 5, 5, 4, 5, 5, 4, 4,
4, 4, 3, 4, 4, 3, 5, 3, 4, 3,
5, 3, 4, 4, 4, 4, 4, 3, 4, 4,
4, 4};
__device__ __constant__ char h_ele_col_bg2_count[52] = {
22, 23, 10, 5, 5, 14, 7, 13, 6, 8,
9, 16, 9, 12, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1};
__global__ void warmup() __global__ void warmup()
{ {
@@ -102,31 +84,28 @@ __global__ void warmup()
extern "C" extern "C"
void warmup_for_GPU(){ void warmup_for_GPU(){
warmup<<<20, 1024>>>(); warmup<<<20, 1024>>>();
} }
extern "C" extern "C"
void set_compact_BG(int Zc,short BG){ void set_compact_BG(int Zc,short BG){
int row, col; int row, col;
if (BG == 1) { if (BG == 1) {
row = 46; row = 46;
col = 68; col = 68;
} } else {
else{
row = 42; row = 42;
col = 52; col = 52;
} }
int compact_row = 30; int compact_row = 30;
int compact_col = 19; int compact_col = 19;
if(BG==2){compact_row = 10, compact_col = 23;} if (BG == 2) {
compact_row = 10, compact_col = 23;
}
int memorySize_h_compact1 = row * compact_col * sizeof(h_element); int memorySize_h_compact1 = row * compact_col * sizeof(h_element);
int memorySize_h_compact2 = compact_row * col * sizeof(h_element); int memorySize_h_compact2 = compact_row * col * sizeof(h_element);
int lift_index = 0; int lift_index = 0;
short lift_set[][9] = { short lift_set[][9] = {{2, 4, 8, 16, 32, 64, 128, 256},
{2,4,8,16,32,64,128,256},
{3, 6, 12, 24, 48, 96, 192, 384}, {3, 6, 12, 24, 48, 96, 192, 384},
{5, 10, 20, 40, 80, 160, 320}, {5, 10, 20, 40, 80, 160, 320},
{7, 14, 28, 56, 112, 224}, {7, 14, 28, 56, 112, 224},
@@ -134,8 +113,7 @@ void set_compact_BG(int Zc,short BG){
{11, 22, 44, 88, 176, 352}, {11, 22, 44, 88, 176, 352},
{13, 26, 52, 104, 208}, {13, 26, 52, 104, 208},
{15, 30, 60, 120, 240}, {15, 30, 60, 120, 240},
{0} {0}};
};
for (int i = 0; lift_set[i][0] != 0; i++) { for (int i = 0; lift_set[i][0] != 0; i++) {
for (int j = 0; lift_set[i][j] != 0; j++) { for (int j = 0; lift_set[i][j] != 0; j++) {
@@ -307,7 +285,6 @@ __global__ void ldpc_cnp_kernel(/*char * dev_llr, char * dev_dt,*/ int BG, int r
} else if (Q_abs < rmin2) { } else if (Q_abs < rmin2) {
rmin2 = Q_abs; rmin2 = Q_abs;
} }
} }
// if(blockIdx.x == 0 && threadIdx.x == 1)printf("min1 %d, min2 %d, min1_idx %d\n", rmin1, rmin2, idx_min); // if(blockIdx.x == 0 && threadIdx.x == 1)printf("min1 %d, min2 %d, min1_idx %d\n", rmin1, rmin2, idx_min);
@@ -317,7 +294,6 @@ __global__ void ldpc_cnp_kernel(/*char * dev_llr, char * dev_dt,*/ int BG, int r
sq = 1 - 2 * ((Q_sign >> i) & 0x01); sq = 1 - 2 * ((Q_sign >> i) & 0x01);
R_temp = 0.75f * sign * sq * (i != idx_min ? rmin1 : rmin2); R_temp = 0.75f * sign * sq * (i != idx_min ? rmin1 : rmin2);
// write results to global memory // write results to global memory
h_element_t = dev_h_compact1[i * row + iBlkRow]; h_element_t = dev_h_compact1[i * row + iBlkRow];
int addr_temp = h_element_t.y * row * Zc + offsetR; int addr_temp = h_element_t.y * row * Zc + offsetR;
@@ -348,8 +324,7 @@ ldpc_vnp_kernel_normal(/*char * dev_llr, char * dev_dt, char * dev_const_llr,*/
int offsetDt = iMCW * row * col * Zc + iBlkCol * row * Zc; int offsetDt = iMCW * row * col * Zc + iBlkCol * row * Zc;
int s = (BG == 1) ? h_ele_col_bg1_count[iBlkCol] : h_ele_col_bg2_count[iBlkCol]; int s = (BG == 1) ? h_ele_col_bg1_count[iBlkCol] : h_ele_col_bg2_count[iBlkCol];
for(int i = 0; i < s; i++) for (int i = 0; i < s; i++) {
{
h_element_t = dev_h_compact2[i * col + iBlkCol]; h_element_t = dev_h_compact2[i * col + iBlkCol];
shift_t = h_element_t.value % Zc; shift_t = h_element_t.value % Zc;
@@ -361,8 +336,10 @@ ldpc_vnp_kernel_normal(/*char * dev_llr, char * dev_dt, char * dev_const_llr,*/
iRow = iBlkRow * Zc + sf; iRow = iBlkRow * Zc + sf;
APP = APP + dev_dt[offsetDt + iRow]; APP = APP + dev_dt[offsetDt + iRow];
} }
if(APP > SCHAR_MAX) APP = SCHAR_MAX; if (APP > SCHAR_MAX)
if(APP < SCHAR_MIN) APP = SCHAR_MIN; APP = SCHAR_MAX;
if (APP < SCHAR_MIN)
APP = SCHAR_MIN;
// write back to device global memory // write back to device global memory
dev_llr[iMCW * col * Zc + iCol] = APP; dev_llr[iMCW * col * Zc + iCol] = APP;
} }
@@ -392,7 +369,9 @@ __global__ void pack_decoded_bit(/*char *dev, unsigned char *host,*/ int col, in
void read_BG(int BG, int *h, int row, int col) void read_BG(int BG, int *h, int row, int col)
{ {
int compact_row = 30, compact_col = 19; int compact_row = 30, compact_col = 19;
if(BG==2){compact_row = 10, compact_col = 23;} if (BG == 2) {
compact_row = 10, compact_col = 23;
}
h_element h_element_temp; h_element h_element_temp;
@@ -463,25 +442,18 @@ void read_BG(int BG, int *h, int row, int col)
extern "C" extern "C"
void init_LLR_DMA(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_out){ void init_LLR_DMA(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_out){
uint16_t Zc = p_decParams->Z; uint16_t Zc = p_decParams->Z;
uint8_t BG = p_decParams->BG; uint8_t BG = p_decParams->BG;
int block_length = p_decParams->block_length; uint8_t col;
uint8_t row,col;
if (BG == 1) { if (BG == 1) {
row = 46;
col = 68; col = 68;
} } else {
else{
row = 42;
col = 52; col = 52;
} }
unsigned char *hard_decision = (unsigned char*)p_out;
int memorySize_llr_cuda = col * Zc * sizeof(char) * MC; int memorySize_llr_cuda = col * Zc * sizeof(char) * MC;
cudaCheck(cudaMemcpyToSymbol(dev_const_llr, p_llr, memorySize_llr_cuda)); cudaCheck(cudaMemcpyToSymbol(dev_const_llr, p_llr, memorySize_llr_cuda));
cudaCheck(cudaMemcpyToSymbol(dev_llr, p_llr, memorySize_llr_cuda)); cudaCheck(cudaMemcpyToSymbol(dev_llr, p_llr, memorySize_llr_cuda));
cudaDeviceSynchronize(); cudaDeviceSynchronize();
} }
using namespace std ; using namespace std ;
@@ -515,19 +487,18 @@ int ldpc_autoinit(void) { // called by the library loader
wcout << " Warp size: " << props.warpSize << endl; wcout << " Warp size: " << props.warpSize << endl;
wcout << " Threads per block: " << props.maxThreadsPerBlock << endl; wcout << " Threads per block: " << props.maxThreadsPerBlock << endl;
wcout << " Max block dimensions: [ " << props.maxThreadsDim[0] << ", " << props.maxThreadsDim[1] << ", " << props.maxThreadsDim[2] << " ]" << endl; wcout << " Max block dimensions: [ " << props.maxThreadsDim[0] << ", " << props.maxThreadsDim[1] << ", " <<
wcout << " Max grid dimensions: [ " << props.maxGridSize[0] << ", " << props.maxGridSize[1] << ", " << props.maxGridSize[2] << " ]" << endl; props.maxThreadsDim[2] << " ]" << endl; wcout << " Max grid dimensions: [ " << props.maxGridSize[0] << ", " <<
wcout << endl; props.maxGridSize[1] << ", " << props.maxGridSize[2] << " ]" << endl; wcout << endl;
} }
*/ */
warmup_for_GPU(); warmup_for_GPU();
return 0; return 0;
} }
extern "C" void LDPCinit(t_nrLDPC_dec_params* p_decParams, int8_t* p_llr, int8_t* p_out) extern "C" int32_t LDPCinit()
{ {
set_compact_BG(p_decParams->Z, p_decParams->BG); return 0;
init_LLR_DMA(p_decParams, p_llr, p_out);
} }
extern "C" void LDPCshutdown() extern "C" void LDPCshutdown()
@@ -535,23 +506,24 @@ extern "C" void LDPCshutdown()
} }
extern "C" int32_t LDPCdecoder(t_nrLDPC_dec_params *p_decParams, extern "C" int32_t LDPCdecoder(t_nrLDPC_dec_params *p_decParams,
uint8_t harq_pid,
uint8_t ulsch_id,
uint8_t C,
int8_t *p_llr, int8_t *p_llr,
int8_t *p_out, int8_t *p_out,
t_nrLDPC_procBuf* p_procBuf, t_nrLDPC_time_stats *,
t_nrLDPC_time_stats* time_decoder) decode_abort_t *ab)
{ {
set_compact_BG(p_decParams->Z, p_decParams->BG);
init_LLR_DMA(p_decParams, p_llr, p_out);
uint16_t Zc = p_decParams->Z; uint16_t Zc = p_decParams->Z;
uint8_t BG = p_decParams->BG; uint8_t BG = p_decParams->BG;
uint8_t numMaxIter = p_decParams->numMaxIter;
int block_length = p_decParams->block_length; int block_length = p_decParams->block_length;
e_nrLDPC_outMode outMode = p_decParams->outMode;
cudaError_t cudaStatus;
uint8_t row, col; uint8_t row, col;
if (BG == 1) { if (BG == 1) {
row = 46; row = 46;
col = 68; col = 68;
} } else {
else{
row = 42; row = 42;
col = 52; col = 52;
} }
@@ -577,17 +549,12 @@ extern "C" int32_t LDPCdecoder(t_nrLDPC_dec_params* p_decParams,
for (int ii = 0; ii < MAX_ITERATION; ii++) { for (int ii = 0; ii < MAX_ITERATION; ii++) {
// first kernel // first kernel
if (ii == 0) { if (ii == 0) {
ldpc_cnp_kernel_1st_iter ldpc_cnp_kernel_1st_iter<<<dimGridKernel1, dimBlockKernel1>>>(/*dev_llr,*/ BG, row, col, Zc);
<<<dimGridKernel1, dimBlockKernel1>>>
(/*dev_llr,*/ BG, row, col, Zc);
} else { } else {
ldpc_cnp_kernel ldpc_cnp_kernel<<<dimGridKernel1, dimBlockKernel1>>>(/*dev_llr,*/ BG, row, col, Zc);
<<<dimGridKernel1, dimBlockKernel1>>>
(/*dev_llr,*/ BG, row, col, Zc);
} }
// second kernel // second kernel
ldpc_vnp_kernel_normal ldpc_vnp_kernel_normal<<<dimGridKernel2, dimBlockKernel2>>>
<<<dimGridKernel2, dimBlockKernel2>>>
// (dev_llr, dev_const_llr,BG, row, col, Zc); // (dev_llr, dev_const_llr,BG, row, col, Zc);
(BG, row, col, Zc); (BG, row, col, Zc);
} }
@@ -599,7 +566,5 @@ extern "C" int32_t LDPCdecoder(t_nrLDPC_dec_params* p_decParams,
cudaCheck(cudaMemcpyFromSymbol((void*)hard_decision, (const void*)dev_tmp, (block_length / 8) * sizeof(unsigned char))); cudaCheck(cudaMemcpyFromSymbol((void*)hard_decision, (const void*)dev_tmp, (block_length / 8) * sizeof(unsigned char)));
cudaDeviceSynchronize(); cudaDeviceSynchronize();
return MAX_ITERATION; return MAX_ITERATION;
} }