Repository navigation
Expand file tree
/
Copy pathbuild.cmd
More file actions
79 lines (74 loc) · 4.85 KB
/
Copy pathbuild.cmd
File metadata and controls
79 lines (74 loc) · 4.85 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
@echo off
rem Build pithos on Windows. Uses gcc (MSYS2 MinGW-w64) if available, otherwise MSVC.
rem build.cmd -> build\pithos.exe
rem build.cmd msvc -> force MSVC
rem build.cmd test -> also build the test programs (build.cmd msvc test with MSVC)
setlocal enabledelayedexpansion
cd /d "%~dp0"
if not exist build mkdir build
set SRC=src\main.c src\model.c src\gguf.c src\tokenizer.c src\sampler.c src\quant.c src\platform.c src\quant_neon.c src\gpu_opencl.c src\gpu_d3d12.c src\gpu_vulkan.c src\json.c src\pcache.c src\server.c src\proc.c src\tools.c src\agent.c src\audio.c src\speech.c src\mp3.c src\decide.c src\values.c src\image.c src\vision.c
set WANT=
set TEST=
for %%a in (%*) do (
if /i "%%a"=="msvc" set WANT=msvc
if /i "%%a"=="test" set TEST=1
)
if "%WANT%"=="msvc" goto msvc
where gcc >nul 2>nul && goto gcc
if exist C:\msys64\mingw64\bin\gcc.exe (
set "PATH=C:\msys64\mingw64\bin;%PATH%"
goto gcc
)
if exist C:\msys64\ucrt64\bin\gcc.exe (
set "PATH=C:\msys64\ucrt64\bin;%PATH%"
goto gcc
)
goto msvc
:gcc
echo [pithos] compiler: gcc
set CFLAGS=-O3 -std=c11 -Wall -Wextra -Wno-unused-parameter
gcc %CFLAGS% -mavx2 -mfma -mf16c -c src\quant_avx2.c -o build\quant_avx2.o || goto fail
gcc %CFLAGS% -mavx -mf16c -c src\quant_avx.c -o build\quant_avx.o || goto fail
gcc %CFLAGS% -municode %SRC% build\quant_avx2.o build\quant_avx.o -o build\pithos.exe -lm -lws2_32 || goto fail
if defined TEST (
gcc %CFLAGS% tests\test_kernels.c src\gguf.c src\quant.c src\platform.c build\quant_avx2.o build\quant_avx.o -o build\test_kernels.exe -lm || goto fail
gcc %CFLAGS% tests\test_gpu.c src\model.c src\gguf.c src\quant.c src\platform.c src\gpu_opencl.c src\gpu_d3d12.c src\gpu_vulkan.c build\quant_avx2.o build\quant_avx.o -o build\test_gpu.exe -lm || goto fail
gcc %CFLAGS% tests\test_dx.c src\model.c src\gguf.c src\tokenizer.c src\quant.c src\platform.c src\gpu_opencl.c src\gpu_d3d12.c src\gpu_vulkan.c build\quant_avx2.o build\quant_avx.o -o build\test_dx.exe -lm || goto fail
gcc %CFLAGS% tests\test_vk.c src\gpu_vulkan.c src\model.c src\gguf.c src\tokenizer.c src\quant.c src\platform.c src\gpu_opencl.c src\gpu_d3d12.c build\quant_avx2.o build\quant_avx.o -o build\test_vk.exe -lm || goto fail
gcc %CFLAGS% tests\test_shell.c src\tools.c src\proc.c src\platform.c src\json.c -o build\test_shell.exe -lm || goto fail
gcc %CFLAGS% tests\test_values.c src\values.c src\json.c -o build\test_values.exe -lm || goto fail
gcc %CFLAGS% tests\test_image.c src\image.c -o build\test_image.exe -lm || goto fail
)
goto ok
:msvc
where cl >nul 2>nul && goto msvc_ready
set "VSINST=%ProgramFiles(x86)%\Microsoft Visual Studio\Installer"
if not exist "%VSINST%\vswhere.exe" goto nocompiler
for /f "delims=" %%i in ('"%VSINST%\vswhere.exe" -latest -products * -requires Microsoft.VisualStudio.Component.VC.Tools.x86.x64 -property installationPath') do set "VSDIR=%%i"
if not defined VSDIR goto nocompiler
call "%VSDIR%\VC\Auxiliary\Build\vcvars64.bat" >nul 2>nul || goto nocompiler
:msvc_ready
echo [pithos] compiler: MSVC
set CLFLAGS=/nologo /O2 /Oi /GL /std:c11 /W3 /D_CRT_SECURE_NO_WARNINGS
cl %CLFLAGS% /arch:AVX2 /c src\quant_avx2.c /Fobuild\quant_avx2.obj || goto fail
cl %CLFLAGS% /arch:AVX /c src\quant_avx.c /Fobuild\quant_avx.obj || goto fail
cl %CLFLAGS% %SRC% build\quant_avx2.obj build\quant_avx.obj /Fobuild\ /Febuild\pithos.exe /link /LTCG || goto fail
if defined TEST (
cl %CLFLAGS% tests\test_kernels.c src\gguf.c src\quant.c src\platform.c build\quant_avx2.obj build\quant_avx.obj /Fobuild\ /Febuild\test_kernels.exe /link /LTCG || goto fail
cl %CLFLAGS% tests\test_gpu.c src\model.c src\gguf.c src\quant.c src\platform.c src\gpu_opencl.c src\gpu_d3d12.c src\gpu_vulkan.c build\quant_avx2.obj build\quant_avx.obj /Fobuild\ /Febuild\test_gpu.exe /link /LTCG || goto fail
cl %CLFLAGS% tests\test_dx.c src\model.c src\gguf.c src\tokenizer.c src\quant.c src\platform.c src\gpu_opencl.c src\gpu_d3d12.c src\gpu_vulkan.c build\quant_avx2.obj build\quant_avx.obj /Fobuild\ /Febuild\test_dx.exe /link /LTCG || goto fail
cl %CLFLAGS% tests\test_vk.c src\gpu_vulkan.c src\model.c src\gguf.c src\tokenizer.c src\quant.c src\platform.c src\gpu_opencl.c src\gpu_d3d12.c build\quant_avx2.obj build\quant_avx.obj /Fobuild\ /Febuild\test_vk.exe /link /LTCG || goto fail
cl %CLFLAGS% tests\test_shell.c src\tools.c src\proc.c src\platform.c src\json.c /Fobuild\ /Febuild\test_shell.exe /link /LTCG || goto fail
cl %CLFLAGS% tests\test_values.c src\values.c src\json.c /Fobuild\ /Febuild\test_values.exe /link /LTCG || goto fail
cl %CLFLAGS% tests\test_image.c src\image.c /Fobuild\ /Febuild\test_image.exe /link /LTCG || goto fail
)
goto ok
:nocompiler
echo [pithos] no C compiler found: install MSYS2 (pacman -S mingw-w64-x86_64-gcc) or Visual Studio Build Tools.
exit /b 1
:fail
echo [pithos] build failed
exit /b 1
:ok
echo [pithos] ok: build\pithos.exe
exit /b 0