Skip to content

Commit 0e5917c

Browse files
committed
[rocm7.0_internal_testing] Define uint32 t when ROCM_VERSION >= 70000 (#2502)
Fixes SWDEV-543698 (https://ontrack-internal.amd.com/browse/SWDEV-543698) This PR fixes the errors like below: ``` [rank3]: RuntimeError: The following operation failed in the TorchScript interpreter. [rank3]: Traceback of TorchScript (most recent call last): [rank3]: RuntimeError: /tmp/comgr-28f951/input/CompileSourceACC062:67:7: error: unknown type name 'uint32_t'; did you mean '__hip_internal::uint32_t'? [rank3]: 67 | uint32_t int32; [rank3]: | ^~~~~~~~ [rank3]: | __hip_internal::uint32_t ``` Earlier uint32_t was defined in HIP headers in std namespace. Now it is moved to __hip_internal namespace in hip headers. This change is made in ROCm 7.0.
1 parent 6e3be13 commit 0e5917c

File tree

1 file changed

+70
-1
lines changed

1 file changed

+70
-1
lines changed

torch/csrc/jit/codegen/fuser/cuda/resource_strings.h

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,13 +260,82 @@ typedef __half half;
260260
)";
261261
#endif
262262

263-
#if defined(USE_ROCM)
263+
#if defined(USE_ROCM) && ROCM_VERSION < 70000
264+
constexpr auto bfloat16_support_literal =
265+
R"(
266+
#ifndef __align__
267+
#define __align__(x) __attribute__((aligned(x)))
268+
#endif
269+
270+
typedef struct __align__(2) {
271+
unsigned short x;
272+
}
273+
__nv_bfloat16_raw;
274+
275+
#if defined(__cplusplus)
276+
struct __align__(2) __nv_bfloat16 {
277+
__host__ __device__ __nv_bfloat16() {}
278+
279+
__host__ __device__ __nv_bfloat16& operator=(const __nv_bfloat16_raw& hr) {
280+
__x = hr.x;
281+
return *this;
282+
}
283+
284+
unsigned short __x;
285+
};
286+
287+
__device__ unsigned short __internal_float2bfloat16(
288+
const float f,
289+
unsigned int& sign,
290+
unsigned int& remainder) {
291+
unsigned int x;
292+
293+
x = __float_as_uint(f);
294+
295+
if ((x & 0x7fffffffU) > 0x7f800000U) {
296+
sign = 0U;
297+
remainder = 0U;
298+
return static_cast<unsigned short>(0x7fffU);
299+
}
300+
sign = x >> 31;
301+
remainder = x << 16;
302+
return static_cast<unsigned short>(x >> 16);
303+
}
304+
305+
/* Definitions of intrinsics */
306+
__device__ __nv_bfloat16 __float2bfloat16(const float a) {
307+
__nv_bfloat16 val;
308+
__nv_bfloat16_raw r;
309+
unsigned int sign;
310+
unsigned int remainder;
311+
r.x = __internal_float2bfloat16(a, sign, remainder);
312+
if ((remainder > 0x80000000U) ||
313+
((remainder == 0x80000000U) && ((r.x & 0x1U) != 0U))) {
314+
r.x++;
315+
}
316+
val = r;
317+
return val;
318+
}
319+
320+
__device__ float __bfloat162float(const __nv_bfloat16 a) {
321+
union
322+
{
323+
uint32_t int32;
324+
float fp32;
325+
} u = {uint32_t(a.__x) << 16};
326+
return u.fp32;
327+
}
328+
#endif /* defined(__cplusplus) */
329+
)";
330+
#elif defined(USE_ROCM) && ROCM_VERSION >= 70000
264331
constexpr auto bfloat16_support_literal =
265332
R"(
266333
#ifndef __align__
267334
#define __align__(x) __attribute__((aligned(x)))
268335
#endif
269336
337+
typedef unsigned int uint32_t;
338+
270339
typedef struct __align__(2) {
271340
unsigned short x;
272341
}

0 commit comments

Comments
 (0)