Skip to content

Commit 02939c9

Browse files
committed
feat: 在 cmake 中增加 mlu 的相关环境编译
1 parent bd6ad6b commit 02939c9

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

CMakeLists.txt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,35 @@ endif()
4444

4545
if (USE_BANG)
4646
add_compile_definitions(USE_BANG)
47+
include_directories(src/kernels/mlu/include)
48+
49+
# Neuware Evironment
50+
if ((NOT DEFINED NEUWARE_HOME) AND (NOT DEFINED ENV{NEUWARE_HOME}))
51+
message(FATAL_ERROR "NEUWARE_HOME is not defined from cmake or env")
52+
elseif (DEFINED NEUWARE_HOME)
53+
set(NEUWARE_HOME ${NEUWARE_HOME} CACHE STRING "NEUWARE_HOME directory for Cambricon Neuware development")
54+
else()
55+
set(NEUWARE_HOME $ENV{NEUWARE_HOME} CACHE STRING "NEUWARE_HOME directory for Cambricon Neuware development")
56+
endif()
57+
message(STATUS "NEUWARE_HOME: ${NEUWARE_HOME}")
58+
59+
# cnrt cndrv cnnl
60+
include_directories("${NEUWARE_HOME}/include")
61+
find_library(CAMBRICON_CNNL libcnnl.so "${NEUWARE_HOME}/lib64")
62+
find_library(CAMBRICON_CNRT libcnrt.so "${NEUWARE_HOME}/lib64")
63+
find_library(CAMBRICON_CNDRV libcndrv.so "${NEUWARE_HOME}/lib64")
64+
find_library(CAMBRICON_CNCL libcncl.so "${NEUWARE_HOME}/lib64")
65+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lstdc++ -Wall -Werror")
66+
67+
if ((NOT DEFINED TARGET_CPU_ARCH) AND (NOT DEFINED ENV{TARGET_CPU_ARCH}))
68+
execute_process(COMMAND uname -m OUTPUT_VARIABLE _uname_m OUTPUT_STRIP_TRAILING_WHITESPACE)
69+
set(TARGET_CPU_ARCH "${_uname_m}" CACHE STRING "Target CPU ARCH")
70+
elseif(DEFINED TARGET_CPU_ARCH)
71+
set(TARGET_CPU_ARCH ${TARGET_CPU_ARCH} CACHE STRING "Target CPU ARCH")
72+
else()
73+
set(TARGET_CPU_ARCH $ENV{TARGET_CPU_ARCH} CACHE STRING "Target CPU ARCH")
74+
endif()
75+
message(STATUS "TARGET_CPU_ARCH: ${TARGET_CPU_ARCH}")
4776
endif()
4877

4978
add_compile_options(-march=native) # this will cause error in some machine

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ CMAKE_EXTRA =
1010

1111
build:
1212
mkdir -p build
13-
cmake -Bbuild -DCMAKE_BUILD_TYPE=$(TYPE) -DUSE_CUDA=$(CUDA) -DUSE_KUNLUN=$(KUNLUN) $(CMAKE_EXTRA)
13+
cmake -Bbuild -DCMAKE_BUILD_TYPE=$(TYPE) -DUSE_CUDA=$(CUDA) -DUSE_KUNLUN=$(KUNLUN) -DUSE_BANG=$(BANG) $(CMAKE_EXTRA)
1414
make -j -C build
1515

1616
install-python: build

src/04kernel/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ if(USE_KUNLUN)
3535
find_library(KUNLUN_DNN libxpuapi.so ${KUNLUN_HOME}/XTDK/shlib)
3636
target_link_libraries(kernel PUBLIC ${KUNLUN_RT} ${KUNLUN_DNN})
3737
endif()
38+
if(USE_BANG)
39+
target_link_libraries(kernel ${CAMBRICON_CNCL} ${CAMBRICON_CNNL} ${CAMBRICON_CNRT} ${CAMBRICON_CNDRV} stdc++)
40+
endif()
3841

3942
file(GLOB_RECURSE KERNEL_TEST test/*.cpp)
4043
if(KERNEL_TEST)

0 commit comments

Comments
 (0)