diff --git a/src/backend/OpenCL/CHIPBackendOpenCL.cc b/src/backend/OpenCL/CHIPBackendOpenCL.cc index 81f01f06a..58cbb17cf 100644 --- a/src/backend/OpenCL/CHIPBackendOpenCL.cc +++ b/src/backend/OpenCL/CHIPBackendOpenCL.cc @@ -281,6 +281,28 @@ 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; + if (Ctx.MemManager_.isHostAllocUsed()) { + clStatus = clSetKernelExecInfo( + KernelAPIHandle, CL_KERNEL_EXEC_INFO_INDIRECT_HOST_ACCESS_INTEL, + sizeof(cl_bool), ¶m); + CHIPERR_CHECK_LOG_AND_THROW_TABLE(clSetKernelExecInfo); + } + if (Ctx.MemManager_.isDeviceAllocUsed()) { + clStatus = clSetKernelExecInfo( + KernelAPIHandle, CL_KERNEL_EXEC_INFO_INDIRECT_DEVICE_ACCESS_INTEL, + sizeof(cl_bool), ¶m); + CHIPERR_CHECK_LOG_AND_THROW_TABLE(clSetKernelExecInfo); + } + if (Ctx.MemManager_.isSharedAllocUsed()) { + clStatus = clSetKernelExecInfo( + KernelAPIHandle, CL_KERNEL_EXEC_INFO_INDIRECT_SHARED_ACCESS_INTEL, + sizeof(cl_bool), ¶m); + CHIPERR_CHECK_LOG_AND_THROW_TABLE(clSetKernelExecInfo); + } + } } return AllocKeepAlives; @@ -1259,13 +1281,8 @@ CHIPQueueOpenCL::launchImpl(chipstar::ExecItem *ExecItem) { LOCK(Backend->DubiousLockOpenCL); #endif - std::unique_ptr>> 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 SyncQueuesEventHandles = getOpenCLHandles(EventsToWait); @@ -1891,7 +1908,8 @@ void CHIPBackendOpenCL::initializeImpl() { std::vector SupportedDevices; std::vector 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) { diff --git a/src/backend/OpenCL/CHIPBackendOpenCL.hh b/src/backend/OpenCL/CHIPBackendOpenCL.hh index 1d6714959..b4b2f7460 100644 --- a/src/backend/OpenCL/CHIPBackendOpenCL.hh +++ b/src/backend/OpenCL/CHIPBackendOpenCL.hh @@ -188,6 +188,11 @@ private: /// The allocation strategy to use. AllocationStrategy AllocStrategy_; + // Add these three bools + bool hostAllocUsed; + bool deviceAllocUsed; + bool sharedAllocUsed; + public: void init(CHIPContextOpenCL *ChipCtxCl); MemoryManager &operator=(MemoryManager &&Rhs); @@ -212,6 +217,11 @@ public: return AllocStrategy_; } + // Add getter methods for the new bools + bool isHostAllocUsed() const { return hostAllocUsed; } + bool isDeviceAllocUsed() const { return deviceAllocUsed; } + bool isSharedAllocUsed() const { return sharedAllocUsed; } + std::pair translateDevPtrToBuffer(const void *DevPtr) const; private: diff --git a/src/backend/OpenCL/MemoryManager.cc b/src/backend/OpenCL/MemoryManager.cc index d8d722036..7d9eb6986 100644 --- a/src/backend/OpenCL/MemoryManager.cc +++ b/src/backend/OpenCL/MemoryManager.cc @@ -106,6 +106,11 @@ void MemoryManager::init(CHIPContextOpenCL *ChipCtxCl_) { } else { std::memset(&USM_, 0, sizeof(USM_)); } + + // Initialize the allocation usage bools + hostAllocUsed = false; + deviceAllocUsed = false; + sharedAllocUsed = false; } MemoryManager &MemoryManager::operator=(MemoryManager &&Rhs) { @@ -241,6 +246,25 @@ void *MemoryManager::allocate(size_t Size, size_t Alignment, logTrace("Memory allocated: {} / {}\n", Ptr.get(), Size); assert(Allocations_.find(Ptr) == Allocations_.end()); Allocations_.emplace(Ptr, Size); + + // Set the appropriate bool based on the MemType + switch (MemType) { + case hipMemoryTypeHost: + hostAllocUsed = true; + break; + case hipMemoryTypeDevice: + deviceAllocUsed = true; + break; + case hipMemoryTypeManaged: + case hipMemoryTypeUnified: + sharedAllocUsed = true; + break; + default: + // Handle unexpected memory type + assert(!"Unexpected memory type!"); + break; + } + return Ptr.get(); } @@ -320,4 +344,4 @@ MemoryManager::translateDevPtrToBuffer(const void *DevPtr) const { } return {DevPtrToBuffer_.at(BasePtr), Offset}; -} +} \ No newline at end of file diff --git a/src/backend/OpenCL/clHipErrorConversion.hh b/src/backend/OpenCL/clHipErrorConversion.hh index 4c4a8e6a4..984fd9275 100644 --- a/src/backend/OpenCL/clHipErrorConversion.hh +++ b/src/backend/OpenCL/clHipErrorConversion.hh @@ -94,7 +94,8 @@ const std::unordered_map 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}, @@ -447,11 +448,6 @@ const std::unordered_map 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},