@@ -241,66 +241,8 @@ if(WITH_ASCEND)
241241 list (APPEND DEVICE_LIST "ascend" )
242242
243243 # Custom `AscendC` kernels (PyTorch extension, requires `torch_npu`).
244- if (BUILD_ASCEND_CUSTOM)
245- # In-tree `ascendc_library()` trips the `CANN` `extract_host_stub.py`
246- # path-handling bug under `scikit-build-core`'s temp-dir builds
247- # (`KeyError` on `/./workspace/...` paths in `$<TARGET_OBJECTS>`).
248- # Work around it by driving the standalone `src/ascend/custom/build.sh`
249- # — that script invokes a separate `cmake` with
250- # `src/ascend/custom/` as its `SOURCE_DIR`, avoiding the buggy
251- # path shape. The produced `.a` is imported and linked into
252- # `ops` with `--whole-archive`.
253- set (_custom_build_dir "${CMAKE_SOURCE_DIR} /build/build_ascend_custom" )
254- set (_custom_lib "${_custom_build_dir} /lib/libno_workspace_kernel.a" )
255-
256- if (NOT DEFINED SOC_VERSION OR "${SOC_VERSION} " STREQUAL "" )
257- include (${CMAKE_CURRENT_SOURCE_DIR} /ascend/custom/cmake/detect_soc.cmake )
258- infiniops_detect_soc (SOC_VERSION )
259- endif ()
260-
261- # Drive `build.sh` as a build-phase target with explicit source
262- # dependencies so that editing any `op_host/` or `op_kernel/`
263- # source re-triggers the build (plain `execute_process` at
264- # configure time would only gate on file existence and leave
265- # stale `.a` files in place).
266- file (GLOB_RECURSE _custom_srcs CONFIGURE_DEPENDS
267- "${CMAKE_CURRENT_SOURCE_DIR} /ascend/custom/*.cpp"
268- "${CMAKE_CURRENT_SOURCE_DIR} /ascend/custom/*.h"
269- "${CMAKE_CURRENT_SOURCE_DIR} /ascend/custom/build.sh" )
270-
271- # Scrub env inherited from the outer `scikit-build-core` invocation
272- # before handing control to `build.sh`:
273- # * `CMAKE_GENERATOR` / `CMAKE_EXPORT_COMPILE_COMMANDS` leaking
274- # into the inner `cmake` change the path format passed to
275- # `ninja`'s `_host_cpp` rule and re-trigger the `CANN`
276- # `extract_host_stub.py` `KeyError` (`/./workspace/...`) that
277- # standalone `build.sh` avoids.
278- # * `PYTHONPATH` from `pip`'s build-isolation overlay makes the
279- # child `python3` skip the system `site-packages` — child
280- # `cmake` modules that `import torch` (`config_envs.cmake`)
281- # then fail with `ModuleNotFoundError` even though `torch` is
282- # installed.
283- add_custom_command (
284- OUTPUT ${_custom_lib}
285- COMMAND ${CMAKE_COMMAND} -E env
286- --unset=CMAKE_GENERATOR
287- --unset=CMAKE_EXPORT_COMPILE_COMMANDS
288- --unset=CMAKE_BUILD_PARALLEL_LEVEL
289- --unset=PYTHONPATH
290- "BUILD_DIR=${_custom_build_dir} "
291- "CMAKE_EXE=${CMAKE_COMMAND} "
292- bash ${CMAKE_CURRENT_SOURCE_DIR} /ascend/custom/build.sh ${SOC_VERSION}
293- WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} /ascend/custom
294- DEPENDS ${_custom_srcs}
295- COMMENT "Building custom AscendC kernels (SOC_VERSION=${SOC_VERSION} )"
296- VERBATIM )
297-
298- add_custom_target (no_workspace_kernel_build ALL DEPENDS ${_custom_lib} )
299-
300- add_library (no_workspace_kernel STATIC IMPORTED GLOBAL )
301- set_target_properties (no_workspace_kernel PROPERTIES
302- IMPORTED_LOCATION "${_custom_lib} " )
303- add_dependencies (no_workspace_kernel no_workspace_kernel_build )
244+ if (BUILD_CUSTOM_KERNEL)
245+ add_subdirectory (ascend/custom )
304246
305247 # Link the compiled `AscendC` kernel objects into `infiniops` so that
306248 # custom kernel implementations (e.g. `RmsNorm` index 1) can call
@@ -437,13 +379,9 @@ if(GENERATE_PYTHON_BINDINGS)
437379 # The `Operator<..., 1>` template instantiations that call
438380 # `aclrtlaunch_*` live in `ops.cc`, so link here with
439381 # `--whole-archive` to ensure all launch functions are available.
440- # `$<TARGET_FILE>` works for both real `ascendc_library()` targets and
441- # `IMPORTED` targets pointing at a pre-built `.a`.
442- if (BUILD_ASCEND_CUSTOM)
382+ if (BUILD_CUSTOM_KERNEL)
443383 target_link_libraries (ops PRIVATE
444- -Wl,--whole-archive $<TARGET_FILE :no_workspace_kernel > -Wl,--no-whole-archive )
445- # `ops` link step must wait for `build.sh` to produce the `.a`.
446- add_dependencies (ops no_workspace_kernel_build )
384+ -Wl,--whole-archive no_workspace_kernel -Wl,--no-whole-archive )
447385 endif ()
448386
449387 set_target_properties (infiniops PROPERTIES INSTALL_RPATH "$ORIGIN" )
0 commit comments