okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5649b9e52
main
1#!/bin/sh 2# Build the Linux CUDA engine package for the release feed. 3# 4# VARIANT=cuda12 packaging/build_cuda_linux.sh # CUDA 12.9: GTX 10 (Pascal), Tesla P100, V100, and the newer cards up to sm_89 5# VARIANT=cuda13 packaging/build_cuda_linux.sh # CUDA 13: RTX 20 and newer (sm_75 .. sm_120) 6# SHAPE=q4_lite packaging/build_cuda_linux.sh # the engine of a model shape, its own component (packaging/shape_build.sh) 7# 8# Run it on a Linux x86_64 box with the CUDA toolkit of that variant on PATH (nvcc) and a Python 3 venv with requirements.txt and 9# requirements-build.txt. ggml comes from the vendored third_party/strata-ggml: nothing is downloaded. STRATA_GGML_DIR=<llama.cpp checkout> 10# builds from that checkout instead (an override, kept for two releases). 11# The package lands in $OUT (default ./out-engine-<variant>). Nothing is uploaded. 12# 13# The cuda12 package is the one the feed and docs/DOCKER.md offer to Pascal and Volta cards, so it needs machine code for sm_60, 14# sm_61 and sm_70 and the -DSTRATA_EXPERIMENTAL_SM60=ON build (#3503: the 0.2.1 package had sm_75 / 86 / 89 only, and a P100 15# container restarted in a loop with "this PC's GPU is sm_60"). packaging/package_engine.py refuses a cuda12 package without them. 16set -eu 17variant =${ VARIANT :-cuda13} 18repo =$( CDPATH = cd -- " $( dirname -- " $ 0" ) /.." && pwd -P ) 19case " $ variant " in 20 cuda12)archs =${ ARCHS :-60 ;61 ;70 ;75 ;80 ;86 ;89} ;mindriver =575.51;sm60 =ON ;; 21 cuda13)archs =${ ARCHS :-75 ;86 ;89 ;120} ;mindriver =580.65;sm60 =OFF ;; 22 *)echo "build_cuda_linux.sh: VARIANT must be cuda12 or cuda13" >&2;exit 2 ;; 23esac 24out =${ OUT :- $ repo /out-engine- $ variant } 25build =${ BUILD :- $ repo /build- $ variant } 26py =${ PYTHON :-python3} 27cudafull =$( nvcc --version | sed -n 's/.*release \([0-9][0-9]*\.[0-9][0-9]*\).*/\1/p' | head -1 ) 28case " $ variant : $ cudafull " in 29 cuda12:12.*| cuda13:13.*) ;; 30 *)echo "build_cuda_linux.sh: $ variant needs the matching CUDA toolkit; nvcc here is ${ cudafull :-missing} " >&2;exit 2 ;; 31esac 32 33real ="" ;for a in $( echo " $ archs " | tr ';,' ' ' ) ;do real =" $ real ; ${ a } -real" ;done ;real =${ real #;} 34last =$( echo " $ archs " | tr ';,' ' ' | awk '{print $NF}' ) 35cd " $ repo " 36ggml ="" ; [ -z" ${ STRATA_GGML_DIR :-} " ] ||ggml ="-DSTRATA_GGML_DIR= $ STRATA_GGML_DIR " 37. " $ repo /packaging/shape_build.sh" ;shape_setup " $ repo " 38# STRATA_CMAKE_EXTRA: more configure arguments for the engine build, e.g. the model shape of a new family: 39# STRATA_CMAKE_EXTRA="-DSTRATA_GEOMETRY_FILE=/abs/path/geometry.hpp" (or -DSTRATA_GEOMETRY=<name>) 40# shellcheck disable=SC2086 41cmake -G Ninja-S .-B " $ build " -DCMAKE_BUILD_TYPE=Release -DSTRATA_ENABLE_CUDA=ON -DSTRATA_BUILD_TESTS=OFF \ 42-DSTRATA_EXPERIMENTAL_SM60= $ sm60 -DSTRATA_NATIVE_EXPERTS=ON -DSTRATA_PORTABLE=ON -DSTRATA_Q6K_EXPERTS=ON -DSTRATA_MMQ_KQUANTS=ON \ 43-DSTRATA_MMQ=OFF "-DCMAKE_CUDA_ARCHITECTURES= ${ real } ; ${ last } -virtual" $ ggml ${ STRATA_CMAKE_EXTRA :-} $ shape_cmake 44# without llama.cpp's MMQ (named here: a build folder configured before keeps ON in its cache); strata_kq (libstrata_kq.so) exists only 45# in a build with it: STRATA_CMAKE_EXTRA=-DSTRATA_MMQ=ON packages the old path (A/B) 46. " $ repo /packaging/engine_targets.sh" 47targets =$( engine_targets cmake " $ build " ) 48# shellcheck disable=SC2086 49cmake --build " $ build " --target $ targets -j " $( nproc ) " 50 51# The picture reader is built for the SAME architectures as the engine (#3669: a reader reused from an older build had no sm_60, and on 52# a Pascal card the engine ran while the reader died with "device kernel image is invalid"). BUILD_VISION=0 ships a text-only package. 53vision_dir =${ BUILD_VISION_DIR :- $ repo /build-vision- $ variant } 54if [" ${ BUILD_VISION :-1} " = 1 ];then 55# strata-vision builds from the vendored third_party/strata-llama (llama, mtmd, ggml at the pin); STRATA_GGML_DIR=<llama.cpp checkout> overrides it 56vision_llama ="" ; [ -z" ${ STRATA_GGML_DIR :-} " ] ||vision_llama ="-DLLAMA_DIR= $ STRATA_GGML_DIR " 57# shellcheck disable=SC2086 58cmake -G Ninja-S tools/vision-B " $ vision_dir " -DCMAKE_BUILD_TYPE=Release $ vision_llama \ 59-DSTRATA_VISION_CUDA=ON -DSTRATA_PORTABLE=ON -DGGML_CUDA_NCCL=OFF "-DCMAKE_CUDA_ARCHITECTURES= ${ real } ; ${ last } -virtual" 60cmake --build " $ vision_dir " --target strata-vision-j " $( nproc ) " 61fi 62 63ver =$( sed -n 's/^[[:space:]]*project([^)]*VERSION[[:space:]]*\([0-9][0-9.]*\).*/\1/p' CMakeLists.txt | head -1 ) 64stage =$( mktemp -d " ${ TMPDIR :-/tmp} /strata-engine-stage.XXXXXX" ) 65trap 'rm -rf "$stage"' EXIT 66cp " $ build /strata" " $ stage /" 67[ -f" $ build /libstrata_kq.so" ]&& cp " $ build /libstrata_kq.so" " $ stage /" 68vision_json ="" 69if [ -f" $ vision_dir /bin/strata-vision" ];then 70cp " $ vision_dir /bin/strata-vision" " $ stage /" 71vision_json =", \"vision_archs\": \" $ archs \"" # package_engine.py refuses a reader whose archs do not cover the engine's 72fi 73echo "{\"version\": \" $ ver \", \"source\": \"packaging/build_cuda_linux.sh\", \"archs\": \" $ archs \", \"cuda\": \" $ cudafull \", \"portable\": true $ vision_json }" > " $ stage /BUILD.json" 74" $ py " packaging/collect_libs.py--binary " $ build /strata" --search /usr/local/cuda/lib64--out " $ stage " --also 'libcublasLt.so*' 75shape_check env LD_LIBRARY_PATH=" $ stage " " $ stage /strata" 76arch_args ="" ;for a in $( echo " $ archs " | tr ';,' ' ' ) ;do arch_args =" $ arch_args --arch sm_ $ a " ;done 77mkdir -p " $ out " 78# shellcheck disable=SC2086 79" $ py " packaging/package_engine.py--src " $ stage " --backend cuda--version " $ ver " --out " $ out " $ arch_args --arch "compute_ $ last " \ 80--min-driver nvidia=$ mindriver --variant " $ variant " --platform linux-x86_64--build-id "release- ${ ver } - ${ variant } - ${ cudafull } " \ 81--include SYSTEM-LIBS.txt--include 'libstrata_kq*' $ shape_pkg 82for d in " $ out " /*/;do " $ py " packaging/package_engine.py--verify " $ d " ;" $ py " packaging/binary_deps.py" $ d " ;done 83echo "built: $ out "