-
Notifications
You must be signed in to change notification settings - Fork 634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overdrive cpp extension #1299
Merged
Merged
Overdrive cpp extension #1299
Changes from 3 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
005ced9
overdrive cpp ext
bhargavkathivarapu 2287893
flake8 fix
bhargavkathivarapu fb89341
JIT issue fix
bhargavkathivarapu 70ebbe5
Use parallel_for on CPU
bhargavkathivarapu d05514c
Minor fix
bhargavkathivarapu 136b266
include torch.h for parallel_for
bhargavkathivarapu 1e8d3f0
Merge remote-tracking branch 'upstream/master' into overdrive-new
bhargavkathivarapu File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ set( | |
sox/effects_chain.cpp | ||
sox/types.cpp | ||
lfilter.cpp | ||
overdrive.cpp | ||
) | ||
|
||
if(BUILD_TRANSDUCER) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include <torch/script.h> | ||
|
||
namespace { | ||
|
||
template <typename scalar_t> | ||
void overdrive_cpu_kernel( | ||
at::TensorAccessor<scalar_t, 2> waveform_accessor, | ||
at::TensorAccessor<scalar_t, 2> temp_accessor, | ||
at::TensorAccessor<scalar_t, 1> last_in_accessor, | ||
at::TensorAccessor<scalar_t, 1> last_out_accessor, | ||
at::TensorAccessor<scalar_t, 2> output_waveform_accessor) { | ||
int64_t n_frames = waveform_accessor.size(1); | ||
int64_t n_channels = waveform_accessor.size(0); | ||
|
||
for (int64_t i_channel = 0; i_channel < n_channels; ++i_channel) { | ||
for (int64_t i_frame = 0; i_frame < n_frames; ++i_frame) { | ||
last_out_accessor[i_channel] = temp_accessor[i_channel][i_frame] - | ||
last_in_accessor[i_channel] + 0.995 * last_out_accessor[i_channel]; | ||
last_in_accessor[i_channel] = temp_accessor[i_channel][i_frame]; | ||
output_waveform_accessor[i_channel][i_frame] = | ||
waveform_accessor[i_channel][i_frame] * 0.5 + | ||
last_out_accessor[i_channel] * 0.75; | ||
} | ||
} | ||
} | ||
|
||
void overdrive_core_loop_cpu( | ||
at::Tensor& waveform, | ||
at::Tensor& temp, | ||
at::Tensor& last_in, | ||
at::Tensor& last_out, | ||
at::Tensor& output_waveform) { | ||
AT_DISPATCH_FLOATING_TYPES(waveform.scalar_type(), "overdrive_cpu", ([&] { | ||
overdrive_cpu_kernel<scalar_t>( | ||
waveform.accessor<scalar_t, 2>(), | ||
temp.accessor<scalar_t, 2>(), | ||
last_in.accessor<scalar_t, 1>(), | ||
last_out.accessor<scalar_t, 1>(), | ||
output_waveform.accessor<scalar_t, 2>()); | ||
})); | ||
} | ||
|
||
} // namespace | ||
|
||
// Note: We want to avoid using "catch-all" kernel. | ||
// The following registration should be replaced with CPU specific registration. | ||
TORCH_LIBRARY_FRAGMENT(torchaudio, m) { | ||
m.def("torchaudio::_overdrive_core_loop", &overdrive_core_loop_cpu); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can get rid of these comments now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mthrok sure will remove them.
Also I will try to implement the
parallel_for
as mentioned by @cpuhrsch in the old PR comments ( #580 ).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bhargavkathivarapu sounds good. Could you try measure the performance improvement?
Something like the following and change the shape of tensor to variety of shapes.
If
numactl
is missing, you can install it withsudo apt-get install -y numactl
on Ubuntu.