Skip to content

Commit 8e050cf

Browse files
committed
Support OpenCL 1.2 command queue creation on macOS by falling back to clCreateCommandQueue
1 parent 5ab3632 commit 8e050cf

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

cpp_src/core/OpenCLContext.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ typedef cl_context (*p_clCreateContext)(
2323
typedef cl_int (*p_clReleaseContext)(cl_context);
2424
typedef cl_command_queue (*p_clCreateCommandQueueWithProperties)(
2525
cl_context, cl_device_id, const cl_queue_properties *, cl_int *);
26+
typedef cl_command_queue (*p_clCreateCommandQueue)(
27+
cl_context, cl_device_id, cl_command_queue_properties, cl_int *);
2628
typedef cl_int (*p_clReleaseCommandQueue)(cl_command_queue);
2729
typedef cl_mem (*p_clCreateBuffer)(cl_context, cl_mem_flags, size_t, void *,
2830
cl_int *);
@@ -67,6 +69,7 @@ static p_clCreateContext f_clCreateContext;
6769
static p_clReleaseContext f_clReleaseContext;
6870
static p_clCreateCommandQueueWithProperties
6971
f_clCreateCommandQueueWithProperties;
72+
static p_clCreateCommandQueue f_clCreateCommandQueue;
7073
static p_clReleaseCommandQueue f_clReleaseCommandQueue;
7174
static p_clCreateBuffer f_clCreateBuffer;
7275
static p_clReleaseMemObject f_clReleaseMemObject;
@@ -111,6 +114,8 @@ bool OpenCLContext::loadLibraries() {
111114
f_clCreateCommandQueueWithProperties =
112115
openclLib->getFunction<p_clCreateCommandQueueWithProperties>(
113116
"clCreateCommandQueueWithProperties");
117+
f_clCreateCommandQueue =
118+
openclLib->getFunction<p_clCreateCommandQueue>("clCreateCommandQueue");
114119
f_clReleaseCommandQueue = openclLib->getFunction<p_clReleaseCommandQueue>(
115120
"clReleaseCommandQueue");
116121
f_clCreateBuffer =
@@ -387,7 +392,13 @@ void OpenCLContext::createContext() {
387392

388393
void OpenCLContext::createCommandQueue() {
389394
cl_int err;
390-
commandQueue = f_clCreateCommandQueueWithProperties(context, device, 0, &err);
395+
if (f_clCreateCommandQueueWithProperties) {
396+
commandQueue = f_clCreateCommandQueueWithProperties(context, device, nullptr, &err);
397+
} else if (f_clCreateCommandQueue) {
398+
commandQueue = f_clCreateCommandQueue(context, device, 0, &err);
399+
} else {
400+
throw std::runtime_error("OpenCL command queue creation functions not found");
401+
}
391402
if (err != CL_SUCCESS) {
392403
throw std::runtime_error("Failed to create OpenCL command queue");
393404
}

cpp_src/core/OpenCLContext.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#else
99
#include <CL/cl.h>
1010
#endif
11+
#ifndef CL_VERSION_2_0
12+
typedef intptr_t cl_queue_properties;
13+
#endif
1114
#include <memory>
1215
#include <stdexcept>
1316
#include <string>

0 commit comments

Comments
 (0)