-
Notifications
You must be signed in to change notification settings - Fork 630
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
Remove Scratchpad from KernelManager #3678
Conversation
dali/kernels/kernel_manager.h
Outdated
auto *old_scratchpad = context.scratchpad; | ||
context.scratchpad = &scratchpad; | ||
inst.get<Kernel>().Run(context, std::forward<OutInArgs>(out_in_args)...); | ||
context.scratchpad = old_scratchpad; |
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.
auto *old_scratchpad = context.scratchpad; | |
context.scratchpad = &scratchpad; | |
inst.get<Kernel>().Run(context, std::forward<OutInArgs>(out_in_args)...); | |
context.scratchpad = old_scratchpad; | |
context.scratchpad = &scratchpad; | |
inst.get<Kernel>().Run(context, std::forward<OutInArgs>(out_in_args)...); | |
context.scratchpad = nullptr; |
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.
👍
cd37436
to
12e4ab6
Compare
…ead_idx from KernelManager API. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
12e4ab6
to
f028d50
Compare
…rnelManager::Run exits, even if the kernel throws. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
struct CallAtExit { | ||
explicit CallAtExit(Callable &&c) : callable(std::move(c)) {} | ||
~CallAtExit() { | ||
callable(); | ||
} | ||
Callable callable; | ||
}; | ||
|
||
template <typename Callable> | ||
CallAtExit<Callable> AtExit(Callable &&c) { | ||
return CallAtExit<Callable>(std::forward<Callable>(c)); | ||
} |
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.
This has been moved to a separate header.
include/dali/core/call_at_exit.h
Outdated
template <typename Callable> | ||
struct CallAtExit { | ||
explicit CallAtExit(Callable &&c) : callable(std::move(c)) {} | ||
~CallAtExit() noexcept(false) { | ||
callable(); | ||
} | ||
Callable callable; | ||
}; | ||
|
||
} // namespace detail | ||
|
||
template <typename Callable> | ||
detail::CallAtExit<Callable> AtBlockExit(Callable &&c) { | ||
return detail::CallAtExit<Callable>(std::forward<Callable>(c)); | ||
} |
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.
Copied from default_resources.cc
@@ -204,8 +204,7 @@ bool SpectrogramImplCpu<time_major>::SetupImpl(std::vector<OutputDesc> &out_desc | |||
if (!w.raw_data()) w.set_pinned(false); | |||
} | |||
|
|||
kmgr_window_.Initialize<WindowKernel>(); |
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.
This call was unnecessary even before this PR, right?
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.
Yes, it's done implicitly in Resize
CI MESSAGE: [3975335]: BUILD STARTED |
CI MESSAGE: [3975335]: BUILD PASSED |
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.
LGTM, with some minor comments
kmgr_.Initialize<Kernel>(); | ||
kmgr_.Resize<Kernel>(1, 1); | ||
kmgr_.Resize<Kernel>(1); |
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.
Remove Initialize?
inst.get<Kernel>().Run(context, std::forward<OutInArgs>(out_in_args)...); | ||
} else { | ||
inst.get<Kernel>().Run(context, std::forward<OutInArgs>(out_in_args)...); |
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.
inst.get<Kernel>().Run(context, std::forward<OutInArgs>(out_in_args)...); | |
} else { | |
inst.get<Kernel>().Run(context, std::forward<OutInArgs>(out_in_args)...); | |
} | |
inst.get<Kernel>().Run(context, std::forward<OutInArgs>(out_in_args)...); |
how about that?
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.
This finally
would go out of scope too early.
@@ -250,7 +249,7 @@ TEST_P(Dct1DGpuPerfTest, DISABLED_PerfTest) { | |||
ctx.gpu.stream = 0; | |||
KernelManager kmgr; | |||
kmgr.Initialize<Kernel>(); | |||
kmgr.Resize<Kernel>(1, 1); | |||
kmgr.Resize<Kernel>(1); |
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.
remove initialize?
@@ -81,7 +80,7 @@ bool MelFilterBank<CPUBackend>::SetupImpl(std::vector<OutputDesc> &output_desc, | |||
TYPE_SWITCH(input.type(), type2id, T, MEL_FBANK_SUPPORTED_TYPES, ( | |||
using MelFilterBankKernel = kernels::audio::MelFilterBankCpu<T>; | |||
kmgr_.Initialize<MelFilterBankKernel>(); | |||
kmgr_.Resize<MelFilterBankKernel>(nthreads, nsamples); | |||
kmgr_.Resize<MelFilterBankKernel>(nsamples); |
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.
remove initialize
@@ -52,7 +52,7 @@ std::vector<OutputDesc> SetupKernel(kernels::KernelManager &kmgr, kernels::Kerne | |||
span<const MFCC<GPUBackend>::DctArgs> args, int axis) { | |||
using Kernel = kernels::signal::dct::Dct1DGpu<T>; | |||
kmgr.Initialize<Kernel>(); | |||
kmgr.Resize<Kernel>(1, 1); | |||
kmgr.Resize<Kernel>(1); |
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.
remove initialize
@@ -24,7 +24,7 @@ class JpegCompressionDistortionGPU : public JpegCompressionDistortion<GPUBackend | |||
public: | |||
explicit JpegCompressionDistortionGPU(const OpSpec &spec) : JpegCompressionDistortion(spec) { | |||
kmgr_.Initialize<JpegDistortionKernel>(); | |||
kmgr_.Resize<JpegDistortionKernel>(1, 1); | |||
kmgr_.Resize<JpegDistortionKernel>(1); |
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.
remove initialize
|
||
TYPE_SWITCH(input.type(), type2id, T, (float), ( | ||
using ToDbKernel = kernels::signal::ToDecibelsCpu<T>; | ||
kmgr_.Initialize<ToDbKernel>(); | ||
kmgr_.Resize<ToDbKernel>(nthreads, nsamples); | ||
kmgr_.Resize<ToDbKernel>(nsamples); |
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.
remove initialize
|
||
// Other types not supported for now | ||
using InputType = float; | ||
using OutputType = float; | ||
VALUE_SWITCH(in_shape.sample_dim(), Dims, FFT_SUPPORTED_NDIMS, ( | ||
using FftKernel = kernels::signal::fft::Fft1DCpu<OutputType, InputType, Dims>; | ||
kmgr_.Initialize<FftKernel>(); | ||
kmgr_.Resize<FftKernel>(nthreads, nsamples); | ||
kmgr_.Resize<FftKernel>(nsamples); |
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.
remove initialize
@@ -204,8 +204,7 @@ bool SpectrogramImplCpu<time_major>::SetupImpl(std::vector<OutputDesc> &out_desc | |||
if (!w.raw_data()) w.set_pinned(false); | |||
} | |||
|
|||
kmgr_window_.Initialize<WindowKernel>(); |
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.
Yes, it's done implicitly in Resize
include/dali/core/call_at_exit.h
Outdated
} // namespace detail | ||
|
||
template <typename Callable> | ||
detail::CallAtExit<Callable> AtBlockExit(Callable &&c) { |
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.
detail::CallAtExit<Callable> AtBlockExit(Callable &&c) { | |
detail::CallAtExit<Callable> AtScopeExit(Callable &&c) { |
would be more understandable, I think
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
CI MESSAGE: [3976332]: BUILD STARTED |
CI MESSAGE: [3976332]: BUILD PASSED |
* Remove ScratchpadAllocator from KernelManager. * Remove num_threads/thread_idx from KernelManager API. * Move CallAtExit to a separate header; rename AtExit to AtScopeExit. * Remove redundant calls to KernelManager::Initialize. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
* Remove ScratchpadAllocator from KernelManager. * Remove num_threads/thread_idx from KernelManager API. * Move CallAtExit to a separate header; rename AtExit to AtScopeExit. * Remove redundant calls to KernelManager::Initialize. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
* Remove ScratchpadAllocator from KernelManager. * Remove num_threads/thread_idx from KernelManager API. * Move CallAtExit to a separate header; rename AtExit to AtScopeExit. * Remove redundant calls to KernelManager::Initialize. Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
A follow-up for #3670
Category:
Refactoring (Redesign of existing code that doesn't affect functionality)
Description:
After dropping the use of preallocated scratchpad in KernelManager, it is quite pointless to keep ScratchpadAllocator instances in it - also, passing thread_idx to
Run
is no longer necessary, since it was only used for indexing scratchpads. As such, this PR removes those obsolete pieces.Additional information:
Affected modules and functionalities:
Key points relevant for the review:
Checklist
Tests
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-2449