Skip to content

Commit 749d8e5

Browse files
authored
Merge pull request intel#1198 from al42and/aa-rocm6
[HIP] Fix build with ROCm 6.0.0
2 parents 810a577 + 34831f4 commit 749d8e5

File tree

4 files changed

+39
-16
lines changed

4 files changed

+39
-16
lines changed

source/adapters/hip/common.hpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,39 @@
1515
#include <hip/hip_runtime.h>
1616
#include <ur/ur.hpp>
1717

18-
// Hipify doesn't support cuArrayGetDescriptor, on AMD the hipArray can just be
19-
// indexed, but on NVidia it is an opaque type and needs to go through
20-
// cuArrayGetDescriptor so implement a utility function to get the array
21-
// properties
22-
inline void getArrayDesc(hipArray *Array, hipArray_Format &Format,
23-
size_t &Channels) {
18+
// Before ROCm 6, hipify doesn't support cuArrayGetDescriptor, on AMD the
19+
// hipArray can just be indexed, but on NVidia it is an opaque type and needs to
20+
// go through cuArrayGetDescriptor so implement a utility function to get the
21+
// array properties
22+
inline static hipError_t getArrayDesc(hipArray *Array, hipArray_Format &Format,
23+
size_t &Channels) {
24+
#if HIP_VERSION_MAJOR >= 6
25+
HIP_ARRAY_DESCRIPTOR ArrayDesc;
26+
hipError_t err = hipArrayGetDescriptor(&ArrayDesc, Array);
27+
if (err == hipSuccess) {
28+
Format = ArrayDesc.Format;
29+
Channels = ArrayDesc.NumChannels;
30+
}
31+
return err;
32+
#else
2433
#if defined(__HIP_PLATFORM_AMD__)
2534
Format = Array->Format;
2635
Channels = Array->NumChannels;
36+
return hipSuccess;
2737
#elif defined(__HIP_PLATFORM_NVIDIA__)
2838
CUDA_ARRAY_DESCRIPTOR ArrayDesc;
29-
cuArrayGetDescriptor(&ArrayDesc, (CUarray)Array);
30-
31-
Format = ArrayDesc.Format;
32-
Channels = ArrayDesc.NumChannels;
39+
CUresult err = cuArrayGetDescriptor(&ArrayDesc, (CUarray)Array);
40+
if (err == CUDA_SUCCESS) {
41+
Format = ArrayDesc.Format;
42+
Channels = ArrayDesc.NumChannels;
43+
return hipSuccess;
44+
} else {
45+
return hipErrorUnknown; // No easy way to map CUerror to hipError
46+
}
3347
#else
3448
#error("Must define exactly one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__");
3549
#endif
50+
#endif
3651
}
3752

3853
// HIP on NVIDIA headers guard hipArray3DCreate behind __CUDACC__, this does not

source/adapters/hip/enqueue.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageRead(
10171017

10181018
hipArray_Format Format;
10191019
size_t NumChannels;
1020-
getArrayDesc(Array, Format, NumChannels);
1020+
UR_CHECK_ERROR(getArrayDesc(Array, Format, NumChannels));
10211021

10221022
int ElementByteSize = imageElementByteSize(Format);
10231023

@@ -1078,7 +1078,7 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageWrite(
10781078

10791079
hipArray_Format Format;
10801080
size_t NumChannels;
1081-
getArrayDesc(Array, Format, NumChannels);
1081+
UR_CHECK_ERROR(getArrayDesc(Array, Format, NumChannels));
10821082

10831083
int ElementByteSize = imageElementByteSize(Format);
10841084

@@ -1141,13 +1141,13 @@ UR_APIEXPORT ur_result_t UR_APICALL urEnqueueMemImageCopy(
11411141
std::get<SurfaceMem>(hImageSrc->Mem).getArray(hQueue->getDevice());
11421142
hipArray_Format SrcFormat;
11431143
size_t SrcNumChannels;
1144-
getArrayDesc(SrcArray, SrcFormat, SrcNumChannels);
1144+
UR_CHECK_ERROR(getArrayDesc(SrcArray, SrcFormat, SrcNumChannels));
11451145

11461146
hipArray *DstArray =
11471147
std::get<SurfaceMem>(hImageDst->Mem).getArray(hQueue->getDevice());
11481148
hipArray_Format DstFormat;
11491149
size_t DstNumChannels;
1150-
getArrayDesc(DstArray, DstFormat, DstNumChannels);
1150+
UR_CHECK_ERROR(getArrayDesc(DstArray, DstFormat, DstNumChannels));
11511151

11521152
UR_ASSERT(SrcFormat == DstFormat,
11531153
UR_RESULT_ERROR_INVALID_IMAGE_FORMAT_DESCRIPTOR);

source/adapters/hip/kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ urKernelSetArgMemObj(ur_kernel_handle_t hKernel, uint32_t argIndex,
282282
auto array = std::get<SurfaceMem>(hArgValue->Mem).getArray(Device);
283283
hipArray_Format Format;
284284
size_t NumChannels;
285-
getArrayDesc(array, Format, NumChannels);
285+
UR_CHECK_ERROR(getArrayDesc(array, Format, NumChannels));
286286
if (Format != HIP_AD_FORMAT_UNSIGNED_INT32 &&
287287
Format != HIP_AD_FORMAT_SIGNED_INT32 &&
288288
Format != HIP_AD_FORMAT_HALF && Format != HIP_AD_FORMAT_FLOAT) {

source/adapters/hip/usm.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ USMFreeImpl([[maybe_unused]] ur_context_handle_t hContext, void *pMem) {
7272
try {
7373
hipPointerAttribute_t hipPointerAttributeType;
7474
UR_CHECK_ERROR(hipPointerGetAttributes(&hipPointerAttributeType, pMem));
75-
unsigned int Type = hipPointerAttributeType.memoryType;
75+
#if HIP_VERSION >= 50600000
76+
const auto Type = hipPointerAttributeType.type;
77+
#else
78+
const auto Type = hipPointerAttributeType.memoryType;
79+
#endif
7680
UR_ASSERT(Type == hipMemoryTypeDevice || Type == hipMemoryTypeHost,
7781
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
7882
if (Type == hipMemoryTypeDevice) {
@@ -170,7 +174,11 @@ urUSMGetMemAllocInfo(ur_context_handle_t hContext, const void *pMem,
170174
return ReturnValue(UR_USM_TYPE_SHARED);
171175
}
172176
UR_CHECK_ERROR(hipPointerGetAttributes(&hipPointerAttributeType, pMem));
177+
#if HIP_VERSION >= 50600000
178+
Value = hipPointerAttributeType.type;
179+
#else
173180
Value = hipPointerAttributeType.memoryType;
181+
#endif
174182
UR_ASSERT(Value == hipMemoryTypeDevice || Value == hipMemoryTypeHost,
175183
UR_RESULT_ERROR_INVALID_MEM_OBJECT);
176184
if (Value == hipMemoryTypeDevice) {

0 commit comments

Comments
 (0)