nrLDPC_load.c 4.51 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */

/*! \file openair1/PHY/CODING/coding_nr_load.c
 * \brief: load library implementing coding/decoding algorithms
 * \author Francois TABURET
 * \date 2020
 * \version 0.1
 * \company NOKIA BellLabs France
 * \email: francois.taburet@nokia-bell-labs.com
 * \note
 * \warning
 */
#define _GNU_SOURCE 
#include <sys/types.h>
#include <stdlib.h>
#include <malloc.h>
#include "assertions.h"
#include "common/utils/LOG/log.h"
#define LDPC_LOADER
#include "PHY/CODING/nrLDPC_extern.h"
#include "common/config/config_userapi.h" 
#include "common/utils/load_module_shlib.h" 


/* function description array, to be used when loading the encoding/decoding shared lib */
45 46 47 48
static loader_shlibfunc_t shlib_fdesc[3];

/* arguments used when called from phy simulators exec's which do not use the config module */
/* arg is used to initialize the config module so that the loader works as expected */
49
char *arg[64]={"ldpctest",NULL};
50

51
int load_nrLDPClib(char *version) {
52
	 char *ptr = (char*)config_get_if();
53
	 char libname[64]="ldpc";
54

55
     if ( ptr==NULL )  {// phy simulators, config module possibly not loaded
56
     	 load_configmodule(1,arg,CONFIG_ENABLECMDLINEONLY) ;
57 58 59 60
     	 logInit();
     }	 
     shlib_fdesc[0].fname = "nrLDPC_decod";
     shlib_fdesc[1].fname = "nrLDPC_encod";
frtabu's avatar
frtabu committed
61
     shlib_fdesc[2].fname = "nrLDPC_initcall";
62 63 64 65 66
     int ret;
     if (version)
       ret=load_module_version_shlib(libname,version,shlib_fdesc,sizeof(shlib_fdesc)/sizeof(loader_shlibfunc_t),NULL);
     else
       ret=load_module_shlib(libname,shlib_fdesc,sizeof(shlib_fdesc)/sizeof(loader_shlibfunc_t),NULL);
67 68 69
     AssertFatal( (ret >= 0),"Error loading ldpc decoder");
     nrLDPC_decoder = (nrLDPC_decoderfunc_t)shlib_fdesc[0].fptr;
     nrLDPC_encoder = (nrLDPC_encoderfunc_t)shlib_fdesc[1].fptr;
frtabu's avatar
frtabu committed
70
     nrLDPC_initcall = (nrLDPC_initcallfunc_t)shlib_fdesc[2].fptr;
71 72 73
return 0;
}

74 75 76 77
int load_nrLDPClib_offload(void) {
     loader_shlibfunc_t shlib_decoffload_fdesc; 
     
     shlib_decoffload_fdesc.fname = "nrLDPC_decod_offload";
78
     int ret=load_module_shlib("ldpc_t1",&shlib_decoffload_fdesc,1,NULL);
79 80 81
     AssertFatal( (ret >= 0),"Error loading ldpc decoder offload");
     nrLDPC_decoder_offload = (nrLDPC_decoffloadfunc_t)shlib_decoffload_fdesc.fptr;

82 83 84 85 86 87 88 89
  t_nrLDPC_dec_params decParams;
  t_nrLDPC_dec_params* p_decParams    = &decParams;
  int8_t   l[68*384];
  int8_t llrProcBuf[22*384];

  p_decParams->Z = 384;
  p_decParams->BG = 1;

90
  AssertFatal(nrLDPC_decoder_offload(p_decParams,0, 0,
91 92 93 94 95 96
				     1,
				     0,
				     0,
				     25344,
				     8,
				     l, 
97
				     llrProcBuf, 0)>=0,
98 99 100 101
	      "error loading LDPC decoder offload library\n");


  return 0;
102 103
}

104 105 106 107 108 109 110 111 112
int free_nrLDPClib_offload(void) {
t_nrLDPC_dec_params decParams;
  t_nrLDPC_dec_params* p_decParams    = &decParams;
  int8_t   l[68*384];
  int8_t llrProcBuf[22*384];

  p_decParams->Z = 384;
  p_decParams->BG = 1;

113
  nrLDPC_decoder_offload(p_decParams,0,0,
114 115 116 117 118 119 120 121 122 123
                        1,
                        0,
                        0,
                        25344,
                        8,
                        l,
                        llrProcBuf, 2);
return 0;
}

124 125 126 127
int load_nrLDPClib_ref(char *libversion, nrLDPC_encoderfunc_t * nrLDPC_encoder_ptr) {
	loader_shlibfunc_t shlib_encoder_fdesc;

     shlib_encoder_fdesc.fname = "nrLDPC_encod";
128 129
     int ret=load_module_version_shlib("ldpc",libversion,&shlib_encoder_fdesc,1,NULL);
     AssertFatal( (ret >= 0),"Error loading ldpc encoder %s\n",(libversion==NULL)?"":libversion);
130 131 132 133 134
     *nrLDPC_encoder_ptr = (nrLDPC_encoderfunc_t)shlib_encoder_fdesc.fptr;
return 0;
}