Skip to content

Commit 7e4cc11

Browse files
authored
[SYCL][HIP] Fix hip prefetch/mem_advise (noop) for rocm < 5.0 (#10958)
The main fix here is to enable prefetch functionality when the HIP backend is built with rocm versions < 5. The change to the prefix/mem_advise UR hip adapter APIs fixes four e2e-tests that fail test-e2e only for HIP 4.x versions (These failures don't come up in the CI since it tests using rocm 5.x). The change to Tracing/image_printers.cpp is effectively re-XFailing this test for rocm 4 only. rocm 4 doesn't support `hipCreateSurfaceObject` which is called by this test. I'm not sure this legacy image functionality (Which as I understand it will be replaced by bindless images) is really working for rocm 5 in a meaningful way, since most other legacy image e2e tests are XFAIL for hip. But this test can still be useful for us for ROCM 5 compatibility testing. The XFAIL was recently removed here 745febe which led to us finding the rocm 4 fail. I guess that the CI at some point switched from testing rocm 4 to testing rocm 5, which meant this test stopped failing in CI. --------- Signed-off-by: Jack Kirk <jack.kirk@codeplay.com>
1 parent 192c301 commit 7e4cc11

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

sycl/plugins/unified_runtime/ur/adapters/hip/enqueue.cpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,7 +1315,6 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
13151315
ur_queue_handle_t hQueue, const void *pMem, size_t size,
13161316
ur_usm_migration_flags_t flags, uint32_t numEventsInWaitList,
13171317
const ur_event_handle_t *phEventWaitList, ur_event_handle_t *phEvent) {
1318-
#if HIP_VERSION_MAJOR >= 5
13191318
void *HIPDevicePtr = const_cast<void *>(pMem);
13201319
ur_device_handle_t Device = hQueue->getContext()->getDevice();
13211320

@@ -1342,12 +1341,15 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
13421341
return UR_RESULT_ERROR_ADAPTER_SPECIFIC;
13431342
}
13441343

1344+
// HIP_POINTER_ATTRIBUTE_RANGE_SIZE is not an attribute in ROCM < 5,
1345+
// so we can't perform this check for such cases.
1346+
#if HIP_VERSION_MAJOR >= 5
13451347
unsigned int PointerRangeSize = 0;
13461348
UR_CHECK_ERROR(hipPointerGetAttribute(&PointerRangeSize,
13471349
HIP_POINTER_ATTRIBUTE_RANGE_SIZE,
13481350
(hipDeviceptr_t)HIPDevicePtr));
13491351
UR_ASSERT(size <= PointerRangeSize, UR_RESULT_ERROR_INVALID_SIZE);
1350-
1352+
#endif
13511353
// flags is currently unused so fail if set
13521354
if (flags != 0)
13531355
return UR_RESULT_ERROR_INVALID_VALUE;
@@ -1376,28 +1378,24 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMPrefetch(
13761378
}
13771379

13781380
return Result;
1379-
#else
1380-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1381-
#endif
13821381
}
13831382

13841383
UR_APIEXPORT ur_result_t UR_APICALL
13851384
urEnqueueUSMAdvise(ur_queue_handle_t hQueue, const void *pMem, size_t size,
13861385
ur_usm_advice_flags_t, ur_event_handle_t *phEvent) {
1387-
#if HIP_VERSION_MAJOR >= 5
13881386
void *HIPDevicePtr = const_cast<void *>(pMem);
1387+
// HIP_POINTER_ATTRIBUTE_RANGE_SIZE is not an attribute in ROCM < 5,
1388+
// so we can't perform this check for such cases.
1389+
#if HIP_VERSION_MAJOR >= 5
13891390
unsigned int PointerRangeSize = 0;
13901391
UR_CHECK_ERROR(hipPointerGetAttribute(&PointerRangeSize,
13911392
HIP_POINTER_ATTRIBUTE_RANGE_SIZE,
13921393
(hipDeviceptr_t)HIPDevicePtr));
13931394
UR_ASSERT(size <= PointerRangeSize, UR_RESULT_ERROR_INVALID_SIZE);
1394-
1395+
#endif
13951396
// TODO implement a mapping to hipMemAdvise once the expected behaviour
13961397
// of urEnqueueUSMAdvise is detailed in the USM extension
13971398
return urEnqueueEventsWait(hQueue, 0, nullptr, phEvent);
1398-
#else
1399-
return UR_RESULT_ERROR_UNSUPPORTED_FEATURE;
1400-
#endif
14011399
}
14021400

14031401
UR_APIEXPORT ur_result_t UR_APICALL urEnqueueUSMFill2D(

sycl/test-e2e/Tracing/image_printers.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@ int main() {
2929
{
3030
sycl::image<2> Img(ImgHostData.data(), ChanOrder, ChanType, ImgSize);
3131
queue Q;
32+
33+
// legacy Images uses an API that is not supported in hip 4.x
34+
#if HIP_VERSION_MAJOR >= 5
3235
Q.submit([&](sycl::handler &CGH) {
3336
auto ImgAcc = Img.get_access<sycl::float4, SYCLWrite>(CGH);
3437

3538
CGH.single_task<class EmptyTask>([=]() {});
3639
});
40+
#endif
3741
}
3842
return 0;
3943
}

0 commit comments

Comments
 (0)