|
15 | 15 | #include <hip/hip_runtime.h>
|
16 | 16 | #include <ur/ur.hpp>
|
17 | 17 |
|
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 |
24 | 33 | #if defined(__HIP_PLATFORM_AMD__)
|
25 | 34 | Format = Array->Format;
|
26 | 35 | Channels = Array->NumChannels;
|
| 36 | + return hipSuccess; |
27 | 37 | #elif defined(__HIP_PLATFORM_NVIDIA__)
|
28 | 38 | 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 | + } |
33 | 47 | #else
|
34 | 48 | #error("Must define exactly one of __HIP_PLATFORM_AMD__ or __HIP_PLATFORM_NVIDIA__");
|
35 | 49 | #endif
|
| 50 | +#endif |
36 | 51 | }
|
37 | 52 |
|
38 | 53 | // HIP on NVIDIA headers guard hipArray3DCreate behind __CUDACC__, this does not
|
|
0 commit comments