84 lines
4.1 KiB
Batchfile
84 lines
4.1 KiB
Batchfile
@echo off
|
|
rem Build igneum-bench-cl for one program pack (Windows, MSVC).
|
|
rem Run from an "x64 Native Tools Command Prompt for VS 2022" (or 2026 with any toolset: this is plain C, no nvcc involved).
|
|
rem Needs the OpenCL headers (CL\cl.h) and the ICD loader import library (OpenCL.lib). The script looks, in order, at:
|
|
rem OPENCL_SDK a Khronos OpenCL-SDK or vcpkg tree: %OPENCL_SDK%\include\CL\cl.h and %OPENCL_SDK%\lib\OpenCL.lib
|
|
rem CUDA_PATH the CUDA Toolkit ships both: %CUDA_PATH%\include\CL\cl.h and %CUDA_PATH%\lib\x64\OpenCL.lib
|
|
rem OCL_ROOT the old AMD APP SDK layout: %OCL_ROOT%\include and %OCL_ROOT%\lib\x86_64
|
|
rem The runtime itself (OpenCL.dll in System32 plus the vendor ICD) comes with the AMD Adrenalin driver; no SDK needed to run.
|
|
rem Usage: build.bat [pack]
|
|
rem pack directory name under ..\proto-cuda\packs\ (default igneum-genesis-mh)
|
|
setlocal
|
|
cd /d "%~dp0"
|
|
|
|
set PACK=%1
|
|
if "%PACK%"=="" set PACK=igneum-genesis-mh
|
|
set PACKDIR=..\proto-cuda\packs\%PACK%
|
|
|
|
where cl >nul 2>nul
|
|
if errorlevel 1 (
|
|
echo cl.exe not found. Open an "x64 Native Tools Command Prompt" ^(Visual Studio Build Tools, Desktop development with C++^) and run this again.
|
|
exit /b 1
|
|
)
|
|
if not exist "%PACKDIR%\kernel.cl" (
|
|
echo no pack at %PACKDIR% ^(expected kernel.cl, program.h, vectors.h^)
|
|
exit /b 1
|
|
)
|
|
|
|
set INC=
|
|
set LIB=
|
|
if not "%OPENCL_SDK%"=="" if exist "%OPENCL_SDK%\include\CL\cl.h" (
|
|
set INC=%OPENCL_SDK%\include
|
|
if exist "%OPENCL_SDK%\lib\OpenCL.lib" set LIB=%OPENCL_SDK%\lib\OpenCL.lib
|
|
if exist "%OPENCL_SDK%\lib\x64\OpenCL.lib" set LIB=%OPENCL_SDK%\lib\x64\OpenCL.lib
|
|
)
|
|
if "%LIB%"=="" if not "%CUDA_PATH%"=="" if exist "%CUDA_PATH%\include\CL\cl.h" (
|
|
set INC=%CUDA_PATH%\include
|
|
set LIB=%CUDA_PATH%\lib\x64\OpenCL.lib
|
|
)
|
|
if "%LIB%"=="" if not "%OCL_ROOT%"=="" if exist "%OCL_ROOT%\include\CL\cl.h" (
|
|
set INC=%OCL_ROOT%\include
|
|
set LIB=%OCL_ROOT%\lib\x86_64\OpenCL.lib
|
|
)
|
|
if "%LIB%"=="" (
|
|
echo No OpenCL SDK found. Set OPENCL_SDK to a tree with include\CL\cl.h and lib\OpenCL.lib, for example:
|
|
echo vcpkg install opencl:x64-windows then set OPENCL_SDK=C:\vcpkg\installed\x64-windows
|
|
echo or the Khronos OpenCL-SDK release zip, or install the CUDA Toolkit ^(it ships CL\cl.h and OpenCL.lib^).
|
|
exit /b 1
|
|
)
|
|
|
|
echo using headers %INC% and import library %LIB%
|
|
rem Find the MSVC runtime libraries and the Windows SDK libraries ourselves, in case the prompt did not set LIB
|
|
rem (seen on a Visual Studio 2026 install where vcvarsall reported success but linking could not find LIBCMT.lib).
|
|
set "EXTRALIB="
|
|
set "MSVCLIB="
|
|
set "SDKLIB="
|
|
set "VSVC=%VCINSTALLDIR%"
|
|
if "%VSVC%"=="" set "VSVC=C:\Program Files\Microsoft Visual Studio\18\Community\VC\"
|
|
set "KITS=C:\Program Files (x86)\Windows Kits\10\Lib"
|
|
for /f "delims=" %%D in ('dir /b /ad /o-n "%VSVC%Tools\MSVC" 2^>nul') do call :msvc "%%D"
|
|
for /f "delims=" %%D in ('dir /b /ad /o-n "%KITS%" 2^>nul') do call :sdk "%%D"
|
|
goto :found
|
|
:msvc
|
|
if not "%MSVCLIB%"=="" goto :eof
|
|
if exist "%VSVC%Tools\MSVC\%~1\lib\x64\libcmt.lib" set "MSVCLIB=%VSVC%Tools\MSVC\%~1\lib\x64"
|
|
goto :eof
|
|
:sdk
|
|
if not "%SDKLIB%"=="" goto :eof
|
|
if exist "%KITS%\%~1\ucrt\x64\libucrt.lib" set "SDKLIB=%KITS%\%~1"
|
|
goto :eof
|
|
:found
|
|
if not "%MSVCLIB%"=="" set "EXTRALIB=/LIBPATH:"%MSVCLIB%""
|
|
if not "%SDKLIB%"=="" set "EXTRALIB=%EXTRALIB% /LIBPATH:"%SDKLIB%\ucrt\x64" /LIBPATH:"%SDKLIB%\um\x64""
|
|
if "%MSVCLIB%"=="" echo warning: no libcmt.lib under any MSVC toolset. Install "Desktop development with C++" in the Visual Studio Installer.
|
|
if "%SDKLIB%"=="" echo warning: no Windows SDK libraries under "%KITS%".
|
|
echo libraries: MSVC="%MSVCLIB%" SDK="%SDKLIB%"
|
|
echo cl /nologo /O2 /W3 /std:c11 /I "%INC%" /I "%PACKDIR%" /DIGNEUM_KERNEL_PATH="\"%PACKDIR:\=/%/kernel.cl\"" /Fe:igneum-bench-cl-%PACK%.exe host.c /link "%LIB%" %EXTRALIB%
|
|
cl /nologo /O2 /W3 /std:c11 /I "%INC%" /I "%PACKDIR%" /DIGNEUM_KERNEL_PATH="\"%PACKDIR:\=/%/kernel.cl\"" /Fe:igneum-bench-cl-%PACK%.exe host.c /link "%LIB%" %EXTRALIB%
|
|
if errorlevel 1 (
|
|
echo build failed. If cl.exe rejects /std:c11, drop that flag: the code is C99 and MSVC's default C mode accepts it.
|
|
exit /b 1
|
|
)
|
|
del host.obj >nul 2>nul
|
|
echo built igneum-bench-cl-%PACK%.exe
|
|
endlocal
|