Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added missing interface for CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR property #113

Merged
merged 5 commits into from
Jun 21, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions layers/11_semaemu/emulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ typedef struct _cl_semaphore_khr
ptrdiff_t numProperties = 0;
cl_semaphore_type_khr type = ~0;

std::vector<cl_device_id> devices;

if( properties )
{
const cl_semaphore_properties_khr* check = properties;
Expand Down Expand Up @@ -78,10 +80,11 @@ typedef struct _cl_semaphore_khr
else
{
found_CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR = true;
++check;
while(*check++ != CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR)
check++;
while(*check != CL_SEMAPHORE_DEVICE_HANDLE_LIST_END_KHR)
{
// TODO: validate device handles.
devices.push_back(((cl_device_id*)check)[0]);
check++;
}
}
break;
Expand All @@ -91,6 +94,38 @@ typedef struct _cl_semaphore_khr
}
}
numProperties = check - properties + 1;

// validate device handles.
if (!devices.empty()) {
std::vector<cl_semaphore_type_khr> types;
for (int i = devices.size() - 1; i >= 0; i--) {
size_t num_types_size = 0;
clGetDeviceInfo_override(devices[i],
CL_DEVICE_SEMAPHORE_TYPES_KHR, 0,
nullptr, &num_types_size, &errorCode);

if (!num_types_size)
continue;

types.resize(num_types_size / sizeof(cl_semaphore_type_khr));
clGetDeviceInfo_override(
devices[i], CL_DEVICE_SEMAPHORE_TYPES_KHR, num_types_size,
types.data(), nullptr, &errorCode);

bool capable = false;
for (auto sema_type : types) {
if (type == sema_type) {
capable = true;
break;
}
}

if (!capable) {
errorCode = CL_INVALID_DEVICE;
break;
bashbaug marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
switch( type )
{
Expand All @@ -111,6 +146,12 @@ typedef struct _cl_semaphore_khr
semaphore->Properties.begin(),
properties,
properties + numProperties );

if (!devices.empty())
semaphore->Devices.assign(
devices.begin(),
devices.end() );
bashbaug marked this conversation as resolved.
Show resolved Hide resolved

}
return semaphore;
}
Expand All @@ -124,6 +165,7 @@ typedef struct _cl_semaphore_khr
const cl_context Context;
const cl_semaphore_type_khr Type;
std::vector<cl_semaphore_properties_khr> Properties;
std::vector<cl_device_id> Devices;

std::atomic<cl_uint> RefCount;
cl_event Event;
Expand Down Expand Up @@ -349,6 +391,16 @@ cl_int CL_API_CALL clGetSemaphoreInfoKHR_EMU(
ptr );
}
break;
case CL_SEMAPHORE_DEVICE_HANDLE_LIST_KHR:
{
auto ptr = (cl_device_id*)param_value;
return writeVectorToMemory(
param_value_size,
semaphore->Devices,
param_value_size_ret,
ptr );
}
break;
default:
return CL_INVALID_VALUE;
}
Expand Down