Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 build.sh
chmod +x deepep/build.sh
chmod +x deepep/compile_ascend_proj.sh
./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
75 changes: 75 additions & 0 deletions csrc/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/bin/bash
echo "Start the cmake script..."
SCRIPT_PATH=$(cd "$(dirname "$0")" && pwd)/$(basename "$0")
export ROOT_PATH=$(dirname "$SCRIPT_PATH")
echo ROOT_PATH: $ROOT_PATH
if [ ! -d "./build_out" ]; then
mkdir build_out
fi
export SRC_PATH="${ROOT_PATH}"
export BUILD_OUT_PATH="${ROOT_PATH}/build_out"
export SCRIPTS_PATH="${ROOT_PATH}"
export TEST_PATH="${ROOT_PATH}/test"

export BUILD_TYPE="Release"
MODULE_NAME="all"
MODULE_BUILD_ARG=""
IS_MODULE_EXIST=0

function PrintHelp() {
echo "
./build.sh [module name] <opt>...
If there are no parameters, all modules are compiled in default mode
module list: [deepep]

opt:
-d: Enable debug
"
}

function ProcessArg() {
while getopts "dh" opt; do
case $opt in
d)
export BUILD_TYPE="Debug"
;;
h)
PrintHelp
exit 0
;;
esac
done
shift $(($OPTIND-1))
}

function IsModuleName() {
if [ -z "$1" ]; then
return 1
fi

if [[ $1 == -* ]]; then
return 1
else
return 0
fi
}

if IsModuleName $@; then
MODULE_NAME=$1
shift
else
ProcessArg $@
fi

if [[ "$MODULE_NAME" == "all" || "$MODULE_NAME" == "deepep" ]]; then
IS_MODULE_EXIST=1
echo "./deepep/build.sh $@"
./deepep/build.sh $@
if [ $? -ne 0 ]; then
exit 1
fi
fi

if [ $IS_MODULE_EXIST -eq 0 ]; then
echo "module not exist"
fi
Comment thread
1329009851 marked this conversation as resolved.
Outdated
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
Suport 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
Comment thread
1329009851 marked this conversation as resolved.
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
Comment thread
1329009851 marked this conversation as resolved.
Outdated
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
Comment thread
1329009851 marked this conversation as resolved.
Outdated
Loading
Loading