Download mfma-core/src/mfma_hls_wrapper.c from Snapkitty/nvidia-stack: direct link, hf CLI and curl.
- Browser
- Download file 2.22 kB
-
https://huggingface.co/Snapkitty/nvidia-stack/resolve/main/mfma-core/src/mfma_hls_wrapper.c
- Command line
-
hf download hf://Snapkitty/nvidia-stack/mfma-core/src/mfma_hls_wrapper.c
-
curl -L -o mfma_hls_wrapper.c https://huggingface.co/Snapkitty/nvidia-stack/resolve/main/mfma-core/src/mfma_hls_wrapper.c
2.22 kB
| // mfma_hls_wrapper.c — HLS-compatible C wrapper for MFMA core | |
| // Stripped of Caml runtime allocation in inner hardware-mapped loop | |
| // IEEE-754 FP16 to FP32 conversion (matches gfx942 hardware) | |
| static inline float half_to_float_ieee754(uint16_t h) { | |
| uint32_t sign = (h >> 15) & 0x1; | |
| uint32_t exp = (h >> 10) & 0x1F; | |
| uint32_t mantissa = h & 0x3FF; | |
| if (exp == 0x1F) { | |
| if (mantissa == 0) { | |
| return sign ? -__builtin_inff() : __builtin_inff(); | |
| } else { | |
| return __builtin_nanf(""); | |
| } | |
| } else if (exp == 0) { | |
| float m = mantissa ? __builtin_ldexpf((float)mantissa, -24) : 0.0f; | |
| return sign ? -m : m; | |
| } else { | |
| float m = __builtin_ldexpf((float)(mantissa | 0x400), (int)exp - 15); | |
| return sign ? -m : m; | |
| } | |
| } | |
| // Hardware-mapped MFMA tile shim (HLS pragma-controlled) | |
| void mfma_tile_hls_hardware_shim( | |
| const uint16_t a_tile[256], | |
| const uint16_t b_tile[256], | |
| const float c_tile[256], | |
| float out_tile[256] | |
| ) { | |
| for (int m = 0; m < 16; m++) { | |
| for (int n = 0; n < 16; n++) { | |
| float acc = c_tile[m * 16 + n]; | |
| for (int k = 0; k < 16; k++) { | |
| float va = half_to_float_ieee754(a_tile[m * 16 + k]); | |
| float vb = half_to_float_ieee754(b_tile[k * 16 + n]); | |
| // IEEE-754 compliant NaN propagation | |
| if (__builtin_isnan(va) || __builtin_isnan(vb) || __builtin_isnan(acc)) { | |
| acc = __builtin_nanf(""); | |
| } else { | |
| acc = __builtin_fma(va, vb, acc); | |
| } | |
| } | |
| out_tile[m * 16 + n] = acc; | |
| } | |
| } | |
| } | |