-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathbuild_library_steps.yaml
More file actions
330 lines (286 loc) · 12.4 KB
/
build_library_steps.yaml
File metadata and controls
330 lines (286 loc) · 12.4 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
################################ Prefix for error highlighting ################################
on:
push:
tags:
- 'lala'
jobs:
lala:
runs-on: lala
################################ Common ################################
steps:
- name: Clone
id: checkout
uses: actions/checkout@v4
with:
submodules: recursive
- name: Upload Artifacts
id: upload_llamalib
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.arch }}.zip
path: ${{ matrix.arch }}.zip
- name: Get number of CPU cores
id: cpu-cores
uses: SimenB/github-actions-cpu-cores@v2
- name: Preparation
id: preparation
shell: bash
run: |
mkdir -p build/libs
echo "CMAKE_VARS=-DARCHITECTURE=${{ matrix.arch }} -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=${{ github.workspace }}/build/libs -DCMAKE_ARCHIVE_OUTPUT_DIRECTORY=${{ github.workspace }}/build/libs -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=${{ github.workspace }}/build/libs ${{ matrix.cmake_vars }}" >> $GITHUB_ENV
- name: Build
id: cmake_build
run: |
cd build
cmake .. ${{ env.CMAKE_VARS }}
cmake --build . --config Release -j ${{ steps.cpu-cores.outputs.count }}
- name: Build OpenSSL
id: build_openssl
run: |
.github/scripts/build_openssl.sh ${{ matrix.arch }}
- name: Test
id: test_build
shell: bash
run: |
flag=0
if [[ "$RUNNER_OS" == "macOS" ]]; then
flag=1
else
CPU_FLAGS=$(grep -o 'avx[^ ]*' /proc/cpuinfo | sort -u | tr '\n' ' ')
ARCH="${{ matrix.arch }}"
FEATURE="${ARCH##*_}"
if echo "$CPU_FLAGS" | grep -qw "$FEATURE"; then
flag=1
fi
fi
if [[ "$flag" == "1" ]]; then
./tests/download_test_models.sh
cd build
if [[ "$RUNNER_OS" == "Windows" ]]; then
./libs/Release/llamalib_tests.exe
./libs/Release/llamalib_tests_runtime.exe
else
./libs/llamalib_tests
./libs/llamalib_tests_runtime
fi
fi
- name: Pack artifacts
shell: bash
run: |
zip -j ${{ matrix.arch }}.zip build/libs/*llamalib* -x '*llamalib_tests*'
- name: Pack artifacts
id: pack_artifacts
shell: bash
run: |
ls -R build
mkdir -p artifacts
mv build/Release/*llamalib* artifacts/ 2>/dev/null || true
mv build/libs/*llamalib* artifacts/ 2>/dev/null || true
mv build/libs/*.so* artifacts/ 2>/dev/null || true
mv build/libs/Release/*llamalib* artifacts/ 2>/dev/null || true
mv build/libs/Release/*.dll artifacts/ 2>/dev/null || true
rm -f artifacts/*llamalib_tests* artifacts/*exp artifacts/*server*lib 2>/dev/null || true
rm -r build
cd artifacts
if [[ "$RUNNER_OS" == "Windows" ]]; then
7z a ../${{ matrix.arch }}.zip *
else
zip ../${{ matrix.arch }}.zip *
fi
################################ Linux ################################
- name: Dependencies
id: setup_libs_linux
run: |
sudo apt-get update
sudo apt-get install -y build-essential cmake zip libssl-dev git libcurl4-openssl-dev curl libgomp1
- name: Dependencies
id: setup_hip_linux
run: |
sudo apt-get install -y rocblas-dev hipblas-dev
echo "CMAKE_VARS=$(echo $CMAKE_VARS | sed "s|${{ github.workspace }}/|$(pwd)/|g") -DCMAKE_HIP_COMPILER=$(hipconfig -l)/clang" >> $GITHUB_ENV
- name: Dependencies Vulcan
id: setup_vulkan_linux
if: contains(matrix.arch, 'vulkan')
run: |
wget -qO - https://packages.lunarg.com/lunarg-signing-key-pub.asc | sudo apt-key add -
sudo wget -qO /etc/apt/sources.list.d/lunarg-vulkan-jammy.list https://packages.lunarg.com/vulkan/lunarg-vulkan-jammy.list
sudo apt-get update -y
sudo apt-get install -y build-essential vulkan-sdk
cp /lib/x86_64-linux-gnu/libvulkan.so.1 build/libs/
- uses: Jimver/cuda-toolkit@v0.2.15
id: setup_cuda_linux
if: contains(matrix.arch, 'blas')
with:
cuda: ${{ env.CUDA }}
method: 'network'
linux-local-args: '["--toolkit"]'
- name: Link Cuda
id: link_cuda_linux
if: contains(matrix.arch, 'blas')
run: |
ln -s ${{ env.CUDA_PATH }} ${{ github.workspace }}/build/cuda
echo "CUDAToolkit_ROOT=$GITHUB_WORKSPACE/build/cuda" >> $GITHUB_ENV
echo "LD_LIBRARY_PATH=''" >> $GITHUB_ENV
################################ macOS ################################
- name: Dependencies
id: setup_libs_macos
continue-on-error: true
run: |
echo "Architecture: $(uname -m)"
echo "Operating System: $(uname -s)"
brew update
- id: download_macos_artifacts
name: Download Artifacts
uses: actions/download-artifact@v4
with:
pattern: osx-*
path: artifacts
- id: combine_macos_libraries
name: Merge macOS libraries
run: |
cd artifacts
for d in *.zip;do
unzip -o $d/$d -d `echo $d|cut -d'.' -f1`
done
mkdir ${{ matrix.arch }}
for acc in no-acc acc;do
for f in `ls osx-x64_$acc`;do
output=${{ matrix.arch }}/`echo $f|sed -e "s:x64:universal:g"`
if [ -f $output ];then continue;fi
lipo -create -output $output osx-x64_$acc/$f osx-arm64_$acc/`echo $f|sed -e "s:x64:arm64:g"`
done
done
zip -j ../${{ matrix.arch }}.zip ${{ matrix.arch }}/*
################################ Windows ################################
- name: Install Vulkan SDK
id: setup_vulcan_windows
if: contains(matrix.arch, 'vulkan')
run: |
mkdir -p .\build\libs\Release
curl.exe -o $env:RUNNER_TEMP/VulkanSDK-Installer.exe -L "https://sdk.lunarg.com/sdk/download/${env:VULKAN_VERSION}/windows/vulkansdk-windows-X64-${env:VULKAN_VERSION}.exe"
& "$env:RUNNER_TEMP\VulkanSDK-Installer.exe" --accept-licenses --default-answer --confirm-command install
Add-Content $env:GITHUB_ENV "VULKAN_SDK=C:\VulkanSDK\${env:VULKAN_VERSION}"
Add-Content $env:GITHUB_PATH "C:\VulkanSDK\${env:VULKAN_VERSION}\bin"
curl.exe -o $env:RUNNER_TEMP/VulkanRT-Components.zip -L "https://sdk.lunarg.com/sdk/download/${env:VULKAN_VERSION}/windows/VulkanRT-X64-${env:VULKAN_VERSION}-Components.zip"
7z x "-o${env:RUNNER_TEMP}" $env:RUNNER_TEMP/VulkanRT-Components.zip
cp ${env:RUNNER_TEMP}/VulkanRT*\x64\vulkan-1.dll .\build\libs\Release
- name: Install OpenSSL
id: setup_openssl_windows
run: |
choco install openssl --no-progress --version 3.5.4
$OPENSSL_ROOT_DIR = 'C:\Program Files\OpenSSL'
Copy-Item $OPENSSL_ROOT_DIR\lib\VC\x64\MD\*.lib $OPENSSL_ROOT_DIR\lib\
Copy-Item $OPENSSL_ROOT_DIR\lib\libcrypto_static.lib $OPENSSL_ROOT_DIR\lib\libcrypto.a
Copy-Item $OPENSSL_ROOT_DIR\lib\libssl_static.lib $OPENSSL_ROOT_DIR\lib\libssl.a
Add-Content $env:GITHUB_ENV "OPENSSL_ROOT_DIR=$OPENSSL_ROOT_DIR"
- name: Build
id: cmake_build_hip_windows
run: |
$env:HIP_PATH=$(Resolve-Path 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' | split-path | split-path)
$env:CMAKE_PREFIX_PATH="${env:HIP_PATH}"
cd build
cmake -G "Unix Makefiles" .. -DCMAKE_C_COMPILER="${env:HIP_PATH}\bin\clang.exe" -DCMAKE_CXX_COMPILER="${env:HIP_PATH}\bin\clang++.exe" -DCMAKE_CXX_FLAGS="-I$($PWD.Path.Replace('\', '/'))/rocwmma/library/include/" ${{ env.CMAKE_VARS }}
cmake --build . --config Release -j ${{ steps.cpu-cores.outputs.count }}
mkdir Release
- uses: Jimver/cuda-toolkit@v0.2.15
id: setup_cuda_windows
if: contains(matrix.arch, 'blas')
with:
cuda: ${{ env.CUDA }}
method: 'network'
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust", "visual_studio_integration"]'
- name: Install
id: setup_hip_windows
run: |
git clone https://github.com/rocm/rocwmma --branch rocm-6.2.4 --depth 1
$ErrorActionPreference = "Stop"
write-host "Downloading AMD HIP SDK Installer"
Invoke-WebRequest -Uri "https://download.amd.com/developer/eula/rocm-hub/AMD-Software-PRO-Edition-24.Q3-WinSvr2022-For-HIP.exe" -OutFile "${env:RUNNER_TEMP}\rocm-install.exe"
write-host "Installing AMD HIP SDK"
Start-Process "${env:RUNNER_TEMP}\rocm-install.exe" -ArgumentList '-install' -NoNewWindow -Wait
write-host "Completed AMD HIP SDK installation"
& 'C:\Program Files\AMD\ROCm\*\bin\clang.exe' --version
- name: Copy Cuda DLLs
id: copy_cuda_dlls
if: contains(matrix.arch, 'cublas')
shell: bash
run: |
mv "${{ env.CUDA_PATH }}"/bin/cudart64_*.dll build/libs/Release
mv "${{ env.CUDA_PATH }}"/bin/cublas64_*.dll build/libs/Release
mv "${{ env.CUDA_PATH }}"/bin/cublasLt64_*.dll build/libs/Release
################################ Android ################################
- name: Build
id: cmake_build_android
run: |
export LD_LIBRARY_PATH=""
export NDK=`ls -d /usr/local/lib/android/sdk/ndk/27.*`
cd build
cmake .. -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake -DANDROID_PLATFORM=android-23 -DANDROID_ABI=${{ matrix.ABI }} ${{ env.CMAKE_VARS }}
cmake --build . --config Release -j ${{ steps.cpu-cores.outputs.count }}
################################ iOS ################################
- id: link_libraries_ios
name: Link libraries
run: |
cd build
lib=libs/libllamalib_${{ matrix.arch }}.a
libtool -static -o $lib `find . -name "*.a"`
nm -u $lib
################################ Release ################################
- id: set_release_version
name: Set version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "RELEASE_NAME=LlamaLib-v$VERSION" >> $GITHUB_ENV
echo "$VERSION" > VERSION
sed -i "s|<PackageVersion>.*</PackageVersion>|<PackageVersion>${VERSION}</PackageVersion>|g" csharp/LlamaLib.csproj
sed -i "s|<LlamaLibVersion>.*</LlamaLibVersion>|<LlamaLibVersion>${VERSION}</LlamaLibVersion>|g" csharp/LlamaLib.targets
sed -i "s|\(Include=\"LlamaLib\" Version=\)\"[^\"]*\"|\1\"${VERSION}\"|g" tests/csharp/LlamaLib.Test.csproj
shell: bash
- name: Download Artifacts
id: download_artifacts
uses: actions/download-artifact@v4
with:
path: release
- name: Create release
id: create_release
run: |
./.github/scripts/release.sh release
mv release ${{ env.RELEASE_NAME }}
zip -r ${{ env.RELEASE_NAME }}.zip ${{ env.RELEASE_NAME }}
sha256sum ${{ env.RELEASE_NAME }}.zip | awk '{print $1}' > ${{ env.RELEASE_NAME }}.zip.sha256
- name: Test cmake
id: test_cmake
run: |
./tests/download_test_models.sh
cd tests/cpp-cmake
cmake . -DLLAMALIB_DIR=../../${{ env.RELEASE_NAME }}
cmake --build . --config Release
./test
- name: Pack nuget
id: pack_nuget
run: |
cd csharp
dotnet pack -c Release
- name: Clean up
id: clean_up_release
run: |
rm -r ${{ env.RELEASE_NAME }}
- name: Test nuget
id: test_nuget
run: |
./tests/download_test_models.sh
mkdir -p ~/.nuget/packages/LlamaLib
ln -s `pwd`/${{ env.RELEASE_NAME }}.zip ~/.nuget/packages/LlamaLib/${{ env.RELEASE_NAME }}.zip
cd tests/csharp
dotnet build -c Release
dotnet test -c Release --logger "console;verbosity=detailed"
- name: Release
id: release
uses: softprops/action-gh-release@v2
with:
name: "Release ${{ env.VERSION }}"
files: |
${{ env.RELEASE_NAME }}.zip
${{ env.RELEASE_NAME }}.zip.sha256
csharp/bin/Release/LlamaLib*nupkg