TensorTonic
Problems
Fused Multiply-Add in Triton
GPU ProgrammingLinear Algebra
Easy

Implement a fused multiply-add (FMA) kernel in Triton. Given a scalar aaa and two 1D float tensors xxx and yyy:

out[i]=a⋅x[i]+y[i]\texttt{out}[i] = a \cdot x[i] + y[i]out[i]=a⋅x[i]+y[i]

Like vector addition this is a pure map, but it introduces two new beats: a scalar parameter passed by value alongside the tensor pointers, and a fused two-input arithmetic expression that the Triton backend lowers to a single hardware FMA instruction per lane.

Loading visualization...

Examples

Input: a = 2.0, x = [1.0, 2.0, 3.0, 4.0], y = [1.0, 1.0, 1.0, 1.0]

Output: [3.0, 5.0, 7.0, 9.0]

Input: a = -1.0, x = [1.0, 2.0, 3.0], y = [10.0, 10.0, 10.0]

Output: [9.0, 8.0, 7.0]

Hint 1

Forward the scalar aaa from the launcher straight into the kernel call. Triton broadcasts a Python float to every lane automatically.

Hint 2

Write the body as a single expression a⋅x+ya \cdot x + ya⋅x+y. Splitting it into a separate multiply and add gives the compiler more freedom but loses the explicit FMA opportunity.

Hint 3

Tail mask discipline is identical to vector add: build one mask at the top, reuse it on both loads and the store.

Requirements

  • Use one Triton program per contiguous tile of the input
  • Express the operation as a single fused a⋅x+ya \cdot x + ya⋅x+y so Triton emits a hardware FMA
  • Mask the tail on every load and store
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1061 \le N \le 10^61≤N≤106.
  • ∣a∣≤10|a| \le 10∣a∣≤10.
  • All tensors are torch.float32 on cuda.
  • Tolerance: atol=1e-3.
Try Similar Problems
Vector Addition in TritonEasyL2 Vector Norm in TritonEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasyScaled Dot-Product Attention in TritonMediumBlock-Pointer Matmul in TritonMediumAutotuned Matrix Multiplication in TritonMediumTiled Transpose in TritonMediumGEMV: Matrix Vector Product in TritonMediumFused Matmul + Bias + ReLU in TritonMediumTiled Matrix Multiplication in TritonMedium

Accepts: number

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Fused Multiply-Add in Triton

Fused Multiply-Add in Triton

GPU ProgrammingLinear Algebra
Easy

Implement a fused multiply-add (FMA) kernel in Triton. Given a scalar aaa and two 1D float tensors xxx and yyy:

out[i]=a⋅x[i]+y[i]\texttt{out}[i] = a \cdot x[i] + y[i]out[i]=a⋅x[i]+y[i]

Like vector addition this is a pure map, but it introduces two new beats: a scalar parameter passed by value alongside the tensor pointers, and a fused two-input arithmetic expression that the Triton backend lowers to a single hardware FMA instruction per lane.

Loading visualization...

Examples

Input: a = 2.0, x = [1.0, 2.0, 3.0, 4.0], y = [1.0, 1.0, 1.0, 1.0]

Output: [3.0, 5.0, 7.0, 9.0]

Input: a = -1.0, x = [1.0, 2.0, 3.0], y = [10.0, 10.0, 10.0]

Output: [9.0, 8.0, 7.0]

Hint 1

Forward the scalar aaa from the launcher straight into the kernel call. Triton broadcasts a Python float to every lane automatically.

Hint 2

Write the body as a single expression a⋅x+ya \cdot x + ya⋅x+y. Splitting it into a separate multiply and add gives the compiler more freedom but loses the explicit FMA opportunity.

Hint 3

Tail mask discipline is identical to vector add: build one mask at the top, reuse it on both loads and the store.

Requirements

  • Use one Triton program per contiguous tile of the input
  • Express the operation as a single fused a⋅x+ya \cdot x + ya⋅x+y so Triton emits a hardware FMA
  • Mask the tail on every load and store
  • The solve\texttt{solve}solve signature must not change

Constraints

  • 1≤N≤1061 \le N \le 10^61≤N≤106.
  • ∣a∣≤10|a| \le 10∣a∣≤10.
  • All tensors are torch.float32 on cuda.
  • Tolerance: atol=1e-3.
Try Similar Problems
Vector Addition in TritonEasyL2 Vector Norm in TritonEasyGELU in TritonEasyReLU in TritonEasySiLU in TritonEasyScaled Dot-Product Attention in TritonMediumBlock-Pointer Matmul in TritonMediumAutotuned Matrix Multiplication in TritonMediumTiled Transpose in TritonMediumGEMV: Matrix Vector Product in TritonMediumFused Matmul + Bias + ReLU in TritonMediumTiled Matrix Multiplication in TritonMedium

Accepts: number

Accepts: array

Accepts: array

You must run your code first.

Kernel performance

Submit a correct solution to see your kernel performance.

Problems
Loading...
1 / 1