llvm / llvm/llvm-project

proper fp8 types lowering from ml_dtypes

Open
#164,895 2 comments 0 reactions 1 assignee Claimed by @makslevental View on GitHub
mlir
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

example mlir
```
module {
func.func @extend_f8_to_f32(%arg0: f8E5M2) -> f32 {
%0 = arith.extf %arg0 : f8E5M2 to f32
return %0 : f32
}
func.func @truncate_f32_to_f8(%arg0: f32) -> f8E5M2 {
%0 = arith.truncf %arg0 : f32 to f8E5M2
return %0 : f8E5M2
}
}
```

fp8 gets lowered into i8

```
backend = LLVMJITBackend()
compiled = backend.compile(
module_finished,
kernel_name="extend_f8_to_f32",
pipeline=Pipeline().lower_to_llvm(),
)
invoker = backend.load(compiled)
input_val = ml_dtypes.float8_e5m2(0.5)
result = invoker.extend_f8_to_f32(input_val)
```
```
mlir.extras.runtime.passes.MlirCompilerError: Lowering IR failed with the following diagnostics:

********************************************************************************
Failure while executing pass pipeline:
error: unknown: 'llvm.fpext' op operand #0 must be floating point LLVM type or LLVM dialect-compatible vector of floating point LLVM type, but got 'i8'
note: unknown: see current operation: %1 = "llvm.fpext"(%arg0) : (i8) -> f32
error: unknown: 'llvm.fptrunc' op result #0 must be floating point LLVM type or LLVM dialect-compatible vector of floating point LLVM type, but got 'i8'
note: unknown: see current operation: %0 = "llvm.fptrunc"(%arg0) : (f32) -> i8
********************************************************************************
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.