From 3c7cb339e21e4253febc509910c88fb31223cd80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 20 Jun 2024 14:58:15 +0800 Subject: [PATCH] OpenCL: fix building on non-apple platforms --- src/detection/opencl/opencl.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/detection/opencl/opencl.c b/src/detection/opencl/opencl.c index 6b97479de..01c8a4c09 100644 --- a/src/detection/opencl/opencl.c +++ b/src/detection/opencl/opencl.c @@ -12,7 +12,7 @@ #include "util/stringUtils.h" #include -#define CL_TARGET_OPENCL_VERSION 100 +#define CL_TARGET_OPENCL_VERSION 110 #ifndef __APPLE__ #include #else @@ -29,8 +29,21 @@ typedef struct OpenCLData static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result) { char buffer[1024] = ""; - if (data->ffclGetPlatformInfo(NULL, CL_PLATFORM_VERSION, sizeof(buffer), buffer, NULL) != CL_SUCCESS) - return "clGetPlatformInfo(NULL, CL_PLATFORM_VERSION) failed"; + cl_int res = data->ffclGetPlatformInfo(NULL, CL_PLATFORM_VERSION, sizeof(buffer), buffer, NULL); + if (res != CL_SUCCESS) + { + switch (res) + { + case CL_INVALID_PLATFORM: + return "clGetPlatformInfo(NULL, CL_PLATFORM_VERSION) failed: CL_INVALID_PLATFORM"; + case CL_INVALID_VALUE: + return "clGetPlatformInfo(NULL, CL_PLATFORM_VERSION) failed: CL_INVALID_VALUE"; + case CL_OUT_OF_HOST_MEMORY: + return "clGetPlatformInfo(NULL, CL_PLATFORM_VERSION) failed: CL_OUT_OF_HOST_MEMORY"; + default: + return "clGetPlatformInfo(NULL, CL_PLATFORM_VERSION) failed: unknown error"; + } + } { const char* versionPretty = buffer; @@ -40,10 +53,10 @@ static const char* openCLHandleData(OpenCLData* data, FFOpenCLResult* result) ffStrbufTrim(&result->version, ' '); } - if (clGetPlatformInfo(NULL, CL_PLATFORM_NAME, sizeof(buffer), buffer, NULL) == CL_SUCCESS) + if (data->ffclGetPlatformInfo(NULL, CL_PLATFORM_NAME, sizeof(buffer), buffer, NULL) == CL_SUCCESS) ffStrbufSetS(&result->name, buffer); - if (clGetPlatformInfo(NULL, CL_PLATFORM_VENDOR, sizeof(buffer), buffer, NULL) == CL_SUCCESS) + if (data->ffclGetPlatformInfo(NULL, CL_PLATFORM_VENDOR, sizeof(buffer), buffer, NULL) == CL_SUCCESS) ffStrbufSetS(&result->vendor, buffer); cl_device_id deviceIDs[32];