Skip to content

Commit 054969e

Browse files
authored
build: Add terapines zcc toolchain support (#14)
* build:Add terapines zcc toolchain support 1.Support the compilation of nmsis_dsp and nmsis_nn using zcc Use : make gen_dsp_lib TOOLCHAIN=terapines 2.Support for terapines' libdsp and libnn * ci: Add zcc build and test workflow * build: Modify the non-standard parts of the previous compiled script 1.Modify the parameters passed in cmake, find the absolute path of the toolchain through the script, and provide it to cmake 2. Remove redundant build parameters from the compilation script * ci: Correct the error in the pipeline configuration file. TOOLCHAIN=terapines instead of zcc
1 parent d98e9ae commit 054969e

File tree

10 files changed

+239
-10
lines changed

10 files changed

+239
-10
lines changed

.gitlab-ci.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,38 @@ build_library:
9191
- mv Library gen/
9292
- exit $buildsts
9393

94+
build_library_terapines:
95+
stage: build
96+
interruptible: true
97+
retry: 1
98+
only:
99+
refs:
100+
- master
101+
- develop
102+
- /^feature\/.*/
103+
- merge_requests
104+
artifacts:
105+
when: always
106+
name: "nmsis_lib_terapines-job${CI_JOB_ID}-${CI_COMMIT_SHA::8}"
107+
paths:
108+
- NMSIS/gen_terapines
109+
- NMSIS/build_terapines.log
110+
expire_in: 2 day
111+
script:
112+
- apt update
113+
- apt install -y python3 python3-pip
114+
- pip3 install prettytable
115+
- cd NMSIS
116+
- echo "Generate NMSIS Library for Nuclei RISC-V Processors with terapines"
117+
- make gen TOOLCHAIN=terapines > build_terapines.log 2>&1
118+
- buildsts=${PIPESTATUS[0]}
119+
- mkdir -p gen_terapines/
120+
- |
121+
if [ -d "Library" ]; then
122+
mv Library gen_terapines/Library
123+
fi
124+
- exit $buildsts
125+
94126
build_align_library:
95127
stage: build
96128
interruptible: true
@@ -192,6 +224,51 @@ test_nn_library:
192224
- zip -q -r log_nmsis_nn_${NUCLEI_DSP}.zip NMSIS/Logs
193225
- rm -rf NMSIS/Logs
194226

227+
test_nn_library_terapines:
228+
<<: *test_job_template_default
229+
dependencies:
230+
- build_nn_lib_terapines
231+
artifacts:
232+
when: always
233+
name: "nmsis_nn_test_terapines_logs-job${CI_JOB_ID}-${CI_COMMIT_SHA::8}"
234+
paths:
235+
- log_nmsis_*.zip
236+
- NMSIS/Logs
237+
expire_in: 2 day
238+
parallel:
239+
matrix:
240+
- NUCLEI_DSP: ["rv32_NO", "rv64_NO", "N1", "N2", "N3"]
241+
script:
242+
- git clone -b $SDK_BRANCH $NUCLEI_SDK NMSIS/nuclei_sdk
243+
- export NUCLEI_SDK_ROOT=$(readlink -f NMSIS/nuclei_sdk)
244+
- pip3 install -r $NUCLEI_SDK_ROOT/tools/scripts/requirements.txt
245+
- export NUCLEI_SDK_NMSIS=$(readlink -f NMSIS)
246+
- export NMSIS_LOGS=$NUCLEI_SDK_NMSIS/Logs
247+
# change ilm/dlm size from 64K to 1M for ${SOC}
248+
- sed -i "s/64K/1M/g" $NUCLEI_SDK_ROOT/SoC/${SOC}/Board/nuclei_fpga_eval/Source/GCC/gcc_${SOC}_ilm.ld
249+
# change ilm/dlm size from 64K to 1M for evalsoc from Nuclei SDK 0.6.0
250+
- |
251+
EVALSOC_MEMORY=$NUCLEI_SDK_ROOT/SoC/evalsoc/Board/nuclei_fpga_eval/Source/GCC/evalsoc.memory
252+
if [ -f $EVALSOC_MEMORY ] ; then
253+
echo "Maybe you are using >= Nuclei SDK 0.6.0, will sed and replace ilm/dlm memory size in $EVALSOC_MEMORY"
254+
sed -i 's/\([ID]LM_MEMORY_SIZE\).*/\1 = 0x100000;/' $EVALSOC_MEMORY
255+
fi
256+
- mkdir $NMSIS_LOGS
257+
- source NMSIS/env.sh
258+
- export SILENT=1
259+
- cd NMSIS
260+
- rm -rf Library
261+
- ln -s gen_terapines_nn/Library .
262+
- make gen_nnref_lib
263+
- export SDK_VERB_BUILDMSG=0
264+
# generate test runner
265+
- python3 NN/Tests/UnitTest/Scripts/generate_test_runner.py
266+
- python3 $NUCLEI_SDK_ROOT/tools/scripts/nsdk_cli/nsdk_bench.py --appcfg Scripts/Runner/nmsis_nn_${NUCLEI_DSP}.json --logdir $NMSIS_LOGS/${NUCLEI_DSP}/nmsis_nn_terapines --parallel=-j --make_options "SIMU=$RUNTARGET TOOLCHAIN=terapines" --run_target $RUNTARGET --run
267+
# zip logs
268+
- cd -
269+
- zip -q -r log_nmsis_nn_terapines_${NUCLEI_DSP}.zip NMSIS/Logs
270+
- rm -rf NMSIS/Logs
271+
195272
test_dsp_library:
196273
<<: *test_job_template_default
197274
artifacts:
@@ -232,6 +309,48 @@ test_dsp_library:
232309
- zip -q -r log_nmsis_dsp_${NUCLEI_DSP}.zip NMSIS/Logs
233310
- rm -rf NMSIS/Logs
234311

312+
test_dsp_library_terapines:
313+
<<: *test_job_template_default
314+
dependencies:
315+
- build_dsp_lib_terapines
316+
artifacts:
317+
when: always
318+
name: "nmsis_dsp_test_terapines_logs-job${CI_JOB_ID}-${CI_COMMIT_SHA::8}"
319+
paths:
320+
- log_nmsis_*.zip
321+
- NMSIS/Logs
322+
expire_in: 2 day
323+
parallel:
324+
matrix:
325+
- NUCLEI_DSP: ["rv32_NO", "rv64_NO", "N1", "N2", "N3", "f16"]
326+
script:
327+
- git clone -b $SDK_BRANCH $NUCLEI_SDK NMSIS/nuclei_sdk
328+
- export NUCLEI_SDK_ROOT=$(readlink -f NMSIS/nuclei_sdk)
329+
- pip3 install -r $NUCLEI_SDK_ROOT/tools/scripts/requirements.txt
330+
- export NUCLEI_SDK_NMSIS=$(readlink -f NMSIS)
331+
- export NMSIS_LOGS=$NUCLEI_SDK_NMSIS/Logs
332+
# change ilm/dlm size from 64K to 1M for ${SOC}
333+
- sed -i "s/64K/1M/g" $NUCLEI_SDK_ROOT/SoC/${SOC}/Board/nuclei_fpga_eval/Source/GCC/gcc_${SOC}_ilm.ld
334+
# change ilm/dlm size from 64K to 1M for evalsoc from Nuclei SDK 0.6.0
335+
- |
336+
EVALSOC_MEMORY=$NUCLEI_SDK_ROOT/SoC/evalsoc/Board/nuclei_fpga_eval/Source/GCC/evalsoc.memory
337+
if [ -f $EVALSOC_MEMORY ] ; then
338+
echo "Maybe you are using >= Nuclei SDK 0.6.0, will sed and replace ilm/dlm memory size in $EVALSOC_MEMORY"
339+
sed -i 's/\([ID]LM_MEMORY_SIZE\).*/\1 = 0x100000;/' $EVALSOC_MEMORY
340+
fi
341+
- mkdir $NMSIS_LOGS
342+
- source NMSIS/env.sh
343+
- export SILENT=1
344+
- cd NMSIS
345+
- rm -rf Library
346+
- ln -s gen_terapines_dsp/Library .
347+
- export SDK_VERB_BUILDMSG=0
348+
- python3 $NUCLEI_SDK_ROOT/tools/scripts/nsdk_cli/nsdk_bench.py --appcfg Scripts/Runner/nmsis_dsp_${NUCLEI_DSP}.json --logdir $NMSIS_LOGS/${NUCLEI_DSP}/nmsis_dsp_terapines --parallel=-j --make_options "SIMU=$RUNTARGET TOOLCHAIN=terapines" --run_target $RUNTARGET --run
349+
# zip logs
350+
- cd -
351+
- zip -q -r log_nmsis_dsp_terapines_${NUCLEI_DSP}.zip NMSIS/Logs
352+
- rm -rf NMSIS/Logs
353+
235354
release_benchmark:
236355
stage: release
237356
interruptible: true
@@ -249,6 +368,8 @@ release_benchmark:
249368
dependencies:
250369
- test_nn_library
251370
- test_dsp_library
371+
- test_nn_library_terapines
372+
- test_dsp_library_terapines
252373
script:
253374
# unzip all log_nmsis_*.zip files
254375
- for zf in `find . -name "log_nmsis*.zip"` ; do unzip -qo $zf ; done
@@ -304,3 +425,4 @@ deploy_website:
304425
- host::whss1
305426
script:
306427
- ./.ci/ftp_deploy.sh $FTPUSER $FTPPWD $FTPSERVER NMSIS/doc/build/html nmsis
428+

NMSIS/DSP/Benchmark/Makefile.common

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ BENCH_UNIT ?=
1212
RISCV_ALIGN ?= OFF
1313
COMMON_FLAGS ?= -O2
1414
STDCLIB ?= newlib_full
15+
16+
ifeq (${TOOLCHAIN}, terapines)
17+
NMSIS_LIB := tpt_dsp
18+
else
1519
NMSIS_LIB := nmsis_dsp
20+
endif
1621

1722
ifeq ($(BENCH_UNIT),instret)
1823
$(warning "Benchmark by reading cpu instret")

NMSIS/DSP/Examples/RISCV/Makefile.common

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ BENCH_UNIT ?=
1212
RISCV_ALIGN ?= OFF
1313
COMMON_FLAGS ?= -O2
1414
STDCLIB ?= newlib_full
15+
16+
ifeq (${TOOLCHAIN}, terapines)
17+
NMSIS_LIB := tpt_dsp
18+
else
1519
NMSIS_LIB := nmsis_dsp
20+
endif
1621

1722
ifeq ($(BENCH_UNIT),instret)
1823
$(warning "Benchmark by reading cpu instret")

NMSIS/DSP/Source/CMakeLists.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ cmake_minimum_required(VERSION 3.14)
22

33
project(NMSISDSP)
44

5-
SET(CMAKE_C_COMPILER riscv64-unknown-elf-gcc)
6-
SET(CMAKE_CXX_COMPILER riscv64-unknown-elf-g++)
7-
SET(CMAKE_AR riscv64-unknown-elf-ar)
5+
SET(CMAKE_C_COMPILER riscv64-unknown-elf-gcc CACHE STRING "C compiler")
6+
SET(CMAKE_CXX_COMPILER riscv64-unknown-elf-g++ CACHE STRING "C++ compiler")
7+
SET(CMAKE_AR riscv64-unknown-elf-ar CACHE STRING "Archiver")
88

99
# DSP Sources
1010
get_filename_component(ROOT "../.." ABSOLUTE)
@@ -25,7 +25,11 @@ add_definitions(-mcmodel=${RISCV_MODEL})
2525

2626
add_definitions(-g -O2 -ffunction-sections -fdata-sections)
2727
# Disable auto vectorization
28-
add_definitions(-fno-tree-vectorize -fno-tree-loop-vectorize -fno-tree-slp-vectorize)
28+
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
29+
add_definitions(-fno-tree-vectorize -fno-tree-loop-vectorize -fno-tree-slp-vectorize)
30+
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
31+
add_definitions(-fno-tree-vectorize -fno-tree-slp-vectorize)
32+
endif()
2933

3034
if(LOOPUNROLL)
3135
add_definitions(-DRISCV_MATH_LOOPUNROLL)

NMSIS/DSP/Test/Makefile.common

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ BENCH_UNIT ?=
1212
RISCV_ALIGN ?= OFF
1313
COMMON_FLAGS ?= -O2
1414
STDCLIB ?= newlib_full
15+
16+
ifeq (${TOOLCHAIN}, terapines)
17+
NMSIS_LIB := tpt_dsp
18+
else
1519
NMSIS_LIB := nmsis_dsp
20+
endif
1621

1722
ifeq ($(BENCH_UNIT),instret)
1823
$(warning "Benchmark by reading cpu instret")

NMSIS/NN/Benchmark/Makefile.common

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ BENCH_UNIT ?=
88
RISCV_ALIGN ?= OFF
99
COMMON_FLAGS ?= -O2
1010
STDCLIB ?= newlib_full
11+
12+
ifeq (${TOOLCHAIN}, terapines)
13+
NMSIS_LIB := tpt_nn
14+
else
1115
NMSIS_LIB := nmsis_nn
16+
endif
1217

1318
SUBDIR:=$(wildcard *)
1419
SRCDIRS += . $(SUBDIR)

NMSIS/NN/Tests/Cases/Makefile.common

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ BENCH_UNIT ?=
1414
RISCV_ALIGN ?= OFF
1515
COMMON_FLAGS ?= -O2
1616
STDCLIB ?= newlib_full
17+
18+
ifeq (${TOOLCHAIN}, terapines)
19+
NMSIS_LIB := tpt_nn
20+
else
1721
NMSIS_LIB := nmsis_nn
22+
endif
1823

1924
ifeq ($(BENCH_UNIT),instret)
2025
$(warning "Benchmark by reading cpu instret")

NMSIS/Scripts/Build/Makefile.nmsis

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ LIBIRAY_ROOT ?= Library
44
BUILD_ROOT ?= build
55
# Previous LIBTYPE is TOOLCHAIN, but now changed to LIBTYPE to avoid mis-usage with SDK TOOLCHAIN var
66
LIBTYPE ?= GCC
7+
TOOLCHAIN ?= nuclei_gnu
78
BUILD_TARGET ?= all
89
PARALLEL_OPTS ?= -j8
910
REBUILD ?= 1
@@ -54,6 +55,11 @@ ifneq ($(EXTRAOPTS),)
5455
EXTRA_NLOPTS += --extraopts ${EXTRAOPTS}
5556
endif
5657

58+
ifneq ($(TOOLCHAIN),)
59+
EXTRA_NLOPTS += --toolchain $(TOOLCHAIN)
60+
endif
61+
62+
5763
.PHONY: nmsis_help gen_dsp_lib gen_nn_lib gen_unalign_dsp_lib gen_unalign_nn_lib gen gen_unalign envsetup check_build check_run check view_report view_logs
5864

5965
nmsis_help:

NMSIS/Scripts/Build/nlbuild.py

Lines changed: 73 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def get_build_artifacts(self, target:str):
8181
buildlog = os.path.join(builddir, "build.log")
8282
return builddir, cmakelog, buildlog
8383

84-
def build(self, target:str, target_alias:list, config:dict, installdir:str, parallel="-j", norebuild=False):
84+
def build(self, target:str, target_alias:list, config:dict, installdir:str, parallel="-j", norebuild=False, cmake_extra_args=None):
8585
if isinstance(config, dict) == False:
8686
return False
8787
cmakefile = os.path.join(self.nl_src, "CMakeLists.txt")
@@ -92,6 +92,10 @@ def build(self, target:str, target_alias:list, config:dict, installdir:str, para
9292
abs_nlsrc = os.path.abspath(self.nl_src)
9393
for key in config:
9494
cmakeopts += "-D%s=%s " % (key, config[key])
95+
96+
if cmake_extra_args:
97+
cmakeopts += ' '.join(cmake_extra_args) + ' '
98+
9599
nl_buildir, nl_cmakelog, nl_buildlog = self.get_build_artifacts(target)
96100
makefile = os.path.join(nl_buildir, "Makefile")
97101
genmake = False
@@ -194,7 +198,7 @@ def strip_library(libroot):
194198
run_command(strip_cmd)
195199
pass
196200

197-
def install_library(libsrc, buildcfgs:dict, aliascfgs:dict, libprefix, libroot, target:str="all", strip=True, parallel="-j", ignore_fail=False, norebuild=False):
201+
def install_library(libsrc, buildcfgs:dict, aliascfgs:dict, libprefix, libroot, target:str="all", strip=True, parallel="-j", ignore_fail=False, norebuild=False, cmake_extra_args=None):
198202
if isinstance(buildcfgs, dict) == False:
199203
print("No build configuration found")
200204
return False
@@ -209,7 +213,7 @@ def install_library(libsrc, buildcfgs:dict, aliascfgs:dict, libprefix, libroot,
209213
print(">>> Build and install %s library for config %s" % (libsrc, key))
210214
_, _, buildlog = nlb.get_build_artifacts(key)
211215
target_alias = aliascfgs.get(key, [])
212-
ret = nlb.build(key, target_alias, buildcfgs[key], libroot, parallel, norebuild)
216+
ret = nlb.build(key, target_alias, buildcfgs[key], libroot, parallel, norebuild, cmake_extra_args)
213217

214218
cost_time = round(time.time() - start_time, 2)
215219
rst_table.add_row([key, ret, cost_time, buildlog])
@@ -224,7 +228,8 @@ def install_library(libsrc, buildcfgs:dict, aliascfgs:dict, libprefix, libroot,
224228
start_time = time.time()
225229
print(">>> Build and install %s library for config %s" % (libsrc, target))
226230
_, _, buildlog = nlb.get_build_artifacts(target)
227-
ret = nlb.build(target, buildcfgs[target], libroot, parallel, norebuild)
231+
target_alias = aliascfgs.get(target, [])
232+
ret = nlb.build(target, target_alias, buildcfgs[target], libroot, parallel, norebuild, cmake_extra_args)
228233
cost_time = round(time.time() - start_time, 2)
229234
rst_table.add_row([target, ret, cost_time, buildlog])
230235
if ret == False:
@@ -253,13 +258,76 @@ def install_library(libsrc, buildcfgs:dict, aliascfgs:dict, libprefix, libroot,
253258
parser.add_argument('--target', default="all", help="if target = all, it means run all the targets defined in config")
254259
parser.add_argument('--parallel', default="-j4", help="parallel build library, default -j4")
255260
parser.add_argument('--ignore_fail', action='store_true', help="If specified, will ignore fail even any build configuration failed")
261+
parser.add_argument('--toolchain', default="nuclei_gnu", help="Select the toolchain profile to use (e.g., nuclei_gnu, nuclei_llvm, terapines)")
256262

257263
args = parser.parse_args()
258264

259265
if sys.platform == "win32":
260266
print("Windows build is not yet supported!")
261267
sys.exit(1)
262268

269+
toolchain_cmake_args = []
270+
toolchain_tools = {}
271+
selected_toolchain = args.toolchain.lower()
272+
273+
TOOLCHAIN_CONFIGS = {
274+
'terapines': {
275+
'name': 'Terapines (zcc)',
276+
'cc_name': 'zcc',
277+
'cxx_name': 'z++',
278+
'ar_name': 'llvm-ar'
279+
},
280+
'nuclei_llvm': {
281+
'name': 'nuclei_llvm',
282+
'cc_name': 'riscv64-unknown-elf-clang',
283+
'cxx_name': 'riscv64-unknown-elf-clang++',
284+
'ar_name': 'riscv64-unknown-elf-ar'
285+
},
286+
'nuclei_gnu': {
287+
'name': 'default GCC',
288+
'cc_name': 'riscv64-unknown-elf-gcc',
289+
'cxx_name': 'riscv64-unknown-elf-g++',
290+
'ar_name': 'riscv64-unknown-elf-ar'
291+
}
292+
}
293+
294+
# Gets the selected toolchain configuration
295+
config = TOOLCHAIN_CONFIGS.get(selected_toolchain)
296+
297+
if not config:
298+
print(f"Warning: Unknown toolchain '{args.toolchain}'. Using GCC default.")
299+
print(">>> Using default GCC toolchain profile.")
300+
config = TOOLCHAIN_CONFIGS['nuclei_gnu']
301+
else:
302+
print(f">>> Using {config['name']} toolchain profile.")
303+
304+
cc_name = config['cc_name']
305+
cc_path = shutil.which(cc_name)
306+
307+
if not cc_path:
308+
print(f"!!! ERROR: Toolchain C compiler '{cc_name}' not found in your system PATH.")
309+
print(f"Please ensure the {config['name']} toolchain is installed and its 'bin' directory is added to PATH.")
310+
sys.exit(1)
311+
312+
print(f" Found CC: {cc_path} (Using absolute path)")
313+
toolchain_bindir = os.path.dirname(cc_path)
314+
315+
toolchain_tools = {
316+
'CC': os.path.abspath(cc_path),
317+
'CXX': os.path.abspath(os.path.join(toolchain_bindir, config['cxx_name'])),
318+
'AR': os.path.abspath(os.path.join(toolchain_bindir, config['ar_name'])),
319+
}
320+
print(f" Using CXX: {toolchain_tools['CXX']} (Using absolute path)")
321+
print(f" Using AR: {toolchain_tools['AR']} (Using absolute path)")
322+
323+
toolchain_cmake_args.extend([
324+
'-D', f"CMAKE_C_COMPILER={toolchain_tools['CC']}",
325+
'-D', f"CMAKE_CXX_COMPILER={toolchain_tools['CXX']}",
326+
'-D', f"CMAKE_AR={toolchain_tools['AR']}",
327+
])
328+
329+
all_cmake_extra_args = toolchain_cmake_args
330+
263331
valid, jsoncfg = load_json(args.config)
264332

265333
if valid != JSON_OK:
@@ -272,7 +340,7 @@ def install_library(libsrc, buildcfgs:dict, aliascfgs:dict, libprefix, libroot,
272340

273341
buildcfgs = get_buildcfgs(jsoncfg)
274342
aliascfgs = get_aliascfgs(jsoncfg)
275-
runrst = install_library(args.lib_src, buildcfgs, aliascfgs, args.lib_prefix, args.lib_root, args.target, args.strip, args.parallel, args.ignore_fail, args.norebuild)
343+
runrst = install_library(args.lib_src, buildcfgs, aliascfgs, args.lib_prefix, args.lib_root, args.target, args.strip, args.parallel, args.ignore_fail, args.norebuild, all_cmake_extra_args)
276344
print("Build Library %s with config %s, generated into %s status: %s" %(args.lib_src, args.config, args.lib_root, runrst))
277345
if args.norebuild:
278346
print("!!!Use Caution: This build is not fully rebuilt, please take care!!!!")

0 commit comments

Comments
 (0)