# Rebuild OSC o-du-phy project using gcc
There are 3 subprojects need to be compiled into single:
1. [fhi_lib](#fhi_lib)
2. [wls_lib](#wls_lib)
3. [fapi_5g](#fapi_5g)
## fhi_lib
---
### 1. Testing compile DPDK using gcc toolchain (4/8)
Testing compile DPDK by changing gcc on local.
```
bee@bee:~$ wget https://fast.dpdk.org/rel/dpdk-19.11.9.tar.xz
bee@bee:~$ tar xvf dpdk-19.11.9.tar.xz
bee@bee:~$ cd dpdk-stable-19.11.9
bee@bee:~/dpdk-stable-19.11.9$ make install T=x86_64-native-linuxapp-gcc
```
ref: https://doc.dpdk.org/guides-2.1/linux_gsg/build_dpdk.html
wait until the build process end with:
```
...
Build complete [x86_64-native-linuxapp-gcc]
Installation cannot run with T defined and DESTDIR undefined
```
make sure local CPU has x86 architecture, otherwise there will be error as shown below:

### 2. Implement the same method to o-du-phy repo (6/8)
#### 1st attempt
Made required changes on o-du-phy repo https://gerrit.o-ran-sc.org/r/admin/repos/o-du/phy .
Change Dockerfile based on the same method when testing compile DPDK.
Dockerfile:

The build process was failed

#### 2nd attempt
Manually change **RTE_TARGET** value from ***x86_64-native-linux-icc*** to ***x86_64-native-linux-gcc*** to make sure initiation process gets the ENV var inside Makefile.
Makefile:

But the build process also failed with similar error message:

#### 3rd attempt
>
> ...
> Replace with the loading of the redistributable run time library for icc available from the following link IntelĀ® C++ and Fortran Compilers Redistributable Libraries by Version.
> [name=Luis Farias] [time=Sun, Jun 13, 2021 9:59 PM] [color=#907bf7]
Follows installation instruction on https://software.intel.com/content/www/us/en/develop/articles/redistributable-libraries-for-intel-c-and-fortran-2020-compilers-for-linux.html
```
bee@bee:~/$ wget https://registrationcenter-download.intel.com/akdlm/irc_nas/17113/l_comp_lib_2020.4.304_comp.cpp_redist.tgz
bee@bee:~/$ tar -zxvf $BUILD_DIR/l_comp_lib_2020.4.304_comp.cpp_redist.tgz
bee@bee:~/$ cd l_comp_lib_2020.4.304_comp.cpp_redist/
```
Redistributable libraries folder doesn't have ready-to-use icc binary
Tree directory:
```
.
|-- bin
| |-- compilervars.csh
| `-- compilervars.sh
|-- compilers_and_libraries_2020.4.304
| `-- linux
| |-- compiler
| | `-- lib
| | |-- ia32_lin
| | | |-- cilk_db.so
| | | |-- libchkp.so
| | | |-- libcilkrts.so
| | | |-- libcilkrts.so.5
| | | |-- libimf.so
| | | |-- libintlc.so
| | | |-- libintlc.so.5
| | | |-- libiomp5.so
| | | |-- libiomp5_db.so
| | | |-- libiompstubs5.so
| | | |-- libirc.so
| | | |-- libirng.so
| | | |-- libistrconv.so
| | | |-- libpdbx.so
| | | |-- libpdbx.so.5
| | | `-- libsvml.so
| | `-- intel64_lin
| | |-- cilk_db.so
| | |-- libchkp.so
| | |-- libcilkrts.so
| | |-- libcilkrts.so.5
| | |-- libimf.so
| | |-- libintlc.so
| | |-- libintlc.so.5
| | |-- libiomp5.so
| | |-- libiomp5_db.so
| | |-- libiompstubs5.so
| | |-- libirc.so
| | |-- libirng.so
| | |-- libistrconv.so
| | |-- libpdbx.so
| | |-- libpdbx.so.5
| | |-- libqkmalloc.so
| | `-- libsvml.so
| `-- lib
| |-- icx-lto.so
| |-- libomp-cmath-fp64.o
| |-- libomp-cmath.o
| |-- libomp-complex-fp64.o
| |-- libomp-complex.o
| |-- libomp-fallback-cassert.spv
| |-- libomp-fallback-cmath-fp64.spv
| |-- libomp-fallback-cmath.spv
| |-- libomp-fallback-complex-fp64.spv
| |-- libomp-fallback-complex.spv
| |-- libomp-glibc.o
| |-- libomptarget-opencl.bc
| |-- libomptarget-spirvdevicertl.o
| |-- libomptarget.rtl.level0.so
| |-- libomptarget.rtl.opencl.so
| |-- libomptarget.rtl.x86_64.so
| |-- libomptarget.so
| |-- libpi_level_zero.so
| |-- libpi_opencl.so
| |-- libsycl-cmath-fp64.o
| |-- libsycl-cmath.o
| |-- libsycl-complex-fp64.o
| |-- libsycl-complex.o
| |-- libsycl-fallback-cassert.o
| |-- libsycl-fallback-cassert.spv
| |-- libsycl-fallback-cmath-fp64.o
| |-- libsycl-fallback-cmath-fp64.spv
| |-- libsycl-fallback-cmath.o
| |-- libsycl-fallback-cmath.spv
| |-- libsycl-fallback-complex-fp64.o
| |-- libsycl-fallback-complex-fp64.spv
| |-- libsycl-fallback-complex.o
| |-- libsycl-fallback-complex.spv
| |-- libsycl-fallback-intel-dot-product.o
| |-- libsycl-fallback-intel-dot-product.spv
| |-- libsycl-glibc.o
| |-- libsycl-intel-dot-product.o
| |-- libsycl.so -> ./libsycl.so.3
| |-- libsycl.so.3 -> ./libsycl.so.3.0.0
| |-- libsycl.so.3.0.0
| |-- libsycl.so.3.0.0-gdb.py
| `-- sycl.conf
|-- credist
|-- install.sh
`-- license.txt
```
Since there is a possibility that redistributable will be used as dependencies, retry building Dockerfile is required.
Changes was made in Dockerfile.
Dockerfile:

The same result shows that failure happened when building xRAN library.

Take a closer look on *fhi_lib* project repository and found out that a section inside Makefile to set tools configuration value set to ***icc*** hard-coded-ly

---
### Update by email from intel engineer (10/8)
>
> ...
> Hi Franciscus:
The link that I provided was for the run-time libraries required when running the L1 binary that we provide in github.
The short-term plan was to replace icc with gcc for the oran fhi lib and the fapi tm.
Thanks
Luis
> [name=Luis Farias] [time=Sun, Aug 8, 2021 11:06 PM] [color=#907bf7]
Intel engineer replied that the runtime redistributable is required when running the L1 binary that we provide in github.
So what i need to do is to change the toolchain(icc to gcc) and adjust related parameter.
### Discussion with bmw member (11/8)
Previously i have asked Jonathan to clarify whether our lab has been doing convertion from icc to gcc but according to him, there was no previous task related to it.
I also have discussed with shuhua about the same thing and the though that no ones has ever done it before.
### Modify Makefile in fhi_lib subproject (13/8)
#### Tools configuration
Original
```
##############################################################
# Tools configuration
##############################################################
CC := icc
CPP := icpc
AS := as
AR := ar
LD := icc
OBJDUMP := objdump
```
After modified
```
##############################################################
# Tools configuration
##############################################################
CC := gcc
CPP := gcc
AS := as
AR := ar
LD := icc
OBJDUMP := objdump
```
After modify the Makefile and run ***docker build*** command, there was an error due to using false flag
**Issue 1:**
:::danger
```
============================================================================================
Building ./build/libxran.so
RTE_TARGET = x86_64-native-linuxapp-gcc
============================================================================================
[BUILD] lib : libxran
[DEP] libxran.dep
gcc: error: unrecognized command line option '-wd1786'
make: *** [__dep__/opt/o-du/phy/fhi_lib/lib/ethernet/ethdi.c] Error 1
"make $COMMAND_LINE MLOG=${MLOG} LIBXRANSO=${LIBXRANSO}" command exited with code 2.
The command '/bin/sh -c cd $BUILD_DIR/fhi_lib/ && export XRAN_LIB_SO=1 && ./build.sh xclean && ./build.sh && cd app && octave gen_test.m' returned a non-zero code: 2
```
:::
The reason is **CC_FLAGS** has unrecognized args **-wd1786**
```
CC_FLAGS += -std=gnu11 -Wall -Wno-deprecated-declarations \
-fdata-sections \
-ffunction-sections \
-g \
-fPIC \
-Wall \
-Wimplicit-function-declaration \
-g -O3 -wd1786
```
Where -wd has function to disable the specified diagnostics.
Output of icc -help:
:::info
```
Deprecated Options
------------------
-use-asm No replacement
-qopt-report [n] use -qopt-report[=n]
-cilk-serialize No replacement
-qcf-protection=shadow_stack use -fcf-protection=return
-qcf-protection=branch_tracking use -fcf-protection=branch
-qcf-protection=[full|none] use -fcf-protection=[full|none]
-march=icelake use -march=icelake-client
-mtune=icelake use -mtune=icelake-client
-mcpu=icelake use -mcpu=icelake-client
-xICELAKE use -xICELAKE-CLIENT
-axICELAKE use -axICELAKE-CLIENT
-Kc++ use -x c++
-wn use -diag-error-limit
-wd use -diag-disable
-we use -diag-error
-ww use -diag-warning
-wr use -diag-remark
-wo use -diag-once
-std=c9x use -std=c99
-rcd No replacement
---
-diag-disable=<v1>[,<v2>,...]
disable the specified diagnostics or diagnostic groups
where <vN> may be individual diagnostic numbers or group names.
where group names include:
thread - diagnostics to aid in thread-enabling source
power - controls whether diagnostics are enabled for
possibly inefficient code that may affect power
consumption when running on Intel(R) processors
port-win - diagnostics for GNU extensions that may
cause errors when porting to Windows
openmp - diagnostics issued by the OpenMP* parallelizer
warn - diagnostics that have "warning" severity level
error - diagnostics that have "error" severity level
remark - diagnostics that are remarks or comments
vec - diagnostics issued by the vectorizer
par - diagnostics issued by the auto-parallelizer
cpu-dispatch
- specifies the CPU dispatch remarks
```
:::
**Issue 2:**
I decided to try remove ***-wd1786*** and found that it passed the build process.
However i have another issue in [tools configuration](https://hackmd.io/Q4HhwRgtRXOQs4gn-ptzgw#Tools-configuration) that is related to **icpc** used by **CPP** resulting another flags issue.
Since cpp files requires **icpc** to compile, all given args is unrecognized by **gcc**.
```
CPP_FLAGS := -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -D_REENTRANT -pipe -no-prec-div \
-no-prec-div -fp-model fast=2 -fPIC \
-no-prec-sqrt -falign-functions=16 -fast-transcendentals \
-Werror -Wno-unused-variable -std=c++11 -mcmodel=large
```
Output:
:::danger
```
============================================================================================
Building ./build/libxran.so
RTE_TARGET = x86_64-native-linuxapp-gcc
============================================================================================
[BUILD] lib : libxran
[DEP] libxran.dep
gcc: error: fast=2: No such file or directory
gcc: warning: '-x core-avx512' after last input file has no effect
gcc: error: unrecognized command line option '-no-prec-div'
gcc: error: unrecognized command line option '-no-prec-div'
gcc: error: unrecognized command line option '-fp-model'
gcc: error: unrecognized command line option '-no-prec-sqrt'
gcc: error: unrecognized command line option '-fast-transcendentals'
gcc: error: unrecognized command line option '-restrict'
gcc: error: unrecognized command line option '-fasm-blocks'
make: *** [__dep__/opt/o-du/phy/fhi_lib/lib/src/xran_compression.cpp] Error 1
"make $COMMAND_LINE MLOG=${MLOG} LIBXRANSO=${LIBXRANSO}" command exited with code 2.
The command '/bin/sh -c cd $BUILD_DIR/fhi_lib/ && export XRAN_LIB_SO=1 && ./build.sh xclean && ./build.sh && cd app && octave gen_test.m' returned a non-zero code: 2
```
:::
But if the icpc is remain, another error shows up
Output:
:::danger
```
============================================================================================
Building ./build/libxran.so
RTE_TARGET = x86_64-native-linuxapp-gcc
============================================================================================
[BUILD] lib : libxran
[DEP] libxran.dep
/bin/sh: icpc: command not found
make: *** [__dep__/opt/o-du/phy/fhi_lib/lib/src/xran_compression.cpp] Error 127
"make $COMMAND_LINE MLOG=${MLOG} LIBXRANSO=${LIBXRANSO}" command exited with code 2.
The command '/bin/sh -c cd $BUILD_DIR/fhi_lib/ && export XRAN_LIB_SO=1 && ./build.sh xclean && ./build.sh && cd app && octave gen_test.m' returned a non-zero code: 2
```
:::
### Is it possible to mapping icpc optimize option to gcc?
Optimize options on icpc:
```yaml=
-no-prec-div
-fp-model
-no-prec-sqrt
-restrict
-fast-transcendentals
-fasm-block
```
TODO:
1. ~~Look for both documentation on similar option definition.~~
2. ~~Ask expert to clarify~~
3. ~~Integrate Intel OneAPI on Dockerfile~~
## wls_lib
## fapi_5g
## IMPORTANT NOTES
**Comment from Prof. Ray:**
Since the issue is too complex and our lab doesn't have previous experience related to this, intel needs to solve replacing icc with gcc by themself and we can help with CI integration if needed.