lhez Skyler Szot Shangqing Gu Alexander Angus Hongqiang Wang Max Krasnyansky commited on
Commit
83a0899
·
1 Parent(s): e1df33d

Introducing experimental OpenCL backend with support for Qualcomm Adreno GPUs (llama/10693)

Browse files

* [cl][adreno] Add Adreno GPU support

Add new OpenCL backend to support Adreno GPUs

---------

Co-authored-by: Skyler Szot <quic_sszot@quicinc.com>
Co-authored-by: Shangqing Gu <quic_shawngu@quicinc.com>
Co-authored-by: Alexander Angus <quic_aangus@quicinc.com>
Co-authored-by: Hongqiang Wang <quic_wangh@quicinc.com>
Co-authored-by: Max Krasnyansky <quic_maxk@quicinc.com>

* [cl][ci] Add workflow for CL

* [cl][adreno] Fix memory leak for non SMALL_ALLOC path

* opencl: integrate backend dyn.load interface and fix compiler and format warnings

* opencl: remove small-alloc support and fix build errors for non-opencl platforms

* opencl: fixed merge conflict (MUSA added twice in cmake)

* opencl-ci: use RUNNER_TEMP instead of github.workspace

* opencl: fix embed tool invocation with python3

* opencl: CI workflow fixes

* opencl: Clean up small-alloc in CMake files

* opencl: cleanup ggml-opencl2 header file

* opencl: use ulong for offsets and strides in ADD kernel

* opencl: use cl_ulong for all offsets

* opencl: use cl_ulong for sizes and strides

* opencl: use `GGML_LOG_xxx` instead of `fprintf(stderr, ...)`

* opencl: rename backend `opencl2` -> `opencl`

* opencl: rename kernel files `ggml-opencl2` -> `ggml-opencl`

* opencl: make OpenCL required, remove redundant lib and inc directories

* `ggml-base`, `..` and `.` are added by `ggml_add_backend_library`

* opencl: rename backend - funcs, structs, etc `opencl2` -> `opencl`

* opencl: remove copyright marker since main license already covers

* opencl: replace some more OPENCL2 leftovers

* opencl: remove limits on `tensor_extra`

* opencl: use pools for `tensor_extra`

* opencl: fix compiler warnings with GCC and Clang

Still getting the warning about clCreateCmdQueue being obsolete.
Will fix that separately.

* opencl: fail gracefully if opencl devices are not available

Also for unsupported GPUs.

* opencl: fix MSVC builds (string length error)

* opencl: check for various requirements, allow deprecated API

* opencl: update log message for unsupported GPUs

---------

Co-authored-by: Skyler Szot <quic_sszot@quicinc.com>
Co-authored-by: Shangqing Gu <quic_shawngu@quicinc.com>
Co-authored-by: Alexander Angus <quic_aangus@quicinc.com>
Co-authored-by: Hongqiang Wang <quic_wangh@quicinc.com>
Co-authored-by: Max Krasnyansky <quic_maxk@quicinc.com>

ggml/CMakeLists.txt CHANGED
@@ -179,6 +179,11 @@ set (GGML_SYCL_TARGET "INTEL" CACHE STRING
179
  set (GGML_SYCL_DEVICE_ARCH "" CACHE STRING
180
  "ggml: sycl device architecture")
181
 
 
 
 
 
 
182
  # extra artifacts
183
  option(GGML_BUILD_TESTS "ggml: build tests" ${GGML_STANDALONE})
184
  option(GGML_BUILD_EXAMPLES "ggml: build examples" ${GGML_STANDALONE})
 
179
  set (GGML_SYCL_DEVICE_ARCH "" CACHE STRING
180
  "ggml: sycl device architecture")
181
 
182
+ option(GGML_OPENCL "ggml: use OpenCL" OFF)
183
+ option(GGML_OPENCL_PROFILING "ggml: use OpenCL profiling (increases overhead)" OFF)
184
+ option(GGML_OPENCL_EMBED_KERNELS "ggml: embed kernels" ON)
185
+ option(GGML_OPENCL_USE_ADRENO_KERNELS "ggml: use optimized kernels for Adreno" ON)
186
+
187
  # extra artifacts
188
  option(GGML_BUILD_TESTS "ggml: build tests" ${GGML_STANDALONE})
189
  option(GGML_BUILD_EXAMPLES "ggml: build examples" ${GGML_STANDALONE})
ggml/include/ggml-opencl.h ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #ifndef GGML_OPENCL_H
2
+ #define GGML_OPENCL_H
3
+
4
+ #include "ggml.h"
5
+ #include "ggml-backend.h"
6
+
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+
11
+ //
12
+ // backend API
13
+ //
14
+ GGML_BACKEND_API ggml_backend_t ggml_backend_opencl_init(void);
15
+ GGML_BACKEND_API bool ggml_backend_is_opencl(ggml_backend_t backend);
16
+
17
+ GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_opencl_buffer_type(void);
18
+ GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_opencl_host_buffer_type(void);
19
+
20
+ GGML_BACKEND_API ggml_backend_reg_t ggml_backend_opencl_reg(void);
21
+
22
+ #ifdef __cplusplus
23
+ }
24
+ #endif
25
+
26
+ #endif // GGML_OPENCL_H
ggml/src/CMakeLists.txt CHANGED
@@ -308,6 +308,7 @@ ggml_add_backend(MUSA)
308
  ggml_add_backend(RPC)
309
  ggml_add_backend(SYCL)
310
  ggml_add_backend(Vulkan)
 
311
 
312
  foreach (target ggml-base ggml)
313
  target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> $<INSTALL_INTERFACE:include>)
 
308
  ggml_add_backend(RPC)
309
  ggml_add_backend(SYCL)
310
  ggml_add_backend(Vulkan)
311
+ ggml_add_backend(OpenCL)
312
 
313
  foreach (target ggml-base ggml)
314
  target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> $<INSTALL_INTERFACE:include>)
ggml/src/ggml-backend-reg.cpp CHANGED
@@ -46,6 +46,10 @@
46
  #include "ggml-vulkan.h"
47
  #endif
48
 
 
 
 
 
49
  #ifdef GGML_USE_BLAS
50
  #include "ggml-blas.h"
51
  #endif
@@ -146,6 +150,9 @@ struct ggml_backend_registry {
146
  #ifdef GGML_USE_VULKAN
147
  register_backend(ggml_backend_vk_reg());
148
  #endif
 
 
 
149
  #ifdef GGML_USE_CANN
150
  register_backend(ggml_backend_cann_reg());
151
  #endif
@@ -539,6 +546,7 @@ void ggml_backend_load_all_from_path(const char * dir_path) {
539
  ggml_backend_load_best("rpc", silent, dir_path);
540
  ggml_backend_load_best("sycl", silent, dir_path);
541
  ggml_backend_load_best("vulkan", silent, dir_path);
 
542
  ggml_backend_load_best("musa", silent, dir_path);
543
  ggml_backend_load_best("cpu", silent, dir_path);
544
  }
 
46
  #include "ggml-vulkan.h"
47
  #endif
48
 
49
+ #ifdef GGML_USE_OPENCL
50
+ #include "ggml-opencl.h"
51
+ #endif
52
+
53
  #ifdef GGML_USE_BLAS
54
  #include "ggml-blas.h"
55
  #endif
 
150
  #ifdef GGML_USE_VULKAN
151
  register_backend(ggml_backend_vk_reg());
152
  #endif
153
+ #ifdef GGML_USE_OPENCL
154
+ register_backend(ggml_backend_opencl_reg());
155
+ #endif
156
  #ifdef GGML_USE_CANN
157
  register_backend(ggml_backend_cann_reg());
158
  #endif
 
546
  ggml_backend_load_best("rpc", silent, dir_path);
547
  ggml_backend_load_best("sycl", silent, dir_path);
548
  ggml_backend_load_best("vulkan", silent, dir_path);
549
+ ggml_backend_load_best("opencl", silent, dir_path);
550
  ggml_backend_load_best("musa", silent, dir_path);
551
  ggml_backend_load_best("cpu", silent, dir_path);
552
  }