Skip to content
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

Merged
merged 2 commits into from
Jun 18, 2021
Merged

Add split shape utility #3062

merged 2 commits into from
Jun 18, 2021

Conversation

jantonguirao
Copy link
Contributor

@jantonguirao jantonguirao commented Jun 16, 2021

Signed-off-by: Joaquin Anton janton@nvidia.com

Why we need this PR?

Pick one, remove the rest

  • It adds a new internal utility needed to split a big shape into blocks for parallelization.

What happened in this PR?

Fill relevant points, put NA otherwise. Replace anything inside []

  • What solution was applied:
    Introduced a utility function that provides per-dimension split factor given a shape, a desired number of blocks and a minimum practical block size.
  • Affected modules and functionalities:
    NA
  • Key points relevant for the review:
    split_shape implementation, tests (did I miss any meaningful testcase?)
  • Validation and testing:
    Unit tested
  • Documentation (including examples):
    Doxygen

JIRA TASK: [DALI-2128]

@jantonguirao jantonguirao marked this pull request as ready for review June 17, 2021 07:02
@banasraf banasraf self-assigned this Jun 17, 2021
/**
* @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
Copy link
Contributor

@mzient mzient Jun 17, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* 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

Comment on lines +31 to +33
template <typename SplitFactor, typename Shape>
void split_shape(SplitFactor& split_factor, const Shape& in_shape, int min_nblocks = 8,
int min_sz = (16 << 10)) {
Copy link
Contributor

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:

  1. If we can divide the shape into a number of threads that's a multiple of thread count, then we need no more partitions.
  2. 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).

Copy link
Contributor Author

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)

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Comment on lines 34 to 35
int ndim = in_shape.size();
assert(static_cast<int>(split_factor.size()) == ndim);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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);

for (int d = 0; d < ndim; d++)
split_factor[d] = 1;

int64_t vol = volume(in_shape.begin(), in_shape.end());
Copy link
Contributor

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.

Suggested change
int64_t vol = volume(in_shape.begin(), in_shape.end());
int64_t vol = volume(in_shape);

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick ;)

Suggested change
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>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2484608]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2484608]: BUILD PASSED

@jantonguirao jantonguirao merged commit ae2b242 into NVIDIA:main Jun 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants