Skip to content

Commit 5538f04

Browse files
lhezquic-sszotshawngu-quicquic-aanguswanghqc
authored andcommitted
Introducing experimental OpenCL backend with support for Qualcomm Adreno GPUs (llama/10693)
* [cl][adreno] Add Adreno GPU support Add new OpenCL backend to support Adreno GPUs --------- Co-authored-by: Skyler Szot <[email protected]> Co-authored-by: Shangqing Gu <[email protected]> Co-authored-by: Alexander Angus <[email protected]> Co-authored-by: Hongqiang Wang <[email protected]> Co-authored-by: Max Krasnyansky <[email protected]> * [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 <[email protected]> Co-authored-by: Shangqing Gu <[email protected]> Co-authored-by: Alexander Angus <[email protected]> Co-authored-by: Hongqiang Wang <[email protected]> Co-authored-by: Max Krasnyansky <[email protected]>
1 parent 874fcb6 commit 5538f04

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

ggml/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ set (GGML_SYCL_TARGET "INTEL" CACHE STRING
179179
set (GGML_SYCL_DEVICE_ARCH "" CACHE STRING
180180
"ggml: sycl device architecture")
181181

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+
182187
# extra artifacts
183188
option(GGML_BUILD_TESTS "ggml: build tests" ${GGML_STANDALONE})
184189
option(GGML_BUILD_EXAMPLES "ggml: build examples" ${GGML_STANDALONE})

ggml/include/ggml-opencl.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ ggml_add_backend(MUSA)
308308
ggml_add_backend(RPC)
309309
ggml_add_backend(SYCL)
310310
ggml_add_backend(Vulkan)
311+
ggml_add_backend(OpenCL)
311312

312313
foreach (target ggml-base ggml)
313314
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include> $<INSTALL_INTERFACE:include>)

ggml/src/ggml-backend-reg.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
#include "ggml-vulkan.h"
4747
#endif
4848

49+
#ifdef GGML_USE_OPENCL
50+
#include "ggml-opencl.h"
51+
#endif
52+
4953
#ifdef GGML_USE_BLAS
5054
#include "ggml-blas.h"
5155
#endif
@@ -146,6 +150,9 @@ struct ggml_backend_registry {
146150
#ifdef GGML_USE_VULKAN
147151
register_backend(ggml_backend_vk_reg());
148152
#endif
153+
#ifdef GGML_USE_OPENCL
154+
register_backend(ggml_backend_opencl_reg());
155+
#endif
149156
#ifdef GGML_USE_CANN
150157
register_backend(ggml_backend_cann_reg());
151158
#endif
@@ -539,6 +546,7 @@ void ggml_backend_load_all_from_path(const char * dir_path) {
539546
ggml_backend_load_best("rpc", silent, dir_path);
540547
ggml_backend_load_best("sycl", silent, dir_path);
541548
ggml_backend_load_best("vulkan", silent, dir_path);
549+
ggml_backend_load_best("opencl", silent, dir_path);
542550
ggml_backend_load_best("musa", silent, dir_path);
543551
ggml_backend_load_best("cpu", silent, dir_path);
544552
}

0 commit comments

Comments
 (0)