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

[OpenCL] Combined CTS fixes #1044

Merged
merged 20 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
77b705d
[OpenCL] Implement urEventSetCallback and urContextSetExtendedDeleter.
aarongreig Oct 18, 2023
2792092
[OpenCL] Add more mappings from CL error codes to UR error codes.
aarongreig Oct 20, 2023
16e28e2
Update match files to reflect removed test case
aarongreig Oct 20, 2023
5c8a86b
[OpenCL] Fix some unchecked dereferencing of optional params.
aarongreig Oct 20, 2023
bfb3dac
[OpenCL] Implement urEnqueueUSMMemcpy2D and allow large fill patterns.
aarongreig Oct 18, 2023
603dcfb
Address feedback
aarongreig Oct 31, 2023
fc34c26
[OpenCL] Make USM functions return UR_RESULT_ERROR_INVALID_USM_SIZE
aarongreig Nov 1, 2023
371e1b8
[OpenCL] Retain native handle objects when properties dictate.
aarongreig Nov 1, 2023
c5fbda0
[OpenCL] Fix enum passed for urKernelSetExecInfo's USM_PTRS property
aarongreig Nov 6, 2023
8125902
Merge branch 'aaron/clCheckDereference' into aaron/clCTSFixMegaBranch
aarongreig Nov 6, 2023
74ad837
Merge branch 'aaron/cl2DUSMOps' into aaron/clCTSFixMegaBranch
aarongreig Nov 6, 2023
5ad3f0a
Merge branch 'aaron/clErrorCodeMapping' into aaron/clCTSFixMegaBranch
aarongreig Nov 6, 2023
4b1dd79
Merge branch 'aaron/ClCallbackEntrypoints' into aaron/clCTSFixMegaBranch
aarongreig Nov 6, 2023
42d00cd
Merge branch 'aaron/clUSMCTSFixes' into aaron/clCTSFixMegaBranch
aarongreig Nov 6, 2023
690fef3
Merge branch 'aaron/clRetainNativeHandles' into aaron/clCTSFixMegaBranch
aarongreig Nov 6, 2023
5d88fc7
Merge branch 'aaron/clCTSKernelExecInfoFix' into aaron/clCTSFixMegaBr…
aarongreig Nov 6, 2023
6a3c63d
[OpenCL] Return INVALID_SIZE from GetInfo entry points.
aarongreig Nov 3, 2023
3029501
Merge branch 'aaron/clCTSInfoFixes' into aaron/clCTSFixMegaBranch
aarongreig Nov 6, 2023
39eec0c
Remove useless const qualifiers from helper function return types.
aarongreig Nov 6, 2023
f65473d
[OpenCL] Add bounds checking to the Enqueue memory operations.
aarongreig Nov 6, 2023
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
17 changes: 17 additions & 0 deletions source/adapters/opencl/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,23 @@ ur_result_t mapCLErrorToUR(cl_int Result) {
return UR_RESULT_ERROR_OUT_OF_RESOURCES;
case CL_INVALID_MEM_OBJECT:
return UR_RESULT_ERROR_INVALID_MEM_OBJECT;
case CL_INVALID_QUEUE_PROPERTIES:
return UR_RESULT_ERROR_INVALID_QUEUE_PROPERTIES;
case CL_INVALID_BUFFER_SIZE:
return UR_RESULT_ERROR_INVALID_BUFFER_SIZE;
case CL_INVALID_IMAGE_SIZE:
return UR_RESULT_ERROR_INVALID_IMAGE_SIZE;
case CL_INVALID_IMAGE_FORMAT_DESCRIPTOR:
case CL_INVALID_IMAGE_DESCRIPTOR:
return UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR;
case CL_IMAGE_FORMAT_NOT_SUPPORTED:
return UR_RESULT_ERROR_UNSUPPORTED_IMAGE_FORMAT;
case CL_PROFILING_INFO_NOT_AVAILABLE:
return UR_RESULT_ERROR_PROFILING_INFO_NOT_AVAILABLE;
case CL_LINK_PROGRAM_FAILURE:
return UR_RESULT_ERROR_PROGRAM_LINK_FAILURE;
case CL_INVALID_ARG_INDEX:
return UR_RESULT_ERROR_INVALID_KERNEL_ARGUMENT_INDEX;
default:
return UR_RESULT_ERROR_UNKNOWN;
}
Expand Down
70 changes: 63 additions & 7 deletions source/adapters/opencl/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

#include "context.hpp"

#include <mutex>
#include <set>
#include <unordered_map>

ur_result_t cl_adapter::getDevicesFromContext(
ur_context_handle_t hContext,
std::unique_ptr<std::vector<cl_device_id>> &DevicesInCtx) {
Expand Down Expand Up @@ -89,10 +93,17 @@ urContextGetInfo(ur_context_handle_t hContext, ur_context_info_t propName,
case UR_CONTEXT_INFO_NUM_DEVICES:
case UR_CONTEXT_INFO_DEVICES:
case UR_CONTEXT_INFO_REFERENCE_COUNT: {

CL_RETURN_ON_FAILURE(
size_t CheckPropSize = 0;
auto ClResult =
clGetContextInfo(cl_adapter::cast<cl_context>(hContext), CLPropName,
propSize, pPropValue, pPropSizeRet));
propSize, pPropValue, &CheckPropSize);
if (pPropValue && CheckPropSize != propSize) {
return UR_RESULT_ERROR_INVALID_SIZE;
}
CL_RETURN_ON_FAILURE(ClResult);
if (pPropSizeRet) {
*pPropSizeRet = CheckPropSize;
}
return UR_RESULT_SUCCESS;
}
default:
Expand Down Expand Up @@ -130,8 +141,53 @@ UR_APIEXPORT ur_result_t UR_APICALL urContextCreateWithNativeHandle(
}

UR_APIEXPORT ur_result_t UR_APICALL urContextSetExtendedDeleter(
[[maybe_unused]] ur_context_handle_t hContext,
[[maybe_unused]] ur_context_extended_deleter_t pfnDeleter,
[[maybe_unused]] void *pUserData) {
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
ur_context_handle_t hContext, ur_context_extended_deleter_t pfnDeleter,
void *pUserData) {
static std::unordered_map<ur_context_handle_t,
std::set<ur_context_extended_deleter_t>>
ContextCallbackMap;
static std::mutex ContextCallbackMutex;

{
std::lock_guard<std::mutex> Lock(ContextCallbackMutex);
// Callbacks can only be registered once and we need to avoid double
// allocating.
if (ContextCallbackMap.count(hContext) &&
ContextCallbackMap[hContext].count(pfnDeleter)) {
return UR_RESULT_SUCCESS;
}

ContextCallbackMap[hContext].insert(pfnDeleter);
}

struct ContextCallback {
void execute() {
pfnDeleter(pUserData);
{
std::lock_guard<std::mutex> Lock(*CallbackMutex);
(*CallbackMap)[hContext].erase(pfnDeleter);
if ((*CallbackMap)[hContext].empty()) {
CallbackMap->erase(hContext);
}
}
delete this;
}
ur_context_handle_t hContext;
ur_context_extended_deleter_t pfnDeleter;
void *pUserData;
std::unordered_map<ur_context_handle_t,
std::set<ur_context_extended_deleter_t>> *CallbackMap;
std::mutex *CallbackMutex;
};
auto Callback =
new ContextCallback({hContext, pfnDeleter, pUserData, &ContextCallbackMap,
&ContextCallbackMutex});
auto ClCallback = [](cl_context, void *pUserData) {
auto *C = static_cast<ContextCallback *>(pUserData);
C->execute();
};
CL_RETURN_ON_FAILURE(clSetContextDestructorCallback(
cl_adapter::cast<cl_context>(hContext), ClCallback, Callback));

return UR_RESULT_SUCCESS;
}
36 changes: 31 additions & 5 deletions source/adapters/opencl/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,23 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,

return ReturnValue(URDeviceType);
}
case UR_DEVICE_INFO_DEVICE_ID: {
bool Supported = false;
CL_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
cl_adapter::cast<cl_device_id>(hDevice), {"cl_khr_pci_bus_info"},
Supported));

if (!Supported) {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}

cl_device_pci_bus_info_khr PciInfo = {};
CL_RETURN_ON_FAILURE(clGetDeviceInfo(
cl_adapter::cast<cl_device_id>(hDevice), CL_DEVICE_PCI_BUS_INFO_KHR,
sizeof(PciInfo), &PciInfo, nullptr));
return ReturnValue(PciInfo.pci_device);
}

case UR_DEVICE_INFO_BACKEND_RUNTIME_VERSION: {
oclv::OpenCLVersion Version;
CL_RETURN_ON_FAILURE(cl_adapter::getDeviceVersion(
Expand Down Expand Up @@ -760,6 +777,16 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,

return ReturnValue(Supported);
}
case UR_DEVICE_INFO_VIRTUAL_MEMORY_SUPPORT: {
return ReturnValue(false);
}
case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED: {
bool Supported = false;
CL_RETURN_ON_FAILURE(cl_adapter::checkDeviceExtensions(
cl_adapter::cast<cl_device_id>(hDevice),
{"cl_intel_program_scope_host_pipe"}, Supported));
return ReturnValue(Supported);
}
case UR_DEVICE_INFO_QUEUE_PROPERTIES:
case UR_DEVICE_INFO_QUEUE_ON_DEVICE_PROPERTIES:
case UR_DEVICE_INFO_QUEUE_ON_HOST_PROPERTIES:
Expand All @@ -775,7 +802,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
/* CL type: cl_bitfield / enum
* UR type: ur_flags_t (uint32_t) */

cl_bitfield CLValue;
cl_bitfield CLValue = 0;
CL_RETURN_ON_FAILURE(
clGetDeviceInfo(cl_adapter::cast<cl_device_id>(hDevice), CLPropName,
sizeof(cl_bitfield), &CLValue, nullptr));
Expand Down Expand Up @@ -898,13 +925,12 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
* sycl/doc/extensions/supported/sycl_ext_intel_device_info.md */
case UR_DEVICE_INFO_UUID:
/* This enums have no equivalent in OpenCL */
case UR_DEVICE_INFO_DEVICE_ID:
case UR_DEVICE_INFO_MAX_REGISTERS_PER_WORK_GROUP:
case UR_DEVICE_INFO_GLOBAL_MEM_FREE:
case UR_DEVICE_INFO_MEMORY_CLOCK_RATE:
case UR_DEVICE_INFO_MEMORY_BUS_WIDTH:
case UR_DEVICE_INFO_ASYNC_BARRIER:
case UR_DEVICE_INFO_HOST_PIPE_READ_WRITE_SUPPORTED: {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
case UR_DEVICE_INFO_ASYNC_BARRIER: {
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
}
default: {
return UR_RESULT_ERROR_INVALID_ENUMERATION;
Expand Down
Loading
Loading