Skip to content

Commit e33ffb2

Browse files
luoyu-intelNeoZhangJianyu
authored andcommitted
[SYCL] Fix windows build and inference (ggml-org#8003)
* add sycl preset * fix debug link error. fix windows crash * update README
1 parent 273ccd9 commit e33ffb2

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
@@ -420,15 +420,9 @@ Output (example):
420420

421421
4. Install build tools
422422

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

425-
b. Download & install mingw-w64 make for Windows provided by w64devkit
426-
427-
- Download the 1.19.0 version of [w64devkit](https://github.com/skeeto/w64devkit/releases/download/v1.19.0/w64devkit-1.19.0.zip).
428-
429-
- Extract `w64devkit` on your pc.
430-
431-
- Add the **bin** folder path in the Windows system PATH environment (for e.g. `C:\xxx\w64devkit\bin\`).
432426

433427
### II. Build llama.cpp
434428

@@ -438,10 +432,10 @@ On the oneAPI command line window, step into the llama.cpp main directory and ru
438432
@call "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 --force
439433
440434
# Option 1: Use FP32 (recommended for better performance in most cases)
441-
cmake -B build -G "MinGW Makefiles" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release
435+
cmake -B build -G "Ninja" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release
442436
443437
# Option 2: Or FP16
444-
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
438+
cmake -B build -G "Ninja" -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=cl -DCMAKE_CXX_COMPILER=icx -DCMAKE_BUILD_TYPE=Release -DLLAMA_SYCL_F16=ON
445439
446440
cmake --build build --config Release -j
447441
```
@@ -451,9 +445,23 @@ Otherwise, run the `win-build-sycl.bat` wrapper which encapsulates the former in
451445
.\examples\sycl\win-build-sycl.bat
452446
```
453447

448+
Or, use CMake presets to build:
449+
```sh
450+
cmake --preset x64-windows-sycl-release
451+
cmake --build build-x64-windows-sycl-release -j --target llama-cli
452+
453+
cmake -DLLAMA_SYCL_F16=ON --preset x64-windows-sycl-release
454+
cmake --build build-x64-windows-sycl-release -j --target llama-cli
455+
456+
cmake --preset x64-windows-sycl-debug
457+
cmake --build build-x64-windows-sycl-debug -j --target llama-cli
458+
```
459+
460+
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.
461+
454462
*Notes:*
455463

456-
- 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`.
464+
- 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`.
457465

458466
### III. Run the inference
459467

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
@@ -4760,7 +4760,7 @@ static void ggml_sycl_cpy(ggml_backend_sycl_context & ctx, const ggml_tensor *sr
47604760
GGML_ASSERT(ggml_nbytes(src0) <= INT_MAX);
47614761
GGML_ASSERT(ggml_nbytes(src1) <= INT_MAX);
47624762

4763-
GGML_TENSOR_BINARY_OP_LOCALS;
4763+
GGML_TENSOR_BINARY_OP_LOCALS01;
47644764

47654765
SYCL_CHECK(ggml_sycl_set_device(ctx.device));
47664766
queue_ptr main_stream = ctx.stream();

0 commit comments

Comments
 (0)