From df58f324a909fd80f54f16dd56dcc320f7620a0f Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Wed, 12 Nov 2025 20:26:29 -0400 Subject: [PATCH] CMake:LivoxGen1: Require OpenCL 1.2+, printf & WRITE_INVALIDATE_REGION --- stimBuffApis/livoxGen1/CMakeLists.txt | 20 +++++- .../openClCollatingAndMeshingEngine.cpp | 62 +++++++++++++++++++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/stimBuffApis/livoxGen1/CMakeLists.txt b/stimBuffApis/livoxGen1/CMakeLists.txt index 5a5020e..21a7c0f 100644 --- a/stimBuffApis/livoxGen1/CMakeLists.txt +++ b/stimBuffApis/livoxGen1/CMakeLists.txt @@ -9,8 +9,8 @@ if(ENABLE_STIMBUFFAPI_livoxGen1) # Find liburing using pkg-config pkg_check_modules(URING REQUIRED liburing) - # Find OpenCL: try find_package first, fall back to pkg-config - find_package(OpenCL QUIET) + # Find OpenCL 1.2 or higher: try find_package first, fall back to pkg-config + find_package(OpenCL 1.2 QUIET) if(OpenCL_FOUND) # Normalize find_package variables to match pkg_check_modules naming set(OPENCL_FOUND TRUE) @@ -23,6 +23,19 @@ if(ENABLE_STIMBUFFAPI_livoxGen1) endif() set(OPENCL_LIBRARY_DIRS "") message(STATUS "Found OpenCL using find_package") + + # Check if version is available and validate + if(OpenCL_VERSION) + if(OpenCL_VERSION VERSION_LESS "1.2") + message(FATAL_ERROR + "OpenCL version ${OpenCL_VERSION} found, but 1.2 or higher is required") + endif() + message(STATUS "OpenCL version: ${OpenCL_VERSION}") + else() + message(WARNING + "OpenCL version could not be determined. " + "Version 1.2+ is required at runtime.") + endif() else() # Fall back to pkg-config pkg_check_modules(OPENCL OpenCL) @@ -35,6 +48,9 @@ if(ENABLE_STIMBUFFAPI_livoxGen1) ) endif() message(STATUS "Found OpenCL using pkg-config") + message(WARNING + "OpenCL version could not be determined via pkg-config. " + "Version 1.2+ is required at runtime.") endif() # Enable assembly language diff --git a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp index fbc37f3..4e09ff2 100644 --- a/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp +++ b/stimBuffApis/livoxGen1/openClCollatingAndMeshingEngine.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,67 @@ bool OpenClCollatingAndMeshingEngine::setup() return false; } + // Check OpenCL version - require 1.2 or higher + char platformVersion[128]; + err = clGetPlatformInfo(platform, CL_PLATFORM_VERSION, + sizeof(platformVersion), platformVersion, nullptr); + if (err == CL_SUCCESS) + { + // Platform version string format: "OpenCL . " + // Extract version number + std::string versionStr(platformVersion); + size_t spacePos = versionStr.find(' '); + if (spacePos != std::string::npos) + { + std::string versionNum = versionStr.substr(spacePos + 1); + size_t dotPos = versionNum.find('.'); + if (dotPos != std::string::npos) + { + int major = std::stoi(versionNum.substr(0, dotPos)); + int minor = std::stoi(versionNum.substr(dotPos + 1)); + if (major < 1 || (major == 1 && minor < 2)) + { + std::cerr << __func__ << ": OpenCL version " << major + << "." << minor << " found, but 1.2 or higher is required" + << std::endl; + return false; + } + std::cout << __func__ << ": OpenCL platform version: " + << platformVersion << std::endl; + } + } + } + + // Also check device version + char deviceVersion[128]; + err = clGetDeviceInfo(device, CL_DEVICE_VERSION, + sizeof(deviceVersion), deviceVersion, nullptr); + if (err == CL_SUCCESS) + { + // Device version string format: "OpenCL . " + std::string versionStr(deviceVersion); + size_t spacePos = versionStr.find(' '); + if (spacePos != std::string::npos) + { + std::string versionNum = versionStr.substr(spacePos + 1); + size_t dotPos = versionNum.find('.'); + if (dotPos != std::string::npos) + { + int major = std::stoi(versionNum.substr(0, dotPos)); + int minor = std::stoi(versionNum.substr(dotPos + 1)); + if (major < 1 || (major == 1 && minor < 2)) + { + std::cerr << __func__ << ": OpenCL device version " << major + << "." << minor << " found, but 1.2 or higher is required" + << std::endl; + return false; + } + std::cout << __func__ << ": OpenCL device version: " + << deviceVersion << std::endl; + } + } + } + // Create context context = clCreateContext(nullptr, 1, &device, nullptr, nullptr, &err); if (err != CL_SUCCESS || !context)