Skip to content

add FlagCX as optional communication library when using iluvatar gpus #1862

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
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
12 changes: 10 additions & 2 deletions backends/iluvatar_gpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ include(external/eigen)
include(external/xxhash)
include(external/zlib)
include(external/protobuf)
if(WITH_FLAGCX)
add_definitions("-DPADDLE_WITH_FLAGCX")
include(external/flagcx)
endif()

set(PLUGIN_VERSION ${PADDLE_VERSION})
set(PROTO_FILE "${PADDLE_SOURCE_DIR}/paddle/phi/core/external_error.proto")
Expand Down Expand Up @@ -66,8 +70,10 @@ target_include_directories(external_error_proto
target_link_libraries(external_error_proto PUBLIC protobuf)
set_target_properties(external_error_proto PROPERTIES POSITION_INDEPENDENT_CODE
ON)

add_custom_target(external_deps DEPENDS eigen3 zlib protobuf)
if(WITH_FLAGCX)
add_custom_target(external_deps DEPENDS flagcx)
endif()

if(WITH_COREX)
add_definitions(-DPADDLE_WITH_COREX)
Expand Down Expand Up @@ -258,7 +264,9 @@ target_link_libraries(
protobuf
external_error_proto
cuinfer
nccl)
nccl
# change nccl to ${FLAGCX_LIB} if compiling with FlagCX ${FLAGCX_LIB}
)

include_directories(BEFORE ${PADDLE_SOURCE_DIR})

Expand Down
20 changes: 15 additions & 5 deletions backends/iluvatar_gpu/build_paddle.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#!/bin/bash

# Copyright (c) 2025 PaddlePaddle Authors. All Rights Reserved.
#
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#
# http://www.apache.org/licenses/LICENSE-2.0
#
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,6 +26,15 @@ export CMAKE_CUDA_ARCHITECTURES=${COREX_ARCH}
CURRENT_DIR=$(pwd)
PADDLE_SOURCE_DIR="${CURRENT_DIR}/../../Paddle"
PATCH_FILE="${CURRENT_DIR}/patches/paddle-corex.patch"
# set BUILD_WITH_FLAGCX to 1 if we want to use flagcx as communication backend
BUILD_WITH_FLAGCX=0
FLAGCX_ROOT="/workspace/FlagCX"

if [ "$BUILD_WITH_FLAGCX" == "1" ]; then
WITH_FLAGCX="ON"
else
WITH_FLAGCX="OFF"
fi

bash clean_paddle.sh

Expand All @@ -51,9 +60,10 @@ if [[ ! -d "build" ]]; then
fi
pushd build

cmake -DPY_VERSION=${PYTHON_VERSION} -DWITH_COREX=ON \
-DWITH_DISTRIBUTE=ON -DWITH_NCCL=ON -DWITH_RCCL=OFF -DCMAKE_BUILD_TYPE=Release \
cmake -DPY_VERSION=${PYTHON_VERSION} -DWITH_COREX=ON -DPADDLE_SOURCE_DIR=${PADDLE_SOURCE_DIR} \
-DWITH_DISTRIBUTE=ON -DWITH_NCCL=ON -DWITH_FLAGCX=${WITH_FLAGCX} -DWITH_RCCL=OFF -DCMAKE_BUILD_TYPE=Release \
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DON_INFER=ON -DCOREX_VERSION=${COREX_VERSION} -DCOREX_ARCH=${COREX_ARCH} \
-DFLAGCX_ROOT=${FLAGCX_ROOT} \
-DCMAKE_CXX_FLAGS='-Wno-error=pessimizing-move -Wno-error=deprecated-copy -Wno-error=init-list-lifetime' \
-DCMAKE_CUDA_FLAGS='-Xclang -fcuda-allow-variadic-functions -mllvm --skip-double' \
-DWITH_ARM=OFF -DWITH_DGC=OFF .. 2>&1 | tee compile.log
Expand Down
41 changes: 41 additions & 0 deletions backends/iluvatar_gpu/cmake/external/flagcx.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
set(CMAKE_FIND_DEBUG_MODE ON)
# flagcx.cmake
if(NOT WITH_FLAGCX)
return()
endif()

set(FLAGCX_SOURCE_DIR "${FLAGCX_ROOT}")
set(FLAGCX_LIB_DIR "${FLAGCX_SOURCE_DIR}/build/lib")
set(FLAGCX_BINARY_DIR "${PADDLE_SOURCE_DIR}/build/third_party/flagcx")
set(THIRD_PARTY_DIR "${PADDLE_SOURCE_DIR}/build/third_party")

file(REMOVE_RECURSE ${FLAGCX_BINARY_DIR})
message(STATUS "removed old flagcx dir")
message(STATUS "Copying third-party source to build directory")
execute_process(COMMAND cp -r ${FLAGCX_SOURCE_DIR} ${THIRD_PARTY_DIR}
RESULT_VARIABLE COPY_RESULT)

if(NOT COPY_RESULT EQUAL 0)
message(FATAL_ERROR "Failed to copy third-party source to build directory")
endif()

# Create a custom target to build the third-party library
message(STATUS "Building third-party library with its Makefile")

find_path(
FLAGCX_INCLUDE_DIR flagcx.h
PATHS ${FLAGCX_SOURCE_DIR}/flagcx/include
NO_DEFAULT_PATH)

message(STATUS "FLAGCX_INCLUDE_DIR is ${FLAGCX_INCLUDE_DIR}")
include_directories(SYSTEM ${FLAGCX_INCLUDE_DIR})

add_library(flagcx INTERFACE)
find_library(
FLAGCX_LIB
NAMES flagcx libflagcx
PATHS ${FLAGCX_LIB_DIR}
DOC "My custom library")

add_dependencies(flagcx FLAGCX_LIB)
message(STATUS "FLAGCX_LIB is ${FLAGCX_LIB}")
Loading