Skip to content
Merged
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: 11 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ function build_memory_saver()
cd -
}

function create_deepep_cmake()
{
cd csrc || exit
chmod +x deepep_cmake_build.sh
chmod +x deepep/build.sh
chmod +x deepep/compile_ascend_proj.sh
./deepep_cmake_build.sh
cd -
}

function make_deepep_package()
{
cd python/deep_ep || exit
Expand Down Expand Up @@ -209,7 +219,7 @@ function make_sgl_kernel_npu_package()

function main()
{

create_deepep_cmake
build_kernels
build_deepep_kernels
if pip3 show wheel;then
Expand Down
40 changes: 40 additions & 0 deletions csrc/deepep/AddCustom.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[
{
"op": "AddCustom",
"language": "cpp",
"input_desc": [
{
"name": "x",
"param_type": "required",
"format": [
"ND"
],
"type": [
"float16"
]
},
{
"name": "y",
"param_type": "required",
"format": [
"ND"
],
"type": [
"float16"
]
}
],
"output_desc": [
{
"name": "z",
"param_type": "required",
"format": [
"ND"
],
"type": [
"float16"
]
}
]
}
]
123 changes: 123 additions & 0 deletions csrc/deepep/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
#!/bin/bash
export MODULE_NAME="deepep"
export MODULE_SRC_PATH="${SRC_PATH}/${MODULE_NAME}"
export MODULE_SCRIPTS_PATH="${SCRIPTS_PATH}/${MODULE_NAME}"
export MODULE_BUILD_OUT_PATH="${BUILD_OUT_PATH}/${MODULE_NAME}"
export MODULE_TEST_PATH="${TEST_PATH}/${MODULE_NAME}"
IS_EXTRACT=0
SOC_VERSION="all"
ENABLE_UT_BUILD=0
ENABLE_PYBIND_BUILD=0
ENABLE_SRC_BUILD=1

BuildPybind() {
DIST_OUT_PATH=$MODULE_BUILD_OUT_PATH
if [ -d $DIST_OUT_PATH/dist ]; then
rm -rf $DIST_OUT_PATH/dist
fi
EXT_PATH=$MODULE_SRC_PATH
cd $EXT_PATH
sh build.sh
DIST_GEN_PATH=$EXT_PATH/dist/
if [ -d $DIST_GEN_PATH ]; then
echo "copy $DIST_GEN_PATH to $DIST_OUT_PATH/"
cp -rf $DIST_GEN_PATH $DIST_OUT_PATH/
else
echo $DIST_GEN_PATH does not exist
echo "BuildPybind fail"
return 1
fi
}

BuildTest() {
cd ${MODULE_TEST_PATH}/ut_gtest
if [ -d "./build" ]; then
rm -rf "./build"
fi
mkdir ./build
cd build
cmake .. && make -j && make install
if [ $? -ne 0 ]; then
echo "BuildTest fail"
return 1
fi
}

PrintHelp() {
echo "
./build.sh comm_operator <opt>...
-x Extract the run package
-c Target SOC VERSION
Support Soc: [ascend910_93, ascend910b4]
-d Enable debug
-t enable UT build
-p enable pybind build
-r enable code coverage
"
}

while getopts "c:xdtprh" opt; do
case $opt in
c)
SOC_VERSION=$OPTARG
;;
x)
IS_EXTRACT=1
;;
d)
export BUILD_TYPE="Debug"
;;
t)
ENABLE_UT_BUILD=1
ENABLE_SRC_BUILD=0
;;
p)
ENABLE_PYBIND_BUILD=1
ENABLE_SRC_BUILD=0
;;
r)
export BUILD_TYPE="Debug"
export ENABLE_COV=1
;;
h)
PrintHelp
exit 0
;;
esac
done

echo "Start creating the CMake file"

if [ ! -d "$BUILD_OUT_PATH/${MODULE_NAME}" ]; then
echo "mkdir $BUILD_OUT_PATH/${MODULE_NAME}"
mkdir $BUILD_OUT_PATH/${MODULE_NAME}
fi

if [ $ENABLE_SRC_BUILD -eq 1 ]; then
if [[ "$SOC_VERSION" == "all" ]]; then
echo "$MODULE_SCRIPTS_PATH/compile_ascend_proj.sh $MODULE_SRC_PATH Ascend910_9382 $IS_EXTRACT $BUILD_TYPE"
bash $MODULE_SCRIPTS_PATH/compile_ascend_proj.sh $MODULE_SRC_PATH Ascend910_9382 $IS_EXTRACT $BUILD_TYPE
else
echo "$MODULE_SCRIPTS_PATH/compile_ascend_proj.sh $MODULE_SRC_PATH $SOC_VERSION $IS_EXTRACT $BUILD_TYPE"
bash $MODULE_SCRIPTS_PATH/compile_ascend_proj.sh $MODULE_SRC_PATH $SOC_VERSION $IS_EXTRACT $BUILD_TYPE
fi
if [ $? -ne 0 ]; then
exit 1
fi
fi

if [ $ENABLE_PYBIND_BUILD -eq 1 ]; then
echo "Start to BuildPybind"
BuildPybind
if [ $? -ne 0 ]; then
exit 1
fi
fi

if [ $ENABLE_UT_BUILD -eq 1 ]; then
echo "Start to BuildTest"
BuildTest
if [ $? -ne 0 ]; then
exit 1
fi
fi
82 changes: 82 additions & 0 deletions csrc/deepep/compile_ascend_proj.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash
CopyOps() {
local src_dir="$1" # Path of Source Directory A
local dst_dir="$2" # Path of Target Directory B

if [ -d "$src_dir/op_host" ]; then
cp -rf "$src_dir/op_host/"* "$dst_dir/op_host/"
echo "cp -rf $src_dir/op_host/* $dst_dir/op_host/"
fi

if [ -d "$src_dir/op_kernel" ]; then
cp -rf "$src_dir/op_kernel/"* "$dst_dir/op_kernel/"
echo "cp -rf $src_dir/op_kernel/* $dst_dir/op_kernel/"
fi

# Ensure that op_host and op_kernel exist in the target directory
mkdir -p "$dst_dir/op_host" "$dst_dir/op_kernel"

# Traverse all direct subdirectories under the source directory (including directory names with spaces)
find "$src_dir" -mindepth 1 -maxdepth 1 -type d -print0 | while IFS= read -r -d '' subdir; do
# Check whether the subdirectory exists (although find has already filtered it, double-checking is safer)
if [ -d "$subdir" ]; then
# Processing the op_host directory
if [ -d "$subdir/op_host" ]; then
cp -rf "$subdir/op_host/"* "$dst_dir/op_host/"
echo "cp -rf $subdir/op_host/* $dst_dir/op_host/"
fi

# Processing the op_kernel directory
if [ -d "$subdir/op_kernel" ]; then
cp -rf "$subdir/op_kernel/"* "$dst_dir/op_kernel/"
echo "cp -rf $subdir/op_kernel/* $dst_dir/op_kernel/"
fi
fi
done
echo "${src_dir} built successfully"
}

BuildOps() {
local proj_name=$1
echo "${proj_name}"
local soc_version=$2

if [ -d "./${proj_name}" ]; then
rm -rf ${proj_name}/cmake
rm -rf ${proj_name}/op_host
rm -rf ${proj_name}/op_kernel
rm -rf ${proj_name}/scripts
rm -rf ${proj_name}/build.sh
rm -rf ${proj_name}/CMakeLists.txt
rm -rf ${proj_name}/CMakePresets.json
rm -rf ${proj_name}/framework
fi

echo "msopgen gen -i ./AddCustom.json -c ai_core-${soc_version} -f pytorch -lan cpp -out ${proj_name}"
msopgen gen -i ./AddCustom.json -c ai_core-${soc_version} -f pytorch -lan cpp -out ${proj_name}
rm -rf ./${proj_name}/op_host/add_custom*
rm -rf ./${proj_name}/op_kernel/add_custom*
}

# Build the operator project and transfer its output to the specified location
BuildAscendProj() {
local os_id=$(grep ^ID= /etc/os-release | cut -d= -f2 | tr -d '"')
local arch=$(uname -m)
local soc_version=$2
local is_extract=$3
local build_type=$4
# Modify the default operator name
export OPS_PROJECT_NAME=aclnnInner
# Enter the compilation path
echo "cd $1"
cd $1

BuildOps "ops_${soc_version}" ${soc_version}
BuildOps "ops2_${soc_version}" ${soc_version}
CopyOps "./ops" "./ops_${soc_version}"
CopyOps "./ops2" "./ops2_${soc_version}"
cp -r ./ops_${soc_version}/cmake ./ops
cp -r ./ops2_${soc_version}/cmake ./ops2
}

BuildAscendProj $1 $2 $3 $4
55 changes: 54 additions & 1 deletion csrc/deepep/ops/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,34 @@ else()
message(FATAL_ERROR "Unsupported host processor: ${CMAKE_SYSTEM_PROCESSOR}. Please specify a valid architecture.")
endif()

set(CANN82_PATH "${ASCEND_CANN_PACKAGE_PATH}/include/experiment/platform/platform/platform_infos_def.h")
set(CANN83_PATH "${ASCEND_CANN_PACKAGE_PATH}/include/platform/platform_infos_def.h")

if (EXISTS "${CANN83_PATH}")
set(CANN_VERSION_MACRO "USE_CANN83_PATH")
message(STATUS "Detected CANN 8.3+ include structure, using ${CANN83_PATH}")
elseif (EXISTS "${CANN82_PATH}")
set(CANN_VERSION_MACRO "USE_CANN82_PATH")
message(STATUS "Detected CANN 8.2 include structure, using ${CANN82_PATH}")
else()
message(FATAL_ERROR
"Cannot find 'platform_infos_def.h' in expected locations.\n"
"Please verify that CANN is correctly installed and that either:\n"
" ${CANN83_PATH}\n"
" or\n"
" ${CANN82_PATH}\n"
"exists and contains the header file."
)
endif()

include(cmake/config.cmake)
include(cmake/func.cmake)
include(func.cmake)
include(cmake/intf.cmake)

if (CANN_VERSION_MACRO)
add_compile_definitions(${CANN_VERSION_MACRO})
endif()

set(CMAKE_COMPILE ${CMAKE_CXX_COMPILER})

if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/framework)
Expand All @@ -39,6 +63,35 @@ add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/scripts/install.sh ${CMAKE_BINARY_
)
add_custom_target(modify_vendor ALL DEPENDS ${CMAKE_BINARY_DIR}/scripts/install.sh ${CMAKE_BINARY_DIR}/scripts/upgrade.sh)

cmake_parse_arguments(OPBUILD "" "OUT_DIR;PROJECT_NAME;ACCESS_PREFIX;ENABLE_SOURCE" "OPS_SRC" ${ARGN})
if (DEFINED CANN_VERSION_MACRO AND NOT "${CANN_VERSION_MACRO}" STREQUAL "")
set(CANN_VERSION_FLAG "-D${CANN_VERSION_MACRO}")
message(STATUS "opbuild: Detected CANN_VERSION_MACRO = ${CANN_VERSION_MACRO}")
else()
set(CANN_VERSION_FLAG "")
message(WARNING "opbuild: No CANN_VERSION_MACRO defined! Possible #error in .cc files.")
endif()

execute_process(
COMMAND ${CMAKE_COMPILE} -g -fPIC -shared -std=c++11
${OPBUILD_OPS_SRC}
-D_GLIBCXX_USE_CXX11_ABI=0
${CANN_VERSION_FLAG}
-I ${ASCEND_CANN_PACKAGE_PATH}/include
-I ${CMAKE_CURRENT_SOURCE_DIR}/../op_kernel
-L ${ASCEND_CANN_PACKAGE_PATH}/lib64
-lexe_graph -lregister -ltiling_api
-o ${OPBUILD_OUT_DIR}/libascend_all_ops.so
RESULT_VARIABLE EXEC_RESULT
OUTPUT_VARIABLE EXEC_INFO
ERROR_VARIABLE EXEC_ERROR
)
if (${EXEC_RESULT})
message("build ops lib info: ${EXEC_INFO}")
message("build ops lib error: ${EXEC_ERROR}")
message(FATAL_ERROR "opbuild run failed!")
endif()

get_system_info(SYSTEM_INFO)

# gen version.info
Expand Down
42 changes: 0 additions & 42 deletions csrc/deepep/ops/cmake/config.cmake

This file was deleted.

Loading