Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(WITH_NCCL "Enable NCCL backend" OFF)
option(WITH_MCCL "Enable MCCL backend" OFF)
option(WITH_CNCL "Enable CNCL backend" OFF)
option(WITH_HCCL "Enable HCCL backend" OFF)
option(WITH_BKCL "Enable BKCL backend" OFF)

# =========================================================
# --- MISC. BUILD OPTIONS ---
Expand All @@ -45,13 +46,15 @@ include(cmake/devices/Cambricon.cmake)
include(cmake/devices/Ascend.cmake)
include(cmake/devices/Hygon.cmake)
include(cmake/devices/THead.cmake)
include(cmake/devices/Kunlun.cmake)

# Backend modules provide backend probes and required dependency resolution.
include(cmake/backends/MPI.cmake)
include(cmake/backends/NCCL.cmake)
include(cmake/backends/MCCL.cmake)
include(cmake/backends/CNCL.cmake)
include(cmake/backends/HCCL.cmake)
include(cmake/backends/BKCL.cmake)

# =========================================================
# --- AUTO-DETECTION: DEVICES ---
Expand Down Expand Up @@ -92,6 +95,10 @@ if(AUTO_DETECT_DEVICES)
infiniccl_resolve_device_detection(
WITH_THEAD "T-Head" infiniccl_detect_thead THEAD_FOUND)

# Kunlun
infiniccl_resolve_device_detection(
WITH_KUNLUN "Kunlun" infiniccl_detect_kunlun KUNLUN_FOUND)

# NVIDIA Final Resolution: resolve conflicts.
if(THEAD_FOUND AND NVIDIA_FOUND AND NOT NVIDIA_REQUESTED)
set(NVIDIA_FOUND FALSE)
Expand Down Expand Up @@ -163,10 +170,21 @@ if(AUTO_DETECT_BACKENDS)
message(STATUS "HCCL library/headers not found in Ascend paths.")
endif()
endif()

# Detect BKCL Dependencies
if(WITH_KUNLUN)
infiniccl_probe_bkcl(BKCL_FOUND)
if(BKCL_FOUND)
set(WITH_BKCL ON)
message(STATUS "Auto-detected BKCL backend.")
else()
message(STATUS "BKCL library/headers not found in Kunlun paths.")
endif()
endif()
endif()

# Fallback: If no backends are enabled or auto-detected, fall back to OpenMPI as the default bootstrap profile.
if(NOT WITH_OMPI AND NOT WITH_MPICH AND NOT WITH_NCCL AND NOT WITH_MCCL AND NOT WITH_CNCL AND NOT WITH_HCCL)
if(NOT WITH_OMPI AND NOT WITH_MPICH AND NOT WITH_NCCL AND NOT WITH_MCCL AND NOT WITH_CNCL AND NOT WITH_HCCL AND NOT WITH_BKCL)
set(WITH_OMPI ON)
message(STATUS "No backend specified or detected. Defaulting to `WITH_OMPI=ON`")
endif()
Expand Down Expand Up @@ -237,6 +255,14 @@ if(WITH_HCCL)
infiniccl_configure_hccl(HCCL_INC HCCL_LIB)
endif()

if(WITH_KUNLUN)
infiniccl_configure_kunlun(KUNLUN_INC KUNLUN_XPURT_LIB)
endif()

if(WITH_BKCL)
infiniccl_configure_bkcl(BKCL_INC BKCL_LIB)
endif()

# Python is required for code generation.
find_package(Python3 REQUIRED)

Expand Down
29 changes: 29 additions & 0 deletions cmake/backends/BKCL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
include_guard(GLOBAL)

function(infiniccl_probe_bkcl output)
infiniccl_collect_kunlun_hints(_hints)
find_path(_INFINICCL_AUTO_BKCL_INC NAMES xccl.h
HINTS ${_hints} PATH_SUFFIXES xccl/include include)
find_library(_INFINICCL_AUTO_BKCL_LIB NAMES bkcl
HINTS ${_hints} PATH_SUFFIXES lib lib64)
if(_INFINICCL_AUTO_BKCL_INC AND _INFINICCL_AUTO_BKCL_LIB)
set(${output} TRUE PARENT_SCOPE)
else()
set(${output} FALSE PARENT_SCOPE)
endif()
endfunction()

function(infiniccl_configure_bkcl include_output library_output)
if(NOT WITH_KUNLUN)
message(FATAL_ERROR "BKCL backend requires Kunlun XPU support. Please enable `WITH_KUNLUN`.")
endif()

infiniccl_collect_kunlun_hints(_hints)
find_path(_INFINICCL_BKCL_INC NAMES xccl.h
HINTS ${_hints} PATH_SUFFIXES xccl/include include REQUIRED)
find_library(_INFINICCL_BKCL_LIB NAMES bkcl
HINTS ${_hints} PATH_SUFFIXES lib lib64 REQUIRED)

set(${include_output} "${_INFINICCL_BKCL_INC}" PARENT_SCOPE)
set(${library_output} "${_INFINICCL_BKCL_LIB}" PARENT_SCOPE)
endfunction()
51 changes: 51 additions & 0 deletions cmake/devices/Kunlun.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
include_guard(GLOBAL)

function(infiniccl_collect_kunlun_hints output)
set(_hints)
if(KUNLUN_HOME)
list(APPEND _hints "${KUNLUN_HOME}")
endif()
if(DEFINED ENV{KUNLUN_HOME} AND NOT "$ENV{KUNLUN_HOME}" STREQUAL "")
list(APPEND _hints "$ENV{KUNLUN_HOME}")
endif()
list(APPEND _hints /usr/local/xtdk)
list(REMOVE_DUPLICATES _hints)
set(${output} "${_hints}" PARENT_SCOPE)
endfunction()

function(infiniccl_detect_kunlun output)
set(_found FALSE)
file(GLOB _KUNLUN_DEV_FILES "/dev/xpu*")
if(_KUNLUN_DEV_FILES)
set(_found TRUE)
else()
find_program(_INFINICCL_KUNLUN_SMI_PATH xpu-smi)
if(_INFINICCL_KUNLUN_SMI_PATH)
execute_process(
COMMAND ${_INFINICCL_KUNLUN_SMI_PATH}
RESULT_VARIABLE _result
OUTPUT_QUIET ERROR_QUIET TIMEOUT 15)
if(_result EQUAL 0)
set(_found TRUE)
endif()
endif()
endif()
set(${output} ${_found} PARENT_SCOPE)
endfunction()

function(infiniccl_configure_kunlun include_output runtime_library_output)
infiniccl_collect_kunlun_hints(_hints)

# `xccl.h` (communication API) ships in the XTDK `xccl/` tree; the XRE
# runtime headers (`xpu/runtime.h`) in `xre/`.
find_path(_INFINICCL_BKCL_INC NAMES xccl.h
HINTS ${_hints} PATH_SUFFIXES xccl/include include REQUIRED)
find_path(_INFINICCL_XRE_INC NAMES xpu/runtime.h
HINTS ${_hints} PATH_SUFFIXES xre/include include REQUIRED)
find_library(_INFINICCL_XPURT_LIB NAMES xpurt
HINTS ${_hints} PATH_SUFFIXES xre/so lib lib64 REQUIRED)

set(${include_output} "${_INFINICCL_BKCL_INC};${_INFINICCL_XRE_INC}"
PARENT_SCOPE)
set(${runtime_library_output} "${_INFINICCL_XPURT_LIB}" PARENT_SCOPE)
endfunction()
15 changes: 15 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ foreach(source_file ${EXAMPLE_SOURCES})
set(target_name ${file_we})
endif()

# The BKCL p2p example drives the kunlun runtime directly and cannot
# compile against backends that lack stream primitives (e.g. CPU).
if(${file_we} STREQUAL "pp_p2p" AND NOT WITH_KUNLUN)
continue()
endif()

add_executable(${target_name} ${source_file})

set_target_properties(${target_name} PROPERTIES
Expand Down Expand Up @@ -65,6 +71,11 @@ foreach(source_file ${EXAMPLE_SOURCES})
target_link_libraries(${target_name} PRIVATE ${HYGON_HIP_RUNTIME_LIB})
endif()

if(WITH_KUNLUN)
target_include_directories(${target_name} PRIVATE ${KUNLUN_INC})
target_link_libraries(${target_name} PRIVATE ${KUNLUN_XPURT_LIB})
endif()

if(WITH_OMPI OR WITH_MPICH)
target_link_libraries(${target_name} PRIVATE MPI::MPI_CXX)
endif()
Expand All @@ -86,6 +97,10 @@ foreach(source_file ${EXAMPLE_SOURCES})
target_include_directories(${target_name} PRIVATE ${HCCL_INC})
endif()

if(WITH_BKCL)
target_include_directories(${target_name} PRIVATE ${BKCL_INC})
endif()

# Explicitly allow examples to "peek" into the internal `src` and binary dirs.
# This is necessary because these were marked `PRIVATE` in the library's CMake.
target_include_directories(${target_name} PRIVATE
Expand Down
Loading