From 3568f633c3bbe8411dfc4e0c88ee187b41e30bd0 Mon Sep 17 00:00:00 2001 From: Xavier Arteaga Date: Thu, 25 Mar 2021 19:44:27 +0100 Subject: [PATCH] Use LDPC RM number of useful LLR and rename functions --- .../srsran/phy/fec/ldpc/ldpc_decoder.h | 19 ++---------------- lib/include/srsran/phy/fec/ldpc/ldpc_rm.h | 2 +- lib/src/phy/fec/ldpc/ldpc_decoder.c | 20 ++++--------------- lib/src/phy/fec/ldpc/ldpc_rm.c | 3 ++- lib/src/phy/fec/ldpc/test/ldpc_chain_test.c | 13 ++++++------ .../phy/fec/ldpc/test/ldpc_dec_avx2_test.c | 2 +- .../phy/fec/ldpc/test/ldpc_dec_avx512_test.c | 2 +- lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c | 2 +- .../phy/fec/ldpc/test/ldpc_rm_chain_test.c | 13 ++++++------ lib/src/phy/fec/ldpc/test/ldpc_rm_test.c | 4 ++-- lib/src/phy/phch/sch_nr.c | 9 +++++++-- 11 files changed, 33 insertions(+), 56 deletions(-) diff --git a/lib/include/srsran/phy/fec/ldpc/ldpc_decoder.h b/lib/include/srsran/phy/fec/ldpc/ldpc_decoder.h index 4875d6797..0539168bc 100644 --- a/lib/include/srsran/phy/fec/ldpc/ldpc_decoder.h +++ b/lib/include/srsran/phy/fec/ldpc/ldpc_decoder.h @@ -126,19 +126,6 @@ srsran_ldpc_decoder_decode_f(srsran_ldpc_decoder_t* q, const float* llrs, uint8_ SRSRAN_API int srsran_ldpc_decoder_decode_s(srsran_ldpc_decoder_t* q, const int16_t* llrs, uint8_t* message, uint32_t cdwd_rm_length); -/*! - * Carries out the actual decoding with 8-bit integer-valued LLRs. It is - * recommended to use a 7-bit representation for the LLRs, given that all - * values exceeding \f$ 2^{7}-1 \f$ (in magnitude) will be considered as infinity. - * \param[in] q A pointer to the LDPC decoder (a srsran_ldpc_decoder_t structure - * instance) that carries out the decoding. - * \param[in] llrs The LLRs obtained from the channel samples that correspond to - * the codeword to be decoded. - * \param[out] message The message (uncoded bits) resulting from the decoding - * operation. - */ -SRSRAN_API int srsran_ldpc_decoder_decode_c(srsran_ldpc_decoder_t* q, const int8_t* llrs, uint8_t* message); - /*! * Carries out the actual decoding with 8-bit integer-valued LLRs. It is * recommended to use a 7-bit representation for the LLRs, given that all @@ -151,9 +138,7 @@ SRSRAN_API int srsran_ldpc_decoder_decode_c(srsran_ldpc_decoder_t* q, const int8 * operation. * \param[in] cdwd_rm_length The number of bits forming the codeword (after rate matching). */ -SRSRAN_API int srsran_ldpc_decoder_decode_rm_c(srsran_ldpc_decoder_t* q, - const int8_t* llrs, - uint8_t* message, - uint32_t cdwd_rm_length); +SRSRAN_API int +srsran_ldpc_decoder_decode_c(srsran_ldpc_decoder_t* q, const int8_t* llrs, uint8_t* message, uint32_t cdwd_rm_length); #endif // SRSRAN_LDPCDECODER_H diff --git a/lib/include/srsran/phy/fec/ldpc/ldpc_rm.h b/lib/include/srsran/phy/fec/ldpc/ldpc_rm.h index c9c5a2f66..05e0fa253 100644 --- a/lib/include/srsran/phy/fec/ldpc/ldpc_rm.h +++ b/lib/include/srsran/phy/fec/ldpc/ldpc_rm.h @@ -169,7 +169,7 @@ SRSRAN_API int srsran_ldpc_rm_rx_init_c(srsran_ldpc_rm_t* q); * \param[in] rv Redundancy version 0,1,2,3. * \param[in] mod_type Modulation type. * \param[in] Nref Size of limited buffer. - * \return An integer: 0 if the function executes correctly, -1 otherwise. + * \return An integer: The number of useful LLR if the function executes correctly, -1 otherwise. */ SRSRAN_API int srsran_ldpc_rm_rx_c(srsran_ldpc_rm_t* q, const int8_t* input, diff --git a/lib/src/phy/fec/ldpc/ldpc_decoder.c b/lib/src/phy/fec/ldpc/ldpc_decoder.c index baba3e5d4..e71601652 100644 --- a/lib/src/phy/fec/ldpc/ldpc_decoder.c +++ b/lib/src/phy/fec/ldpc/ldpc_decoder.c @@ -1028,22 +1028,10 @@ int srsran_ldpc_decoder_decode_s(srsran_ldpc_decoder_t* q, return q->decode_s(q, llrs, message, cdwd_rm_length); } -int srsran_ldpc_decoder_decode_c(srsran_ldpc_decoder_t* q, const int8_t* llrs, uint8_t* message) -{ - uint32_t cdwd_rm_length = q->liftN - 2 * q->ls; - - // Trim input LLR to find last zero - while (llrs[cdwd_rm_length - 1] == 0 && cdwd_rm_length > 0) { - cdwd_rm_length--; - } - - return q->decode_c(q, llrs, message, cdwd_rm_length); -} - -int srsran_ldpc_decoder_decode_rm_c(srsran_ldpc_decoder_t* q, - const int8_t* llrs, - uint8_t* message, - uint32_t cdwd_rm_length) +int srsran_ldpc_decoder_decode_c(srsran_ldpc_decoder_t* q, + const int8_t* llrs, + uint8_t* message, + uint32_t cdwd_rm_length) { return q->decode_c(q, llrs, message, cdwd_rm_length); } diff --git a/lib/src/phy/fec/ldpc/ldpc_rm.c b/lib/src/phy/fec/ldpc/ldpc_rm.c index 5ae4d91e8..a52b80806 100644 --- a/lib/src/phy/fec/ldpc/ldpc_rm.c +++ b/lib/src/phy/fec/ldpc/ldpc_rm.c @@ -686,5 +686,6 @@ int srsran_ldpc_rm_rx_c(srsran_ldpc_rm_t* q, bit_selection_rm_rx_c(tmp_rm_symbol, q->E, output, indices, ini_exclude, end_exclude, q->k0, q->Ncb); } - return 0; + // Return the number of useful LLR + return (int)((q->k0 + q->E) % q->Ncb); } diff --git a/lib/src/phy/fec/ldpc/test/ldpc_chain_test.c b/lib/src/phy/fec/ldpc/test/ldpc_chain_test.c index c67d75f77..2670fb6a2 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_chain_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_chain_test.c @@ -422,8 +422,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( - &decoder_c, symbols_c + j * finalN, messages_sim_c + j * finalK, n_useful_symbols); + srsran_ldpc_decoder_decode_c(&decoder_c, symbols_c + j * finalN, messages_sim_c + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); get_time_interval(t); @@ -444,7 +443,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_c_flood, symbols_c + j * finalN, messages_sim_c_flood + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); @@ -467,7 +466,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_avx, symbols_c + j * finalN, messages_sim_avx + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); @@ -489,7 +488,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_avx_flood, symbols_c + j * finalN, messages_sim_avx_flood + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); @@ -513,7 +512,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_avx512, symbols_c + j * finalN, messages_sim_avx512 + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); @@ -534,7 +533,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_avx512_flood, symbols_c + j * finalN, messages_sim_avx512_flood + j * finalK, n_useful_symbols); } gettimeofday(&t[2], NULL); diff --git a/lib/src/phy/fec/ldpc/test/ldpc_dec_avx2_test.c b/lib/src/phy/fec/ldpc/test/ldpc_dec_avx2_test.c index 95d8abd9c..306848143 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_dec_avx2_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_dec_avx2_test.c @@ -207,7 +207,7 @@ int main(int argc, char** argv) printf(" codeword %d\n", j); gettimeofday(&t[1], NULL); for (l = 0; l < nof_reps; l++) { - srsran_ldpc_decoder_decode_rm_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); + srsran_ldpc_decoder_decode_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); } gettimeofday(&t[2], NULL); diff --git a/lib/src/phy/fec/ldpc/test/ldpc_dec_avx512_test.c b/lib/src/phy/fec/ldpc/test/ldpc_dec_avx512_test.c index 658bc5b45..a3391ce65 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_dec_avx512_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_dec_avx512_test.c @@ -206,7 +206,7 @@ int main(int argc, char** argv) printf(" codeword %d\n", j); gettimeofday(&t[1], NULL); for (l = 0; l < nof_reps; l++) { - srsran_ldpc_decoder_decode_rm_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); + srsran_ldpc_decoder_decode_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); } gettimeofday(&t[2], NULL); diff --git a/lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c b/lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c index 79508e64b..a698c22a6 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_dec_c_test.c @@ -197,7 +197,7 @@ int main(int argc, char** argv) gettimeofday(&t[1], NULL); for (j = 0; j < NOF_MESSAGES; j++) { printf(" codeword %d\n", j); - srsran_ldpc_decoder_decode_rm_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); + srsran_ldpc_decoder_decode_c(&decoder, symbols + j * finalN, messages_sim + j * finalK, finalN); } gettimeofday(&t[2], NULL); get_time_interval(t); diff --git a/lib/src/phy/fec/ldpc/test/ldpc_rm_chain_test.c b/lib/src/phy/fec/ldpc/test/ldpc_rm_chain_test.c index c022902c7..5047a5fc2 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_rm_chain_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_rm_chain_test.c @@ -554,7 +554,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_c, symbols_c + j * finalN, messages_sim_c + j * finalK, n_useful_symbols_dec); } gettimeofday(&t[2], NULL); @@ -576,7 +576,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_c_flood, symbols_c + j * finalN, messages_sim_c_flood + j * finalK, n_useful_symbols_dec); } gettimeofday(&t[2], NULL); @@ -599,7 +599,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_avx, symbols_c + j * finalN, messages_sim_avx + j * finalK, n_useful_symbols_dec); } gettimeofday(&t[2], NULL); @@ -621,7 +621,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_avx_flood, symbols_c + j * finalN, messages_sim_avx_flood + j * finalK, n_useful_symbols_dec); } gettimeofday(&t[2], NULL); @@ -645,8 +645,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( - &decoder_avx512, symbols_c + j * finalN, messages_sim_avx512 + j * finalK, finalN); + srsran_ldpc_decoder_decode_c(&decoder_avx512, symbols_c + j * finalN, messages_sim_avx512 + j * finalK, finalN); } gettimeofday(&t[2], NULL); get_time_interval(t); @@ -667,7 +666,7 @@ int main(int argc, char** argv) // Recover messages gettimeofday(&t[1], NULL); for (j = 0; j < batch_size; j++) { - srsran_ldpc_decoder_decode_rm_c( + srsran_ldpc_decoder_decode_c( &decoder_avx512_flood, symbols_c + j * finalN, messages_sim_avx512_flood + j * finalK, finalN); } gettimeofday(&t[2], NULL); diff --git a/lib/src/phy/fec/ldpc/test/ldpc_rm_test.c b/lib/src/phy/fec/ldpc/test/ldpc_rm_test.c index 57d8cd652..1fa3a4ef3 100644 --- a/lib/src/phy/fec/ldpc/test/ldpc_rm_test.c +++ b/lib/src/phy/fec/ldpc/test/ldpc_rm_test.c @@ -256,7 +256,8 @@ int main(int argc, char** argv) exit(-1); } if (srsran_ldpc_rm_rx_c( - &rm_rx_c, rm_symbols_c + r * E, unrm_symbols_c + r * N, E, F, base_graph, lift_size, rv, mod_type, Nref)) { + &rm_rx_c, rm_symbols_c + r * E, unrm_symbols_c + r * N, E, F, base_graph, lift_size, rv, mod_type, Nref) < + 0) { exit(-1); } @@ -269,7 +270,6 @@ int main(int argc, char** argv) ((unrm_symbols[i + r * N] < 0) && (codewords[i + r * N]))) { // any of these cases are ok } else { - error = -1; break; } diff --git a/lib/src/phy/phch/sch_nr.c b/lib/src/phy/phch/sch_nr.c index c77964f58..a28a40253 100644 --- a/lib/src/phy/phch/sch_nr.c +++ b/lib/src/phy/phch/sch_nr.c @@ -581,10 +581,15 @@ int sch_nr_decode(srsran_sch_nr_t* q, tb->rv, cfg.Qm, cfg.Nref); - srsran_ldpc_rm_rx_c(&q->rx_rm, input_ptr, rm_buffer, E, cfg.F, cfg.bg, cfg.Z, tb->rv, tb->mod, cfg.Nref); + int n_llr = + srsran_ldpc_rm_rx_c(&q->rx_rm, input_ptr, rm_buffer, E, cfg.F, cfg.bg, cfg.Z, tb->rv, tb->mod, cfg.Nref); + if (n_llr < SRSRAN_SUCCESS) { + ERROR("Error in LDPC rate mateching"); + return SRSRAN_ERROR; + } // Decode - srsran_ldpc_decoder_decode_c(decoder, rm_buffer, q->temp_cb); + srsran_ldpc_decoder_decode_c(decoder, rm_buffer, q->temp_cb, n_llr); // Compute CB CRC uint32_t cb_len = cfg.Kp - cfg.L_cb;