From c1c139084c260ae6950fc3f44ee7b1104862b05d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrien=20Gallou=C3=ABt?= Date: Wed, 30 Sep 2026 23:59:46 +0200 Subject: [PATCH] ggml-opencl : replace alloca() with std::vector (llama/29765) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Adrien Gallouët --- ggml/src/ggml-opencl/ggml-opencl.cpp | 40 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/ggml/src/ggml-opencl/ggml-opencl.cpp b/ggml/src/ggml-opencl/ggml-opencl.cpp index 4dcc9e957..74bddd703 100644 --- a/ggml/src/ggml-opencl/ggml-opencl.cpp +++ b/ggml/src/ggml-opencl/ggml-opencl.cpp @@ -6612,14 +6612,14 @@ static bool ggml_opencl_is_device_supported(ggml_backend_dev_t dev) { #endif size_t ext_str_size; - clGetDeviceInfo(dev_ctx->device, CL_DEVICE_EXTENSIONS, 0, NULL, &ext_str_size); + CL_CHECK(clGetDeviceInfo(dev_ctx->device, CL_DEVICE_EXTENSIONS, 0, NULL, &ext_str_size)); - char *ext_buffer = (char *)alloca(ext_str_size + 1); - clGetDeviceInfo(dev_ctx->device, CL_DEVICE_EXTENSIONS, ext_str_size, ext_buffer, NULL); + std::vector ext_buffer(ext_str_size + 1); + CL_CHECK(clGetDeviceInfo(dev_ctx->device, CL_DEVICE_EXTENSIONS, ext_str_size, ext_buffer.data(), NULL)); ext_buffer[ext_str_size] = '\0'; // Check if ext_buffer contains cl_khr_fp16 - bool fp16_support = strstr(ext_buffer, "cl_khr_fp16") != NULL; + bool fp16_support = strstr(ext_buffer.data(), "cl_khr_fp16") != NULL; if (!fp16_support) { GGML_LOG_WARN("ggml_opencl: device does not support FP16\n"); return false; @@ -6627,8 +6627,8 @@ static bool ggml_opencl_is_device_supported(ggml_backend_dev_t dev) { // If OpenCL 3.0 is supported, then check for cl_khr_subgroups, which becomes // optional in OpenCL 3.0 (cl_khr_subgroup is mandatory in OpenCL 2.x) - if (opencl_c_version.major == 3 && strstr(ext_buffer, "cl_khr_subgroups") == NULL && - strstr(ext_buffer, "cl_intel_subgroups") == NULL) { + if (opencl_c_version.major == 3 && strstr(ext_buffer.data(), "cl_khr_subgroups") == NULL && + strstr(ext_buffer.data(), "cl_intel_subgroups") == NULL) { GGML_LOG_WARN("ggml_opencl: device does not support subgroups (cl_khr_subgroups or cl_intel_subgroups) " "(note that subgroups is an optional feature in OpenCL 3.0)\n"); return false; @@ -6691,13 +6691,13 @@ static ggml_backend_opencl_context * ggml_cl_init(ggml_backend_dev_t dev) { // Check driver version size_t driver_version_str_size; - clGetDeviceInfo(device, CL_DRIVER_VERSION, 0, NULL, &driver_version_str_size); - char *driver_version = (char *)alloca(driver_version_str_size + 1); - clGetDeviceInfo(device, CL_DRIVER_VERSION, driver_version_str_size, driver_version, NULL); + CL_CHECK(clGetDeviceInfo(device, CL_DRIVER_VERSION, 0, NULL, &driver_version_str_size)); + std::vector driver_version(driver_version_str_size + 1); + CL_CHECK(clGetDeviceInfo(device, CL_DRIVER_VERSION, driver_version_str_size, driver_version.data(), NULL)); driver_version[driver_version_str_size] = '\0'; - backend_ctx->driver_version = driver_version; + backend_ctx->driver_version = driver_version.data(); - backend_ctx->adreno_cl_compiler_version = get_adreno_cl_compiler_version(driver_version); + backend_ctx->adreno_cl_compiler_version = get_adreno_cl_compiler_version(driver_version.data()); backend_ctx->has_vector_subgroup_broadcast = (backend_ctx->adreno_cl_compiler_version.type == E031 && backend_ctx->adreno_cl_compiler_version.major >= 47) || (backend_ctx->adreno_cl_compiler_version.type == DX && backend_ctx->adreno_cl_compiler_version.major >= 17); @@ -6713,33 +6713,33 @@ static ggml_backend_opencl_context * ggml_cl_init(ggml_backend_dev_t dev) { !backend_ctx->adreno_cl_compiler_version.newer_than_or_same(E031, 45, 0, 0); size_t ext_str_size; - clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &ext_str_size); - char *ext_buffer = (char *)alloca(ext_str_size + 1); - clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, ext_str_size, ext_buffer, NULL); + CL_CHECK(clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &ext_str_size)); + std::vector ext_buffer(ext_str_size + 1); + CL_CHECK(clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, ext_str_size, ext_buffer.data(), NULL)); ext_buffer[ext_str_size] = '\0'; // ensure it is null terminated // check support for qcom_subgroup_shuffle - if (strstr(ext_buffer, "cl_qcom_subgroup_shuffle") != NULL) { + if (strstr(ext_buffer.data(), "cl_qcom_subgroup_shuffle") != NULL) { backend_ctx->has_qcom_subgroup_shuffle = true; } // Check if ext_buffer contains cl_khr_fp16 - backend_ctx->fp16_support = strstr(ext_buffer, "cl_khr_fp16") != NULL; + backend_ctx->fp16_support = strstr(ext_buffer.data(), "cl_khr_fp16") != NULL; // check Adreno large buffer support - backend_ctx->adreno_has_large_buffer = strstr(ext_buffer, "cl_qcom_large_buffer") != NULL; + backend_ctx->adreno_has_large_buffer = strstr(ext_buffer.data(), "cl_qcom_large_buffer") != NULL; // subgroup shuffle support (N_SPLIT>1 FA kernel) - backend_ctx->has_qcom_subgroup_shuffle = strstr(ext_buffer, "cl_qcom_subgroup_shuffle") != NULL; + backend_ctx->has_qcom_subgroup_shuffle = strstr(ext_buffer.data(), "cl_qcom_subgroup_shuffle") != NULL; backend_ctx->has_subgroup_shuffle = - strstr(ext_buffer, "cl_khr_subgroup_shuffle") != NULL || + strstr(ext_buffer.data(), "cl_khr_subgroup_shuffle") != NULL || backend_ctx->has_qcom_subgroup_shuffle; // check for cl_khr_integer_dot_product // cl_qcom_dot_product8 uses signed * unsigned // while cl_khr_integer_dot_product uses signed * signed -- we stick with khr for now backend_ctx->has_integer_dot = - strstr(ext_buffer, "cl_khr_integer_dot_product") != NULL; + strstr(ext_buffer.data(), "cl_khr_integer_dot_product") != NULL; cl_uint base_align_in_bits; CL_CHECK(clGetDeviceInfo(device, CL_DEVICE_MEM_BASE_ADDR_ALIGN, sizeof(cl_uint), &base_align_in_bits, NULL));