E3052

E3052 — Arithmetic on fp8 or fp4 values (f8e4m3, f8e5m2 or f4e2m1) with no written result type, as in print(a * b). The compiler computes in f32 and rounds once to the written type, so the program must write it: let c : f32 = a * b;. Also += and the other compound operators on these values, and any operator on tensors of them.

What the compiler reports

Error[E3052] at [[@LINE+1]]:{{[0-9]+}}: `*` on `f8e4m3` values needs a written result type, such as `let c : f32 = ...`. The compiler computes in f32, and rounds once to that type
Error[E3052] at [[@LINE+1]]:{{[0-9]+}}: `-` on `f4e2m1` values needs a written result type
Error[E3052] at [[@LINE+2]]:{{[0-9]+}}: `+` on `f8e4m3` values gives a float, and the written result type is `i32`. Write a float type, and convert the result with `as i32`
Error[E3001] at [[@LINE+1]]:{{[0-9]+}}: 'i' is declared i32 but its initializer is f8e4m3
Error[E3052] at [[@LINE+1]]:{{[0-9]+}}: `+=` on `f8e4m3` values is not supported. Write `x = x + y`, which computes in f32 and rounds once to the type of `x`
Error[E3004] at [[@LINE+2]]:{{[0-9]+}}: Type mismatch in binary operation: f8e4m3 vs f32
Error[E3001] at [[@LINE+1]]:{{[0-9]+}}: 'm' is declared f32 but its initializer is f8e4m3
Error[E3052] at [[@LINE+1]]:{{[0-9]+}}: The compiler cannot compute `@` on tensors of `f4e2m1` yet. Convert the elements with `as f32`

The fragments the test suite holds the compiler to. An ellipsis marks text the test does not constrain; the emitted message also carries a source location.

A program that triggers it

//
// Part of the Vx Project, under the Apache License v2.0 with LLVM Exceptions.
// See LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//
// Arithmetic on fp8 and fp4 values needs a written float result type. A compound operator such
// as `+=`, an f32 operand in the same expression, and an operator on tensors of these types are
// errors too. A negative literal is not an error.

fn main() -> i32 {
  let a : f8e4m3 = -1.5;
  let b : f4e2m1 = 2.0;
  let mut c : f8e4m3 = 3.0;
  let x : f32 = 2.0;
  let t = Tensor<f4e2m1, [2, 2]>::new();
  let u = Tensor<f4e2m1, [2, 2]>::new();
  let p = a * a;
  print(-b);
  let i : i32 = a + a;
  c += a;
  let m : f32 = a * x;
  let mm = t @ u;
  let q : f32 = a * b;
  print(q);
  return 0;
}

From tests/frontend/fail/arithmetic_on_fp8_and_fp4_values.vx, which asserts this diagnostic on every commit.

Related