Implement inverted dropout on the GPU using an externally provided binary mask. For each element of the input array:
output[i]=1−pinput[i]⋅mask[i]The mask buffer is a device array of 0 or 1 values: a 1 keeps the activation, a 0 drops it. The scalar p∈[0,1) is the dropout probability and is passed by value to solve.
The 1−p1 factor is the inverted-dropout rescale: it keeps the expected value of each kept activation equal to the original input, so no rescaling is needed at inference time.
Input, mask, and output buffers are device pointers owned by the harness. The output array has the same length as the input.
Input: input = [1, 2, 3, 4], mask = [1, 0, 1, 0], p = 0.5
Output: [2.0, 0.0, 6.0, 0.0]
Kept elements are multiplied by 1/(1−0.5)=2; dropped elements become 0.
Input: input = [0.5, 1.0, 1.5, 2.0], mask = [1, 1, 0, 1], p = 0.25
Output: [0.6667, 1.3333, 0.0, 2.6667]
Each kept element is scaled by 1/0.75≈1.3333.
Compute the scale 1.0f / (1.0f - p) once per thread before writing to output[idx].
The mask is supplied externally as a device array of 0 or 1 floats. You do not need any random number generation inside the kernel.
A single multiply chain works: output[idx] = input[idx] * mask[idx] * scale.
Accepts: array
Accepts: array
Accepts: number
Submit a correct solution to see your kernel performance.
Implement inverted dropout on the GPU using an externally provided binary mask. For each element of the input array:
output[i]=1−pinput[i]⋅mask[i]The mask buffer is a device array of 0 or 1 values: a 1 keeps the activation, a 0 drops it. The scalar p∈[0,1) is the dropout probability and is passed by value to solve.
The 1−p1 factor is the inverted-dropout rescale: it keeps the expected value of each kept activation equal to the original input, so no rescaling is needed at inference time.
Input, mask, and output buffers are device pointers owned by the harness. The output array has the same length as the input.
Input: input = [1, 2, 3, 4], mask = [1, 0, 1, 0], p = 0.5
Output: [2.0, 0.0, 6.0, 0.0]
Kept elements are multiplied by 1/(1−0.5)=2; dropped elements become 0.
Input: input = [0.5, 1.0, 1.5, 2.0], mask = [1, 1, 0, 1], p = 0.25
Output: [0.6667, 1.3333, 0.0, 2.6667]
Each kept element is scaled by 1/0.75≈1.3333.
Compute the scale 1.0f / (1.0f - p) once per thread before writing to output[idx].
The mask is supplied externally as a device array of 0 or 1 floats. You do not need any random number generation inside the kernel.
A single multiply chain works: output[idx] = input[idx] * mask[idx] * scale.
Accepts: array
Accepts: array
Accepts: number
Submit a correct solution to see your kernel performance.