forked from sgl-project/sgl-kernel-npu
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
126 lines (103 loc) · 2.97 KB
/
build.sh
File metadata and controls
126 lines (103 loc) · 2.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
set -e
BUILD_TYPE=""
while getopts ":a:" opt; do
case ${opt} in
a )
BUILD_TYPE=$OPTARG
if [[ "$BUILD_TYPE" != "deepep" ]]; then
echo "Error: Invalid value, only 'deepep' is allowed"
exit 1
fi
;;
\? )
echo "Error: unknown flag: -$OPTARG" 1>&2
exit 1
;;
: )
echo "Error: -$OPTARG requires a value" 1>&2
exit 1
;;
esac
done
shift $((OPTIND -1))
SOC_VERSION="${1:-Ascend910_9382}"
if [ -n "$ASCEND_HOME_PATH" ]; then
_ASCEND_INSTALL_PATH=$ASCEND_HOME_PATH
else
_ASCEND_INSTALL_PATH=/usr/local/Ascend/ascend-toolkit/latest
fi
export ASCEND_TOOLKIT_HOME=${_ASCEND_INSTALL_PATH}
export ASCEND_HOME_PATH=${_ASCEND_INSTALL_PATH}
echo "ascend path: ${ASCEND_HOME_PATH}"
source $(dirname ${ASCEND_HOME_PATH})/set_env.sh
CURRENT_DIR=$(pwd)
PROJECT_ROOT=$(dirname "$CURRENT_DIR")
VERSION="1.0.0"
OUTPUT_DIR=$CURRENT_DIR/output
echo "outpath: ${OUTPUT_DIR}"
COMPILE_OPTIONS=""
function build_kernels()
{
CMAKE_DIR=""
BUILD_DIR="build"
cd "$CMAKE_DIR" || exit
rm -rf $BUILD_DIR
mkdir -p $BUILD_DIR
cmake $COMPILE_OPTIONS -DCMAKE_INSTALL_PREFIX="$OUTPUT_DIR" -DASCEND_HOME_PATH=$ASCEND_HOME_PATH -DSOC_VERSION=$SOC_VERSION -DBUILD_TYPE=$BUILD_TYPE -B "$BUILD_DIR" -S .
cmake --build "$BUILD_DIR" -j8 && cmake --build "$BUILD_DIR" --target install
cd -
}
function build_deepep_kernels()
{
KERNEL_DIR="csrc/deepep/ops"
CUSTOM_OPP_DIR="${CURRENT_DIR}/python/deep_ep/deep_ep"
cd "$KERNEL_DIR" || exit
chmod +x build.sh
chmod +x cmake/util/gen_ops_filter.sh
./build.sh
custom_opp_file=$(find ./build_out -maxdepth 1 -type f -name "custom_opp*.run")
if [ -z "$custom_opp_file" ]; then
echo "can not find run package"
exit 1
else
echo "find run package: $custom_opp_file"
chmod +x "$custom_opp_file"
fi
./build_out/custom_opp_*.run --install-path=$CUSTOM_OPP_DIR
cd -
}
function make_deepep_package()
{
cd python/deep_ep || exit
cp -v ${OUTPUT_DIR}/lib/* "$CURRENT_DIR"/python/deep_ep/deep_ep/
rm -rf "$CURRENT_DIR"/python/deep_ep/build
python3 setup.py clean --all
python3 setup.py bdist_wheel
mv -v "$CURRENT_DIR"/python/deep_ep/dist/deep_ep*.whl ${OUTPUT_DIR}/
rm -rf "$CURRENT_DIR"/python/deep_ep/dist
cd -
}
function make_sgl_kernel_npu_package()
{
cd python/sgl_kernel_npu || exit
rm -rf "$CURRENT_DIR"/python/sgl_kernel_npu/dist
python3 setup.py clean --all
python3 setup.py bdist_wheel
mv -v "$CURRENT_DIR"/python/sgl_kernel_npu/dist/sgl_kernel_npu*.whl ${OUTPUT_DIR}/
rm -rf "$CURRENT_DIR"/python/sgl_kernel_npu/dist
cd -
}
function main()
{
build_kernels
build_deepep_kernels
if pip3 show wheel;then
echo "wheel has been installed"
else
pip3 install wheel
fi
make_deepep_package
make_sgl_kernel_npu_package
}
main