ML::NN::GPUOps
GPU operations module
Constants
Instance methods
Add bias: output = input + bias (broadcast over batch)
Batched matrix multiply: C[b] = A[b] @ B[b] A: [batch, M, K], B: [batch, K, N], C: [batch, M, N]
Batched matmul with transpose: C[b] = A[b] @ B[b]^T A: [batch, M, K], B: [batch, N, K], C: [batch, M, N]
Conv2D forward: output = conv2d(input, weight) + bias input: [batch, H, W, in_channels] (NHWC format) weight: [out_channels, in_channels, kH, kW] (OIHW format) bias: [out_channels] or nil output: [batch, H_out, W_out, out_channels]
Fused scaled dot-product attention: output = softmax(Q @ K^T / sqrt(d)) @ V Q, K, V: [batch_heads, seq_len, head_dim] Output: [batch_heads, seq_len, head_dim]
Fused attention with tiled optimization (for larger sequences)
Fused LayerNorm + Linear: output = Linear(LayerNorm(input))
Fused LayerNorm + Linear + GELU
LayerNorm forward input: [batch, features] gamma, beta: [features] output: [batch, features]
Linear forward: output = input @ weight^T + bias input: [batch, in_features] weight: [out_features, in_features] bias: [out_features] or nil output: [batch, out_features]
Linear forward with fused GELU activation
Reshape [batch, seq, embed] -> [batch * heads, seq, head_dim]
Reshape [batch * heads, seq, head_dim] -> [batch, seq, embed]
Fused resize + normalize for image preprocessing input: [h, w, 3] HWC in [0,1] output: [3, out_h, out_w] CHW normalized
RMSNorm forward
Apply RoPE to [batch, seq, embed]
Softmax over last dimension input/output: [rows, cols]
Bilinear 2x upsampling (GPU, higher quality)
Nearest neighbor 2x upsampling (GPU) input: [batch, h, w, channels] NHWC output: [batch, h2, w2, channels]