Skip to content

Commit fea8722

Browse files
AidanBeltonSjordankanter
authored andcommitted
[SYCL] Add support for SYCL Nvidia target (ggml-org#5738)
* Add support for nvidia target in CMake * Update sycl read-me for Nvidia target * Fix errors
1 parent 579aa3e commit fea8722

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

CMakeLists.txt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ option(LLAMA_MPI "llama: use MPI"
116116
option(LLAMA_QKK_64 "llama: use super-block size of 64 for k-quants" OFF)
117117
option(LLAMA_SYCL "llama: use SYCL" OFF)
118118
option(LLAMA_SYCL_F16 "llama: use 16 bit floats for sycl calculations" OFF)
119+
set(LLAMA_SYCL_TARGET "INTEL" CACHE STRING "llama: sycl target device")
119120
option(LLAMA_CPU_HBM "llama: use memkind for CPU HBM" OFF)
120121

121122
option(LLAMA_BUILD_TESTS "llama: build tests" ${LLAMA_STANDALONE})
@@ -534,6 +535,10 @@ if (LLAMA_HIPBLAS)
534535
endif()
535536

536537
if (LLAMA_SYCL)
538+
if (NOT LLAMA_SYCL_TARGET MATCHES "^(INTEL|NVIDIA)$")
539+
message(FATAL_ERROR "Invalid backend chosen, supported options are INTEL or NVIDIA")
540+
endif()
541+
537542
if ( NOT DEFINED ENV{ONEAPI_ROOT})
538543
message(FATAL_ERROR "Not detect ENV {ONEAPI_ROOT}, please install oneAPI & source it, like: source /opt/intel/oneapi/setvars.sh")
539544
endif()
@@ -555,14 +560,21 @@ if (LLAMA_SYCL)
555560
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
556561
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
557562
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl -L${MKLROOT}/lib")
563+
if (LLAMA_SYCL_TARGET STREQUAL "NVIDIA")
564+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl-targets=nvptx64-nvidia-cuda")
565+
endif()
558566

559567
set(GGML_HEADERS_SYCL ggml-sycl.h)
560568
set(GGML_SOURCES_SYCL ggml-sycl.cpp)
561569

562570
if (WIN32)
563571
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)
564572
else()
565-
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} -fsycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread)
573+
if (LLAMA_SYCL_TARGET STREQUAL "INTEL")
574+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} -fsycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread)
575+
elseif (LLAMA_SYCL_TARGET STREQUAL "NVIDIA")
576+
set(LLAMA_EXTRA_LIBS ${LLAMA_EXTRA_LIBS} -fsycl pthread m dl onemkl)
577+
endif()
566578
endif()
567579
endif()
568580

README-sycl.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,29 @@ For iGPU, please make sure the shared memory from host memory is enough. For lla
7373

7474
For dGPU, please make sure the device memory is enough. For llama-2-7b.Q4_0, recommend the device memory is 4GB+.
7575

76+
## Nvidia GPU
77+
78+
### Verified
79+
80+
|Intel GPU| Status | Verified Model|
81+
|-|-|-|
82+
|Ampere Series| Support| A100|
83+
84+
### oneMKL
85+
86+
The current oneMKL release does not contain the oneMKL cuBlas backend.
87+
As a result for Nvidia GPU's oneMKL must be built from source.
88+
89+
```
90+
git clone https://github.com/oneapi-src/oneMKL
91+
cd oneMKL
92+
mkdir build
93+
cd build
94+
cmake -G Ninja .. -DCMAKE_CXX_COMPILER=icpx -DCMAKE_C_COMPILER=icx -DENABLE_MKLGPU_BACKEND=OFF -DENABLE_MKLCPU_BACKEND=OFF -DENABLE_CUBLAS_BACKEND=ON
95+
ninja
96+
// Add paths as necessary
97+
```
98+
7699
## Docker
77100

78101
Note:
@@ -186,6 +209,9 @@ source /opt/intel/oneapi/setvars.sh
186209
# Or, for FP32:
187210
cmake .. -DLLAMA_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
188211

212+
# For Nvidia GPUs
213+
cmake .. -DLLAMA_SYCL=ON -DLLAMA_SYCL_TARGET=NVIDIA -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx
214+
189215
# Build example/main only
190216
#cmake --build . --config Release --target main
191217

0 commit comments

Comments
 (0)