From fabee87f14e283c71acac617bf6c288f9d5d8d9d Mon Sep 17 00:00:00 2001 From: nscipione Date: Thu, 27 Mar 2025 16:29:34 +0100 Subject: [PATCH 01/10] Add CMake configuration to use Visual Studio project to build ggml-sycl --- ggml/src/ggml-sycl/CMakeLists.txt | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/ggml/src/ggml-sycl/CMakeLists.txt b/ggml/src/ggml-sycl/CMakeLists.txt index 6747fd88361f7..16a1224d2bc85 100644 --- a/ggml/src/ggml-sycl/CMakeLists.txt +++ b/ggml/src/ggml-sycl/CMakeLists.txt @@ -95,10 +95,19 @@ if (GGML_SYCL_GRAPH) target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_GRAPH) endif() +if (WIN32) + if( ${CMAKE_GENERATOR} MATCHES "Visual Studio" AND NOT (${CMAKE_GENERATOR_TOOLSET} MATCHES "Intel C")) + set_target_properties(ggml-sycl PROPERTIES VS_PLATFORM_TOOLSET "Intel C++ Compiler 2025") + set(CMAKE_CXX_COMPILER "icx") + set(CMAKE_CXX_COMPILER_ID "IntelLLVM") + endif() +endif() + # Link against Intel oneMKL or oneMath if (GGML_SYCL_TARGET STREQUAL "INTEL") # Intel devices use Intel oneMKL directly instead of oneMath to avoid the limitation of linking Intel oneMKL statically # See https://github.com/uxlfoundation/oneMath/issues/654 + find_package(IntelSYCL REQUIRED) find_package(MKL REQUIRED) target_link_libraries(ggml-sycl PRIVATE MKL::MKL_SYCL::BLAS) target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_USE_INTEL_ONEMKL) From 5b5b759204543062271cb5fac7006084b02c958e Mon Sep 17 00:00:00 2001 From: nscipione Date: Thu, 27 Mar 2025 17:38:49 +0100 Subject: [PATCH 02/10] Add documentation on how to generate and use Visual Studio Project for ggml-sycl --- docs/backend/SYCL.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/docs/backend/SYCL.md b/docs/backend/SYCL.md index 19fe8a9d22126..f28f6b1499c8d 100644 --- a/docs/backend/SYCL.md +++ b/docs/backend/SYCL.md @@ -468,6 +468,12 @@ b. Enable oneAPI running environment: "C:\Program Files (x86)\Intel\oneAPI\setvars.bat" intel64 ``` +- if you are using Powershell, enable the runtime environment with the following: + +``` +cmd.exe "/K" '"C:\Program Files (x86)\Intel\oneAPI\setvars.bat" && powershell' +``` + c. Verify installation In the oneAPI command line, run the following to print the available SYCL devices: @@ -541,6 +547,29 @@ You can use Visual Studio to open llama.cpp folder as a CMake project. Choose th - 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`. +4. Visual Studio Project + +You can use Visual Studio projects to build and work on llama.cpp on Windows. You need to convert the CMake Project into a `.sln` file. + +If you want to use Intel C++ compiler for the entire llama.cpp project: +``` +cmake -B build -G "Visual Studio 17 2022" -T "Intel C++ Compiler 2025" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release +``` + +If you want to use Intel C++ Compiler only for ggml-sycl: +``` +cmake -B build -G "Visual Studio 17 2022" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release -DSYCL_INCLUDE_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\include" -DSYCL_LIBRARY_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\lib" +``` + +In both cases, after the Visual Studio is created open it, right click on `ggml-sycl` and open properties. In the left column open `C/C++` sub menu and select `DPC++`. In the option window on the right set `Enable SYCL offload` to `yes` and apply changes. + +Properties -> C\C++ -> DPC++ -> Enable SYCL offload(yes) + +Now you can build llama.cpp with SYCL backend as a Visual Studio project. + +*Notes:* +- you can avoid to specify `SYCL_INCLUDE_DIR` and `SYCL_LIBRARY_DIR` if set the two env vars `SYCL_INCLUDE_DIR_HINT` and `SYCL_LIBRARY_DIR_HINT`. + ### III. Run the inference #### Retrieve and prepare model From d6bb9725b063a112a8d95c7ad9f153008dc02733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Scipione?= Date: Mon, 31 Mar 2025 10:13:23 +0200 Subject: [PATCH 03/10] Update docs/backend/SYCL.md Co-authored-by: Svetlozar Georgiev <55534064+sgeor255@users.noreply.github.com> --- docs/backend/SYCL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/backend/SYCL.md b/docs/backend/SYCL.md index f28f6b1499c8d..8635898b56a14 100644 --- a/docs/backend/SYCL.md +++ b/docs/backend/SYCL.md @@ -561,7 +561,7 @@ If you want to use Intel C++ Compiler only for ggml-sycl: cmake -B build -G "Visual Studio 17 2022" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release -DSYCL_INCLUDE_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\include" -DSYCL_LIBRARY_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\lib" ``` -In both cases, after the Visual Studio is created open it, right click on `ggml-sycl` and open properties. In the left column open `C/C++` sub menu and select `DPC++`. In the option window on the right set `Enable SYCL offload` to `yes` and apply changes. +In both cases, after the Visual Studio solution is created, open it, right click on `ggml-sycl` and open properties. In the left column open `C/C++` sub menu and select `DPC++`. In the option window on the right set `Enable SYCL offload` to `yes` and apply changes. Properties -> C\C++ -> DPC++ -> Enable SYCL offload(yes) From 0b9e673da69f6caad87e7c71ed9dfd777227e97c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Scipione?= Date: Mon, 31 Mar 2025 10:13:34 +0200 Subject: [PATCH 04/10] Update docs/backend/SYCL.md Co-authored-by: Svetlozar Georgiev <55534064+sgeor255@users.noreply.github.com> --- docs/backend/SYCL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/backend/SYCL.md b/docs/backend/SYCL.md index 8635898b56a14..0ef2e0425c677 100644 --- a/docs/backend/SYCL.md +++ b/docs/backend/SYCL.md @@ -568,7 +568,7 @@ Properties -> C\C++ -> DPC++ -> Enable SYCL offload(yes) Now you can build llama.cpp with SYCL backend as a Visual Studio project. *Notes:* -- you can avoid to specify `SYCL_INCLUDE_DIR` and `SYCL_LIBRARY_DIR` if set the two env vars `SYCL_INCLUDE_DIR_HINT` and `SYCL_LIBRARY_DIR_HINT`. +- you can avoid specifying `SYCL_INCLUDE_DIR` and `SYCL_LIBRARY_DIR` by setting the two environment variables `SYCL_INCLUDE_DIR_HINT` and `SYCL_LIBRARY_DIR_HINT`. ### III. Run the inference From ceb389f220c7cb1951290ebdb64090cc0338cf50 Mon Sep 17 00:00:00 2001 From: nscipione Date: Mon, 31 Mar 2025 11:05:39 +0200 Subject: [PATCH 05/10] Add specific requirements for compiling with a mix of MSCV and Intel Compiler --- docs/backend/SYCL.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/backend/SYCL.md b/docs/backend/SYCL.md index 0ef2e0425c677..3e2c9e9d209de 100644 --- a/docs/backend/SYCL.md +++ b/docs/backend/SYCL.md @@ -556,7 +556,7 @@ If you want to use Intel C++ compiler for the entire llama.cpp project: cmake -B build -G "Visual Studio 17 2022" -T "Intel C++ Compiler 2025" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release ``` -If you want to use Intel C++ Compiler only for ggml-sycl: +If you want, you can use Intel C++ Compiler only for ggml-sycl, but `ggml` and its backend libraries *must* be build as shared libraries(i.e. `-DBUILD_SHARED_LIBRARIES=ON`): ``` cmake -B build -G "Visual Studio 17 2022" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release -DSYCL_INCLUDE_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\include" -DSYCL_LIBRARY_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\lib" ``` From fa197b1a10f76b5a0622500b2b2adbc58b99cb56 Mon Sep 17 00:00:00 2001 From: nscipione Date: Tue, 1 Apr 2025 15:40:37 +0100 Subject: [PATCH 06/10] Fix CMake after merging with recent changes --- ggml/src/ggml-sycl/CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/ggml/src/ggml-sycl/CMakeLists.txt b/ggml/src/ggml-sycl/CMakeLists.txt index 16a1224d2bc85..6699b70bad0d7 100644 --- a/ggml/src/ggml-sycl/CMakeLists.txt +++ b/ggml/src/ggml-sycl/CMakeLists.txt @@ -27,6 +27,15 @@ file(GLOB GGML_HEADERS_SYCL "*.hpp") file(GLOB GGML_SOURCES_SYCL "*.cpp") target_sources(ggml-sycl PRIVATE ${GGML_HEADERS_SYCL} ${GGML_SOURCES_SYCL}) +if (WIN32) + # To generate a Visual Studio solution, using Intel C++ Compiler for ggml-sycl is mandatory + if( ${CMAKE_GENERATOR} MATCHES "Visual Studio" AND NOT (${CMAKE_GENERATOR_TOOLSET} MATCHES "Intel C")) + set_target_properties(ggml-sycl PROPERTIES VS_PLATFORM_TOOLSET "Intel C++ Compiler 2025") + set(CMAKE_CXX_COMPILER "icx") + set(CMAKE_CXX_COMPILER_ID "IntelLLVM") + endif() +endif() + find_package(IntelSYCL) if (IntelSYCL_FOUND) # Use oneAPI CMake when possible @@ -95,19 +104,10 @@ if (GGML_SYCL_GRAPH) target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_GRAPH) endif() -if (WIN32) - if( ${CMAKE_GENERATOR} MATCHES "Visual Studio" AND NOT (${CMAKE_GENERATOR_TOOLSET} MATCHES "Intel C")) - set_target_properties(ggml-sycl PROPERTIES VS_PLATFORM_TOOLSET "Intel C++ Compiler 2025") - set(CMAKE_CXX_COMPILER "icx") - set(CMAKE_CXX_COMPILER_ID "IntelLLVM") - endif() -endif() - # Link against Intel oneMKL or oneMath if (GGML_SYCL_TARGET STREQUAL "INTEL") # Intel devices use Intel oneMKL directly instead of oneMath to avoid the limitation of linking Intel oneMKL statically # See https://github.com/uxlfoundation/oneMath/issues/654 - find_package(IntelSYCL REQUIRED) find_package(MKL REQUIRED) target_link_libraries(ggml-sycl PRIVATE MKL::MKL_SYCL::BLAS) target_compile_definitions(ggml-sycl PRIVATE GGML_SYCL_USE_INTEL_ONEMKL) From bae66c3345c87d87f248b5d5b1c47ad3fabd98ce Mon Sep 17 00:00:00 2001 From: nscipione Date: Wed, 2 Apr 2025 09:43:09 +0200 Subject: [PATCH 07/10] Rewrote documentation about Visual Studio usage Merged 3rd and 4th point under only one point related to Visual Studio. Specify better how to build and use Visual Studio solution. Add note about tested configuration. --- docs/backend/SYCL.md | 78 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 65 insertions(+), 13 deletions(-) diff --git a/docs/backend/SYCL.md b/docs/backend/SYCL.md index 3e2c9e9d209de..b8c845e6ba91a 100644 --- a/docs/backend/SYCL.md +++ b/docs/backend/SYCL.md @@ -541,34 +541,86 @@ cmake --build build-x64-windows-sycl-debug -j --target llama-cli 3. Visual Studio -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. +You have two options to use Visual Studio to build llama.cpp: +- As CMake Project using CMake presets. +- Creating a Visual Studio solution to handle the project. + +1. Open as a CMake Project + +You can use Visual Studio to open the `llama.cpp` folder directly as a CMake project. Before compiling, select one of the SYCL CMake presets: + +- `x64-windows-sycl-release` + +- `x64-windows-sycl-debug` *Notes:* +- For a minimal experimental setup, you can build only the inference executable using: -- 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`. + ```Powershell + cmake --build build --config Release -j --target llama-cli + ``` -4. Visual Studio Project +2. Generating a Visual Studio Solution -You can use Visual Studio projects to build and work on llama.cpp on Windows. You need to convert the CMake Project into a `.sln` file. +You can use Visual Studio solution to build and work on llama.cpp on Windows. You need to convert the CMake Project into a `.sln` file. -If you want to use Intel C++ compiler for the entire llama.cpp project: -``` +- Using Intel C++ Compiler for the Entire Project + +If you want to use the Intel C++ Compiler for the entire `llama.cpp` project, run the following command: + +```Powershell cmake -B build -G "Visual Studio 17 2022" -T "Intel C++ Compiler 2025" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release ``` -If you want, you can use Intel C++ Compiler only for ggml-sycl, but `ggml` and its backend libraries *must* be build as shared libraries(i.e. `-DBUILD_SHARED_LIBRARIES=ON`): +- Using Intel C++ Compiler Only for ggml-sycl + +If you prefer to use the Intel C++ Compiler only for `ggml-sycl`, ensure that `ggml` and its backend libraries are built as shared libraries ( i.e. `-DBUILD_SHARED_LIBRARIES=ON`, this is default behaviour): + +```Powershell +cmake -B build -G "Visual Studio 17 2022" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release \ + -DSYCL_INCLUDE_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\include" \ + -DSYCL_LIBRARY_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\lib" ``` -cmake -B build -G "Visual Studio 17 2022" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release -DSYCL_INCLUDE_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\include" -DSYCL_LIBRARY_DIR="C:\Program Files (x86)\Intel\oneAPI\compiler\latest\lib" + +If successful the build files have been written to: *path/to/llama.cpp/build* +Open the project file **build/llama.cpp.sln** with Visual Studio. + +- Configuring SYCL Offload in Visual Studio + +Once the Visual Studio solution is created, follow these steps: + +1. Open the solution in Visual Studio. + +2. Right-click on `ggml-sycl` and select **Properties**. + +3. In the left column, expand **C/C++** and select **DPC++**. + +4. In the right panel, find **Enable SYCL Offload** and set it to `Yes`. + +5. Apply the changes and save. + + +### Navigation Path: + +``` +Properties -> C/C++ -> DPC++ -> Enable SYCL Offload (Yes) ``` -In both cases, after the Visual Studio solution is created, open it, right click on `ggml-sycl` and open properties. In the left column open `C/C++` sub menu and select `DPC++`. In the option window on the right set `Enable SYCL offload` to `yes` and apply changes. +- Build -Properties -> C\C++ -> DPC++ -> Enable SYCL offload(yes) +Now, you can build `llama.cpp` with the SYCL backend as a Visual Studio project. +To do it from menu: `Build -> Build Solution`. +Once it is completed, final results will be in **build/Release/bin** -Now you can build llama.cpp with SYCL backend as a Visual Studio project. +*Additional Note* -*Notes:* -- you can avoid specifying `SYCL_INCLUDE_DIR` and `SYCL_LIBRARY_DIR` by setting the two environment variables `SYCL_INCLUDE_DIR_HINT` and `SYCL_LIBRARY_DIR_HINT`. +- You can avoid specifying `SYCL_INCLUDE_DIR` and `SYCL_LIBRARY_DIR` in the CMake command by setting the environment variables: + + - `SYCL_INCLUDE_DIR_HINT` + + - `SYCL_LIBRARY_DIR_HINT` + +- Above instruction has been tested with Visual Studio 17 Community edition and oneAPI 2025.0. We expect them to work also with future version if the instructions are adapted accordingly. ### III. Run the inference From 321cf7f3afa4d2072e6436ba28fcaa86597da8f5 Mon Sep 17 00:00:00 2001 From: nscipione Date: Wed, 2 Apr 2025 09:47:04 +0200 Subject: [PATCH 08/10] Minor changes to documentation --- docs/backend/SYCL.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/backend/SYCL.md b/docs/backend/SYCL.md index b8c845e6ba91a..2888cea936f92 100644 --- a/docs/backend/SYCL.md +++ b/docs/backend/SYCL.md @@ -545,6 +545,10 @@ You have two options to use Visual Studio to build llama.cpp: - As CMake Project using CMake presets. - Creating a Visual Studio solution to handle the project. +**Note**: + +All following commands are executed in PowerShell. + 1. Open as a CMake Project You can use Visual Studio to open the `llama.cpp` folder directly as a CMake project. Before compiling, select one of the SYCL CMake presets: @@ -600,7 +604,7 @@ Once the Visual Studio solution is created, follow these steps: 5. Apply the changes and save. -### Navigation Path: +*Navigation Path:* ``` Properties -> C/C++ -> DPC++ -> Enable SYCL Offload (Yes) From 980c96db71c113fbed1b6df5938a75d6366fe4fd Mon Sep 17 00:00:00 2001 From: nscipione Date: Fri, 4 Apr 2025 11:13:26 +0200 Subject: [PATCH 09/10] Improving subsection layout --- docs/backend/SYCL.md | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/docs/backend/SYCL.md b/docs/backend/SYCL.md index 2888cea936f92..3ecccc7f91558 100644 --- a/docs/backend/SYCL.md +++ b/docs/backend/SYCL.md @@ -504,13 +504,13 @@ You could download the release package for Windows directly, which including bin Choose one of following methods to build from source code. -1. Script +#### 1. Script ```sh .\examples\sycl\win-build-sycl.bat ``` -2. CMake +#### 2. CMake On the oneAPI command line window, step into the llama.cpp main directory and run the following: @@ -539,7 +539,7 @@ cmake --preset x64-windows-sycl-debug cmake --build build-x64-windows-sycl-debug -j --target llama-cli ``` -3. Visual Studio +#### 3. Visual Studio You have two options to use Visual Studio to build llama.cpp: - As CMake Project using CMake presets. @@ -549,7 +549,7 @@ You have two options to use Visual Studio to build llama.cpp: All following commands are executed in PowerShell. -1. Open as a CMake Project +###### - Open as a CMake Project You can use Visual Studio to open the `llama.cpp` folder directly as a CMake project. Before compiling, select one of the SYCL CMake presets: @@ -564,7 +564,7 @@ You can use Visual Studio to open the `llama.cpp` folder directly as a CMake pro cmake --build build --config Release -j --target llama-cli ``` -2. Generating a Visual Studio Solution +###### - Generating a Visual Studio Solution You can use Visual Studio solution to build and work on llama.cpp on Windows. You need to convert the CMake Project into a `.sln` file. @@ -589,8 +589,6 @@ cmake -B build -G "Visual Studio 17 2022" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TY If successful the build files have been written to: *path/to/llama.cpp/build* Open the project file **build/llama.cpp.sln** with Visual Studio. -- Configuring SYCL Offload in Visual Studio - Once the Visual Studio solution is created, follow these steps: 1. Open the solution in Visual Studio. @@ -610,8 +608,6 @@ Once the Visual Studio solution is created, follow these steps: Properties -> C/C++ -> DPC++ -> Enable SYCL Offload (Yes) ``` -- Build - Now, you can build `llama.cpp` with the SYCL backend as a Visual Studio project. To do it from menu: `Build -> Build Solution`. Once it is completed, final results will be in **build/Release/bin** From 9390da9a0e4c1b6911218f63c2651800d9e2dddf Mon Sep 17 00:00:00 2001 From: nscipione Date: Fri, 4 Apr 2025 14:40:34 +0200 Subject: [PATCH 10/10] Small fix to documentation style --- docs/backend/SYCL.md | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/backend/SYCL.md b/docs/backend/SYCL.md index 3ecccc7f91558..ee017d6e5a762 100644 --- a/docs/backend/SYCL.md +++ b/docs/backend/SYCL.md @@ -549,7 +549,7 @@ You have two options to use Visual Studio to build llama.cpp: All following commands are executed in PowerShell. -###### - Open as a CMake Project +##### - Open as a CMake Project You can use Visual Studio to open the `llama.cpp` folder directly as a CMake project. Before compiling, select one of the SYCL CMake presets: @@ -564,20 +564,16 @@ You can use Visual Studio to open the `llama.cpp` folder directly as a CMake pro cmake --build build --config Release -j --target llama-cli ``` -###### - Generating a Visual Studio Solution +##### - Generating a Visual Studio Solution You can use Visual Studio solution to build and work on llama.cpp on Windows. You need to convert the CMake Project into a `.sln` file. -- Using Intel C++ Compiler for the Entire Project - If you want to use the Intel C++ Compiler for the entire `llama.cpp` project, run the following command: ```Powershell cmake -B build -G "Visual Studio 17 2022" -T "Intel C++ Compiler 2025" -A x64 -DGGML_SYCL=ON -DCMAKE_BUILD_TYPE=Release ``` -- Using Intel C++ Compiler Only for ggml-sycl - If you prefer to use the Intel C++ Compiler only for `ggml-sycl`, ensure that `ggml` and its backend libraries are built as shared libraries ( i.e. `-DBUILD_SHARED_LIBRARIES=ON`, this is default behaviour): ```Powershell @@ -616,9 +612,9 @@ Once it is completed, final results will be in **build/Release/bin** - You can avoid specifying `SYCL_INCLUDE_DIR` and `SYCL_LIBRARY_DIR` in the CMake command by setting the environment variables: - - `SYCL_INCLUDE_DIR_HINT` + - `SYCL_INCLUDE_DIR_HINT` - - `SYCL_LIBRARY_DIR_HINT` + - `SYCL_LIBRARY_DIR_HINT` - Above instruction has been tested with Visual Studio 17 Community edition and oneAPI 2025.0. We expect them to work also with future version if the instructions are adapted accordingly.