Compute softmax over the entire input vector of N float32 values on the GPU.
yi=∑j=0N−1exjexiHere, x is the input vector, y is the probability vector, N is its length, and i and j index its elements. The normalization includes every element, not a separate group for each thread block. Results must remain valid for large positive or negative inputs.
Write all N probabilities into the preallocated float32 output device buffer, preserving their order and leaving the input unchanged. The function returns no value.
Input: input = [1, 2, 3]
Output: [0.090031, 0.244728, 0.665241]
Explanation: The largest score receives the largest probability, and the three probabilities sum to one.
Input: input = [1, -2, 3, -4]
Output: [0.118405, 0.005895, 0.874902, 0.000798]
Subtracting a common maximum keeps exponential arguments nonpositive.
A grid-stride loop can cover a vector longer than a thread block.
Block-wide reductions require every participating thread to reach their barriers.
Accepts: array
Submit a correct solution to see your kernel performance.
Compute softmax over the entire input vector of N float32 values on the GPU.
yi=∑j=0N−1exjexiHere, x is the input vector, y is the probability vector, N is its length, and i and j index its elements. The normalization includes every element, not a separate group for each thread block. Results must remain valid for large positive or negative inputs.
Write all N probabilities into the preallocated float32 output device buffer, preserving their order and leaving the input unchanged. The function returns no value.
Input: input = [1, 2, 3]
Output: [0.090031, 0.244728, 0.665241]
Explanation: The largest score receives the largest probability, and the three probabilities sum to one.
Input: input = [1, -2, 3, -4]
Output: [0.118405, 0.005895, 0.874902, 0.000798]
Subtracting a common maximum keeps exponential arguments nonpositive.
A grid-stride loop can cover a vector longer than a thread block.
Block-wide reductions require every participating thread to reach their barriers.
Accepts: array
Submit a correct solution to see your kernel performance.