PTX ISA v9.4

9.7.6.4. Alternate Floating Point Instructions: fma

fma

Fused multiply-add.

Syntax

ptx
fma{.rnd}{.satfinite}.cdtype.atype.btype  d, a, b, c;

.cdtype = { .e5m2x4, .e4m3x4 };
.atype  = .btype = { .e5m2x4, .e4m3x4, .e3m2x4, .e2m3x4, .e2m1x4, .e2m1p4x4, .ue8m0x4 };
.rnd    = { .rn };

Description

Performs a fused multiply-add with no loss of precision in the intermediate product and addition.

First forms input vectors by extracting four values of the specified type from packed source operands. These extracted input vectors are then operated in parallel with an infinite precision. The resulting values are then rounded to the destination type using the rounding mode specified by .rnd.

Operands d and c must be of type .b32. When .atype is .e2m1x4, operand a must be of type .b16; otherwise operand a must be of type .b32. Similarly, if .btype is .e2m1x4, operand b must be of type .b16; otherwise it must be of type .b32.

Semantics

ptx
if (isF8x4(atype) || isUE8M0x4(atype)) {
    iA[0] = a[0:7];
    iA[1] = a[8:15];
    iA[2] = a[16:23];
    iA[3] = a[24:31];
} else if (isF6x4(atype)) {
    iA[0] = a[0:5];
    iA[1] = a[8:13];
    iA[2] = a[16:21];
    iA[3] = a[24:29];
} else if (isE2M1P4x4(atype)) {
    iA[0] = a[0:3];
    iA[1] = a[8:11];
    iA[2] = a[16:19];
    iA[3] = a[24:27];
} else if (isE2M1x4(atype)) {
    iA[0] = a[0:3];
    iA[1] = a[4:7];
    iA[2] = a[8:11];
    iA[3] = a[12:15];
}

if (isF8x4(btype) || isUE8M0x4(btype)) {
    iB[0] = b[0:7];
    iB[1] = b[8:15];
    iB[2] = b[16:23];
    iB[3] = b[24:31];
} else if (isF6x4(btype)) {
    iB[0] = b[0:5];
    iB[1] = b[8:13];
    iB[2] = b[16:21];
    iB[3] = b[24:29];
} else if (isE2M1P4x4(btype)) {
    iB[0] = b[0:3];
    iB[1] = b[8:11];
    iB[2] = b[16:19];
    iB[3] = b[24:27];
} else if (isE2M1x4(btype)) {
    iB[0] = b[0:3];
    iB[1] = b[4:7];
    iB[2] = b[8:11];
    iB[3] = b[12:15];
}

iC[0] = c[0:7];
iC[1] = c[8:15];
iC[2] = c[16:23];
iC[3] = c[24:31];

for (i = 0; i < 4; i++) {
    d[i] = iA[i] * iB[i] + iC[i];
}

Notes

fma with .e5m2x4, .e4m3x4 computes the product of a and b to infinite precision and then adds c to this product, again in infinite precision. The resulting value is then rounded to the nearest representation in the destination format.

Rounding modifier:

  • .rn — round to nearest with ties to even

The default value of rounding modifier is .rn.

Saturation modifier:

  • .satfinite: If the absolute value of output (ignoring sign) is greater than MAX_NORM of the specified destination format, then the result is sign-preserved MAX_NORM of the destination format. In absence of .satfinite for .e4m3x4 destination format, results beyond the largest representable target format are converted to NaN.

PTX ISA Notes

fma with .e5m2x4, .e4m3x4, .e3m2x4, .e2m3x4, .e2m1x4, .e2m1p4x4, .ue8m0x4 as instruction types introduced in PTX ISA version 9.4.

Target ISA Notes

fma with .e5m2x4, .e4m3x4, .e3m2x4, .e2m3x4, .e2m1x4, .e2m1p4x4, .ue8m0x4 as instruction types is supported on the following architectures:

  • sm_100a
  • sm_103a

Examples

ptx
.reg .b32 rd, ra, rb, rc;

// multiply ue8m0x4 with f4x4 and add f8x4
mov.b32 ra, {ba0, ba1, ba2, ba3};   // pack four ue8m0
mov.b32 rb, {bb0, bb1, ba2, ba3};   // pack four f4 as f4x4 in b32 operand. Each f4 resides within lower half of a byte.
mov.b32 rc, {ba0, ba1, ba2, ba3};   // pack four f8 as f8x4
fma.rn.e5m2x4.ue8m0x4.e2m1p4x4.satfinite rd, ra, rb, rc;

// multiply f6x4 with f4x4 and add f8x4
mov.b32 ra, {ba0, ba1, ba2, ba3}; // pack four f6 as f6x4
.reg .b16 rb16;
mov.b16 rb16, {bb0, bb1};         // pack four f4 as f4x4 in .b16 operand
mov.b32 rc, {ba0, ba1, ba2, ba3}; // pack four f8 as f8x4
fma.rn.e4m3x4.e3m2x4.e2m1x4.satfinite rd, ra, rb16, rc; // SIMD fused-multiply-add

// multiply ue8m0x4 with f8x4 and add f8x4
mov.b32 ra, {ba0, ba1, ba2, ba3}; // pack four ue8m0 values
mov.b32 rb, {bb0, bb1, bb2, bb3}; // pack four f8 as f8x4
mov.b32 rc, {ba0, ba1, ba2, ba3}; // pack four f8 as f8x4
fma.rn.e4m3x4.ue8m0x4.e5m2x4 rd, ra, rb, rc; // SIMD fused-multiply-add
esc
Type to search across all documentation