Skip to content

Commit 1d4a725

Browse files
Merge branch 'main' into steffen/make_ext_func_fail_unsupported
2 parents a4604d9 + 4c22f5c commit 1d4a725

File tree

4 files changed

+45
-5
lines changed

4 files changed

+45
-5
lines changed

source/adapters/hip/device.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,20 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
539539
// native asserts are in progress
540540
std::string SupportedExtensions = "";
541541
SupportedExtensions += "pi_ext_intel_devicelib_assert ";
542-
// Return supported for the UR command-buffer experimental feature
543-
SupportedExtensions += "ur_exp_command_buffer ";
542+
543+
int RuntimeVersion = 0;
544+
UR_CHECK_ERROR(hipRuntimeGetVersion(&RuntimeVersion));
545+
546+
// Return supported for the UR command-buffer experimental feature on
547+
// ROCM 5.5.1 and later. This is to workaround HIP driver bug
548+
// https://github.com/ROCm/HIP/issues/2450 in older versions.
549+
//
550+
// The version is returned as (10000000 major + 1000000 minor + patch).
551+
const int CmdBufDriverMinVersion = 50530202; // ROCM 5.5.1
552+
if (RuntimeVersion >= CmdBufDriverMinVersion) {
553+
SupportedExtensions += "ur_exp_command_buffer ";
554+
}
555+
544556
SupportedExtensions += " ";
545557

546558
hipDeviceProp_t Props;
@@ -844,9 +856,18 @@ UR_APIEXPORT ur_result_t UR_APICALL urDeviceGetInfo(ur_device_handle_t hDevice,
844856
return UR_RESULT_ERROR_UNSUPPORTED_ENUMERATION;
845857

846858
case UR_DEVICE_INFO_COMMAND_BUFFER_SUPPORT_EXP:
847-
case UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP:
848-
return ReturnValue(true);
859+
case UR_DEVICE_INFO_COMMAND_BUFFER_UPDATE_SUPPORT_EXP: {
860+
int DriverVersion = 0;
861+
UR_CHECK_ERROR(hipDriverGetVersion(&DriverVersion));
849862

863+
// Return supported for the UR command-buffer experimental feature on
864+
// ROCM 5.5.1 and later. This is to workaround HIP driver bug
865+
// https://github.com/ROCm/HIP/issues/2450 in older versions.
866+
//
867+
// The version is returned as (10000000 major + 1000000 minor + patch).
868+
const int CmdBufDriverMinVersion = 50530202; // ROCM 5.5.1
869+
return ReturnValue(DriverVersion >= CmdBufDriverMinVersion);
870+
}
850871
default:
851872
break;
852873
}

source/adapters/level_zero/device.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ bool ur_device_handle_t_::useDriverInOrderLists() {
10741074
static const bool UseDriverInOrderLists = [] {
10751075
const char *UrRet = std::getenv("UR_L0_USE_DRIVER_INORDER_LISTS");
10761076
if (!UrRet)
1077-
return false;
1077+
return true;
10781078
return std::atoi(UrRet) != 0;
10791079
}();
10801080

source/adapters/level_zero/memory.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urMemBufferCreateWithNativeHandle(
18331833
UR_CALL(
18341834
Buffer->getZeHandle(ZeHandleDst, ur_mem_handle_t_::write_only, Device));
18351835

1836+
// Indicate that this buffer has the device buffer mapped to a native buffer
1837+
// and track the native pointer such that the memory is synced later at
1838+
// memory free.
1839+
Buffer->DeviceMappedHostNativePtr = Ptr;
18361840
// zeCommandListAppendMemoryCopy must not be called from simultaneous
18371841
// threads with the same command list handle, so we need exclusive lock.
18381842
std::scoped_lock<ur_mutex> Lock(Context->ImmediateCommandListMutex);
@@ -2169,6 +2173,17 @@ ur_result_t _ur_buffer::free() {
21692173
? Plt->ContextsMutex
21702174
: UrContext->Mutex);
21712175

2176+
// If this memory was allocated as a proxy device buffer, then we must
2177+
// copy the final memory contents back to the original native pointer
2178+
// before releasing the buffer memory.
2179+
if (DeviceMappedHostNativePtr != nullptr) {
2180+
// zeCommandListAppendMemoryCopy must not be called from simultaneous
2181+
// threads with the same command list handle, so we need exclusive lock.
2182+
std::scoped_lock<ur_mutex> Lock(UrContext->ImmediateCommandListMutex);
2183+
ZE2UR_CALL(zeCommandListAppendMemoryCopy,
2184+
(UrContext->ZeCommandListInit, DeviceMappedHostNativePtr,
2185+
ZeHandle, Size, nullptr, 0, nullptr));
2186+
}
21722187
UR_CALL(USMFreeHelper(reinterpret_cast<ur_context_handle_t>(UrContext),
21732188
ZeHandle));
21742189
break;

source/adapters/level_zero/memory.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ struct _ur_buffer final : ur_mem_handle_t_ {
158158
// Tells the host allocation to use for buffer map operations.
159159
char *MapHostPtr{nullptr};
160160

161+
// Pointer to the original native buffer handle given this memory is a proxy
162+
// device buffer.
163+
void *DeviceMappedHostNativePtr{nullptr};
164+
161165
// Supplementary data to keep track of the mappings of this buffer
162166
// created with piEnqueueMemBufferMap.
163167
struct Mapping {

0 commit comments

Comments
 (0)