From 5fbff1aa3a37761c0013af4e8c398398973bf791 Mon Sep 17 00:00:00 2001 From: chraac Date: Thu, 15 Jan 2026 11:57:37 +0800 Subject: [PATCH] feat: add OpenCL kernel support for division operations and update includes --- ggml/src/ggml-opencl/CMakeLists.txt | 2 ++ ggml/src/ggml-opencl/ggml-opencl.cpp | 4 +++ ggml/src/ggml-opencl/kernels/div.h | 46 ++++++++++++------------- ggml/src/ggml-opencl/kernels/ocl_defs.h | 6 ++-- 4 files changed, 33 insertions(+), 25 deletions(-) diff --git a/ggml/src/ggml-opencl/CMakeLists.txt b/ggml/src/ggml-opencl/CMakeLists.txt index 2a4b79eb6a..977b945d16 100644 --- a/ggml/src/ggml-opencl/CMakeLists.txt +++ b/ggml/src/ggml-opencl/CMakeLists.txt @@ -22,6 +22,8 @@ if (GGML_OPENCL_USE_ADRENO_KERNELS) add_compile_definitions(GGML_OPENCL_USE_ADRENO_KERNELS) endif () +target_include_directories(${TARGET_NAME} PRIVATE "${CMAKE_CURRENT_LIST_DIR}/kernels") + if (GGML_OPENCL_EMBED_KERNELS) add_compile_definitions(GGML_OPENCL_EMBED_KERNELS) diff --git a/ggml/src/ggml-opencl/ggml-opencl.cpp b/ggml/src/ggml-opencl/ggml-opencl.cpp index 982fa59e43..38d72cba6b 100644 --- a/ggml/src/ggml-opencl/ggml-opencl.cpp +++ b/ggml/src/ggml-opencl/ggml-opencl.cpp @@ -29,6 +29,10 @@ #include #include +namespace ocl_kernel_prototypes { + #include "div.h" +} + #undef MIN #undef MAX #define MIN(a, b) ((a) < (b) ? (a) : (b)) diff --git a/ggml/src/ggml-opencl/kernels/div.h b/ggml/src/ggml-opencl/kernels/div.h index 75f66a0a2a..fd65b5706f 100644 --- a/ggml/src/ggml-opencl/kernels/div.h +++ b/ggml/src/ggml-opencl/kernels/div.h @@ -4,28 +4,28 @@ #include "ocl_defs.h" -kernel void kernel_div(global char * src0, - ulong offset0, - global char * src1, - ulong offset1, - global char * dst, - ulong offsetd, - ulong nb00, - ulong nb01, - ulong nb02, - ulong nb03, - int ne10, - int ne11, - int ne12, - int ne13, - ulong nb10, - ulong nb11, - ulong nb12, - ulong nb13, - int ne0, - ulong nb0, - ulong nb1, - ulong nb2, - ulong nb3); +OCL_KERNEL void kernel_div(OCL_GLOBAL char * src0, + ulong offset0, + OCL_GLOBAL char * src1, + ulong offset1, + OCL_GLOBAL char * dst, + ulong offsetd, + ulong nb00, + ulong nb01, + ulong nb02, + ulong nb03, + int ne10, + int ne11, + int ne12, + int ne13, + ulong nb10, + ulong nb11, + ulong nb12, + ulong nb13, + int ne0, + ulong nb0, + ulong nb1, + ulong nb2, + ulong nb3); #endif // __KERNELS_DIV_H__ diff --git a/ggml/src/ggml-opencl/kernels/ocl_defs.h b/ggml/src/ggml-opencl/kernels/ocl_defs.h index a0b8feedb1..3faf1ecf56 100644 --- a/ggml/src/ggml-opencl/kernels/ocl_defs.h +++ b/ggml/src/ggml-opencl/kernels/ocl_defs.h @@ -4,10 +4,12 @@ #ifdef __OPENCL_C_VERSION__ // Device (OpenCL) Definitions +# define OCL_KERNEL kernel +# define OCL_GLOBAL global #else // Host (C++) Definitions -# define kernel -# define global +# define OCL_KERNEL +# define OCL_GLOBAL # define __kernel # define __global # define ulong cl_ulong