Skip to content

Commit ca74884

Browse files
authored
opencl : use strstr to check if fp16 supported (#1611)
* Use strstr to check if fp16 supported * Ensure ext_buffer is null terminated
1 parent a670464 commit ca74884

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

ggml-opencl.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -469,16 +469,11 @@ void ggml_cl_init(void) {
469469

470470
size_t ext_str_size;
471471
clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, 0, NULL, &ext_str_size);
472-
char* ext_buffer = (char*) malloc(sizeof(char) * ext_str_size);
472+
char *ext_buffer = (char *)alloca(ext_str_size + 1);
473473
clGetDeviceInfo(device, CL_DEVICE_EXTENSIONS, ext_str_size, ext_buffer, NULL);
474+
ext_buffer[ext_str_size] = '\0'; // ensure it is null terminated
474475
// Check if ext_buffer contains cl_khr_fp16
475-
for (size_t i = 0; i < ext_str_size - 12; i++) {
476-
if (memcmp(ext_buffer + i, "cl_khr_fp16", 11) == 0) {
477-
fp16_support = true;
478-
break;
479-
}
480-
}
481-
free(ext_buffer);
476+
fp16_support = strstr(ext_buffer, "cl_khr_fp16") != NULL;
482477
fprintf(stderr, "ggml_opencl: device FP16 support: %s\n", fp16_support ? "true" : "false");
483478

484479
cl_context_properties properties[] = {

0 commit comments

Comments
 (0)