Skip to content

Commit 9a59aa2

Browse files
Rbiessyarthw
authored andcommitted
sycl : Add option to set the SYCL architecture for all targets (ggml-org#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 e975c44 commit 9a59aa2

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
@@ -317,12 +317,14 @@ export CPLUS_INCLUDE_DIR=/path/to/oneMKL/buildWithCublas/include:$CPLUS_INCLUDE_
317317
export CPLUS_INCLUDE_DIR=/path/to/oneMKL/include:$CPLUS_INCLUDE_DIR
318318

319319
# Build LLAMA with Nvidia BLAS acceleration through SYCL
320+
# Setting GGML_SYCL_DEVICE_ARCH is optional but can improve performance
321+
GGML_SYCL_DEVICE_ARCH=sm_80 # Example architecture
320322

321323
# Option 1: Use FP32 (recommended for better performance in most cases)
322-
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
324+
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
323325

324326
# Option 2: Use FP16
325-
cmake -B build -DGGML_SYCL=ON -DGGML_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx -DGGML_SYCL_F16=ON
327+
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
326328

327329
# build all binary
328330
cmake --build build --config Release -j -v
@@ -340,8 +342,9 @@ export CPLUS_INCLUDE_DIR=/path/to/oneMKL/buildWithrocBLAS/include:$CPLUS_INCLUDE
340342

341343
## AMD
342344
# Use FP32, FP16 is not supported
343-
# Find your GGML_SYCL_HIP_TARGET with rocminfo, under the key 'Name:'
344-
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
345+
# Find your GGML_SYCL_DEVICE_ARCH with rocminfo, under the key 'Name:'
346+
GGML_SYCL_DEVICE_ARCH=gfx90a # Example architecture
347+
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
345348

346349
# build all binary
347350
cmake --build build --config Release -j -v
@@ -684,6 +687,7 @@ use 1 SYCL GPUs: [0] with Max compute units:512
684687
|--------------------|---------------------------------------|---------------------------------------------|
685688
| GGML_SYCL | ON (mandatory) | Enable build with SYCL code path.<br>FP32 path - recommended for better perforemance than FP16 on quantized model|
686689
| GGML_SYCL_TARGET | INTEL *(default)* \| NVIDIA \| AMD | Set the SYCL target device type. |
690+
| 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. |
687691
| GGML_SYCL_F16 | OFF *(default)* \|ON *(optional)* | Enable FP16 build with SYCL code path. |
688692
| CMAKE_C_COMPILER | `icx` *(Linux)*, `icx/cl` *(Windows)* | Set `icx` compiler for SYCL code path. |
689693
| 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)