Neural Network Activation Functions #
GPU kernels for common activation functions using the ShaderM monad. All operations are element-wise on tensors.
Configuration for activation function kernels
Instances For
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Number of workgroups needed
Equations
- config.numWorkgroups = (config.size + config.workgroupSize - 1) / config.workgroupSize
Instances For
ReLU activation kernel: f(x) = max(0, x)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Leaky ReLU kernel: f(x) = max(alpha * x, x)
Equations
- One or more equations did not get rendered due to their size.
Instances For
GELU activation kernel (approximate)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Sigmoid activation kernel: f(x) = 1 / (1 + exp(-x))
Equations
- One or more equations did not get rendered due to their size.
Instances For
Tanh activation kernel: f(x) = tanh(x)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Swish/SiLU activation kernel: f(x) = x * sigmoid(x)
Equations
- One or more equations did not get rendered due to their size.
Instances For
ELU activation kernel: f(x) = x if x > 0 else alpha * (exp(x) - 1)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Softplus activation kernel: f(x) = log(1 + exp(x))
Equations
- One or more equations did not get rendered due to their size.
Instances For
Mish activation kernel: f(x) = x * tanh(softplus(x))
Equations
- One or more equations did not get rendered due to their size.
Instances For
Softmax activation kernel (simplified version for demo) Note: This is a simplified implementation. Production softmax requires multi-pass reduction for finding max and sum across the entire array.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Generate WGSL shader for ReLU
Equations
- Hesper.NN.Activation.generateReLUShader config = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.reluKernel config)
Instances For
Generate WGSL shader for Leaky ReLU
Equations
- Hesper.NN.Activation.generateLeakyReLUShader config alpha = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.leakyReluKernel config alpha)
Instances For
Generate WGSL shader for GELU
Equations
- Hesper.NN.Activation.generateGELUShader config = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.geluKernel config)
Instances For
Generate WGSL shader for Sigmoid
Equations
- Hesper.NN.Activation.generateSigmoidShader config = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.sigmoidKernel config)
Instances For
Generate WGSL shader for Tanh
Equations
- Hesper.NN.Activation.generateTanhShader config = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.tanhKernel config)
Instances For
Generate WGSL shader for Swish/SiLU
Equations
- Hesper.NN.Activation.generateSwishShader config = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.swishKernel config)
Instances For
Generate WGSL shader for ELU
Equations
- Hesper.NN.Activation.generateELUShader config alpha = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.eluKernel config alpha)
Instances For
Generate WGSL shader for Softplus
Equations
- Hesper.NN.Activation.generateSoftplusShader config = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.softplusKernel config)
Instances For
Generate WGSL shader for Mish
Equations
- Hesper.NN.Activation.generateMishShader config = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.mishKernel config)
Instances For
Generate WGSL shader for Softmax (simplified version)
Equations
- Hesper.NN.Activation.generateSoftmaxShader config = Hesper.WGSL.CodeGen.generateWGSL "main" { x := config.workgroupSize } [] [] (Hesper.NN.Activation.softmaxKernel config)