11add_library (infiniops SHARED )
2-
32file (GLOB BASE_SRCS CONFIGURE_DEPENDS "*.cc" )
43target_sources (infiniops PRIVATE ${BASE_SRCS} )
5-
64set (DEVICE_LIST "" )
7-
85if (WITH_CPU)
96 set (CPU_PATTERNS
107 "cpu/*.cc"
118 "cpu/*.cpp"
129 )
13-
1410 file (GLOB_RECURSE CPU_SOURCES CONFIGURE_DEPENDS ${CPU_PATTERNS} )
1511 list (APPEND CORE_SOURCES ${CPU_SOURCES} )
16-
1712 target_compile_definitions (infiniops PUBLIC WITH_CPU=1 )
18-
1913 find_package (OpenMP REQUIRED )
2014 target_link_libraries (infiniops PRIVATE OpenMP::OpenMP_CXX )
21-
2215 list (APPEND DEVICE_LIST "cpu" )
2316endif ()
24-
2517if (WITH_NVIDIA)
2618 set (NVIDIA_PATTERNS
2719 "cuda/*.cc"
@@ -31,24 +23,18 @@ if(WITH_NVIDIA)
3123 "nvidia/*.cpp"
3224 "nvidia/*.cu"
3325 )
34-
3526 file (GLOB_RECURSE NVIDIA_SOURCES CONFIGURE_DEPENDS ${NVIDIA_PATTERNS} )
36-
3727 enable_language (CUDA )
38-
3928 target_compile_definitions (infiniops PUBLIC WITH_NVIDIA=1 )
4029 target_sources (infiniops PRIVATE ${NVIDIA_SOURCES} )
41-
4230 find_package (CUDAToolkit REQUIRED )
4331 target_link_libraries (infiniops PUBLIC CUDA::cudart CUDA::cublas CUDA::cuda_driver )
44-
4532 list (APPEND DEVICE_LIST "nvidia" )
4633 set_target_properties (infiniops PROPERTIES
4734 CUDA_STANDARD 17
4835 CUDA_STANDARD_REQUIRED ON
4936 )
5037endif ()
51-
5238if (WITH_ILUVATAR)
5339 set (ILUVATAR_PATTERNS
5440 "cuda/*.cc"
@@ -58,135 +44,112 @@ if(WITH_ILUVATAR)
5844 "iluvatar/*.cpp"
5945 "iluvatar/*.cu"
6046 )
61-
6247 file (GLOB_RECURSE ILUVATAR_SOURCES CONFIGURE_DEPENDS ${ILUVATAR_PATTERNS} )
63-
6448 enable_language (CUDA )
65-
6649 target_compile_definitions (infiniops PUBLIC WITH_ILUVATAR=1 )
6750 target_sources (infiniops PRIVATE ${ILUVATAR_SOURCES} )
68-
6951 find_package (CUDAToolkit REQUIRED )
7052 target_link_libraries (infiniops PUBLIC CUDA::cudart CUDA::cublas CUDA::cuda_driver )
71-
7253 set_target_properties (infiniops PROPERTIES
7354 CUDA_STANDARD 17
7455 CUDA_STANDARD_REQUIRED ON
7556 )
76-
7757 list (APPEND DEVICE_LIST "iluvatar" )
7858endif ()
79-
8059if (WITH_METAX)
8160 set (METAX_PATTERNS
8261 "cuda/*.cc"
8362 "cuda/*.cpp"
8463 "metax/*.cc"
8564 "metax/*.maca"
8665 )
87-
8866 file (GLOB_RECURSE METAX_SOURCES CONFIGURE_DEPENDS ${METAX_PATTERNS} )
89-
9067 set_source_files_properties (${METAX_SOURCES} PROPERTIES LANGUAGE CXX )
91-
9268 target_compile_definitions (infiniops PRIVATE WITH_METAX=1 )
9369 target_compile_options (infiniops PUBLIC "-x" "maca" )
9470 target_sources (infiniops PRIVATE ${METAX_SOURCES} )
95-
9671 target_include_directories (infiniops PUBLIC "${MACA_PATH} /include" )
9772 target_link_libraries (infiniops PUBLIC
9873 ${MACA_RUNTIME_LIB}
9974 ${MACA_DNN_LIB}
10075 ${MACA_BLAS_LIB}
10176 )
102-
10377 list (APPEND DEVICE_LIST "metax" )
10478endif ()
105-
10679if (WITH_CAMBRICON)
10780 file (GLOB_RECURSE CAMBRICON_MLU_SOURCES CONFIGURE_DEPENDS "cambricon/*/*.mlu" )
10881 find_program (CNCC_COMPILER cncc HINTS "${NEUWARE_HOME} /bin" "$ENV{NEUWARE_HOME} /bin" /usr/local/neuware/bin )
109-
11082 if (CNCC_COMPILER)
11183 message (STATUS "Found cncc: ${CNCC_COMPILER} " )
112-
11384 set (MLU_COMPILE_OPTS
11485 -c --bang-mlu-arch=mtp_592 -O3 -fPIC -Wall -Werror -std=c++17 -pthread
11586 -I${CMAKE_CURRENT_SOURCE_DIR} -I${NEUWARE_HOME} /include
87+ # FIX 1: Explicitly pass the fallback directory to the custom cncc command
88+ -idirafter /usr/local/neuware/lib/clang/11.1.0/include
11689 )
117-
11890 function (compile_mlu_file src_file )
11991 get_filename_component (name ${src_file} NAME_WE )
12092 get_filename_component (path ${src_file} DIRECTORY )
12193 set (out_file "${CMAKE_CURRENT_BINARY_DIR} /${path} /${name} .o" )
12294 file (MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR} /${path} " )
123-
12495 add_custom_command (OUTPUT ${out_file}
12596 COMMAND ${CNCC_COMPILER} ${MLU_COMPILE_OPTS} -c ${src_file} -o ${out_file}
12697 DEPENDS ${src_file}
12798 COMMENT "Building MLU kernel: ${src_file} "
12899 )
129100 set_property (DIRECTORY APPEND PROPERTY CAMBRICON_OBJECTS ${out_file} )
130101 endfunction ()
131-
132102 foreach (src ${CAMBRICON_MLU_SOURCES} )
133103 compile_mlu_file (${src} )
134104 endforeach ()
135-
136105 get_directory_property (CAMBRICON_OBJECT_FILES CAMBRICON_OBJECTS )
137106 if (CAMBRICON_OBJECT_FILES)
138107 target_sources (infiniops PRIVATE ${CAMBRICON_OBJECT_FILES} )
139108 endif ()
140109 else ()
141110 message (WARNING "cncc compiler not found. MLU kernels will not be compiled." )
142111 endif ()
143-
144112 target_compile_definitions (infiniops PRIVATE WITH_CAMBRICON=1 )
145113 target_include_directories (infiniops PUBLIC "${NEUWARE_HOME} /include" )
146114 target_link_libraries (infiniops PUBLIC ${CAMBRICON_RUNTIME_LIB} ${CAMBRICON_CNNL_LIB} ${CAMBRICON_CNNL_EXTRA_LIB} ${CAMBRICON_PAPI_LIB} )
147-
115+ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang" )
116+ # FIX 2 & 3: Make it PUBLIC so the Pybind ops target sees it.
117+ # Use SHELL: so CMake doesn't split it, and constrain it to CXX files.
118+ target_compile_options (infiniops PUBLIC
119+ "$<$<COMPILE_LANGUAGE :CXX >:SHELL :-idirafter /usr /local /neuware /lib /clang /11.1.0/include >"
120+ )
121+ endif ()
148122 list (APPEND DEVICE_LIST "cambricon" )
149123endif ()
150-
151124target_include_directories (infiniops PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
152-
153125if (GENERATE_PYTHON_BINDINGS)
154126 execute_process (
155127 COMMAND python ${PROJECT_SOURCE_DIR} /scripts/generate_wrappers.py --devices ${DEVICE_LIST}
156128 WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
157129 RESULT_VARIABLE script_result
158130 )
159-
160131 if (NOT script_result EQUAL 0)
161132 message (FATAL_ERROR "Generating wrappers - failed" )
162133 else ()
163134 message (STATUS "Generating wrappers - done" )
164135 endif ()
165-
166136 set (PYBIND11_SOURCES "${PROJECT_SOURCE_DIR} /generated/bindings/ops.cc" )
167-
168137 # TODO: There might be a better solution.
169138 if (WITH_NVIDIA OR WITH_ILUVATAR)
170139 set_source_files_properties (${PYBIND11_SOURCES} PROPERTIES LANGUAGE CUDA )
171140 endif ()
172-
173141 find_package (Python COMPONENTS Interpreter Development )
174142 find_package (pybind11 CONFIG )
175-
176143 if (PYBIND11_ENABLE_EXTRAS)
177144 pybind11_add_module (ops ${PYBIND11_SOURCES} )
178145 else ()
179146 pybind11_add_module (ops NO_EXTRAS ${PYBIND11_SOURCES} )
180147 endif ()
181-
182148 target_include_directories (ops PRIVATE ${PROJECT_SOURCE_DIR} )
183149 target_link_libraries (ops PRIVATE infiniops )
184-
185150 set_target_properties (infiniops PROPERTIES INSTALL_RPATH "$ORIGIN" )
186151 set_target_properties (ops PROPERTIES INSTALL_RPATH "$ORIGIN" )
187-
188152 install (TARGETS infiniops ops DESTINATION .)
189-
190153 file (WRITE "${CMAKE_CURRENT_BINARY_DIR} /__init__.py" "" )
191154 install (FILES "${CMAKE_CURRENT_BINARY_DIR} /__init__.py" DESTINATION .)
192- endif ()
155+ endif ()
0 commit comments