IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo function

cast_float_to_fp4e2m1_amd

def cast_float_to_fp4e2m1_amd[dtype: DType, width: SIMDLength, //](input: SIMD[dtype, width], scale: Float32) -> UInt32

Converts up to eight floating-point values to packed FP4 E2M1 using AMD CDNA4 intrinsics.

Applies the provided scale factor before quantization using the llvm.amdgcn.cvt.scalef32.pk.fp4.* intrinsics, packing pairs of values per call.

Constraints:

Requires AMD CDNA4 or newer (MI355X and above).

Parameters:

  • ​dtype (DType): Input element type (bfloat16 or float32).
  • ​width (SIMDLength): Number of input elements; must be even and at most 8.

Args:

  • ​input (SIMD[dtype, width]): Input floating-point vector to convert.
  • ​scale (Float32): Scale factor applied before FP4 quantization.

Returns:

UInt32: A UInt32 with the converted FP4 E2M1 nibbles packed in order.

Was this page helpful?