| 1 |
// RUN: %run_test hipify "%s" "%t" %hipify_args 3 --amap --skip-excluded-preprocessor-conditional-blocks --experimental %clang_args -ferror-limit=500 |
| 2 |
|
| 3 |
// CHECK: #include <hip/hip_runtime.h> |
| 4 |
#include <cuda_runtime.h> |
| 5 |
#include <stdio.h> |
| 6 |
// CHECK: #include "hip/hip_fp8.h" |
| 7 |
#include "cuda_fp8.h" |
| 8 |
// CHECK-NOT: #include "hip/hip_fp8.h" |
| 9 |
// CHECK-NOT: #include "cuda_fp8.h" |
| 10 |
|
| 11 |
int main() { |
| 12 |
printf("24. CUDA Device API to HIP Device API synthetic test\n"); |
| 13 |
|
| 14 |
double da = 0.0f; |
| 15 |
double dx = 0.0f; |
| 16 |
float fa = 0.0f; |
| 17 |
float fx = 0.0f; |
| 18 |
short int shi = 0; |
| 19 |
unsigned short int ushi = 0; |
| 20 |
double2 d2 = { 0.0f, 0.0f }; |
| 21 |
float2 f2 = { 0.0f, 0.0f }; |
| 22 |
__half hx = { 0.0f }; |
| 23 |
__half hy = { 0.0f }; |
| 24 |
__half2 h2 = { 0.0f, 0.0f }; |
| 25 |
__half_raw hrx = { 0 }; |
| 26 |
__half2_raw h2rx = { 0, 0 }; |
| 27 |
|
| 28 |
// CHECK: hipRoundMode RoundMode; |
| 29 |
cudaRoundMode RoundMode; |
| 30 |
|
| 31 |
#if CUDA_VERSION >= 11000 |
| 32 |
// CHECK: __hip_bfloat16 _bf16 = { 0.0f }; |
| 33 |
// CHECK-NEXT: __hip_bfloat16 bf16a = { 0.0f }; |
| 34 |
// CHECK-NEXT: __hip_bfloat16 bf16b = { 0.0f }; |
| 35 |
__nv_bfloat16 _bf16 = { 0.0f }; |
| 36 |
__nv_bfloat16 bf16a = { 0.0f }; |
| 37 |
__nv_bfloat16 bf16b = { 0.0f }; |
| 38 |
|
| 39 |
// CHECK: hip_bfloat16 bf16 = { 0 }; |
| 40 |
nv_bfloat16 bf16 = { 0 }; |
| 41 |
|
| 42 |
// CHECK: __hip_bfloat16_raw bf16r = { 0 }; |
| 43 |
__nv_bfloat16_raw bf16r = { 0 }; |
| 44 |
|
| 45 |
// CHECK: __hip_bfloat162 bf162 = { 0, 0 }; |
| 46 |
// CHECK-NEXT: __hip_bfloat162 bf162a = { 0, 0 }; |
| 47 |
// CHECK-NEXT: __hip_bfloat162 bf162b = { 0, 0 }; |
| 48 |
__nv_bfloat162 bf162 = { 0, 0 }; |
| 49 |
__nv_bfloat162 bf162a = { 0, 0 }; |
| 50 |
__nv_bfloat162 bf162b = { 0, 0 }; |
| 51 |
|
| 52 |
// CHECK: __hip_bfloat162_raw bf162r = { 0, 0 }; |
| 53 |
__nv_bfloat162_raw bf162r = { 0, 0 }; |
| 54 |
|
| 55 |
// CUDA: __CUDA_HOSTDEVICE_BF16_DECL__ __nv_bfloat16 __double2bfloat16(const double a); |
| 56 |
// HIP: __BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __double2bfloat16(const double a) |
| 57 |
// CHECK: _bf16 = __double2bfloat16(da); |
| 58 |
_bf16 = __double2bfloat16(da); |
| 59 |
|
| 60 |
// CUDA: __CUDA_HOSTDEVICE_BF16_DECL__ __nv_bfloat16 __float2bfloat16(const float a); |
| 61 |
// HIP: __BF16_HOST_DEVICE_STATIC__ __hip_bfloat16 __float2bfloat16(float f); |
| 62 |
// CHECK: _bf16 = __float2bfloat16(fa); |
| 63 |
_bf16 = __float2bfloat16(fa); |
| 64 |
|
| 65 |
// CUDA: __CUDA_HOSTDEVICE_BF16_DECL__ float __bfloat162float(const __nv_bfloat16 a); |
| 66 |
// HIP: __BF16_HOST_DEVICE_STATIC__ float __bfloat162float(__hip_bfloat16 a); |
| 67 |
// CHECK: _bf16 = __bfloat162float(fa); |
| 68 |
_bf16 = __bfloat162float(fa); |
| 69 |
|
| 70 |
// CUDA: __CUDA_HOSTDEVICE_BF16_DECL__ float2 __bfloat1622float2(const __nv_bfloat162 a); |
| 71 |
// HIP: __BF16_HOST_DEVICE_STATIC__ float2 __bfloat1622float2(const __hip_bfloat162 a); |
| 72 |
// CHECK: f2 = __bfloat1622float2(bf162); |
| 73 |
f2 = __bfloat1622float2(bf162); |
| 74 |
|
| 75 |
// CUDA: __CUDA_HOSTDEVICE_BF16_DECL__ __nv_bfloat162 __float22bfloat162_rn(const float2 a); |
| 76 |
// HIP: __BF16_HOST_DEVICE_STATIC__ __hip_bfloat162 __float22bfloat162_rn(const float2 a); |
| 77 |
// CHECK: bf162 = __float22bfloat162_rn(f2); |
| 78 |
bf162 = __float22bfloat162_rn(f2); |
| 79 |
#endif |
| 80 |
|
| 81 |
#if CUDA_VERSION >= 11080 |
| 82 |
// CHECK: __hip_fp8_storage_t fp8_storage_t; |
| 83 |
__nv_fp8_storage_t fp8_storage_t; |
| 84 |
|
| 85 |
// CHECK: __hip_fp8x2_storage_t fp8x2_storage_t; |
| 86 |
__nv_fp8x2_storage_t fp8x2_storage_t; |
| 87 |
|
| 88 |
// CHECK: __hip_fp8x4_storage_t fp8x4_storage_t; |
| 89 |
__nv_fp8x4_storage_t fp8x4_storage_t; |
| 90 |
|
| 91 |
// CHECK: __hip_fp8_e5m2_fnuz fp8_e5m2; |
| 92 |
__nv_fp8_e5m2 fp8_e5m2; |
| 93 |
|
| 94 |
// CHECK: __hip_fp8x2_e5m2_fnuz fp8x2_e5m2; |
| 95 |
__nv_fp8x2_e5m2 fp8x2_e5m2; |
| 96 |
|
| 97 |
// CHECK: __hip_fp8_e4m3_fnuz fp8_e4m3; |
| 98 |
__nv_fp8_e4m3 fp8_e4m3; |
| 99 |
|
| 100 |
// CHECK: __hip_fp8x2_e4m3_fnuz fp8x2_e4m3; |
| 101 |
__nv_fp8x2_e4m3 fp8x2_e4m3; |
| 102 |
|
| 103 |
// CHECK: __hip_fp8x4_e4m3_fnuz fp8x4_e4m3; |
| 104 |
__nv_fp8x4_e4m3 fp8x4_e4m3; |
| 105 |
|
| 106 |
// CHECK: __hip_saturation_t saturation_t; |
| 107 |
// CHECK-NEXT: __hip_saturation_t NOSAT = __HIP_NOSAT; |
| 108 |
// CHECK-NEXT: __hip_saturation_t SATFINITE = __HIP_SATFINITE; |
| 109 |
__nv_saturation_t saturation_t; |
| 110 |
__nv_saturation_t NOSAT = __NV_NOSAT; |
| 111 |
__nv_saturation_t SATFINITE = __NV_SATFINITE; |
| 112 |
|
| 113 |
// CHECK: __hip_fp8_interpretation_t fp8_interpretation_t; |
| 114 |
// CHECK-NEXT: __hip_fp8_interpretation_t E4M3 = __HIP_E4M3_FNUZ; |
| 115 |
// CHECK-NEXT: __hip_fp8_interpretation_t E5M2 = __HIP_E5M2_FNUZ; |
| 116 |
__nv_fp8_interpretation_t fp8_interpretation_t; |
| 117 |
__nv_fp8_interpretation_t E4M3 = __NV_E4M3; |
| 118 |
__nv_fp8_interpretation_t E5M2 = __NV_E5M2; |
| 119 |
|
| 120 |
// CHECK: __hip_fp8x4_e5m2_fnuz fp8x4_e5m2; |
| 121 |
__nv_fp8x4_e5m2 fp8x4_e5m2; |
| 122 |
|
| 123 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __nv_fp8_storage_t __nv_cvt_double_to_fp8(const double x, const __nv_saturation_t saturate, const __nv_fp8_interpretation_t fp8_interpretation); |
| 124 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __hip_fp8_storage_t __hip_cvt_double_to_fp8(const double d, const __hip_saturation_t sat, const __hip_fp8_interpretation_t type); |
| 125 |
// CHECK: fp8_storage_t = __hip_cvt_double_to_fp8(dx, saturation_t, fp8_interpretation_t); |
| 126 |
fp8_storage_t = __nv_cvt_double_to_fp8(dx, saturation_t, fp8_interpretation_t); |
| 127 |
|
| 128 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __nv_fp8x2_storage_t __nv_cvt_double2_to_fp8x2(const double2 x, const __nv_saturation_t saturate, const __nv_fp8_interpretation_t fp8_interpretation); |
| 129 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __hip_fp8x2_storage_t __hip_cvt_double2_to_fp8x2(const double2 d2, const __hip_saturation_t sat, const __hip_fp8_interpretation_t type); |
| 130 |
// CHECK: fp8x2_storage_t = __hip_cvt_double2_to_fp8x2(d2, saturation_t, fp8_interpretation_t); |
| 131 |
fp8x2_storage_t = __nv_cvt_double2_to_fp8x2(d2, saturation_t, fp8_interpretation_t); |
| 132 |
|
| 133 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __nv_fp8_storage_t __nv_cvt_float_to_fp8(const float x, const __nv_saturation_t saturate, const __nv_fp8_interpretation_t fp8_interpretation); |
| 134 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __hip_fp8_storage_t __hip_cvt_float_to_fp8(const float f, const __hip_saturation_t sat, const __hip_fp8_interpretation_t type); |
| 135 |
// CHECK: fp8_storage_t = __hip_cvt_float_to_fp8(fx, saturation_t, fp8_interpretation_t); |
| 136 |
fp8_storage_t = __nv_cvt_float_to_fp8(fx, saturation_t, fp8_interpretation_t); |
| 137 |
|
| 138 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __nv_fp8x2_storage_t __nv_cvt_float2_to_fp8x2(const float2 x, const __nv_saturation_t saturate, const __nv_fp8_interpretation_t fp8_interpretation); |
| 139 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __hip_fp8x2_storage_t __hip_cvt_float2_to_fp8x2(const float2 f2, const __hip_saturation_t sat, const __hip_fp8_interpretation_t type); |
| 140 |
// CHECK: fp8x2_storage_t = __hip_cvt_float2_to_fp8x2(f2, saturation_t, fp8_interpretation_t); |
| 141 |
fp8x2_storage_t = __nv_cvt_float2_to_fp8x2(f2, saturation_t, fp8_interpretation_t); |
| 142 |
|
| 143 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __nv_fp8_storage_t __nv_cvt_halfraw_to_fp8(const __half_raw x, const __nv_saturation_t saturate, const __nv_fp8_interpretation_t fp8_interpretation); |
| 144 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __hip_fp8_storage_t __hip_cvt_halfraw_to_fp8(const __half_raw x, const __hip_saturation_t sat, const __hip_fp8_interpretation_t type); |
| 145 |
// CHECK: fp8_storage_t = __hip_cvt_halfraw_to_fp8(hrx, saturation_t, fp8_interpretation_t); |
| 146 |
fp8_storage_t = __nv_cvt_halfraw_to_fp8(hrx, saturation_t, fp8_interpretation_t); |
| 147 |
|
| 148 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __nv_fp8x2_storage_t __nv_cvt_halfraw2_to_fp8x2(const __half2_raw x, const __nv_saturation_t saturate, const __nv_fp8_interpretation_t fp8_interpretation); |
| 149 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __hip_fp8x2_storage_t __hip_cvt_halfraw2_to_fp8x2(const __half2_raw x, const __hip_saturation_t sat, const __hip_fp8_interpretation_t type); |
| 150 |
// CHECK: fp8x2_storage_t = __hip_cvt_halfraw2_to_fp8x2(h2rx, saturation_t, fp8_interpretation_t); |
| 151 |
fp8x2_storage_t = __nv_cvt_halfraw2_to_fp8x2(h2rx, saturation_t, fp8_interpretation_t); |
| 152 |
|
| 153 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __nv_fp8_storage_t __nv_cvt_bfloat16raw_to_fp8(const __nv_bfloat16_raw x, const __nv_saturation_t saturate, const __nv_fp8_interpretation_t fp8_interpretation); |
| 154 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __hip_fp8_storage_t __hip_cvt_bfloat16raw_to_fp8(const __hip_bfloat16_raw hr, const __hip_saturation_t sat, const __hip_fp8_interpretation_t type); |
| 155 |
// CHECK: fp8_storage_t = __hip_cvt_bfloat16raw_to_fp8(bf16r, saturation_t, fp8_interpretation_t); |
| 156 |
fp8_storage_t = __nv_cvt_bfloat16raw_to_fp8(bf16r, saturation_t, fp8_interpretation_t); |
| 157 |
|
| 158 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __nv_fp8x2_storage_t __nv_cvt_bfloat16raw2_to_fp8x2(const __nv_bfloat162_raw x, const __nv_saturation_t saturate, const __nv_fp8_interpretation_t fp8_interpretation); |
| 159 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __hip_fp8x2_storage_t __hip_cvt_bfloat16raw2_to_fp8x2(const __hip_bfloat162_raw hr, const __hip_saturation_t sat, const __hip_fp8_interpretation_t type); |
| 160 |
// CHECK: fp8x2_storage_t = __hip_cvt_bfloat16raw2_to_fp8x2(bf162r, saturation_t, fp8_interpretation_t); |
| 161 |
fp8x2_storage_t = __nv_cvt_bfloat16raw2_to_fp8x2(bf162r, saturation_t, fp8_interpretation_t); |
| 162 |
|
| 163 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __half_raw __nv_cvt_fp8_to_halfraw(const __nv_fp8_storage_t x, const __nv_fp8_interpretation_t fp8_interpretation); |
| 164 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __half_raw __hip_cvt_fp8_to_halfraw(const __hip_fp8_storage_t x, const __hip_fp8_interpretation_t type); |
| 165 |
// CHECK: hrx = __hip_cvt_fp8_to_halfraw(fp8_storage_t, fp8_interpretation_t); |
| 166 |
hrx = __nv_cvt_fp8_to_halfraw(fp8_storage_t, fp8_interpretation_t); |
| 167 |
|
| 168 |
// CUDA: __CUDA_HOSTDEVICE_FP8_DECL__ __half2_raw __nv_cvt_fp8x2_to_halfraw2(const __nv_fp8x2_storage_t x, const __nv_fp8_interpretation_t fp8_interpretation); |
| 169 |
// HIP: __FP8_HOST_DEVICE_STATIC__ __half2_raw __hip_cvt_fp8x2_to_halfraw2(const __hip_fp8x2_storage_t x, const __hip_fp8_interpretation_t type); |
| 170 |
// CHECK: h2rx = __hip_cvt_fp8x2_to_halfraw2(fp8x2_storage_t, fp8_interpretation_t); |
| 171 |
h2rx = __nv_cvt_fp8x2_to_halfraw2(fp8x2_storage_t, fp8_interpretation_t); |
| 172 |
#endif |
| 173 |
|
| 174 |
#if CUDA_VERSION >= 12020 |
| 175 |
// CUDA: __CUDA_HOSTDEVICE_FP16_DECL__ __half2 make_half2(const __half x, const __half y); |
| 176 |
// HIP: __HOST_DEVICE__ __half2 make_half2(__half x, __half y); |
| 177 |
// CHECK: h2 = make_half2(hx, hy); |
| 178 |
h2 = make_half2(hx, hy); |
| 179 |
|
| 180 |
// CHECK: __half _INF_FP16 = HIPRT_INF_FP16; |
| 181 |
// CHECK-NEXT: __half _MAX_NORMAL_FP16 = HIPRT_MAX_NORMAL_FP16; |
| 182 |
// CHECK-NEXT: __half _MIN_DENORM_FP16 = HIPRT_MIN_DENORM_FP16; |
| 183 |
// CHECK-NEXT: __half _NAN_FP16 = HIPRT_NAN_FP16; |
| 184 |
// CHECK-NEXT: __half _NEG_ZERO_FP16 = HIPRT_NEG_ZERO_FP16; |
| 185 |
// CHECK-NEXT: __half _ONE_FP16 = HIPRT_ONE_FP16; |
| 186 |
// CHECK-NEXT: __half _ZERO_FP16 = HIPRT_ZERO_FP16; |
| 187 |
__half _INF_FP16 = CUDART_INF_FP16; |
| 188 |
__half _MAX_NORMAL_FP16 = CUDART_MAX_NORMAL_FP16; |
| 189 |
__half _MIN_DENORM_FP16 = CUDART_MIN_DENORM_FP16; |
| 190 |
__half _NAN_FP16 = CUDART_NAN_FP16; |
| 191 |
__half _NEG_ZERO_FP16 = CUDART_NEG_ZERO_FP16; |
| 192 |
__half _ONE_FP16 = CUDART_ONE_FP16; |
| 193 |
__half _ZERO_FP16 = CUDART_ZERO_FP16; |
| 194 |
#endif |
| 195 |
|
| 196 |
return 0; |
| 197 |
} |