Skip to content

Commit a0ddd83

Browse files
authored
whisper : add SYCL support (ggerganov#1863)
* add changes from llama upstream * add sycl abstraction * add sycl build * update cmake * add sycl build config * fix bug * fix bug * refactor build * fix bug * update build * call build * use sycl header * add examples * add target * fix typecast in quant.c * readd fp16 and readme * fix quant typecast * add sample * add readme * remove cxx file check
1 parent a250690 commit a0ddd83

10 files changed

+510
-6
lines changed

.github/workflows/build.yml

+100
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,106 @@ jobs:
150150
make
151151
ctest -L gh --output-on-failure'
152152
153+
ubuntu-22-cmake-sycl:
154+
runs-on: ubuntu-22.04
155+
156+
strategy:
157+
fail-fast: false
158+
matrix:
159+
dwhisper_sycl: [ON]
160+
dcmake_c_compiler: [icx]
161+
dcmake_cxx_compiler: [icpx]
162+
arch: [linux/amd64, linux/arm64, linux/arm/v7, linux/ppc64le]
163+
164+
continue-on-error: true
165+
166+
steps:
167+
- name: Clone
168+
uses: actions/checkout@v3
169+
170+
- name: add oneAPI to apt
171+
shell: bash
172+
run: |
173+
cd /tmp
174+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
175+
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
176+
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
177+
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
178+
179+
- name: install oneAPI dpcpp compiler
180+
shell: bash
181+
run: |
182+
sudo apt update
183+
sudo apt install intel-oneapi-compiler-dpcpp-cpp
184+
185+
- name: install oneAPI MKL library
186+
shell: bash
187+
run: |
188+
sudo apt install intel-oneapi-mkl-devel
189+
190+
- name: Clone
191+
id: checkout
192+
uses: actions/checkout@v3
193+
194+
- name: Build
195+
id: cmake_build
196+
run: |
197+
source /opt/intel/oneapi/setvars.sh
198+
mkdir build
199+
cd build
200+
cmake -DWHISPER_SYCL=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx ..
201+
cmake --build . --config Release -j $(nproc)
202+
203+
ubuntu-22-cmake-sycl-fp16:
204+
runs-on: ubuntu-22.04
205+
206+
strategy:
207+
fail-fast: false
208+
matrix:
209+
dwhisper_sycl: [ON]
210+
dcmake_c_compiler: [icx]
211+
dcmake_cxx_compiler: [icpx]
212+
arch: [linux/amd64, linux/arm64, linux/arm/v7, linux/ppc64le]
213+
214+
continue-on-error: true
215+
216+
steps:
217+
- name: Clone
218+
uses: actions/checkout@v3
219+
220+
- name: add oneAPI to apt
221+
shell: bash
222+
run: |
223+
cd /tmp
224+
wget https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
225+
sudo apt-key add GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
226+
rm GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB
227+
sudo add-apt-repository "deb https://apt.repos.intel.com/oneapi all main"
228+
229+
- name: install oneAPI dpcpp compiler
230+
shell: bash
231+
run: |
232+
sudo apt update
233+
sudo apt install intel-oneapi-compiler-dpcpp-cpp
234+
235+
- name: install oneAPI MKL library
236+
shell: bash
237+
run: |
238+
sudo apt install intel-oneapi-mkl-devel
239+
240+
- name: Clone
241+
id: checkout
242+
uses: actions/checkout@v3
243+
244+
- name: Build
245+
id: cmake_build
246+
run: |
247+
source /opt/intel/oneapi/setvars.sh
248+
mkdir build
249+
cd build
250+
cmake -DWHISPER_SYCL_F16=ON -DCMAKE_C_COMPILER=icx -DCMAKE_CXX_COMPILER=icpx ..
251+
cmake --build . --config Release -j $(nproc)
252+
153253
windows:
154254
runs-on: windows-latest
155255

CMakeLists.txt

+41-6
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,14 @@ if (APPLE)
7070
option(WHISPER_COREML_ALLOW_FALLBACK "whisper: allow non-CoreML fallback" OFF)
7171
option(WHISPER_METAL_EMBED_LIBRARY "whisper: embed Metal library" OFF)
7272
else()
73-
option(WHISPER_BLAS "whisper: use BLAS libraries" OFF)
74-
option(WHISPER_BLAS_VENDOR "whisper: BLAS library vendor" Generic)
75-
option(WHISPER_OPENBLAS "whisper: prefer OpenBLAS" OFF)
76-
option(WHISPER_CUBLAS "whisper: support for cuBLAS" OFF)
77-
option(WHISPER_HIPBLAS "whisper: support for hipBLAS" OFF)
78-
option(WHISPER_CLBLAST "whisper: use CLBlast" OFF)
73+
option(WHISPER_BLAS "whisper: use BLAS libraries" OFF)
74+
option(WHISPER_BLAS_VENDOR "whisper: BLAS library vendor" Generic)
75+
option(WHISPER_OPENBLAS "whisper: prefer OpenBLAS" OFF)
76+
option(WHISPER_CUBLAS "whisper: support for cuBLAS" OFF)
77+
option(WHISPER_HIPBLAS "whisper: support for hipBLAS" OFF)
78+
option(WHISPER_CLBLAST "whisper: use CLBlast" OFF)
79+
option(WHISPER_SYCL "whisper: use SYCL" OFF)
80+
option(WHISPER_SYCL_F16 "whisper: use 16 bit floats for sycl calculations" OFF)
7981
endif()
8082

8183
option(WHISPER_PERF "whisper: enable perf timings" OFF)
@@ -106,6 +108,13 @@ endif()
106108

107109
find_package(Threads REQUIRED)
108110

111+
#compile flag sycl
112+
if (WHISPER_SYCL)
113+
set(CMAKE_CXX_STANDARD 17)
114+
else()
115+
set(CMAKE_CXX_STANDARD 11)
116+
endif()
117+
109118
# on APPLE
110119
if (APPLE)
111120
# include Accelerate framework
@@ -309,6 +318,30 @@ if( WHISPER_OPENVINO )
309318
find_package(OpenVINO REQUIRED COMPONENTS Runtime)
310319
endif()
311320

321+
if (WHISPER_SYCL)
322+
if ( NOT DEFINED ENV{ONEAPI_ROOT})
323+
message(FATAL_ERROR "Not detect ENV {ONEAPI_ROOT}, please install oneAPI & source it, like: source /opt/intel/oneapi/setvars.sh")
324+
endif()
325+
#todo: AOT
326+
327+
find_package(IntelSYCL REQUIRED)
328+
if (WHISPER_SYCL_F16)
329+
add_compile_definitions(GGML_SYCL_F16)
330+
endif()
331+
add_compile_definitions(GGML_USE_SYCL)
332+
333+
add_compile_options(-I./) #include DPCT
334+
add_compile_options(-I/${SYCL_INCLUDE_DIR})
335+
336+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-narrowing")
337+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
338+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsycl -L${MKLROOT}/lib")
339+
340+
set(GGML_HEADERS_SYCL ggml-sycl.h)
341+
set(GGML_SOURCES_SYCL ggml-sycl.cpp)
342+
343+
set(WHISPER_EXTRA_LIBS ${WHISPER_EXTRA_LIBS} sycl OpenCL mkl_core pthread m dl mkl_sycl_blas mkl_intel_ilp64 mkl_tbb_thread)
344+
endif()
312345
# compiler flags
313346

314347
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
@@ -503,6 +536,8 @@ add_library(${TARGET}
503536
${GGML_SOURCES_METAL}
504537
${GGML_SOURCES_CUDA}
505538
${GGML_SOURCES_OPENCL}
539+
${GGML_SOURCES_SYCL}
540+
${GGML_HEADERS_SYCL}
506541
whisper.h
507542
whisper.cpp
508543
)

0 commit comments

Comments
 (0)