]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
opencl : use strstr to check if fp16 supported (#1611)
authorHoward Su <redacted>
Sun, 28 May 2023 17:09:56 +0000 (01:09 +0800)
committerGitHub <redacted>
Sun, 28 May 2023 17:09:56 +0000 (20:09 +0300)
* Use strstr to check if fp16 supported

* Ensure ext_buffer is null terminated

ggml-opencl.cpp

index 667f55e795abd3ec0dea782c575a3df90cb6840c..8f2e5fbca8263af9b72f94e9a445ddf41a9f37ba 100644 (file)
@@ -469,16 +469,11 @@ void ggml_cl_init(void) {
 
     size_t ext_str_size;
     clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &ext_str_size);
-    char* ext_buffer = (char*) malloc(sizeof(char) * ext_str_size);
+    char *ext_buffer = (char *)alloca(ext_str_size + 1);
     clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, ext_str_size, ext_buffer, NULL);
+    ext_buffer[ext_str_size] = '\0'; // ensure it is null terminated
     // Check if ext_buffer contains cl_khr_fp16
-    for (size_t i = 0; i < ext_str_size - 12; i++) {
-        if (memcmp(ext_buffer + i, "cl_khr_fp16", 11) == 0) {
-            fp16_support = true;
-            break;
-        }
-    }
-    free(ext_buffer);
+    fp16_support = strstr(ext_buffer, "cl_khr_fp16") != NULL;
     fprintf(stderr, "ggml_opencl: device FP16 support: %s\n", fp16_support ? "true" : "false");
 
     cl_context_properties properties[] = {