In this repo, what part of the code lowers the operation of casting fp8 to fp16 on AMD?…
Private research annotation
Sign in to add a private research label or note.
- User
In this repo, what part of the code lowers the operation of casting fp8 to fp16 on AMD? What AMDGCN does it generate?
Assistant
I will start by listing the files in
third_party/amdto understand the structure of the AMD-specific code and identify likely locations for the lowering logic.Assistant
I will list the contents of
third_party/amd/libto look for conversion-related directories, mirroring the main project structure.Assistant
I will list the contents of
third_party/amd/lib/TritonAMDGPUToLLVMto find the specific files responsible for the lowering process.Assistant
I will search for "fp8" within the
third_party/amd/lib/TritonAMDGPUToLLVMdirectory to locate code handling floating-point 8 conversion logic.Assistant
I will read
third_party/amd/lib/TritonAMDGPUToLLVM/ElementwiseOpToLLVM.cpparound lines 900-1000 to understand the context of the conversion logic.Assistant
I will search for the definition of
ROCDLdialect inthird_party/amdto understand howCvtScaleF32PkF16Fp8Opmaps to the underlying assembly instruction.Assistant
I will search for the TableGen definition of
CvtScaleF32PkF16Fp8Opor genericROCDL_Opdefinitions inthird_party/amdandincludeto determine the corresponding instruction.Assistant
I will search for
ROCDLOps.tdor similar files to locate the definition or extension of theROCDLdialect.Assistant
I will examine the
include/triton/Dialectdirectory to verify ifROCDLrelated files are present there.Assistant
I will verify the contents of
third_party/amd/lib/Dialectto see if there are any local extensions forROCDLops.Assistant
I will now check the contents of
third_party/amd/lib/Dialect/TritonAMDGPUto investigate further.Assistant
I will examine
third_party/amd/lib/Dialect/TritonAMDGPU/IRto check for any relevant instruction definitions.Assistant
I will check
third_party/amd/include/Dialect/TritonAMDGPU/IRfor.tdfiles that might contain the instruction definitions.Assistant
I will read
bin/RegisterTritonDialects.hto see how dialects are registered and if there are any custom ops being added.Assistant
I will read lines 1145-1200 and 1591-1630 of
third_party/amd/lib/TritonAMDGPUToLLVM/ElementwiseOpToLLVM.cppto identify the specific AMDGCN instructions generated for Nanoo FP8 conversions on CDNA3 and confirm the OCP FP8 instructions for CDNA4.Assistant
I will read
third_party/amd/lib/TritonAMDGPUToLLVM/ElementwiseOpToLLVM.cpparound lines 1591-1630 to confirm the lowering logic for Nanoo FP8 (E4M3FNUZ) to FP16 conversions on CDNA3.Assistant
I will read the
cvtScalePkUpcastFromFp8implementation inthird_party/amd/lib/TritonAMDGPUToLLVM/ElementwiseOpToLLVM.cppto verify if it performs any additional operations and to confirm how the conversion is handled.Assistant
The code responsible for lowering the operation of casting
fp8tofp16on AMD is primarily located in:third_party/amd/lib/TritonAMDGPUToLLVM/ElementwiseOpToLLVM.cppThis file handles the lowering of elementwise operations, including type conversions, from the TritonGPU dialect to LLVM IR (which eventually lowers to AMDGCN ISA).
The specific logic depends on the AMD architecture generation (CDNA3 vs. CDNA4) and the specific 8-bit floating-point format (OCP FP8 vs. Nanoo FP8).
- User
How is it lowered on RDNA3, which does not seem to have native fp8?
Assistant
I will read the software implementation functions
Fp8E4M3FN_to_Fp16_SWandFp8E4M3FNUZ_to_Fp16_SWinthird_party/amd/lib/TritonAMDGPUToLLVM/ElementwiseOpToLLVM.cpp.Assistant
I will now check
third_party/amd/lib/TritonAMDGPUToLLVM/TargetInfo.cppto confirm howISAFamilyis determined for RDNA3 (Navi 3x) architectures.Assistant
I will read
third_party/amd/lib/TritonAMDGPUToLLVM/TargetUtils.cppto understand how theISAFamilyenum is populated from the architecture string, to confirm that RDNA3 maps to anISAFamilythat falls through to the SW path.- User
In a new file, write a Triton kernel that implements the algorithm in
Fp8E4M3FN_to_Fp16_oneValue Assistant
The Triton kernel has been implemented in
fp8_cast_kernel.py. It replicates the logic fromFp8E4M3FN_to_Fp16_oneValueusing bitwise operations to handle the conversion from FP8 (E4M3FN) to FP16, including special handling for denormals and NaNs. The script also includes a test harness to run the kernel on all 256 possible inputs and verify key values.