Tensara Logo

tensara

Matrix Multiplication with Swish Activation

MEDIUM

Perform matrix multiplication followed by Swish activation and scaling:

output=scaling_factor(inputweightT+bias)σ((inputweightT+bias))\text{output} = \text{scaling\_factor} \cdot (\text{input} \cdot \text{weight}^T + \text{bias}) \cdot \sigma((\text{input} \cdot \text{weight}^T + \text{bias}))

where σ(x)\sigma(x) is the sigmoid function:

σ(x)=11+ex\sigma(x) = \frac{1}{1 + e^{-x}}

The operation consists of three main steps:

  1. Linear transformation: z=inputweightT+biasz = \text{input} \cdot \text{weight}^T + \text{bias}
  2. Swish activation: swish(z)=zσ(z)\text{swish}(z) = z \cdot \sigma(z)
  3. Scaling: output=scaling_factorswish(z)\text{output} = \text{scaling\_factor} \cdot \text{swish}(z)

Input:

  • Matrix input_matrix of size batch_size×in_features\text{batch\_size} \times \text{in\_features}
  • Matrix weight_matrix of size out_features×in_features\text{out\_features} \times \text{in\_features}
  • Vector bias of size out_features\text{out\_features}
  • Scalar scaling_factor for final scaling

Output:

  • Matrix output of size batch_size×out_features\text{batch\_size} \times \text{out\_features}

Notes:

  • All matrices are stored in row-major order
  • This problem is adapted from KernelBench

GPU Type

Language

Loading...

Loading editor...

CUDA C++ environment

Sample Run Results

Hit "Run" to test your code with sample inputs

Desktop Required for Code Submission

For the best coding experience, please switch to a desktop device to write and submit your solution.