-
Notifications
You must be signed in to change notification settings - Fork 610
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 split shape utility #3062
Add split shape utility #3062
Conversation
17f7922
to
294ee75
Compare
dali/kernels/common/split_shape.h
Outdated
/** | ||
* @brief Utility to divide a bigger shape into smaller blocks, given a desired number of blocks | ||
* and a minimum practical block size. | ||
* The algorithm start splitting from the outtermost dimension until the number of blocks |
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.
* The algorithm start splitting from the outtermost dimension until the number of blocks | |
* The algorithm starts splitting from the outermost dimension until the number of blocks |
template <typename SplitFactor, typename Shape> | ||
void split_shape(SplitFactor& split_factor, const Shape& in_shape, int min_nblocks = 8, | ||
int min_sz = (16 << 10)) { |
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.
If this is intended for threading, then there are several issues:
- If we can divide the shape into a number of threads that's a multiple of thread count, then we need no more partitions.
- We should avoid uneven splits unless there's a good chance that it will be masked by the large number of blocks (much more than threads).
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.
My idea is that the caller will specify a suitable value for min_nblocks (a multiple of the number of threads)
294ee75
to
9676f7c
Compare
Signed-off-by: Joaquin Anton <janton@nvidia.com>
9676f7c
to
b57f9e4
Compare
dali/kernels/common/split_shape.h
Outdated
int ndim = in_shape.size(); | ||
assert(static_cast<int>(split_factor.size()) == ndim); |
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.
int ndim = in_shape.size(); | |
assert(static_cast<int>(split_factor.size()) == ndim); | |
int ndim = dali::size(in_shape); | |
assert(static_cast<int>(dali::size(size) == ndim); |
dali/kernels/common/split_shape.h
Outdated
for (int d = 0; d < ndim; d++) | ||
split_factor[d] = 1; | ||
|
||
int64_t vol = volume(in_shape.begin(), in_shape.end()); |
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.
If it's iterable, volume should know what to do.
int64_t vol = volume(in_shape.begin(), in_shape.end()); | |
int64_t vol = volume(in_shape); |
aa6041b
to
648d04d
Compare
TensorShape<> sh(10, 10, 10); | ||
std::vector<int> split_factor = {1, 1, 1}; | ||
|
||
split_shape(split_factor, sh, 3, 1000); // minimum volume is bigger than the input volume |
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.
Nitpick ;)
split_shape(split_factor, sh, 3, 1000); // minimum volume is bigger than the input volume | |
split_shape(split_factor, sh, 3, 1000); // minimum volume is equal than the input volume |
Signed-off-by: Joaquin Anton <janton@nvidia.com>
648d04d
to
66717ff
Compare
!build |
CI MESSAGE: [2484608]: BUILD STARTED |
CI MESSAGE: [2484608]: BUILD PASSED |
Signed-off-by: Joaquin Anton janton@nvidia.com
Why we need this PR?
Pick one, remove the rest
What happened in this PR?
Fill relevant points, put NA otherwise. Replace anything inside []
Introduced a utility function that provides per-dimension split factor given a shape, a desired number of blocks and a minimum practical block size.
NA
split_shape implementation, tests (did I miss any meaningful testcase?)
Unit tested
Doxygen
JIRA TASK: [DALI-2128]