-
Notifications
You must be signed in to change notification settings - Fork 615
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
Add ScatterGatherCPU and rework Copy op to batch processing #3266
Conversation
* ScatterGatherCPU * Copy with batch processing * Adjust ElementExtract to changes Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
!build |
CI MESSAGE: [2807037]: BUILD STARTED |
CI MESSAGE: [2807037]: BUILD PASSED |
dali/kernels/common/scatter_gather.h
Outdated
* @param reset - if true, calls Reset after processing is over | ||
*/ | ||
template <typename ExecutionEngine> | ||
DLL_PUBLIC void Run(ExecutionEngine &exec_engine, bool reset = true) { |
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.
DLL_PUBLIC void Run(ExecutionEngine &exec_engine, bool reset = true) { | |
void Run(ExecutionEngine &exec_engine, bool reset = true) { |
Not needed on an inline function, I guess?
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.
done
dali/kernels/common/scatter_gather.h
Outdated
/** | ||
* @brief Reserves GPU memory for the description of the blocks. | ||
*/ | ||
void ReserveGPUBlocks(); | ||
|
||
size_t max_size_per_block_ = kDefaultBlockSize; | ||
std::vector<CopyRange> blocks_; | ||
kernels::memory::KernelUniquePtr<CopyRange> blocks_dev_; |
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.
When you're at it - perhaps use DeviceBuffer<CopyRange>
? Then you could allocate and copy it with simple blocks_dev_.from_host(blocks_);
- it would handle buffer growth and all other stuff.
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.
done
dali/kernels/common/scatter_gather.h
Outdated
Coalesce(); | ||
for (auto &r : ranges_) { | ||
exec_engine.AddWork([=](int thread_id) { std::memcpy(r.dst, r.src, r.size); }, r.size); | ||
} | ||
exec_engine.RunAll(); |
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 method of doing things here is quite counterproductive. If you really want to leverage parallelism, then after coalescing you should split the buffers into suitably-sized blocks. Otherwise coalescing decreases parallelism.
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 missed the make blocks and thought that coalesce already does split again.
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.
Now it can split either for target number of blocks or the size.
AllocType alloc = | ||
std::is_same<TypeParam, ScatterGatherCPU>::value ? AllocType::Host : AllocType::GPU; | ||
|
||
auto in_ptr = kernels::memory::alloc_unique<char>(alloc, in.size()); | ||
auto out_ptr = kernels::memory::alloc_unique<char>(alloc, out.size()); |
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 that so much of this test is guarded with if-else that we'd be better off having two tests - one for GPU, one for CPU. Note that kernels::memory
is slated for removal and there will be no run-time selection of memory kind!
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.
Moved to generic functions.
kernels::ScatterGatherGPU> scatter_gather_; | ||
// 1 MB per block for CPU, 256 kB per block for GPU | ||
static constexpr size_t kMaxSizePerBlock = | ||
std::is_same<Backend, CPUBackend>::value ? 1 << 20 : 1 << 18; |
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.
Why would we like to have larger blocks on CPU? Have you benchmarked it or is it just guessing?
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.
Just guessing. I think I will go with trying at least number of threads * 3
tasks, and for the small buffer without the thread pool.
template <typename ExecutionEngine> | ||
DLL_PUBLIC void Run(ExecutionEngine &exec_engine, bool reset = true) { | ||
Coalesce(); | ||
for (auto &r : ranges_) { |
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.
Optimization opportunity: if the total size is small enough, it's better to use sequential execution engine and avoid the overhead of synchronization.
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.
Done
layout=layout) | ||
if dev == "gpu": | ||
input = input.gpu() | ||
output = fn.copy(input) |
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.
Why do we even have such an operator!?
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.
Don't ask me.
Signed-off-by: Krzysztof Lecki <klecki@nvidia.com>
!build |
CI MESSAGE: [2823621]: BUILD STARTED |
CI MESSAGE: [2823621]: BUILD PASSED |
Description
What happened in this PR
Copy
operator with batch processing using ScatterGatherSigned-off-by: Krzysztof Lecki klecki@nvidia.com
Additional information
Affected modules and functionalities:
ScatterGather, Copy, ElementExtract
Key points relevant for the review:
Block size for CPU copy?
Checklist
Tests
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-2258