Skip to content

Commit 2a1507c

Browse files
authored
sycl : Add option to set the SYCL architecture for all targets (#10266)
* Add option to set the SYCL architecture for all targets * Convert GGML_SYCL_HIP_TARGET to the more generic GGML_SYCL_ARCH option * Document that setting GGML_SYCL_ARCH can improve the performance
1 parent b3e5859 commit 2a1507c

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

docs/backend/SYCL.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,14 @@ export CPLUS_INCLUDE_DIR=/path/to/oneMKL/buildWithCublas/include:$CPLUS_INCLUDE_
312312
export CPLUS_INCLUDE_DIR=/path/to/oneMKL/include:$CPLUS_INCLUDE_DIR
313313

314314
# Build LLAMA with Nvidia BLAS acceleration through SYCL
315+
# Setting GGML_SYCL_DEVICE_ARCH is optional but can improve performance
316+
GGML_SYCL_DEVICE_ARCH=sm_80 # Example architecture
315317

316318
# Option 1: Use FP32 (recommended for better performance in most cases)
317-
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
319+
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DGGML_SYCL_DEVICE_ARCH=${GGML_SYCL_DEVICE_ARCH} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
318320

319321
# Option 2: Use FP16
320-
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON
322+
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DGGML_SYCL_DEVICE_ARCH=${GGML_SYCL_DEVICE_ARCH} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON
321323

322324
# build all binary
323325
cmake --build build --config Release -j -v
@@ -335,8 +337,9 @@ export CPLUS_INCLUDE_DIR=/path/to/oneMKL/buildWithrocBLAS/include:$CPLUS_INCLUDE
335337

336338
## AMD
337339
# Use FP32, FP16 is not supported
338-
# Find your GGML_SYCL_HIP_TARGET with rocminfo, under the key 'Name:'
339-
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=AMD -DGGML_SYCL_HIP_TARGET=${GGML_SYCL_HIP_TARGET} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
340+
# Find your GGML_SYCL_DEVICE_ARCH with rocminfo, under the key 'Name:'
341+
GGML_SYCL_DEVICE_ARCH=gfx90a # Example architecture
342+
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=AMD -DGGML_SYCL_DEVICE_ARCH=${GGML_SYCL_DEVICE_ARCH} -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
340343

341344
# build all binary
342345
cmake --build build --config Release -j -v
@@ -646,6 +649,7 @@ use 1 SYCL GPUs: [0] with Max compute units:512
646649
|--------------------|---------------------------------------|---------------------------------------------|
647650
| GGML_SYCL | ON (mandatory) | Enable build with SYCL code path.<br>FP32 path - recommended for better perforemance than FP16 on quantized model|
648651
| GGML_SYCL_TARGET | INTEL *(default)* \| NVIDIA \| AMD | Set the SYCL target device type. |
652+
| GGML_SYCL_DEVICE_ARCH | Optional (except for AMD) | Set the SYCL device architecture, optional except for AMD. Setting the device architecture can improve the performance. See the table [--offload-arch](https://github.com/intel/llvm/blob/sycl/sycl/doc/design/OffloadDesign.md#--offload-arch) for a list of valid architectures. |
649653
| GGML_SYCL_F16 | OFF *(default)* \|ON *(optional)* | Enable FP16 build with SYCL code path. |
650654
| CMAKE_C_COMPILER | `icx` *(Linux)*, `icx/cl` *(Windows)* | Set `icx` compiler for SYCL code path. |
651655
| CMAKE_CXX_COMPILER | `icpx` *(Linux)*, `icx` *(Windows)* | Set `icpx/icx` compiler for SYCL code path. |

ggml/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,8 @@ option(GGML_SYCL "ggml: use SYCL"
164164
option(GGML_SYCL_F16 "ggml: use 16 bit floats for sycl calculations" OFF)
165165
set (GGML_SYCL_TARGET "INTEL" CACHE STRING
166166
"ggml: sycl target device")
167+
set (GGML_SYCL_DEVICE_ARCH "" CACHE STRING
168+
"ggml: sycl device architecture")
167169

168170
# extra artifacts
169171
option(GGML_BUILD_TESTS "ggml: build tests" ${GGML_STANDALONE})

ggml/src/ggml-sycl/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,14 @@ else()
7272
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=nvptx64-nvidia-cuda")
7373
target_link_libraries(ggml-sycl PRIVATE sycl pthread m dl onemkl)
7474
elseif (GGML_SYCL_TARGET STREQUAL "AMD")
75-
if (GGML_SYCL_HIP_TARGET STREQUAL "")
76-
message(ERROR "Can't enable SYCL hip backend, GGML_SYCL_HIP_TARGET has not been set.")
75+
if (NOT GGML_SYCL_DEVICE_ARCH)
76+
message(ERROR "Can't enable SYCL hip backend, GGML_SYCL_DEVICE_ARCH has not been set.")
7777
endif()
78-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=amdgcn-amd-amdhsa -Xsycl-target-backend --offload-arch=${GGML_SYCL_HIP_TARGET}")
78+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=amdgcn-amd-amdhsa")
7979
target_link_libraries(ggml-sycl PRIVATE sycl pthread m dl onemkl)
8080
endif()
81+
82+
if (GGML_SYCL_DEVICE_ARCH)
83+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xsycl-target-backend --offload-arch=${GGML_SYCL_DEVICE_ARCH}")
84+
endif()
8185
endif()

0 commit comments

Comments
 (0)