Skip to content

Commit de391e4

Browse files
authored
[SYCL] Fix windows build and inference (#8003)
* add sycl preset * fix debug link error. fix windows crash * update README
1 parent d50f889 commit de391e4

File tree

7 files changed

+241
-255
lines changed

7 files changed

+241
-255
lines changed

CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ if (LLAMA_SYCL)
665665
#todo: AOT
666666

667667
find_package(IntelSYCL REQUIRED)
668+
find_package(MKL REQUIRED)
668669

669670
message(STATUS "SYCL found")
670671

@@ -679,11 +680,9 @@ if (LLAMA_SYCL)
679680
endif()
680681

681682
add_compile_options(-I./) #include DPCT
682-
add_compile_options(-I/${SYCL_INCLUDE_DIR})
683683

684684
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
685685
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
686-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl -L${MKLROOT}/lib")
687686
if (LLAMA_SYCL_TARGET STREQUAL "NVIDIA")
688687
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=nvptx64-nvidia-cuda")
689688
endif()
@@ -693,8 +692,10 @@ if (LLAMA_SYCL)
693692
list(APPEND GGML_SOURCES_SYCL "ggml-sycl.cpp")
694693

695694
if (WIN32)
696-
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} -fsycl sycl7 OpenCL mkl_sycl_blas_dll.lib mkl_intel_ilp64_dll.lib mkl_sequential_dll.lib mkl_core_dll.lib)
695+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} IntelSYCL::SYCL_CXX MKL::MKL MKL::MKL_SYCL)
697696
else()
697+
add_compile_options(-I/${SYCL_INCLUDE_DIR})
698+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl -L${MKLROOT}/lib")
698699
if (LLAMA_SYCL_TARGET STREQUAL "INTEL")
699700
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} -fsycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread)
700701
elseif (LLAMA_SYCL_TARGET STREQUAL "NVIDIA")

CMakePresets.json

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@
1111
"CMAKE_INSTALL_RPATH": "$ORIGIN;$ORIGIN/.."
1212
}
1313
},
14-
14+
{
15+
"name": "sycl-base",
16+
"hidden": true,
17+
"generator": "Ninja",
18+
"binaryDir": "${sourceDir}/build-${presetName}",
19+
"cacheVariables": {
20+
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON",
21+
"CMAKE_CXX_COMPILER": "icx",
22+
"LLAMA_SYCL": "ON",
23+
"CMAKE_INSTALL_RPATH": "$ORIGIN;$ORIGIN/.."
24+
}
25+
},
1526
{ "name": "debug", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Debug" } },
16-
{ "name": "release", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" } },
27+
{ "name": "release", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "Release" } },
28+
{ "name": "reldbg", "hidden": true, "cacheVariables": { "CMAKE_BUILD_TYPE": "RelWithDebInfo" } },
1729
{ "name": "static", "hidden": true, "cacheVariables": { "LLAMA_STATIC": "ON" } },
1830

1931
{
@@ -35,15 +47,18 @@
3547
},
3648

3749
{ "name": "arm64-windows-llvm-debug" , "inherits": [ "base", "arm64-windows-llvm", "debug" ] },
38-
{ "name": "arm64-windows-llvm-release", "inherits": [ "base", "arm64-windows-llvm", "release" ] },
39-
{ "name": "arm64-windows-llvm+static-release", "inherits": [ "base", "arm64-windows-llvm", "release", "static" ] },
50+
{ "name": "arm64-windows-llvm-release", "inherits": [ "base", "arm64-windows-llvm", "reldbg" ] },
51+
{ "name": "arm64-windows-llvm+static-release", "inherits": [ "base", "arm64-windows-llvm", "reldbg", "static" ] },
4052

4153
{ "name": "arm64-windows-msvc-debug" , "inherits": [ "base", "arm64-windows-msvc", "debug" ] },
42-
{ "name": "arm64-windows-msvc-release", "inherits": [ "base", "arm64-windows-msvc", "release" ] },
43-
{ "name": "arm64-windows-msvc+static-release", "inherits": [ "base", "arm64-windows-msvc", "release", "static" ] },
54+
{ "name": "arm64-windows-msvc-release", "inherits": [ "base", "arm64-windows-msvc", "reldbg" ] },
55+
{ "name": "arm64-windows-msvc+static-release", "inherits": [ "base", "arm64-windows-msvc", "reldbg", "static" ] },
4456

4557
{ "name": "x64-windows-msvc-debug" , "inherits": [ "base", "debug" ] },
46-
{ "name": "x64-windows-msvc-release", "inherits": [ "base", "release" ] },
47-
{ "name": "x64-windows-msvc+static-release", "inherits": [ "base", "release", "static" ] }
58+
{ "name": "x64-windows-msvc-release", "inherits": [ "base", "reldbg" ] },
59+
{ "name": "x64-windows-msvc+static-release", "inherits": [ "base", "reldbg", "static" ] },
60+
61+
{ "name": "x64-windows-sycl-debug" , "inherits": [ "sycl-base", "debug" ] },
62+
{ "name": "x64-windows-sycl-release", "inherits": [ "sycl-base", "release" ] }
4863
]
4964
}

README-sycl.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,15 +410,9 @@ Output (example):
410410

411411
4. Install build tools
412412

413-
a. Download & install cmake for Windows: https://cmake.org/download/
413+
a. Download & install cmake for Windows: https://cmake.org/download/ (CMake can also be installed from Visual Studio Installer)
414+
b. The new Visual Studio will install Ninja as default. (If not, please install it manually: https://ninja-build.org/)
414415

415-
b. Download & install mingw-w64 make for Windows provided by w64devkit
416-
417-
- Download the 1.19.0 version of [w64devkit](https://github.com/skeeto/w64devkit/releases/download/v1.19.0/w64devkit-1.19.0.zip).
418-
419-
- Extract `w64devkit` on your pc.
420-
421-
- Add the **bin** folder path in the Windows system PATH environment (for e.g. `C:\xxx\w64devkit\bin\`).
422416

423417
### II. Build llama.cpp
424418

@@ -428,10 +422,10 @@ On the oneAPI command line window, step into the llama.cpp main directory and ru
428422
@call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 --force
429423
430424
# Option 1: Use FP32 (recommended for better performance in most cases)
431-
cmake -B build -G "MinGW Makefiles" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release
425+
cmake -B build -G "Ninja" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release
432426
433427
# Option 2: Or FP16
434-
cmake -B build -G "MinGW Makefiles" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release -DLLAMA_SYCL_F16=ON
428+
cmake -B build -G "Ninja" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release -DLLAMA_SYCL_F16=ON
435429
436430
cmake --build build --config Release -j
437431
```
@@ -441,9 +435,23 @@ Otherwise, run the `win-build-sycl.bat` wrapper which encapsulates the former in
441435
.\examples\sycl\win-build-sycl.bat
442436
```
443437

438+
Or, use CMake presets to build:
439+
```sh
440+
cmake --preset x64-windows-sycl-release
441+
cmake --build build-x64-windows-sycl-release -j --target llama-cli
442+
443+
cmake -DLLAMA_SYCL_F16=ON --preset x64-windows-sycl-release
444+
cmake --build build-x64-windows-sycl-release -j --target llama-cli
445+
446+
cmake --preset x64-windows-sycl-debug
447+
cmake --build build-x64-windows-sycl-debug -j --target llama-cli
448+
```
449+
450+
Or, you can use Visual Studio to open llama.cpp folder as a CMake project. Choose the sycl CMake presets (`x64-windows-sycl-release` or `x64-windows-sycl-debug`) before you compile the project.
451+
444452
*Notes:*
445453

446-
- By default, calling `make` will build all target binary files. In case of a minimal experimental setup, the user can build the inference executable only through `make llama-cli`.
454+
- In case of a minimal experimental setup, the user can build the inference executable only through `cmake --build build --config Release -j --target llama-cli`.
447455

448456
### III. Run the inference
449457

examples/sycl/win-build-sycl.bat

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ if %errorlevel% neq 0 goto ERROR
1313

1414
:: for FP16
1515
:: faster for long-prompt inference
16-
:: cmake -G "MinGW Makefiles" .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DLLAMA_SYCL_F16=ON
16+
:: cmake -G "MinGW Makefiles" .. -DLLAMA_SYCL=ON -DCMAKE_CXX_COMPILER=icx -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release -DLLAMA_SYCL_F16=ON
1717

1818
:: for FP32
19-
cmake -G "MinGW Makefiles" .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release
19+
cmake -G "Ninja" .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=icx -DBUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release
2020
if %errorlevel% neq 0 goto ERROR
2121
:: build example/main only
2222
:: make main
2323

2424
:: build all binary
25-
make -j
25+
cmake --build . -j
2626
if %errorlevel% neq 0 goto ERROR
2727

2828
cd ..

ggml-sycl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4911,7 +4911,7 @@ static void ggml_sycl_cpy(ggml_backend_sycl_context & ctx, const ggml_tensor *sr
49114911
GGML_ASSERT(ggml_nbytes(src0) <= INT_MAX);
49124912
GGML_ASSERT(ggml_nbytes(src1) <= INT_MAX);
49134913

4914-
GGML_TENSOR_BINARY_OP_LOCALS;
4914+
GGML_TENSOR_BINARY_OP_LOCALS01;
49154915

49164916
SYCL_CHECK(ggml_sycl_set_device(ctx.device));
49174917
queue_ptr main_stream = ctx.stream();

0 commit comments

Comments
 (0)