Repository navigation
[HIPIFY][fix] Map nv_bfloat16 and nv_bfloat162 to __hip_bfloat16 and __hip_bfloat162 - #2810
yassinsolim wants to merge 1 commit into
Conversation
…__hip_bfloat162 nv_bfloat162 was marked unsupported, so hipify-perl and hipify-clang left it in place. nv_bfloat16 was mapped to hip_bfloat16, which hip/hip_bf16.h does not declare (it lives in hip/hip_bfloat16.h), so converted code did not compile. Both are typedefs of the double-underscore types in cuda_bf16.h, so map them to the matching __hip_ types, like __nv_bfloat16 and __nv_bfloat162. Regenerate bin/hipify-perl and the device API table. Tested: synthetic/libraries/cudevice2hipdevice.cu fails on the base commit and passes with this change (LLVM 20.1.8, CUDA 12.8).
Security scan found no critical or high findings on lines changed by this pull requestView the security scan run for complete reports. “New” means the finding is located in a changed file on an added or modified line; it is not a base-versus-head findings delta. |
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues remain for the CUDA bfloat16 typedef mapping updates.
No open issues 🎉
What changed in this PR
Fixes #2809 by mapping CUDA’s nv_bfloat16 and nv_bfloat162 typedefs to the HIP types declared in hip/hip_bf16.h, matching the existing double-underscore mappings.
Changes:
- Corrects
nv_bfloat16conversion and enables support fornv_bfloat162. - Updates the generated Perl converter and support documentation.
- Adjusts the scalar regression expectation and adds coverage for the paired type.
| File | Description |
|---|---|
tests/unit_tests/synthetic/libraries/cudevice2hipdevice.cu |
Checks both typedefs convert to the correct HIP types. |
src/CUDA2HIP_Device_types.cpp |
Corrects both mappings and removes the unsupported flag for nv_bfloat162. |
docs/reference/tables/CUDA_Device_API_supported_by_HIP.md |
Documents the corrected mappings and ROCm availability. |
bin/hipify-perl |
Synchronizes generated mappings and supported-type lists. |
Review effort: Balanced
| |`nv_bfloat16`|11.0| | | |`__hip_bfloat16`|5.7.0| | | | | | | ||
| |`nv_bfloat162`|11.0| | | |`__hip_bfloat162`|5.7.0| | | | | | |
There was a problem hiding this comment.
No, it's generated. I rebuilt hipify-clang from this branch (LLVM 18.1.3), reran the --perl and --md generators (joint and separate), and they give no diff against the PR.
There was a problem hiding this comment.
But in the PR, HIP versions of the newly supported data types are not present in the source code.
There was a problem hiding this comment.
They're already in the source, just not in this diff. HIP_DEVICE_TYPE_NAME_VER_MAP in src/CUDA2HIP_Device_types.cpp has __hip_bfloat16 and __hip_bfloat162 as HIP_5070 at lines 239 and 257. They came in with 5466c48 for __nv_bfloat16 and __nv_bfloat162. The doc generator looks the HIP version up by HIP name, so the nv_ typedef rows get 5.7.0 as well. curandRngType and curandRngType_t share hiprandRngType_t the same way. If you meant something else, could you point me to it?
There was a problem hiding this comment.
hip_bfloat16 is declared in hip/amd_detail/amd_hip_bfloat16.h (clr):
typedef struct {
uint16_t data;
} hip_bfloat16;__hip_bfloat16 is declared in hip/amd_detail/amd_hip_bf16.h (clr):
struct __attribute__((aligned(2))) __hip_bfloat16 {
protected:
union {
/*! \brief raw representation of bfloat16 */
unsigned short __x;
/*! \brief bf16 represenation */
__bf16 __x_bf16;
};Yes, there is a corresponding typedef for them:
typedef __hip_bfloat16 hip_bfloat16;But 1) it is not reachable by default; 2) they are still different types.
The question with hip_bfloat16 is different: should it be visible to the compiler by default, or does it require an explicit include?
As for hip_bfloat162, it is not declared in clr. It probably needs to be declared; thus, a ticket for clr would help determine this.
So, I'd not recommend mixing different types in the hipification process, but I'm open to discussion.
There was a problem hiding this comment.
The PR doesn't map to hip_bfloat16, it maps nv_bfloat16 and nv_bfloat162 to __hip_bfloat16 and __hip_bfloat162. In cuda_bf16.h nv_bfloat16 is only typedef __nv_bfloat16 nv_bfloat16, so it's the same type HIPIFY already maps to __hip_bfloat16, and this keeps clear of the old hip_bfloat16 struct and the missing hip_bfloat162. If you'd rather map to the typedef names once clr declares hip_bfloat162, I can open that clr ticket.
There was a problem hiding this comment.
Was:
nv_bfloat16 -> hip_bfloat16
nv_bfloat162 -> unsupported by HIP
Now:
nv_bfloat16 -> __hip_bfloat16
nv_bfloat162 -> __hip_bfloat162
Why I'm for Was, I explained above.
emankov
left a comment
There was a problem hiding this comment.
Please regenerate hipify-perl and CUDA2HIP documentation for the PR.
Motivation
Fixes #2809.
hipify-perl and hipify-clang convert
nv_bfloat16tohip_bfloat16, a type thathip/hip_bf16.hdoes not declare.nv_bfloat162has no mapping, so it is marked unsupported and left in place. The converted file then fails to compile with hipcc (unknown type name 'hip_bfloat16').nv_bfloat16andnv_bfloat162are typedefs of__nv_bfloat16and__nv_bfloat162incuda_bf16.h. The double-underscore names already map to__hip_bfloat16and__hip_bfloat162, so the typedef names should map the same way.Technical Details
src/CUDA2HIP_Device_types.cpp:nv_bfloat16maps to__hip_bfloat16(waship_bfloat16), andnv_bfloat162maps to__hip_bfloat162(was unsupported).bin/hipify-perlanddocs/reference/tables/CUDA_Device_API_supported_by_HIP.mdare regenerated with hipify-clang built from this branch, using the commands in the repo docs (--perl, and--mdwith--doc-roc=jointandseparate).bin/hipify-perlchanged upstream since the branch was first written, so it was regenerated on the currentamd-developinstead of merged by hand. Regenerating again gives no diff.tests/unit_tests/synthetic/libraries/cudevice2hipdevice.cu:nv_bfloat16now expects__hip_bfloat16, and there is a newnv_bfloat162case.What could break:
nv_bfloat16changes fromhip_bfloat16to__hip_bfloat16for every user. Code that converted before and compiled only because it also includedhip/hip_bfloat16.hnow gets thehip/hip_bf16.htype, which matches how__nv_bfloat16is already mapped. The table lists__hip_bfloat16as available since ROCm 5.7.0.Test Plan
cudevice2hipdevice.cuand the full lit suite with hipify-clang built fromamd-developand from this branch.nv_bfloat16andnv_bfloat162with hipify-perl and hipify-clang before and after, and compile the output with hipcc.Test Result
LLVM 20.1.8, CUDA 12.8, Linux. The cuDNN, cuTensor, cuFile and cuSPARSELt tests are excluded because no roots were available.
amd-develop(9a85980) with the updatedcudevice2hipdevice.cu: 141 of 142 pass, and that test fails becausenv_bfloat16 bf16becomeship_bfloat16 bf16andnv_bfloat162 bf162cstays unconverted. With this change the full suite passes, 142 of 142. The lit output of the failing run is cut off by lit's output limit, so the two lines above come from running hipify-clang on the test file directly.bf16_in.cu(nv_bfloat16 *x, nv_bfloat162 *y): before,hip_bfloat16 *x, nv_bfloat162 *yand a warning fornv_bfloat162. After,__hip_bfloat16 *x, __hip_bfloat162 *yand no warning.--offload-arch=gfx942 --cuda-device-only -c: the output from before fails withunknown type name 'hip_bfloat16'andunknown type name 'nv_bfloat162'(hipify-perl and hipify-clang output both). The output from after compiles, rc 0 for both. The same input written with__nv_bfloat16and__nv_bfloat162converts with hipify-perl to the same__hip_types onamd-developalready and compiles, rc 0.Submission Checklist