* INTC Contribution to the O-RAN F Release for O-DU Low
[o-du/phy.git] / fhi_lib / test / test_xran / Makefile
1 #/******************************************************************************
2 #*
3 #*   Copyright (c) 2020 Intel.
4 #*
5 #*   Licensed under the Apache License, Version 2.0 (the "License");
6 #*   you may not use this file except in compliance with the License.
7 #*   You may obtain a copy of the License at
8 #*
9 #*       http://www.apache.org/licenses/LICENSE-2.0
10 #*
11 #*   Unless required by applicable law or agreed to in writing, software
12 #*   distributed under the License is distributed on an "AS IS" BASIS,
13 #*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #*   See the License for the specific language governing permissions and
15 #*   limitations under the License.
16 #*
17 #*******************************************************************************/
18
19
20 .SUFFIXES: .o .c .s .i .cpp
21
22 ##############################################################
23 #  Tools configuration
24 ##############################################################
25 ifeq ($(WIRELESS_SDK_TOOLCHAIN),icc)
26 CC  := icc
27 CXX := icpc
28 CPP := icpc
29 AS := as
30 AR := ar
31 LD := icc
32 else ifeq ($(WIRELESS_SDK_TOOLCHAIN),icx)
33     CC  := icx
34     CXX := icpx
35     CPP := icpx
36     AS  := as
37     AR  := llvm-ar
38     LD  := icx
39 else
40     $(error "Please define WIRELESS_SDK_TOOLCHAIN environment variable")
41 endif
42
43 OBJDUMP := objdump
44
45 ifeq ($(SHELL),cmd.exe)
46 MD := mkdir.exe -p
47 CP := cp.exe -f
48 RM := rm.exe -rf
49 else
50 MD := mkdir -p
51 CP := cp -f
52 RM := rm -rf
53 endif
54 TARGET_PROCESSOR =
55
56 ifeq ($(WIRELESS_SDK_TOOLCHAIN),icx)
57         ifeq ($(WIRELESS_SDK_TARGET_ISA),sse)
58                 TARGET_PROCESSOR := -xSSE4.2
59         else ifeq ($(WIRELESS_SDK_TARGET_ISA),avx2)
60                 TARGET_PROCESSOR := -xCORE-AVX2
61         else ifeq ($(WIRELESS_SDK_TARGET_ISA),avx512)
62                 TARGET_PROCESSOR := -xCORE-AVX512
63         else ifeq ($(WIRELESS_SDK_TARGET_ISA),snc)
64                 TARGET_PROCESSOR := -xicelake-server
65         else ifeq ($(WIRELESS_SDK_TARGET_ISA),spr)
66                 TARGET_PROCESSOR := -march=sapphirerapids
67         endif
68
69         ifeq ($(TARGET_PROCESSOR),)
70                 $(error "Please define valid WIRELESS_SDK_TARGET_ISA environment variable $(WIRELESS_SDK_TARGET_ISA)")
71         endif
72 endif
73
74 ifeq ($(RTE_SDK),)
75     $(error "Please define RTE_SDK environment variable")
76 endif
77
78 ifeq ($(MLOG_DIR),)
79     MLOG_DIR=$(XRAN_DIR)/../mlog
80 endif
81
82 RTE_LIBS = $(shell PKG_CONFIG_PATH=/usr/lib64/pkgconfig:$(RTE_SDK)/build/meson-uninstalled pkgconf --static --libs libdpdk)
83 RTE_INC := $(shell PKG_CONFIG_PATH=/usr/lib64/pkgconfig:$(RTE_SDK)/build/meson-uninstalled pkgconf --cflags-only-I libdpdk)
84
85 # Where to find user code.
86 COMMON_TEST_DIR = $(XRAN_DIR)/test/common
87 USER_DIR = $(XRAN_DIR)/lib/src
88 USER_ETH = $(XRAN_DIR)/lib/ethernet
89 USER_API = $(XRAN_DIR)/lib/api
90
91 # Flags passed to the preprocessor.
92 # Set Google Test's header directory as a system directory, such that
93 # the compiler doesn't generate warnings in Google Test headers.
94 CPPFLAGS += -isystem $(GTEST_ROOT)/include -Wno-unused-variable
95
96 # Flags passed to the C++ compiler.
97 CXXFLAGS += -g -std=c++14 -pthread  -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D_GNU_SOURCE -D_REENTRANT -pipe  -mcmodel=large -Wno-unused-variable -fPIC \
98     -falign-functions=16 $(TARGET_PROCESSOR) -I$(USER_API) -I$(USER_DIR) -I$(USER_ETH) -I$(MLOG_DIR)/source -I $(COMMON_TEST_DIR) -I$(RTE_INC)
99
100
101
102 # All tests produced by this Makefile.  Remember to add new tests you
103 # created to the list.
104 TESTS = unittests
105
106 # All Google Test headers.  Usually you shouldn't change this
107 # definition.
108 GTEST_HEADERS = $(GTEST_ROOT)/include/gtest/*.h \
109                 $(GTEST_ROOT)/include/gtest/internal/*.h
110
111 CFLAGS += -std=gnu11 -Wall -Wno-deprecated-declarations \
112         -fdata-sections \
113         -ffunction-sections \
114         -g \
115         -Wall \
116         -Wimplicit-function-declaration  \
117         -mcmodel=large \
118         -Wno-unused-variable \
119         -Wno-unused-parameter \
120         $(TARGET_PROCESSOR) \
121         -I$(USER_API) -I$(USER_DIR) -I$(USER_ETH) -I$(MLOG_DIR)/source -I$(RTE_INC)
122
123 ifeq ($(WIRELESS_SDK_TOOLCHAIN),icc)
124 CXXFLAGS += -Wall -Wextra
125 CFLAGS += -wd1786 -restrict
126 endif
127
128 ifeq ($(WIRELESS_SDK_TOOLCHAIN),icx)
129 CFLAGS += -mintrinsic-promote -Wno-intrinsic-promote -Wno-error -Wno-unused-but-set-variable
130 endif
131
132
133 C_SRC = \
134         $(USER_ETH)/ethdi.c \
135         $(USER_ETH)/ethernet.c \
136         $(USER_DIR)/xran_up_api.c \
137         $(USER_DIR)/xran_sync_api.c \
138         $(USER_DIR)/xran_timer.c \
139         $(USER_DIR)/xran_cp_api.c \
140         $(USER_DIR)/xran_transport.c \
141         $(USER_DIR)/xran_common.c \
142         $(USER_DIR)/xran_ul_tables.c \
143         $(USER_DIR)/xran_frame_struct.c \
144         $(USER_DIR)/xran_dev.c \
145         $(USER_DIR)/xran_rx_proc.c      \
146         $(USER_DIR)/xran_tx_proc.c      \
147         $(USER_DIR)/xran_cp_proc.c      \
148         $(USER_DIR)/xran_cb_proc.c      \
149         $(USER_DIR)/xran_mem_mgr.c      \
150         $(USER_DIR)/xran_main.c \
151     $(USER_DIR)/xran_delay_measurement.c
152
153 CC_SRC = \
154         $(COMMON_TEST_DIR)/xranlib_unit_test_main.cc \
155         c_plane_tests.cc \
156         chain_tests.cc \
157         prach_functional.cc \
158         prach_performance.cc \
159         u_plane_functional.cc \
160         u_plane_performance.cc \
161         init_sys_functional.cc \
162         compander_functional.cc \
163         mod_compression_unit_test.cc \
164         unittests.cc
165
166 #       u_plane_performance.cc \
167
168 CPP_SRC = $(COMMON_TEST_DIR)/common.cpp \
169         $(USER_DIR)/xran_compression.cpp \
170         $(USER_DIR)/xran_bfp_ref.cpp \
171         $(USER_DIR)/xran_bfp_cplane8.cpp \
172         $(USER_DIR)/xran_bfp_cplane16.cpp \
173         $(USER_DIR)/xran_bfp_cplane32.cpp \
174         $(USER_DIR)/xran_bfp_cplane64.cpp \
175         $(USER_DIR)/xran_bfp_uplane_9b16rb.cpp \
176         $(USER_DIR)/xran_bfp_uplane.cpp \
177         $(USER_DIR)/xran_mod_compression.cpp
178
179 CPP_SRC_SNC = $(USER_DIR)/xran_compression_snc.cpp \
180         $(USER_DIR)/xran_bfp_cplane8_snc.cpp \
181         $(USER_DIR)/xran_bfp_cplane16_snc.cpp \
182         $(USER_DIR)/xran_bfp_cplane32_snc.cpp \
183         $(USER_DIR)/xran_bfp_cplane64_snc.cpp \
184         $(USER_DIR)/xran_bfp_uplane_snc.cpp
185
186
187 C_OBJS := $(patsubst %.c,%.o,$(C_SRC))
188 CC_OBJS := $(patsubst %.cc,%.o,$(CC_SRC))
189 CPP_OBJS := $(patsubst %.cpp,%.o,$(CPP_SRC))
190 CPP_SNC_OBJS := $(patsubst %.cpp,%.o,$(CPP_SRC_SNC))
191
192 CPPFLAGS += -I$(USER_DIR) -I$(USER_API)
193
194 #-qopt-report=5 -qopt-matmul -qopt-report-phase=all
195 CPP_COMP := -O3 -DNDEBUG  -xcore-avx512 -fPIE -fasm-blocks
196 CPP_COMP_SNC := -O3 -DNDEBUG -march=icelake-server -fPIE -fasm-blocks
197
198 ifeq ($(WIRELESS_SDK_TOOLCHAIN),icc)
199 CPP_COMP += -fp-model fast=2 -no-prec-div -no-prec-sqrt -fast-transcendentals -restrict
200 CPP_COMP_SNC += -fp-model fast=2 -no-prec-div -no-prec-sqrt -fast-transcendentals -restrict
201 endif
202
203 ifeq ($(WIRELESS_SDK_TOOLCHAIN),icx)
204 CPP_COMP += -fp-model fast -mintrinsic-promote -Wno-intrinsic-promote -Wno-error -Wno-unused-variable
205 CPP_COMP_SNC += -fp-model fast -mintrinsic-promote -Wno-intrinsic-promote -Wno-error -Wno-unused-variable
206 endif
207
208 CPP_COMP := $(CPP_COMP)
209 CPP_COMP_SNC := $(CPP_COMP_SNC)
210
211 ifeq ($(GEN_ASM), 1)
212 CPP_ASMS := $(patsubst %.cpp,%.asm,$(CPP_SRC))
213 CPP_SNC_ASMS := $(patsubst %.cpp,%.asm,$(CPP_SRC_SNC))
214 CPP_COMP += -qopt-report=5 -qopt-matmul -qopt-report-phase=all
215 CPP_COMP_SNC += -qopt-report=5 -qopt-matmul -qopt-report-phase=all
216 endif
217
218 PROJECT_DEP_FILE := $(TESTS).dep
219
220 ifeq ($(wildcard $(PROJECT_DEP_FILE)),$(PROJECT_DEP_FILE))
221 GENERATE_DEPS :=
222 else
223 C_DEPS  := $(addprefix __dep__,$(subst ../,__up__,$(C_SRC)))
224 CC_DEPS  := $(addprefix __dep__,$(subst ../,__up__,$(CC_SRC)))
225 CPP_DEPS  := $(addprefix __dep__,$(subst ../,__up__,$(CPP_SRC)))
226 CPP_SNC_DEPS  := $(addprefix __dep__,$(subst ../,__up__,$(CPP_SRC_SNC)))
227 GENERATE_DEPS := generate_deps
228 endif
229
230
231 # House-keeping build targets.
232 all : echo_start_build $(GENERATE_DEPS) $(TESTS)
233
234 clean :
235         @echo [CLEAN]
236         @$(RM) -f $(TESTS) *.o $(COMMON_TEST_DIR)/*.o $(USER_DIR)/*.o $(USER_ETH)/*.o \
237         *.asm $(COMMON_TEST_DIR)/*.asm $(USER_DIR)/*.asm $(USER_ETH)/*.asm \
238         *.asm $(COMMON_TEST_DIR)/*.asm2 $(USER_DIR)/*.asm2 $(USER_ETH)/*.asm2 \
239         *.optrpt $(COMMON_TEST_DIR)/*.optrpt $(USER_DIR)/*.optrpt $(USER_ETH)/*.optrpt;\
240         $(RM) $(PROJECT_DEP_FILE)
241
242 .PHONY: xclean
243 xclean: clean
244
245 .PHONY : clear_dep
246 clear_dep:
247         @$(RM) $(PROJECT_DEP_FILE)
248         @echo [DEP] $(PROJECT_DEP_FILE)
249
250 $(C_DEPS) :
251         @$(CC) -MM $(subst __up__,../,$(subst __dep__,,$@)) -MT $(patsubst %.c,%.o,$(subst __up__,../,$(subst __dep__,,$@))) $(CFLAGS)  >> $(PROJECT_DEP_FILE)
252
253 $(CC_DEPS) :
254         @$(CC) -MM $(subst __up__,../,$(subst __dep__,,$@)) -MT $(patsubst %.cc,%.o,$(subst __up__,../,$(subst __dep__,,$@))) $(CPPFLAGS) $(CXXFLAGS) >> $(PROJECT_DEP_FILE)
255
256 $(CPP_DEPS) :
257         @$(CPP) -MM $(subst __up__,../,$(subst __dep__,,$@)) -MT $(patsubst %.cpp,%.o,$(subst __up__,../,$(subst __dep__,,$@))) $(CPPFLAGS) $(CXXFLAGS) $(CPP_COMP) >> $(PROJECT_DEP_FILE)
258
259 $(CPP_SNC_DEPS) :
260         @$(CPP) -MM $(subst __up__,../,$(subst __dep__,,$@)) -MT $(patsubst %.cpp,%.o,$(subst __up__,../,$(subst __dep__,,$@))) $(CPPFLAGS) $(CXXFLAGS) $(CPP_COMP_SNC) >> $(PROJECT_DEP_FILE)
261
262 .PHONY : generate_deps
263 generate_deps : clear_dep $(C_DEPS) $(CC_DEPS) $(CPP_DEPS) $(CPP_SNC_DEPS)
264
265 ifeq ($(wildcard $(PROJECT_DEP_FILE)),$(PROJECT_DEP_FILE))
266
267 include $(PROJECT_DEP_FILE)
268
269 endif
270
271 .PHONY : echo_start_build
272 echo_start_build :
273         @echo Build Tests with
274         @echo $(USER_DIR)
275         @echo $(USER_API)
276
277 $(CC_OBJS) : $(CC_SRC)
278         @echo "[CC] $@"
279         @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o"$@" $(patsubst %.o,%.cc,$@)
280
281 $(CPP_ASMS) :
282         @echo "[CPP->ASM] $@"
283         @$(CXX) -S $(CPPFLAGS) $(CXXFLAGS) $(CPP_COMP) -fsource-asm -save-temps -o"$@" $(patsubst %.asm,%.cpp,$@)
284         @cat $@ | grep -v '^..LN' |grep -v '    .loc' > $@2
285
286 $(CPP_OBJS) : $(CPP_ASMS)
287         @echo "[CPP] $@"
288         @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CPP_COMP) -o"$@" $(patsubst %.o,%.cpp,$@)
289
290 $(CPP_SNC_ASMS) :
291         @echo "[CPP-SNC->ASM] $@"
292         @$(CXX) -S $(CPPFLAGS) $(CXXFLAGS) $(CPP_COMP_SNC) -fsource-asm -save-temps -o"$@" $(patsubst %.asm,%.cpp,$@)
293         @cat $@ | grep -v '^..LN' |grep -v '    .loc' > $@2
294
295 $(CPP_SNC_OBJS) : $(CPP_SNC_ASMS)
296         @echo "[CPP-SNC] $@"
297         @$(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(CPP_COMP_SNC) -o"$@" $(patsubst %.o,%.cpp,$@)
298
299 $(C_OBJS) :
300         @echo "[C] $@"
301         @$(CC) -c $(CFLAGS) -o"$@" $(patsubst %.o,%.c,$@)
302
303 $(TESTS) : $(CC_OBJS) $(CPP_OBJS) $(CPP_SNC_OBJS) $(C_OBJS) $(GTEST_ROOT)/libgtest.a
304         @echo "[LD] $@"
305         @$(CXX) $(CPPFLAGS) $(CXXFLAGS) -L$(MLOG_DIR)/bin -Wl, $(RTE_LIBS) -lpthread -lnuma -Wl,-lstdc++ $^ -o $@