Faster matmul_backward_bias
using coalesced reads and shared memory in the kernel
#221
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This kernel seems to offer a <4x runtime improvement over
matmul_backward_bias_kernel2
on an RTX 2070 Super GPU, runtime comparison shown below:The kernel passes
test_gpt2cu
without any issue, and also the tests indev/cuda/matmul_backward_bias.cu
after increasing the tolerance from 1e-3 to 5e-3: with the tolerence set to 1e-3, the weights printed to the console are very similar to the CPU reference weights, so I am hazarding that this is an acceptable change -- I've seen a tolerance of up to 1e-2 in other parts of the code...In
test_gpt2cu
, the runtime seems to reduce from ~42 ms/iter to ~39 ms/iter (again, using an RTX 2070 Super GPU).I've included some comments at the start of the kernel to explain the philosophy behind it.
Happy to receive feedback to improve the PR, sorry if I've missed something obvious.