@@ -1618,25 +1618,57 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMMemcpy2D(
1618
1618
hipPointerAttribute_t srcAttribs{};
1619
1619
hipPointerAttribute_t dstAttribs{};
1620
1620
1621
+ // Determine if pSrc and/or pDst are system allocated pageable host memory.
1621
1622
bool srcIsSystemAlloc{false };
1622
1623
bool dstIsSystemAlloc{false };
1623
1624
1624
1625
hipError_t hipRes{};
1625
- // hipErrorInvalidValue returned from hipPointerGetAttributes for a non-null
1626
- // pointer refers to an OS-allocation, hence pageable host memory. However,
1627
- // this means we cannot rely on the attributes result, hence we mark system
1628
- // pageable memory allocation manually as host memory. The HIP runtime can
1629
- // handle the registering/unregistering of the memory as long as the right
1630
- // copy-kind (direction) is provided to hipMemcpy2DAsync for this case.
1631
- hipRes = hipPointerGetAttributes (&srcAttribs, (const void *)pSrc);
1626
+ // Error code hipErrorInvalidValue returned from hipPointerGetAttributes
1627
+ // for a non-null pointer refers to an OS-allocation, hence we can work
1628
+ // with the assumption that this is a pointer to a pageable host memory.
1629
+ // Since ROCm version 6.0.0, the enum hipMemoryType can also be marked as
1630
+ // hipMemoryTypeUnregistered explicitly to relay that information better.
1631
+ // This means we cannot rely on any attribute result, hence we just mark
1632
+ // the pointer handle as system allocated pageable host memory.
1633
+ // The HIP runtime can handle the registering/unregistering of the memory
1634
+ // as long as the right copy-kind (direction) is provided to hipMemcpy2D*.
1635
+ hipRes = hipPointerGetAttributes (&srcAttribs, pSrc);
1632
1636
if (hipRes == hipErrorInvalidValue && pSrc)
1633
1637
srcIsSystemAlloc = true ;
1634
1638
hipRes = hipPointerGetAttributes (&dstAttribs, (const void *)pDst);
1635
1639
if (hipRes == hipErrorInvalidValue && pDst)
1636
1640
dstIsSystemAlloc = true ;
1641
+ #if HIP_VERSION_MAJOR >= 6
1642
+ srcIsSystemAlloc |= srcAttribs.type == hipMemoryTypeUnregistered;
1643
+ dstIsSystemAlloc |= dstAttribs.type == hipMemoryTypeUnregistered;
1644
+ #endif
1637
1645
1638
- const unsigned int srcMemType{srcAttribs.type };
1639
- const unsigned int dstMemType{dstAttribs.type };
1646
+ unsigned int srcMemType{srcAttribs.type };
1647
+ unsigned int dstMemType{dstAttribs.type };
1648
+
1649
+ // ROCm 5.7.1 finally started updating the type attribute member to
1650
+ // hipMemoryTypeManaged for shared memory allocations(hipMallocManaged).
1651
+ // Hence, we use a separate query that verifies the pointer use via flags.
1652
+ #if HIP_VERSION >= 50700001
1653
+ // Determine the source/destination memory type for shared allocations.
1654
+ //
1655
+ // NOTE: The hipPointerGetAttribute API is marked as [BETA] and fails with
1656
+ // exit code -11 when passing a system allocated pointer to it.
1657
+ if (!srcIsSystemAlloc && srcAttribs.isManaged ) {
1658
+ UR_ASSERT (srcAttribs.hostPointer && srcAttribs.devicePointer ,
1659
+ UR_RESULT_ERROR_INVALID_VALUE);
1660
+ UR_CHECK_ERROR (hipPointerGetAttribute (
1661
+ &srcMemType, HIP_POINTER_ATTRIBUTE_MEMORY_TYPE,
1662
+ reinterpret_cast <hipDeviceptr_t>(const_cast <void *>(pSrc))));
1663
+ }
1664
+ if (!dstIsSystemAlloc && dstAttribs.isManaged ) {
1665
+ UR_ASSERT (dstAttribs.hostPointer && dstAttribs.devicePointer ,
1666
+ UR_RESULT_ERROR_INVALID_VALUE);
1667
+ UR_CHECK_ERROR (
1668
+ hipPointerGetAttribute (&dstMemType, HIP_POINTER_ATTRIBUTE_MEMORY_TYPE,
1669
+ reinterpret_cast <hipDeviceptr_t>(pDst)));
1670
+ }
1671
+ #endif
1640
1672
1641
1673
const bool srcIsHost{(srcMemType == hipMemoryTypeHost) || srcIsSystemAlloc};
1642
1674
const bool srcIsDevice{srcMemType == hipMemoryTypeDevice};
0 commit comments