Removed PDSCH threads and refactored RI/PMI select

master
Xavier Arteaga 7 years ago
parent f2db2db81b
commit ed19a4d200

@ -35,13 +35,6 @@
#ifndef PDSCH_ #ifndef PDSCH_
#define PDSCH_ #define PDSCH_
#ifndef SRSLTE_SINGLE_THREAD
#include <pthread.h>
#include <semaphore.h>
#endif /* SRSLTE_SINGLE_THREAD */
#include "srslte/config.h" #include "srslte/config.h"
#include "srslte/phy/common/phy_common.h" #include "srslte/phy/common/phy_common.h"
#include "srslte/phy/mimo/precoding.h" #include "srslte/phy/mimo/precoding.h"
@ -59,34 +52,6 @@ typedef struct {
bool sequence_generated; bool sequence_generated;
} srslte_pdsch_user_t; } srslte_pdsch_user_t;
#ifndef SRSLTE_SINGLE_THREAD
typedef struct {
/* Thread identifier: they must set before thread creation */
uint32_t codeword_idx;
void *pdsch_ptr;
/* Configuration Encoder/Decoder: they must be set before posting start semaphore */
srslte_pdsch_cfg_t *cfg;
uint16_t rnti;
/* Encoder/Decoder data pointers: they must be set before posting start semaphore */
uint8_t *data;
void *softbuffer;
/* Execution status */
int ret_status;
/* Semaphores */
sem_t start;
sem_t finish;
/* Thread kill flag */
bool quit;
} srslte_pdsch_thread_args_t;
#endif /* SRSLTE_SINGLE_THREAD */
/* PDSCH object */ /* PDSCH object */
typedef struct SRSLTE_API { typedef struct SRSLTE_API {
srslte_cell_t cell; srslte_cell_t cell;
@ -111,13 +76,6 @@ typedef struct SRSLTE_API {
srslte_sch_t dl_sch[SRSLTE_MAX_CODEWORDS]; srslte_sch_t dl_sch[SRSLTE_MAX_CODEWORDS];
#ifndef SRSLTE_SINGLE_THREAD
pthread_t threads[SRSLTE_MAX_CODEWORDS];
srslte_pdsch_thread_args_t thread_args[SRSLTE_MAX_CODEWORDS];
#endif /* SRSLTE_SINGLE_THREAD */
} srslte_pdsch_t; } srslte_pdsch_t;
SRSLTE_API int srslte_pdsch_init(srslte_pdsch_t *q, SRSLTE_API int srslte_pdsch_init(srslte_pdsch_t *q,
@ -190,14 +148,13 @@ SRSLTE_API int srslte_pdsch_decode_multi(srslte_pdsch_t *q,
uint16_t rnti, uint16_t rnti,
uint8_t *data[SRSLTE_MAX_CODEWORDS]); uint8_t *data[SRSLTE_MAX_CODEWORDS]);
SRSLTE_API int srslte_pdsch_ri_pmi_select(srslte_pdsch_t *q, SRSLTE_API int srslte_pdsch_pmi_select(srslte_pdsch_t *q,
srslte_pdsch_cfg_t *cfg, srslte_pdsch_cfg_t *cfg,
cf_t *ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], cf_t *ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS],
float noise_estimate, float noise_estimate,
uint32_t nof_ce, uint32_t nof_ce,
uint32_t *ri, uint32_t pmi[SRSLTE_MAX_LAYERS],
uint32_t *pmi, float sinr[SRSLTE_MAX_LAYERS][SRSLTE_MAX_CODEBOOKS]);
float *current_sinr);
SRSLTE_API void srslte_pdsch_set_max_noi(srslte_pdsch_t *q, int max_iter); SRSLTE_API void srslte_pdsch_set_max_noi(srslte_pdsch_t *q, int max_iter);

@ -95,6 +95,11 @@ typedef struct SRSLTE_API {
cf_t *ce[SRSLTE_MAX_PORTS]; // compatibility cf_t *ce[SRSLTE_MAX_PORTS]; // compatibility
cf_t *ce_m[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS]; cf_t *ce_m[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS];
/* RI, PMI and SINR for MIMO statistics */
float sinr[SRSLTE_MAX_LAYERS][SRSLTE_MAX_CODEBOOKS];
uint32_t pmi[SRSLTE_MAX_LAYERS];
uint32_t ri;
srslte_dci_format_t dci_format; srslte_dci_format_t dci_format;
uint64_t pkt_errors; uint64_t pkt_errors;
uint64_t pkts_total; uint64_t pkts_total;

@ -33,13 +33,6 @@
#include <assert.h> #include <assert.h>
#include <math.h> #include <math.h>
#ifndef SRSLTE_SINGLE_THREAD
#include <pthread.h>
#include <semaphore.h>
#endif /* SRSLTE_SINGLE_THREAD */
#include "prb_dl.h" #include "prb_dl.h"
#include "srslte/phy/phch/pdsch.h" #include "srslte/phy/phch/pdsch.h"
#include "srslte/phy/phch/sch.h" #include "srslte/phy/phch/sch.h"
@ -64,13 +57,6 @@ extern int indices[100000];
extern int indices_ptr; extern int indices_ptr;
#endif #endif
#ifndef SRSLTE_SINGLE_THREAD
static void *srslte_pdsch_encode_thread (void *arg);
static void *srslte_pdsch_decode_thread (void *arg);
#endif /* SRSLTE_SINGLE_THREAD */
float srslte_pdsch_coderate(uint32_t tbs, uint32_t nof_re) float srslte_pdsch_coderate(uint32_t tbs, uint32_t nof_re)
{ {
return (float) (tbs + 24)/(nof_re); return (float) (tbs + 24)/(nof_re);
@ -263,20 +249,6 @@ int srslte_pdsch_init_multi(srslte_pdsch_t *q, srslte_cell_t cell, uint32_t nof_
goto clean; goto clean;
} }
#ifndef SRSLTE_SINGLE_THREAD
if (sem_init(&q->thread_args[i].start, 0, 0)) {
ERROR("Creating semaphore");
goto clean;
}
if (sem_init(&q->thread_args[i].finish, 0, 0)) {
ERROR("Creating semaphore");
goto clean;
}
q->thread_args[i].codeword_idx = (uint32_t) i;
q->thread_args[i].pdsch_ptr = q;
pthread_create(&q->threads[i], NULL, (is_receiver) ? srslte_pdsch_decode_thread : srslte_pdsch_encode_thread,
(void *) &q->thread_args[i]);
#endif /* SRSLTE_SINGLE_THREAD */
} }
/* Layer mapped symbols memory allocation */ /* Layer mapped symbols memory allocation */
@ -339,15 +311,6 @@ void srslte_pdsch_free(srslte_pdsch_t *q) {
for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) { for (i = 0; i < SRSLTE_MAX_CODEWORDS; i++) {
#ifndef SRSLTE_SINGLE_THREAD
/* Stop threads */
q->thread_args[i].quit = true;
sem_post(&q->thread_args[i].start);
pthread_join(q->threads[i], NULL);
pthread_detach(q->threads[i]);
#endif /* SRSLTE_SINGLE_THREAD */
if (q->e[i]) { if (q->e[i]) {
free(q->e[i]); free(q->e[i]);
} }
@ -359,7 +322,6 @@ void srslte_pdsch_free(srslte_pdsch_t *q) {
/* Free sch objects */ /* Free sch objects */
srslte_sch_free(&q->dl_sch[i]); srslte_sch_free(&q->dl_sch[i]);
} }
for (i = 0; i < q->cell.nof_ports; i++) { for (i = 0; i < q->cell.nof_ports; i++) {
@ -506,7 +468,7 @@ int srslte_pdsch_set_rnti(srslte_pdsch_t *q, uint16_t rnti) {
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
static inline int srslte_pdsch_codeword_encode(srslte_pdsch_t *pdsch, srslte_pdsch_cfg_t *cfg, static int srslte_pdsch_codeword_encode(srslte_pdsch_t *pdsch, srslte_pdsch_cfg_t *cfg,
srslte_softbuffer_tx_t *softbuffer, uint16_t rnti, uint8_t *data, srslte_softbuffer_tx_t *softbuffer, uint16_t rnti, uint8_t *data,
uint32_t codeword_idx) { uint32_t codeword_idx) {
srslte_sch_t *dl_sch = &pdsch->dl_sch[codeword_idx]; srslte_sch_t *dl_sch = &pdsch->dl_sch[codeword_idx];
@ -550,33 +512,7 @@ static inline int srslte_pdsch_codeword_encode(srslte_pdsch_t *pdsch, srslte_pds
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
static int srslte_pdsch_codeword_decode(srslte_pdsch_t *pdsch, srslte_pdsch_cfg_t *cfg,
#ifndef SRSLTE_SINGLE_THREAD
static void *srslte_pdsch_encode_thread(void *arg) {
srslte_pdsch_thread_args_t *q = (srslte_pdsch_thread_args_t *) arg;
uint32_t codeword_idx = q->codeword_idx;
INFO("[PDSCH Encoder CW %d] waiting for data\n", codeword_idx);
sem_wait(&q->start);
while (!q->quit) {
q->ret_status = srslte_pdsch_codeword_encode(q->pdsch_ptr, q->cfg, q->softbuffer, q->rnti, q->data, codeword_idx);
/* Post finish semaphore */
sem_post(&q->finish);
/* Wait for next loop */
sem_wait(&q->start);
}
pthread_exit(NULL);
return q;
}
#endif /* SRSLTE_SINGLE_THREAD */
static inline int srslte_pdsch_codeword_decode(srslte_pdsch_t *pdsch, srslte_pdsch_cfg_t *cfg,
srslte_softbuffer_rx_t *softbuffer, uint16_t rnti, uint8_t *data, srslte_softbuffer_rx_t *softbuffer, uint16_t rnti, uint8_t *data,
uint32_t codeword_idx) { uint32_t codeword_idx) {
srslte_sch_t *dl_sch = &pdsch->dl_sch[codeword_idx]; srslte_sch_t *dl_sch = &pdsch->dl_sch[codeword_idx];
@ -588,6 +524,10 @@ static inline int srslte_pdsch_codeword_decode(srslte_pdsch_t *pdsch, srslte_pds
cfg->sf_idx, codeword_idx, srslte_mod_string(mcs->mod), mcs->tbs, cfg->sf_idx, codeword_idx, srslte_mod_string(mcs->mod), mcs->tbs,
nbits->nof_re, nbits->nof_bits, (codeword_idx == 0) ? cfg->rv : cfg->rv2); nbits->nof_re, nbits->nof_bits, (codeword_idx == 0) ? cfg->rv : cfg->rv2);
/* demodulate symbols
* The MAX-log-MAP algorithm used in turbo decoding is unsensitive to SNR estimation,
* thus we don't need tot set it in the LLRs normalization
*/
srslte_demod_soft_demodulate_s(mcs->mod, pdsch->d[codeword_idx], pdsch->e[codeword_idx], cfg->nbits.nof_re); srslte_demod_soft_demodulate_s(mcs->mod, pdsch->d[codeword_idx], pdsch->e[codeword_idx], cfg->nbits.nof_re);
if (pdsch->users[rnti] && pdsch->users[rnti]->sequence_generated) { if (pdsch->users[rnti] && pdsch->users[rnti]->sequence_generated) {
@ -609,32 +549,6 @@ static inline int srslte_pdsch_codeword_decode(srslte_pdsch_t *pdsch, srslte_pds
return SRSLTE_SUCCESS; return SRSLTE_SUCCESS;
} }
#ifndef SRSLTE_SINGLE_THREAD
static void *srslte_pdsch_decode_thread(void *arg) {
srslte_pdsch_thread_args_t *q = (srslte_pdsch_thread_args_t *) arg;
uint32_t codeword_idx = q->codeword_idx;
INFO("[PDSCH Encoder CW %d] waiting for data\n", codeword_idx);
sem_wait(&q->start);
while (!q->quit) {
q->ret_status = srslte_pdsch_codeword_decode(q->pdsch_ptr, q->cfg, q->softbuffer, q->rnti, q->data, codeword_idx);
/* Post finish semaphore */
sem_post(&q->finish);
/* Wait for next loop */
sem_wait(&q->start);
}
pthread_exit(NULL);
return q;
}
#endif /* SRSLTE_SINGLE_THREAD */
void srslte_pdsch_free_rnti(srslte_pdsch_t* q, uint16_t rnti) void srslte_pdsch_free_rnti(srslte_pdsch_t* q, uint16_t rnti)
{ {
if (q->users[rnti]) { if (q->users[rnti]) {
@ -760,32 +674,9 @@ int srslte_pdsch_decode_multi(srslte_pdsch_t *q,
srslte_vec_save_file("pdsch_symbols.dat", q->d, cfg->nbits.nof_re*sizeof(cf_t)); srslte_vec_save_file("pdsch_symbols.dat", q->d, cfg->nbits.nof_re*sizeof(cf_t));
} }
#ifndef SRSLTE_SINGLE_THREAD
for (i = 0; i < cfg->grant.nof_tb; i++) {
srslte_pdsch_thread_args_t *thread_args = &q->thread_args[i];
thread_args->cfg = cfg;
thread_args->softbuffer = &softbuffers[i];
thread_args->data = data[i];
thread_args->rnti = rnti;
sem_post(&thread_args->start);
}
for (i = 0; i < cfg->grant.nof_tb; i++) {
srslte_pdsch_thread_args_t *thread_args = &q->thread_args[i];
sem_wait(&thread_args->finish);
ret |= thread_args->ret_status;
}
#else
/* demodulate symbols
* The MAX-log-MAP algorithm used in turbo decoding is unsensitive to SNR estimation,
* thus we don't need tot set it in the LLRs normalization
*/
for (uint32_t tb = 0; tb < cfg->grant.nof_tb; tb ++) { for (uint32_t tb = 0; tb < cfg->grant.nof_tb; tb ++) {
ret |= srslte_pdsch_codeword_decode(q, cfg, &softbuffers[tb], rnti, data[tb], tb); ret |= srslte_pdsch_codeword_decode(q, cfg, &softbuffers[tb], rnti, data[tb], tb);
} }
#endif /* SRSLTE_SINGLE_THREAD */
if (SRSLTE_VERBOSE_ISDEBUG()) { if (SRSLTE_VERBOSE_ISDEBUG()) {
DEBUG("SAVED FILE llr.dat: LLR estimates after demodulation and descrambling\n",0); DEBUG("SAVED FILE llr.dat: LLR estimates after demodulation and descrambling\n",0);
@ -799,70 +690,20 @@ int srslte_pdsch_decode_multi(srslte_pdsch_t *q,
} }
} }
int srslte_pdsch_ri_pmi_select(srslte_pdsch_t *q, int srslte_pdsch_pmi_select(srslte_pdsch_t *q,
srslte_pdsch_cfg_t *cfg, srslte_pdsch_cfg_t *cfg,
cf_t *ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], float noise_estimate, uint32_t nof_ce, cf_t *ce[SRSLTE_MAX_PORTS][SRSLTE_MAX_PORTS], float noise_estimate, uint32_t nof_ce,
uint32_t *ri, uint32_t *pmi, uint32_t pmi[SRSLTE_MAX_LAYERS], float sinr[SRSLTE_MAX_LAYERS][SRSLTE_MAX_CODEBOOKS]) {
float *current_sinr) {
uint32_t best_pmi_1l;
uint32_t best_pmi_2l;
float sinr_1l[SRSLTE_MAX_CODEBOOKS];
float sinr_2l[SRSLTE_MAX_CODEBOOKS];
float best_sinr_1l = 0.0;
float best_sinr_2l = 0.0;
int n1, n2;
if (q->cell.nof_ports == 2 && q->nof_rx_antennas == 2) { if (q->cell.nof_ports == 2 && q->nof_rx_antennas == 2) {
n1 = srslte_precoding_pmi_select(ce, nof_ce, noise_estimate, 1, &best_pmi_1l, sinr_1l); for (int nof_layers = 1; nof_layers <= cfg->nof_layers; nof_layers++ ) {
if (n1 < 0) { if (sinr[nof_layers - 1] && pmi) {
ERROR("PMI Select for 1 layer"); if (srslte_precoding_pmi_select(ce, nof_ce, noise_estimate, nof_layers, &pmi[nof_layers - 1],
sinr[nof_layers - 1]) < 0) {
ERROR("PMI Select for %d layers", nof_layers);
return SRSLTE_ERROR; return SRSLTE_ERROR;
} }
n2 = srslte_precoding_pmi_select(ce, nof_ce, noise_estimate, 2, &best_pmi_2l, sinr_2l);
if (n2 < 0) {
ERROR("PMI Select for 2 layer");
return SRSLTE_ERROR;
} }
for (int i = 0; i < n1; i++) {
if (sinr_1l[i] > best_sinr_1l) {
best_sinr_1l = sinr_1l[i];
}
}
for (int i = 0; i < n2; i++) {
if (sinr_2l[i] > best_sinr_2l) {
best_sinr_2l = sinr_2l[i];
}
}
/* Set RI */
if (ri != NULL) {
*ri = (best_sinr_1l > best_sinr_2l) ? 1 : 2;
}
/* Set PMI */
if (pmi != NULL) {
*pmi = (best_sinr_1l > best_sinr_2l) ? best_pmi_1l : best_pmi_2l;
}
/* Set current SINR */
if (current_sinr != NULL && cfg->mimo_type == SRSLTE_MIMO_TYPE_SPATIAL_MULTIPLEX) {
if (cfg->nof_layers == 1) {
*current_sinr = sinr_1l[cfg->codebook_idx];
} else if (cfg->nof_layers == 2) {
*current_sinr = sinr_2l[cfg->codebook_idx - 1];
} else {
ERROR("Not implemented number of layers");
return SRSLTE_ERROR;
}
}
/* Print Trace */
if (ri != NULL && pmi != NULL && current_sinr != NULL) {
INFO("PDSCH Select RI=%d; PMI=%d; Current SINR=%.1fdB (nof_layers=%d, codebook_idx=%d)\n", *ri, *pmi,
10*log10(*current_sinr), cfg->nof_layers, cfg->codebook_idx);
} }
} else { } else {
ERROR("Not implemented configuration"); ERROR("Not implemented configuration");
@ -981,28 +822,9 @@ int srslte_pdsch_encode_multi(srslte_pdsch_t *q,
return SRSLTE_ERROR_INVALID_INPUTS; return SRSLTE_ERROR_INVALID_INPUTS;
} }
#ifndef SRSLTE_SINGLE_THREAD
for (int tb = 0; tb < cfg->grant.nof_tb; tb++) {
srslte_pdsch_thread_args_t *thread_args = &q->thread_args[tb];
thread_args->cfg = cfg;
thread_args->softbuffer = &softbuffers[tb];
thread_args->data = data[tb];
thread_args->rnti = rnti;
sem_post(&thread_args->start);
}
for (int tb = 0; tb < cfg->grant.nof_tb; tb++) {
srslte_pdsch_thread_args_t *thread_args = &q->thread_args[tb];
sem_wait(&thread_args->finish);
ret |= thread_args->ret_status;
}
#else
for (uint32_t tb = 0; tb < cfg->grant.nof_tb; tb ++) { for (uint32_t tb = 0; tb < cfg->grant.nof_tb; tb ++) {
ret |= srslte_pdsch_codeword_encode(q, cfg, &softbuffers[tb], rnti, data[tb], tb); ret |= srslte_pdsch_codeword_encode(q, cfg, &softbuffers[tb], rnti, data[tb], tb);
} }
#endif /* SRSLTE_SINGLE_THREAD */
if (q->cell.nof_ports > 1) { if (q->cell.nof_ports > 1) {
int nof_symbols; int nof_symbols;

@ -454,9 +454,58 @@ int srslte_ue_dl_decode_rnti_multi(srslte_ue_dl_t *q, cf_t *input[SRSLTE_MAX_POR
int srslte_ue_dl_ri_pmi_select(srslte_ue_dl_t *q, uint32_t *ri, uint32_t *pmi, float *current_sinr) { int srslte_ue_dl_ri_pmi_select(srslte_ue_dl_t *q, uint32_t *ri, uint32_t *pmi, float *current_sinr) {
float noise_estimate = srslte_chest_dl_get_noise_estimate(&q->chest); float noise_estimate = srslte_chest_dl_get_noise_estimate(&q->chest);
return srslte_pdsch_ri_pmi_select(&q->pdsch, &q->pdsch_cfg, q->ce_m, noise_estimate, float best_sinr = -INFINITY;
SRSLTE_SF_LEN_RE(q->cell.nof_prb, q->cell.cp), uint32_t best_pmi = 0, best_ri = 0;
ri, pmi, current_sinr);
if (q->cell.nof_ports == 2 && q->nof_rx_antennas == 2) {
if (srslte_pdsch_pmi_select(&q->pdsch, &q->pdsch_cfg, q->ce_m, noise_estimate,
SRSLTE_SF_LEN_RE(q->cell.nof_prb, q->cell.cp), q->pmi, q->sinr)) {
ERROR("SINR calculation error");
return SRSLTE_ERROR;
}
/* Select the best Rank indicator (RI) and Precoding Matrix Indicator (PMI) */
for (uint32_t nof_layers = 1; nof_layers <= q->pdsch_cfg.nof_layers; nof_layers++ ) {
if (q->sinr[nof_layers][q->pmi[nof_layers]] > best_sinr) {
best_sinr = q->sinr[nof_layers][q->pmi[nof_layers]];
best_pmi = q->pmi[nof_layers];
best_ri = nof_layers;
}
}
/* Set RI */
if (ri != NULL) {
*ri = best_ri;
}
/* Set PMI */
if (pmi != NULL) {
*pmi = best_pmi;
}
/* Set current SINR */
if (current_sinr != NULL && q->pdsch_cfg.mimo_type == SRSLTE_MIMO_TYPE_SPATIAL_MULTIPLEX) {
if (q->pdsch_cfg.nof_layers == 1) {
*current_sinr = q->sinr[0][q->pdsch_cfg.codebook_idx];
} else if (q->pdsch_cfg.nof_layers == 2) {
*current_sinr = q->sinr[1][q->pdsch_cfg.codebook_idx - 1];
} else {
ERROR("Not implemented number of layers");
return SRSLTE_ERROR;
}
}
/* Print Trace */
if (ri != NULL && pmi != NULL && current_sinr != NULL) {
INFO("PDSCH Select RI=%d; PMI=%d; Current SINR=%.1fdB (nof_layers=%d, codebook_idx=%d)\n", *ri, *pmi,
10*log10(*current_sinr), q->pdsch_cfg.nof_layers, q->pdsch_cfg.codebook_idx);
}
} else {
ERROR("Not implemented configuration");
return SRSLTE_ERROR_INVALID_INPUTS;
}
return SRSLTE_SUCCESS;
} }
uint32_t srslte_ue_dl_get_ncce(srslte_ue_dl_t *q) { uint32_t srslte_ue_dl_get_ncce(srslte_ue_dl_t *q) {

Loading…
Cancel
Save