okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5649b9e52
main
1"""packaging/build_cuda_windows.py: the Windows NVIDIA engine package recipe (the release's configure line, the targets the build tree has). 2 3python -m unittest tools.test_build_cuda_windows -v 4""" 5from __future__import annotations 6 7import os 8import shutil 9import stat 10import subprocess 11import sys 12import tempfile 13import unittest 14from pathlib import Path 15 16ROOT = Path (__file__ ).resolve ().parents [1 ] 17sys .path .insert (0 ,str (ROOT / "packaging" )) 18import build_cuda_windows as B # noqa: E402 19 20CUDA13 = Path ("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0" ) 21CUDA12 = Path ("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.9" ) 22 23 24class ConfigureLine (unittest .TestCase ): 25def test_cuda13_is_the_release_line (self ): 26# the 0.1.59 zips' line: 75;86;89;120 real + 120 PTX, portable, native experts, no tests (the K-quant and Q6_K options at their defaults) 27got = B .configure_args (Path ("S" ),Path ("Bd" ),"cuda13" ,CUDA13 , []) 28self .assertEqual (got , ["-G" ,"Ninja" ,"-S" ,"S" ,"-B" ,"Bd" ,"-DCMAKE_BUILD_TYPE=Release" ,"-DSTRATA_ENABLE_CUDA=ON" ,"-DSTRATA_BUILD_TESTS=OFF" , 29"-DSTRATA_NATIVE_EXPERTS=ON" ,"-DSTRATA_PORTABLE=ON" ,"-DSTRATA_MMQ=OFF" , 30"-DCMAKE_CUDA_ARCHITECTURES=75-real;86-real;89-real;120-real;120-virtual" , 31"-DCMAKE_CUDA_COMPILER=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0/bin/nvcc.exe" , 32"-DCUDAToolkit_ROOT=C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v13.0" ]) 33 34def test_cuda12_is_the_pascal_and_volta_build (self ): 35got = B .configure_args (Path ("S" ),Path ("Bd" ),"cuda12" ,CUDA12 , []) 36self .assertIn ("-DSTRATA_EXPERIMENTAL_SM60=ON" ,got ) 37self .assertIn ("-DCMAKE_CUDA_ARCHITECTURES=60-real;61-real;70-real;75-real;80-real;86-real;89-real;89-virtual" ,got ) 38self .assertEqual (B .VARIANTS ["cuda12" ][2 ],"576.02" )# the 0.1.59 cuda12 zip's min_driver 39self .assertEqual (B .VARIANTS ["cuda13" ][2 ],"580.65" ) 40 41def test_extra_arguments_come_last_and_the_override_is_named (self ): 42got = B .configure_args (Path ("S" ),Path ("Bd" ),"cuda13" ,CUDA13 , ["-DSTRATA_MMQ=ON" ],ggml_dir = "C:\\ref\\llama.cpp" ) 43self .assertEqual (got [- 2 :], ["-DSTRATA_GGML_DIR=C:/ref/llama.cpp" ,"-DSTRATA_MMQ=ON" ]) 44self .assertLess (got .index ("-DSTRATA_MMQ=OFF" ),got .index ("-DSTRATA_MMQ=ON" ))# the A/B override wins (the last -D counts) 45 46def test_an_arch_override_keeps_ptx_for_the_last (self ): 47self .assertEqual (B .parse_archs ("120" ), (120 ,)) 48self .assertEqual (B .parse_archs ("86; 89,120" ), (86 ,89 ,120 )) 49got = B .configure_args (Path ("S" ),Path ("Bd" ),"cuda13" ,CUDA13 , [],archs = (120 ,)) 50self .assertIn ("-DCMAKE_CUDA_ARCHITECTURES=120-real;120-virtual" ,got ) 51for bad in ("" ,"sm_120" ,"120;x" ): 52with self .assertRaises (SystemExit ): 53B .parse_archs (bad ) 54 55def test_it_refuses_to_run_off_windows (self ): 56if os .name == "nt" : 57self .skipTest ("Linux only" ) 58with self .assertRaises (SystemExit ): 59B .main (["cuda13" ]) 60self .assertEqual (B .main (["cuda11" ]),2 ) 61 62 63FAKE_CMAKE = """#!/bin/sh 64case "$FAKE_MODE" in 65kq) exit 0 ;; 66nokq) echo "ninja: error: unknown target 'strata_kq'" >&2; exit 1 ;; 67*) echo "ninja: error: loading 'build.ninja': No such file or directory" >&2; exit 1 ;; 68esac 69""" 70 71 72@ unittest . skipIf ( os . name == "nt" , "POSIX stand-in cmake" ) 73class Targets (unittest .TestCase ): 74def setUp (self ): 75self .tmp = Path (tempfile .mkdtemp ()) 76self .cmake = self .tmp / "cmake" 77self .cmake .write_text (FAKE_CMAKE ,encoding = "utf-8" ,newline = "\n" ) 78self .cmake .chmod (self .cmake .stat ().st_mode | stat .S_IXUSR ) 79 80def tearDown (self ): 81shutil .rmtree (self .tmp ,ignore_errors = True ) 82 83def call (self ,mode ): 84return B .engine_targets (str (self .cmake ),self .tmp ,env = dict (os .environ ,FAKE_MODE = mode )) 85 86def test_with_and_without_strata_kq (self ): 87self .assertEqual (self .call ("kq" ), ["strata" ,"strata_kq" ]) 88self .assertEqual (self .call ("nokq" ), ["strata" ]) 89 90def test_any_other_failure_stops (self ): 91with self .assertRaises (SystemExit ): 92self .call ("broken" ) 93 94@ unittest . skipUnless ( shutil . which ( "cmake" ) and shutil . which ( "ninja" ), "cmake and ninja" ) 95def test_real_ninja_trees (self ): 96for with_kq in (True ,False ): 97src ,build = self .tmp / ("s%d" % with_kq ),self .tmp / ("b%d" % with_kq ) 98src .mkdir () 99text = "cmake_minimum_required(VERSION 3.16)\nproject(t NONE)\nadd_custom_target(strata)\n" + ("add_custom_target(strata_kq)\n" if with_kq else "" ) 100 (src / "CMakeLists.txt" ).write_text (text ,encoding = "utf-8" ) 101subprocess .run (["cmake" ,"-G" ,"Ninja" ,"-S" ,str (src ),"-B" ,str (build )],check = True ,capture_output = True ,timeout = 600 ) 102self .assertEqual (B .engine_targets ("cmake" ,build ), ["strata" ,"strata_kq" ]if with_kq else ["strata" ]) 103 104 105if __name__ == "__main__" : 106unittest .main ()