CMake:LivoxGen1: Require OpenCL 1.2+, printf & WRITE_INVALIDATE_REGION
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <iostream>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <boost/system/error_code.hpp>
|
||||
#include <asynchronousContinuation.h>
|
||||
#include <callback.h>
|
||||
@@ -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 <major>.<minor> <vendor info>"
|
||||
// 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 <major>.<minor> <vendor info>"
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user