[Mlir-commits] [mlir] [mlir][gpu] Add pass for emulating unsupported types. (PR #138087)
Krzysztof Drewniak
llvmlistbot at llvm.org
Thu May 1 13:30:49 PDT 2025
krzysz00 wrote:
Thanks for taking the time for explaining your motivations, though I still fundamentally disagree with them.
The lowering to SPIR-V should replace all mentions of `bf16` with `i16`, and replace `arith.extf %x : bf16 to i32` and `arith.truncf %x : f32 to bf16` with operations that produce `i16`.
See, for example, the equivalent code in LLVMTypeConverter
```c++
Type LLVMTypeConverter::convertFloatType(FloatType type) const {
// Valid LLVM float types are used directly.
if (LLVM::isCompatibleType(type))
return type;
// F4, F6, F8 types are converted to integer types with the same bit width.
if (isa<Float8E5M2Type, Float8E4M3Type, Float8E4M3FNType, Float8E5M2FNUZType,
Float8E4M3FNUZType, Float8E4M3B11FNUZType, Float8E3M4Type,
Float4E2M1FNType, Float6E2M3FNType, Float6E3M2FNType,
Float8E8M0FNUType>(type))
return IntegerType::get(&getContext(), type.getWidth());
// Other floating-point types: A custom type conversion rule must be
// specified by the user.
return Type();
}
```
This should correctly convert kernel arguments etc.
One other thing we may want to do here is to relax the verifier on `gpu.launch_func` to allow a bf16/i16 mismatch if it turns out that's an issue. I think that's a better solution than this thing
https://github.com/llvm/llvm-project/pull/138087
More information about the Mlir-commits
mailing list