Skip to content

Commit 16d5fbd

Browse files
authored
Create build-cu.yml
1 parent 6562e5a commit 16d5fbd

File tree

1 file changed

+223
-0
lines changed

1 file changed

+223
-0
lines changed

.github/workflows/build-cu.yml

Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
name: JUSTBUILD
2+
3+
on:
4+
workflow_dispatch: # allows manual triggering
5+
inputs:
6+
create_release:
7+
description: "Create new release"
8+
required: true
9+
type: boolean
10+
push:
11+
branches:
12+
- master
13+
paths:
14+
[
15+
".github/workflows/build-ci.yml",
16+
"**/CMakeLists.txt",
17+
"**/Makefile",
18+
"**/*.h",
19+
"**/*.hpp",
20+
"**/*.c",
21+
"**/*.cpp",
22+
"**/*.cu",
23+
"**/*.cuh",
24+
"**/*.swift",
25+
"**/*.m",
26+
"**/*.metal",
27+
]
28+
pull_request:
29+
types: [opened, synchronize, reopened]
30+
paths:
31+
[
32+
".github/workflows/build-ci.yml",
33+
"**/CMakeLists.txt",
34+
"**/Makefile",
35+
"**/*.h",
36+
"**/*.hpp",
37+
"**/*.c",
38+
"**/*.cpp",
39+
"**/*.cu",
40+
"**/*.cuh",
41+
"**/*.swift",
42+
"**/*.m",
43+
"**/*.metal",
44+
]
45+
46+
concurrency:
47+
group: ${{ github.workflow }}-${{ github.head_ref && github.ref || github.run_id }}
48+
cancel-in-progress: true
49+
50+
# Fine-grant permission
51+
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication#modifying-the-permissions-for-the-github_token
52+
#permissions:
53+
# contents: write # for creating release
54+
permissions: write-all
55+
56+
env:
57+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
58+
#GGML_NLOOP: 3
59+
#GGML_N_THREADS: 1
60+
#LLAMA_LOG_COLORS: 1
61+
#LLAMA_LOG_PREFIX: 1
62+
#LLAMA_LOG_TIMESTAMPS: 1
63+
64+
jobs:
65+
# CUDA Release
66+
67+
ubuntu-latest-cuda-cmake:
68+
runs-on: ubuntu-latest
69+
70+
steps:
71+
#- name: Free Disk Space (Ubuntu)
72+
# uses: jlumbroso/free-disk-space@main
73+
# with:
74+
# this might remove tools that are actually needed,
75+
# if set to "true" but frees about 6 GB
76+
# tool-cache: true
77+
78+
# all of these default to true, but feel free to set to
79+
# "false" if necessary for your workflow
80+
# android: true
81+
# dotnet: true
82+
# haskell: true
83+
# large-packages: false
84+
# docker-images: true
85+
# swap-storage: false
86+
87+
- name: Clone
88+
id: checkout
89+
uses: actions/checkout@v4
90+
with:
91+
fetch-depth: 0
92+
93+
- name: Dependencies
94+
id: depends
95+
run: |
96+
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
97+
sudo dpkg -i cuda-keyring_1.1-1_all.deb
98+
sudo apt-get update # Run apt-get update only once
99+
sudo apt-get install -y build-essential libcurl4-openssl-dev ccache cuda-12-8
100+
# sudo apt install software-properties-common
101+
# sudo add-apt-repository ppa:ubuntu-toolchain-r/test
102+
# sudo apt update
103+
# sudo apt install gcc-13 g++-13
104+
# sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 13 --slave /usr/bin/g++ g++ /usr/bin/g++-13
105+
106+
- name: Build
107+
id: cmake_build
108+
run: |
109+
export PATH=/usr/local/cuda/bin${PATH:+:${PATH}}
110+
export LD_LIBRARY_PATH=/usr/local/cuda/lib64 ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
111+
mkdir build
112+
cd build
113+
cmake .. -DLLAMA_FATAL_WARNINGS=OFF -DBUILD_SHARED_LIBS=ON -DGGML_NATIVE=OFF \
114+
-DGGML_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=86-real \
115+
-DCMAKE_EXE_LINKER_FLAGS=-Wl,--allow-shlib-undefined \
116+
-DCMAKE_C_FLAGS_RELEASE="-Ofast -DNDEBUG -fno-finite-math-only -fmath-errno -march=znver3" \
117+
-DCMAKE_CXX_FLAGS_RELEASE="-Ofast -DNDEBUG -march=znver3" \
118+
-DCMAKE_CUDA_FLAGS_RELEASE="-O3 -ffast-math -DNDEBUG -Xcompiler=-Ofast,-march=znver3"
119+
cmake --build . --config Release -j $(nproc)
120+
121+
- name: Determine tag name
122+
id: tag
123+
shell: bash
124+
run: |
125+
BUILD_NUMBER="$(git rev-list --count HEAD)"
126+
SHORT_HASH="$(git rev-parse --short=7 HEAD)"
127+
if [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then
128+
echo "name=b${BUILD_NUMBER}" >> $GITHUB_OUTPUT
129+
else
130+
SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
131+
echo "name=${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}" >> $GITHUB_OUTPUT
132+
fi
133+
134+
- name: Pack artifacts
135+
id: pack_artifacts
136+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
137+
run: |
138+
cp LICENSE ./build/bin/
139+
# cp $(find . -name "*.so") ./build/bin/ # Not needed anymore
140+
zip -r -j cudart-server-${{ steps.tag.outputs.name }}-rtx30-ubuntu-x64.zip ./build/bin/*
141+
142+
- name: Upload artifacts
143+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
144+
uses: actions/upload-artifact@v4
145+
with:
146+
path: cudart-server-${{ steps.tag.outputs.name }}-rtx30-ubuntu-x64.zip
147+
name: cudart-server-rtx30-ubuntu-x64.zip
148+
149+
# TODO: build with GGML_NO_METAL because test-backend-ops fail on "Apple Paravirtual device" and I don't know
150+
# how to debug it.
151+
# ref: https://github.com/ggerganov/llama.cpp/actions/runs/7131777249/job/19420981052#step:5:1124
152+
153+
release:
154+
permissions: write-all
155+
156+
157+
if: ${{ ( github.event_name == 'push' && github.ref == 'refs/heads/master' ) || github.event.inputs.create_release == 'true' }}
158+
159+
runs-on: ubuntu-latest
160+
161+
needs:
162+
- ubuntu-latest-cuda-cmake
163+
#- ubuntu-latest-vulkan-cmake
164+
165+
steps:
166+
- name: Clone
167+
id: checkout
168+
uses: actions/checkout@v4
169+
with:
170+
fetch-depth: 0
171+
172+
- name: Determine tag name
173+
id: tag
174+
shell: bash
175+
run: |
176+
BUILD_NUMBER="$(git rev-list --count HEAD)"
177+
SHORT_HASH="$(git rev-parse --short=7 HEAD)"
178+
if [[ "${{ env.BRANCH_NAME }}" == "master" ]]; then
179+
echo "name=b${BUILD_NUMBER}" >> $GITHUB_OUTPUT
180+
else
181+
SAFE_NAME=$(echo "${{ env.BRANCH_NAME }}" | tr '/' '-')
182+
echo "name=${SAFE_NAME}-b${BUILD_NUMBER}-${SHORT_HASH}" >> $GITHUB_OUTPUT
183+
fi
184+
185+
- name: Download artifacts
186+
id: download-artifact
187+
uses: actions/download-artifact@v4
188+
with:
189+
path: ./artifact
190+
191+
- name: Move artifacts
192+
id: move_artifacts
193+
run: mkdir -p ./artifact/release && mv ./artifact/*/*.zip ./artifact/release
194+
195+
- name: Create release
196+
id: create_release
197+
uses: anzz1/action-create-release@v1
198+
env:
199+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
200+
with:
201+
tag_name: ${{ steps.tag.outputs.name }}
202+
203+
- name: Upload release
204+
id: upload_release
205+
uses: actions/github-script@v3
206+
with:
207+
github-token: ${{secrets.GITHUB_TOKEN}}
208+
script: |
209+
const path = require('path');
210+
const fs = require('fs');
211+
const release_id = '${{ steps.create_release.outputs.id }}';
212+
for (let file of await fs.readdirSync('./artifact/release')) {
213+
if (path.extname(file) === '.zip') {
214+
console.log('uploadReleaseAsset', file);
215+
await github.repos.uploadReleaseAsset({
216+
owner: context.repo.owner,
217+
repo: context.repo.repo,
218+
release_id: release_id,
219+
name: file,
220+
data: await fs.readFileSync(`./artifact/release/${file}`)
221+
});
222+
}
223+
}

0 commit comments

Comments
 (0)