okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5649b9e52
main
1#!/bin/sh 2# Build the Strata CUDA engine for an NVIDIA DGX Spark (GB10, sm_121, arm64 Linux) into a ready-made engine folder. 3# 4# Runs on arm64 Linux with a CUDA 13 toolkit (13.0 is the release toolkit), on the Spark itself. 5# 6# spark/build_engine.sh # engine + picture reader -> ./out-spark/engine 7# BUILD_VISION=0 spark/build_engine.sh # text only (faster) 8# ARCHS="121" OUT=/tmp/eng JOBS=8 spark/build_engine.sh 9# SHAPE=q4_lite spark/build_engine.sh # the engine of a model shape (packaging/shape_build.sh) 10# STRATA_CMAKE_EXTRA="-DSTRATA_GEOMETRY_FILE=/abs/path/geometry.hpp" more configure arguments for the engine build 11# 12# The result is the folder setup.py keeps a ready-made engine in: copy it to Strata/engine on the Spark and run 13# ./setup.sh there (docs/DGX_SPARK_LINUX.md). packaging/build_cuda_linux_aarch64.sh runs this and then makes the engine 14# package for the signed feed. The flags are packaging/build_cuda_linux.sh's (the release build), for arm64: 15# STRATA_PORTABLE makes ggml-cpu a baseline Armv8.2 build (dotprod + fp16 + i8mm, what a Grace CPU has) instead of the build 16# host's, and both programs find the CUDA libraries beside themselves ($ORIGIN), never the toolkit they were built with. 17set -eu 18repo =$( CDPATH = cd -- " $( dirname -- " $ 0" ) /.." && pwd -P ) 19archs =${ ARCHS :-121} 20out =${ OUT :- $ repo /out-spark/engine} 21build =${ BUILD :- $ repo /build-spark} 22vision_dir =${ BUILD_VISION_DIR :- $ repo /build-vision-spark} 23jobs =${ JOBS :-$( nproc )} 24py =${ PYTHON :-python3} 25cmake =${ CMAKE :-cmake} 26llama =${ STRATA_GGML_DIR :-} # an override: a llama.cpp checkout to take ggml from (kept for two releases); empty: the vendored third_party/strata-ggml 27ggml ="" ; [ -z" $ llama " ] ||ggml ="-DSTRATA_GGML_DIR= $ llama " 28 29case " $( uname -s ) - $( uname -m ) " in 30 Linux-aarch64| Linux-arm64) ;; 31 *)echo "build_engine.sh: this builds on arm64 Linux (the DGX Spark)" >&2;exit 2 ;; 32esac 33# DGX OS keeps the toolkit outside PATH for a plain user; the release build's toolkit is 13.0 34if !command -v nvcc> /dev/null2 >&1&& [ -x /usr/local/cuda/bin/nvcc ];then 35PATH =/usr/local/cuda/bin:$ PATH 36export PATH 37fi 38cudafull =$( nvcc --version | sed -n 's/.*release \([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -1 ) 39case " $ cudafull " in 40 13.0| 13.1) ;; 41 13.2)echo "build_engine.sh: warning: CUDA 13.2.0 / 13.2.1 miscompiled the engine for sm_120 (13.2.2 is fixed;" \ 42"docs/TROUBLESHOOTING.md); 13.0 is the release toolkit" >&2 ;; 43 13.*)echo "build_engine.sh: note: CUDA $ cudafull has not been tried for this build; 13.0 is the release toolkit" >&2 ;; 44 *)echo "build_engine.sh: needs the CUDA 13 toolkit (nvcc here: ${ cudafull :-missing} )" >&2;exit 2 ;; 45esac 46. " $ repo /packaging/shape_build.sh" ;shape_setup " $ repo " 47 48real ="" ;for a in $( echo " $ archs " | tr ';,' ' ' ) ;do real =" $ real ; ${ a } -real" ;done ;real =${ real #;} 49last =$( echo " $ archs " | tr ';,' ' ' | awk '{print $NF}' ) 50cd " $ repo " 51" $ cmake " -G Ninja-S .-B " $ build " -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \ 52-DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON \ 53-DCMAKE_BUILD_WITH_INSTALL_RPATH=ON -DCMAKE_SKIP_BUILD_RPATH=OFF '-DCMAKE_INSTALL_RPATH=$ORIGIN' \ 54-DSTRATA_MMQ=ON "-DCMAKE_CUDA_ARCHITECTURES= ${ real } ; ${ last } -virtual" $ ggml ${ STRATA_CMAKE_EXTRA :-} $ shape_cmake 55# -DSTRATA_MMQ=ON: not measured without MMQ; kept as in 0.2.13 (the engine default is OFF since then) 56# strata_kq (libstrata_kq.so) exists only in a build with llama.cpp's MMQ: STRATA_CMAKE_EXTRA=-DSTRATA_MMQ=OFF builds without it 57. " $ repo /packaging/engine_targets.sh" 58targets =$( engine_targets " $ cmake " " $ build " ) 59# shellcheck disable=SC2086 60" $ cmake " --build " $ build " --target $ targets -j " $ jobs " 61 62if [" ${ BUILD_VISION :-1} " = 1 ];then 63# strata-vision builds from the vendored third_party/strata-llama; STRATA_GGML_DIR=<llama.cpp checkout> overrides it 64vision_llama ="" ; [ -z" $ llama " ] ||vision_llama ="-DLLAMA_DIR= $ llama " 65# shellcheck disable=SC2086 66" $ cmake " -G Ninja-S tools/vision-B " $ vision_dir " -DCMAKE_BUILD_TYPE=Release $ vision_llama \ 67-DSTRATA_VISION_CUDA=ON -DSTRATA_PORTABLE=ON -DGGML_CUDA_NCCL=OFF -DGGML_CPU_ARM_ARCH=armv8.2-a+dotprod+fp16+i8mm \ 68"-DCMAKE_CUDA_ARCHITECTURES= ${ real } ; ${ last } -virtual" 69" $ cmake " --build " $ vision_dir " --target strata-vision-j " $ jobs " 70fi 71 72ver =$( sed -n 's/^[[:space:]]*project([^)]*VERSION[[:space:]]*\([0-9][0-9.]*\).*/\1/p' CMakeLists.txt | head -1 ) 73rm -rf " $ out " 74mkdir -p " $ out " 75cp " $ build /strata" " $ out /" 76[ -f" $ build /libstrata_kq.so" ]&& cp " $ build /libstrata_kq.so" " $ out /" 77vision_json ="" 78if [" ${ BUILD_VISION :-1} " = 1 ]&& [ -f" $ vision_dir /bin/strata-vision" ];then 79cp " $ vision_dir /bin/strata-vision" " $ out /" 80vision_json =", \"vision_archs\": \" $ archs \"" 81fi 82# the CUDA libraries the engine loads (cuBLAS, cuBLASLt, cudart) go beside it: the Spark needs only its driver 83" $ py " packaging/collect_libs.py--binary " $ build /strata" --search /usr/local/cuda/lib64--out " $ out " --also 'libcublasLt.so*' 84echo "{\"version\": \" $ ver \", \"source\": \"spark/build_engine.sh\", \"platform\": \"linux-aarch64\", \"archs\": \" $ archs \", \"ptx\": true, \"cuda\": \" $ cudafull \", \"portable\": true $ vision_json }" > " $ out /BUILD.json" 85" $ out /strata" --version 2 > /dev/null ||true 86echo "built: $ out "