Skip to content

Commit

Permalink
Intel USM Properly annotate indirect kernel access
Browse files Browse the repository at this point in the history
Have to annotate kernels with all types

CL_KERNEL_EXEC_INFO_INDIRECT_HOST_ACCESS_INTEL
CL_KERNEL_EXEC_INFO_INDIRECT_DEVICE_ACCESS_INTEL
CL_KERNEL_EXEC_INFO_INDIRECT_SHARED_ACCESS_INTEL

since a kernel might have allocations of varied types
  • Loading branch information
pvelesko committed Aug 16, 2024
1 parent fc6d412 commit 7664b80
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
25 changes: 17 additions & 8 deletions src/backend/OpenCL/CHIPBackendOpenCL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,19 @@ annotateIndirectPointers(const CHIPContextOpenCL &Ctx,
AnnotationList.size() * sizeof(void *),
AnnotationList.data());
CHIPERR_CHECK_LOG_AND_THROW_TABLE(clSetKernelExecInfo);

if (Ctx.getAllocStrategy() == AllocationStrategy::IntelUSM) {
cl_bool param = CL_TRUE;

Check warning on line 286 in src/backend/OpenCL/CHIPBackendOpenCL.cc

View workflow job for this annotation

GitHub Actions / cpp-linter

src/backend/OpenCL/CHIPBackendOpenCL.cc:286:15 [readability-identifier-naming]

invalid case style for local variable 'param'
clStatus = clSetKernelExecInfo(KernelAPIHandle, CL_KERNEL_EXEC_INFO_INDIRECT_HOST_ACCESS_INTEL,
sizeof(cl_bool), &param);
CHIPERR_CHECK_LOG_AND_THROW_TABLE(clSetKernelExecInfo);
clStatus = clSetKernelExecInfo(KernelAPIHandle, CL_KERNEL_EXEC_INFO_INDIRECT_DEVICE_ACCESS_INTEL,
sizeof(cl_bool), &param);
CHIPERR_CHECK_LOG_AND_THROW_TABLE(clSetKernelExecInfo);
clStatus = clSetKernelExecInfo(KernelAPIHandle, CL_KERNEL_EXEC_INFO_INDIRECT_SHARED_ACCESS_INTEL,
sizeof(cl_bool), &param);
CHIPERR_CHECK_LOG_AND_THROW_TABLE(clSetKernelExecInfo);
}
}

return AllocKeepAlives;
Expand Down Expand Up @@ -1259,13 +1272,8 @@ CHIPQueueOpenCL::launchImpl(chipstar::ExecItem *ExecItem) {
LOCK(Backend->DubiousLockOpenCL);
#endif

std::unique_ptr<std::vector<std::shared_ptr<void>>> AllocationsToKeepAlive;
// Disable annotation for CPU device. Runtime errror.
// https://community.intel.com/t5/OpenCL-for-CPU/OpenCL-Using-USM-on-Intel-CPU-Runtime-along-with/m-p/1621136#M7350
if (ChipEnvVars.getDevice().getType() != DeviceType::CPU) {
AllocationsToKeepAlive = annotateIndirectPointers(
*OclContext, Kernel->getModule()->getInfo(), KernelHandle);
}
auto AllocationsToKeepAlive = annotateIndirectPointers(
*OclContext, Kernel->getModule()->getInfo(), KernelHandle);

auto [EventsToWait, EventLocks] = getSyncQueuesLastEvents(LaunchEvent, false);
std::vector<cl_event> SyncQueuesEventHandles = getOpenCLHandles(EventsToWait);
Expand Down Expand Up @@ -1891,7 +1899,8 @@ void CHIPBackendOpenCL::initializeImpl() {
std::vector<cl::Device> SupportedDevices;
std::vector<cl::Device> Dev;
clStatus = SelectedPlatform.getDevices(SelectedDevType, &Dev);
CHIPERR_CHECK_LOG_AND_THROW_TABLE(clGetPlatformIDs);
CHIPERR_CHECK_LOG_AND_THROW_TABLE(
clGetDeviceIDs); // C equivalent of getDevices

for (auto D : Dev) {

Expand Down
8 changes: 2 additions & 6 deletions src/backend/OpenCL/clHipErrorConversion.hh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ const std::unordered_map<void *, cl_hip_error_map_t> CL_HIP_ERROR_MAPS = {
{CL_OUT_OF_RESOURCES, hipErrorOutOfMemory},
{CL_MEM_OBJECT_ALLOCATION_FAILURE, hipErrorOutOfMemory},
{CL_INVALID_EVENT_WAIT_LIST, hipErrorInvalidResourceHandle},
{CL_OUT_OF_HOST_MEMORY, hipErrorOutOfMemory}}},
{CL_OUT_OF_HOST_MEMORY, hipErrorOutOfMemory},
{CL_INVALID_OPERATION, hipErrorInvalidValue}}},

{(void *)&clEnqueueReadBuffer,
{{CL_SUCCESS, hipSuccess},
Expand Down Expand Up @@ -447,11 +448,6 @@ const std::unordered_map<void *, cl_hip_error_map_t> CL_HIP_ERROR_MAPS = {
{CL_INVALID_EVENT_WAIT_LIST, hipErrorInvalidResourceHandle},
{CL_OUT_OF_HOST_MEMORY, hipErrorOutOfMemory}}},

{(void *)&clGetPlatformIDs,
{{CL_SUCCESS, hipSuccess},
{CL_INVALID_VALUE, hipErrorInvalidValue},
{CL_OUT_OF_HOST_MEMORY, hipErrorOutOfMemory}}},

{(void *)&clCreateProgramWithIL,
{{CL_SUCCESS, hipSuccess},
{CL_INVALID_CONTEXT, hipErrorInvalidResourceHandle},
Expand Down

0 comments on commit 7664b80

Please sign in to comment.