Skip to content

Commit 00561f0

Browse files
authored
add build script and release workflow (#9)
1 parent bde4bc1 commit 00561f0

File tree

18 files changed

+574
-90
lines changed

18 files changed

+574
-90
lines changed

.clang-format

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
Language: Cpp
2+
AccessModifierOffset: -4
3+
AlignAfterOpenBracket: Align
4+
AllowShortEnumsOnASingleLine: false
5+
AlignConsecutiveAssignments: true
6+
AlignConsecutiveDeclarations: true
7+
AlignEscapedNewlines: Right
8+
AlignOperands: true
9+
AlignTrailingComments: true
10+
AllowAllParametersOfDeclarationOnNextLine: true
11+
AllowAllArgumentsOnNextLine: true
12+
AllowShortBlocksOnASingleLine: Empty
13+
AllowShortCaseLabelsOnASingleLine: false
14+
AllowShortFunctionsOnASingleLine: Empty
15+
AllowShortIfStatementsOnASingleLine: Never
16+
AllowShortLoopsOnASingleLine: false
17+
AlwaysBreakAfterReturnType: None
18+
AlwaysBreakBeforeMultilineStrings: false
19+
AlwaysBreakTemplateDeclarations: true
20+
BinPackArguments: false
21+
BinPackParameters: false
22+
BreakBeforeBinaryOperators: NonAssignment
23+
BreakBeforeBraces: Stroustrup
24+
BreakBeforeTernaryOperators: false
25+
BreakConstructorInitializers: AfterColon
26+
BreakInheritanceList: AfterColon
27+
BreakStringLiterals: false
28+
ColumnLimit: 120
29+
CompactNamespaces: false
30+
ConstructorInitializerAllOnOneLineOrOnePerLine: true
31+
ConstructorInitializerIndentWidth: 4
32+
ContinuationIndentWidth: 4
33+
Cpp11BracedListStyle: true
34+
DerivePointerAlignment: false
35+
FixNamespaceComments: true
36+
IndentCaseLabels: true
37+
IndentPPDirectives: None
38+
IndentWidth: 4
39+
IndentWrappedFunctionNames: false
40+
KeepEmptyLinesAtTheStartOfBlocks: true
41+
MaxEmptyLinesToKeep: 1
42+
NamespaceIndentation: None
43+
PointerAlignment: Left
44+
ReflowComments: true
45+
SortIncludes: true
46+
SortUsingDeclarations: false
47+
SpaceAfterCStyleCast: false
48+
SpaceAfterTemplateKeyword: false
49+
SpaceBeforeAssignmentOperators: true
50+
SpaceBeforeCtorInitializerColon: false
51+
SpaceBeforeInheritanceColon: false
52+
SpaceBeforeParens: ControlStatements
53+
SpaceInEmptyParentheses: false
54+
SpacesBeforeTrailingComments: 2
55+
SpacesInAngles: false
56+
SpacesInCStyleCastParentheses: false
57+
SpacesInContainerLiterals: false
58+
SpacesInParentheses: false
59+
SpacesInSquareBrackets: false
60+
Standard: c++17
61+
TabWidth: 4
62+
UseTab: Never
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
name: cuda11.8-whl-release
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
linux-build:
14+
strategy:
15+
matrix:
16+
pyver: [py38, py39, py310, py311, py312]
17+
runs-on: ubuntu-latest
18+
env:
19+
PYTHON_VERSION: ${{ matrix.pyver }}
20+
PLAT_NAME: manylinux2014_x86_64
21+
DOCKER_TAG: cuda11.8
22+
OUTPUT_FOLDER: cuda11.8_dist
23+
CUDA_VER: 11.8
24+
steps:
25+
- name: Free disk space
26+
uses: jlumbroso/free-disk-space@main
27+
with:
28+
# This might remove tools that are actually needed, if set to "true" but frees about 6 GB
29+
tool-cache: false
30+
docker-images: false
31+
# All of these default to true, but feel free to set to "false" if necessary for your workflow
32+
android: true
33+
dotnet: true
34+
haskell: true
35+
large-packages: true
36+
swap-storage: false
37+
- name: Checkout repository
38+
uses: actions/checkout@v3
39+
- name: Build
40+
run: |
41+
echo ${PYTHON_VERSION}
42+
echo ${PLAT_NAME}
43+
echo ${DOCKER_TAG}
44+
echo ${OUTPUT_FOLDER}
45+
# remove -it
46+
sed -i 's/docker run --rm -it/docker run --rm/g' builder/manylinux/build_wheel.sh
47+
bash builder/manylinux/build_wheel.sh ${PYTHON_VERSION} ${PLAT_NAME} ${DOCKER_TAG} ${OUTPUT_FOLDER}
48+
- name: Upload Artifacts
49+
uses: actions/upload-artifact@v4
50+
with:
51+
if-no-files-found: error
52+
path: builder/manylinux/${{ env.OUTPUT_FOLDER }}/*
53+
retention-days: 1
54+
name: linux-${{ matrix.pyver }}
55+
56+
windows-build:
57+
strategy:
58+
matrix:
59+
pyver: ['3.8', '3.9', '3.10', '3.11', '3.12']
60+
runs-on: windows-latest
61+
steps:
62+
- name: Checkout repository
63+
uses: actions/checkout@v3
64+
- name: Set up python
65+
uses: actions/setup-python@v4
66+
with:
67+
python-version: ${{ matrix.pyver }}
68+
- name: Install python packages
69+
run: |
70+
pip install pybind11 wheel
71+
- name: Setup CUDA Toolkit
72+
id: cuda-toolkit
73+
shell: pwsh
74+
run: ./builder/windows/setup_cuda.ps1
75+
env:
76+
INPUT_CUDA_VERSION: '11.8.0'
77+
- name: Build wheel
78+
run: |
79+
mkdir build
80+
cd build
81+
pip install -U setuptools
82+
..\builder\windows\generate.ps1
83+
cmake --build . --config Release -- /m /v:q
84+
if (-Not $?) {
85+
echo "build failed"
86+
exit 1
87+
}
88+
cmake --install . --config Release
89+
cd ..
90+
rm build -Force -Recurse
91+
python setup.py bdist_wheel -d build/wheel
92+
- name: Upload Artifacts
93+
uses: actions/upload-artifact@v4
94+
with:
95+
if-no-files-found: error
96+
path: build/wheel/*
97+
retention-days: 1
98+
name: windows-${{ matrix.pyver }}
99+
100+
publish:
101+
runs-on: ubuntu-latest
102+
environment: 'prod'
103+
needs:
104+
- linux-build
105+
- windows-build
106+
steps:
107+
- name: Checkout repository
108+
uses: actions/checkout@v3
109+
- name: Download artifacts
110+
uses: actions/download-artifact@v4
111+
with:
112+
path: artifact
113+
merge-multiple: true
114+
- name: Add cuda version to package name
115+
run: |
116+
ver=$(cat turbomind/version.py | grep '__version__ =' | cut -d\' -f2)
117+
cuver=$ver+cu118
118+
ls -lh
119+
cd artifact
120+
for file in *; do
121+
mv "$file" "`echo $file | sed "s/$ver/$cuver/g"`";
122+
done
123+
- name: Display artifacts
124+
run: ls artifact/ -lh
125+
- name: Publish
126+
uses: softprops/action-gh-release@v1
127+
if: startsWith(github.ref, 'refs/tags/')
128+
with:
129+
files: artifact/*

.github/workflows/pypi.yml

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
name: publish to pypi
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- "turbomind/version.py"
9+
workflow_dispatch:
10+
11+
12+
jobs:
13+
linux-build:
14+
strategy:
15+
matrix:
16+
pyver: [py38, py39, py310, py311, py312]
17+
runs-on: ubuntu-latest
18+
env:
19+
PYTHON_VERSION: ${{ matrix.pyver }}
20+
PLAT_NAME: manylinux2014_x86_64
21+
DOCKER_TAG: cuda12.1
22+
OUTPUT_FOLDER: cuda12.1_dist
23+
steps:
24+
- name: Free disk space
25+
uses: jlumbroso/free-disk-space@main
26+
with:
27+
# This might remove tools that are actually needed, if set to "true" but frees about 6 GB
28+
tool-cache: false
29+
docker-images: false
30+
# All of these default to true, but feel free to set to "false" if necessary for your workflow
31+
android: true
32+
dotnet: true
33+
haskell: true
34+
large-packages: true
35+
swap-storage: false
36+
- name: Checkout repository
37+
uses: actions/checkout@v3
38+
- name: Build
39+
run: |
40+
echo ${PYTHON_VERSION}
41+
echo ${PLAT_NAME}
42+
echo ${DOCKER_TAG}
43+
echo ${OUTPUT_FOLDER}
44+
# remove -it
45+
sed -i 's/docker run --rm -it/docker run --rm/g' builder/manylinux/build_wheel.sh
46+
bash builder/manylinux/build_wheel.sh ${PYTHON_VERSION} ${PLAT_NAME} ${DOCKER_TAG} ${OUTPUT_FOLDER}
47+
- name: Upload Artifacts
48+
uses: actions/upload-artifact@v4
49+
with:
50+
if-no-files-found: error
51+
path: builder/manylinux/${{ env.OUTPUT_FOLDER }}/*
52+
retention-days: 1
53+
name: linux-${{ matrix.pyver }}
54+
55+
windows-build:
56+
strategy:
57+
matrix:
58+
pyver: ['3.8', '3.9', '3.10', '3.11', '3.12']
59+
runs-on: windows-latest
60+
steps:
61+
- name: Checkout repository
62+
uses: actions/checkout@v3
63+
- name: Set up python
64+
uses: actions/setup-python@v4
65+
with:
66+
python-version: ${{ matrix.pyver }}
67+
- name: Install python packages
68+
run: |
69+
pip install -r requirements/build.txt
70+
pip install wheel
71+
- name: Setup CUDA Toolkit
72+
id: cuda-toolkit
73+
shell: pwsh
74+
run: ./builder/windows/setup_cuda.ps1
75+
env:
76+
INPUT_CUDA_VERSION: '12.1.0'
77+
- name: Build wheel
78+
run: |
79+
mkdir build
80+
cd build
81+
# https://github.com/pypa/setuptools/issues/1631
82+
pip install -U setuptools
83+
..\builder\windows\generate.ps1
84+
cmake --build . --config Release -- /m /v:q
85+
if (-Not $?) {
86+
echo "build failed"
87+
exit 1
88+
}
89+
cmake --install . --config Release
90+
cd ..
91+
rm build -Force -Recurse
92+
python setup.py bdist_wheel -d build/wheel
93+
- name: Upload Artifacts
94+
uses: actions/upload-artifact@v4
95+
with:
96+
if-no-files-found: error
97+
path: build/wheel/*
98+
retention-days: 1
99+
name: windows-${{ matrix.pyver }}
100+
101+
publish:
102+
runs-on: ubuntu-latest
103+
environment: 'prod'
104+
needs:
105+
- linux-build
106+
- windows-build
107+
steps:
108+
- name: Download artifacts
109+
uses: actions/download-artifact@v4
110+
with:
111+
path: artifact
112+
merge-multiple: true
113+
- name: Display artifacts
114+
run: ls artifact/ -lh
115+
- name: Set up python3.8
116+
uses: actions/setup-python@v4
117+
with:
118+
python-version: '3.8'
119+
- name: Upload to pypi
120+
run: |
121+
pip install twine
122+
twine upload artifact/* -u __token__ -p ${{ secrets.pypi_password }}

README_zh-CN.md

Whitespace-only changes.

builder/manylinux/build_wheel.sh

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
set -eux
3+
4+
PYTHON_VERSION="$1"
5+
PLAT_NAME="$2"
6+
DOCKER_TAG="$3"
7+
OUTPUT_DIR="$4"
8+
9+
DOCKER_IMAGE="openmmlab/lmdeploy-builder:${DOCKER_TAG}"
10+
export USERID=$(id -u)
11+
export GROUPID=$(id -g)
12+
13+
cd "$(dirname "$0")" # move inside the script directory
14+
mkdir -p "${OUTPUT_DIR}"
15+
docker pull ${DOCKER_IMAGE}
16+
docker run --rm -it \
17+
--env PYTHON_VERSION="${PYTHON_VERSION}" \
18+
--env PLAT_NAME="${PLAT_NAME}" \
19+
--env USERID="${USERID}" \
20+
--env GROUPID="${GROUPID}" \
21+
--volume "$(pwd)/../../:/turbomind" \
22+
--volume "$(pwd)/${OUTPUT_DIR}:/turbomind_build" \
23+
--volume "$(pwd)/entrypoint_build.sh:/entrypoint_build.sh" \
24+
--entrypoint /entrypoint_build.sh \
25+
${DOCKER_IMAGE}

builder/manylinux/entrypoint_build.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env bash
2+
set -eux
3+
4+
export PYTHON_VERSION=$PYTHON_VERSION
5+
export PLAT_NAME=$PLAT_NAME
6+
export USERID=${USERID}
7+
export GROUPID=${GROUPID}
8+
export CUDAVER=$(nvcc --version | sed -n 's/^.*release \([0-9]\+\).*$/\1/p')
9+
10+
source /opt/conda/bin/activate
11+
conda activate $PYTHON_VERSION
12+
13+
cd turbomind
14+
rm -rf turbomind/lib
15+
mkdir -p build && cd build && rm -rf *
16+
bash ../generate.sh make
17+
make -j$(nproc) && make install
18+
if [ $? != 0 ]; then
19+
echo "build failed"
20+
exit 1
21+
fi
22+
cd ..
23+
rm -rf build
24+
python setup.py bdist_wheel --cuda=${CUDAVER} --plat-name $PLAT_NAME -d /tmpbuild/
25+
chown ${USERID}:${GROUPID} /tmpbuild/*
26+
mv /tmpbuild/* /turbomind_build/

builder/windows/generate.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
cmake .. -A x64 -T "v142,cuda=$env:CUDA_PATH" `
2+
-DCMAKE_BUILD_TYPE=Release `
3+
-DCMAKE_INSTALL_PREFIX=install `
4+
-DBUILD_PY_FFI=ON `
5+
-DBUILD_MULTI_GPU=OFF `
6+
-DCMAKE_CUDA_FLAGS="-lineinfo" `
7+
-DUSE_NVTX=ON `
8+
-DBUILD_TEST="$env:BUILD_TEST"

0 commit comments

Comments
 (0)