perf: implement Conv1D with im2col and GEMM #1597
Merged
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 PR implements Conv1D operation on CPU with im2col and GEMM.
It brings upto 16x speedup. See test results below, they show
total duration spent on 2 Conv1D layers of
whisper-tiny
encoder.On MacBook Pro with M2 Pro (10 core,
GemmBackend=Accelerate
):On Android (Samsung Galaxy S21,
GemmBackend=RUY
):The test results above are measured when
batch_size=1
, but thespeedup
ratio isapproximately same when tested with
batch_size=4
(on MacBook):EDIT: I want to add some information about memory usage of this implementation.
Previous implementation applies
Transpose
toinput
andweight
, and if I am not wrong it allocates same size ofinput
andweight
.This one creates temporary
im2col
tensor havingbatch_size * (in_channels * kernel_size) * out_length
. Hence it allocates slightly more than previous implementation:Here are example numbers for
whisper-tiny
(out_channel = 384; kernel_size =3
):