Skip to content

Commit 41aa318

Browse files
opencl: integrate backend dyn.load interface and fix compiler warnings
1 parent 1b8adbf commit 41aa318

File tree

3 files changed

+11
-21
lines changed

3 files changed

+11
-21
lines changed

ggml/include/ggml-opencl2.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ GGML_BACKEND_API bool ggml_backend_is_opencl2(ggml_backend_t backend);
3030
GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_opencl2_buffer_type(void);
3131
GGML_BACKEND_API ggml_backend_buffer_type_t ggml_backend_opencl2_host_buffer_type(void);
3232

33-
GGML_BACKEND_API ggml_backend_t ggml_backend_reg_opencl2_init(const char * params, void * user_data);
34-
3533
GGML_BACKEND_API ggml_backend_reg_t ggml_backend_opencl2_reg(void);
3634

3735
#ifdef __cplusplus

ggml/src/ggml-opencl2/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if (OpenCL_FOUND)
66

77
set(TARGET_NAME ggml-opencl2)
88

9-
add_library(${TARGET_NAME}
9+
ggml_add_backend_library(${TARGET_NAME}
1010
ggml-opencl2.cpp
1111
../../include/ggml-opencl2.h)
1212
target_link_libraries(${TARGET_NAME} PRIVATE ggml-base ${OpenCL_LIBRARIES})

ggml/src/ggml-opencl2/ggml-opencl2.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
// SPDX-FileCopyrightText: Copyright (c) Qualcomm Innovation Center, Inc. All rights reserved
22
// SPDX-License-Identifier: MIT
33

4+
#define CL_TARGET_OPENCL_VERSION 220
5+
6+
// suppress warnings in CL headers for GCC and Clang
7+
#pragma GCC diagnostic ignored "-Wgnu-anonymous-struct"
8+
#pragma GCC diagnostic ignored "-Woverlength-strings"
9+
410
#include "ggml-opencl2.h"
511
#include "ggml-backend.h"
612
#include "ggml-impl.h"
@@ -1237,10 +1243,6 @@ static void ggml_backend_opencl2_buffer_init_tensor(ggml_backend_buffer_t buffer
12371243
tensor->extra = extra;
12381244
}
12391245
}
1240-
1241-
// This should be removed. Keep it to make it easier to identify the backend
1242-
// when debugging until backend is removed from tensor.
1243-
tensor->backend = GGML_BACKEND_TYPE_GPU;
12441246
}
12451247

12461248
// The optimized gemm and gemv kernels are used for large matrices without batch.
@@ -1938,18 +1940,7 @@ static struct ggml_backend_device_i ggml_backend_opencl2_device_i = {
19381940
/* .event_synchronize = */ NULL,
19391941
};
19401942

1941-
//
1942-
// Backend registration
1943-
//
1944-
1945-
GGML_API ggml_backend_t ggml_backend_reg_opencl2_init(const char * params, void * user_data) {
1946-
return ggml_backend_opencl2_init();
1947-
1948-
GGML_UNUSED(params);
1949-
GGML_UNUSED(user_data);
1950-
}
1951-
1952-
// new API
1943+
// Backend registry
19531944

19541945
static const char * ggml_backend_opencl2_reg_get_name(ggml_backend_reg_t reg) {
19551946
return "OpenCL2";
@@ -1986,6 +1977,7 @@ ggml_backend_reg_t ggml_backend_opencl2_reg(void) {
19861977

19871978
if (!initialized) {
19881979
reg = ggml_backend_reg {
1980+
/* .api_version = */ GGML_BACKEND_API_VERSION,
19891981
/* .iface = */ ggml_backend_opencl2_reg_i,
19901982
/* .context = */ NULL,
19911983
};
@@ -2004,6 +1996,8 @@ ggml_backend_reg_t ggml_backend_opencl2_reg(void) {
20041996
return ®
20051997
}
20061998

1999+
GGML_BACKEND_DL_IMPL(ggml_backend_opencl2_reg)
2000+
20072001
//------------------------------------------------------------------------------
20082002
// Debugging utils
20092003
//------------------------------------------------------------------------------
@@ -2921,13 +2915,11 @@ static void ggml_cl_mul_mat(ggml_backend_t backend, const ggml_tensor * src0, co
29212915
// init CL objects
29222916
// <--------------------------------------------> //
29232917
cl_int status;
2924-
cl_event evt;
29252918
cl_image_format img_fmt_1d;
29262919
cl_image_desc img_desc_1d;
29272920
cl_buffer_region region;
29282921
cl_mem A_image1d;
29292922
cl_mem B_image1d;
2930-
cl_mem A_sub_buffer;
29312923
cl_mem B_sub_buffer;
29322924
cl_mem C_d;
29332925
// for B transpose

0 commit comments

Comments
 (0)