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

Reductions: min, max #2342

Merged
merged 15 commits into from
Oct 13, 2020
Merged

Reductions: min, max #2342

merged 15 commits into from
Oct 13, 2020

Conversation

awolant
Copy link
Contributor

@awolant awolant commented Oct 9, 2020

Why we need this PR?

  • It adds new feature needed because of TLT

What happened in this PR?

  • What solution was applied:
    Added CPU operator for reductions: sum, min, max
  • Affected modules and functionalities:
    Operators, Kernels
  • Key points relevant for the review:
    Operator implementation
  • Validation and testing:
    Added python test to compare against NumPy
  • Documentation (including examples):
    Added doc strings

JIRA TASK: [DALI-1621]

Signed-off-by: Albert Wolant <awolant@nvidia.com>
Signed-off-by: Albert Wolant <awolant@nvidia.com>
Signed-off-by: Albert Wolant <awolant@nvidia.com>
Signed-off-by: Albert Wolant <awolant@nvidia.com>
Signed-off-by: Albert Wolant <awolant@nvidia.com>
Signed-off-by: Albert Wolant <awolant@nvidia.com>
Signed-off-by: Albert Wolant <awolant@nvidia.com>
@awolant
Copy link
Contributor Author

awolant commented Oct 9, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1688761]: BUILD STARTED


DALI_SCHEMA(ReduceBase)
.AddOptionalArg(
"axes",
Copy link
Contributor

Choose a reason for hiding this comment

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

Also support "axis_names", perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For sure. How about doing that in next PR? This is nice extension of the API, but right now this op can already be useful as it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine with me. There are already several operators using it (SliceAttr family, Erase,...). Maybe it'd be good to make a PR that extracts that to AxesAttr or something like this, so we reuse the implementation and the arg documentation.

dali/operators/generic/reduce/reduce.cc Outdated Show resolved Hide resolved
dali/operators/generic/reduce/reduce.h Outdated Show resolved Hide resolved
dali/operators/generic/reduce/reduce.h Outdated Show resolved Hide resolved
dali/operators/generic/reduce/reduce.h Outdated Show resolved Hide resolved
dali/operators/generic/reduce/reduce.h Outdated Show resolved Hide resolved
dali/operators/generic/reduce/reduce.h Outdated Show resolved Hide resolved
dali/operators/generic/reduce/reduce.h Outdated Show resolved Hide resolved
dali/operators/generic/reduce/reduce.h Outdated Show resolved Hide resolved
dali/operators/generic/reduce/reduce.h Outdated Show resolved Hide resolved
dali/test/python/test_operator_reduce.py Outdated Show resolved Hide resolved
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1688761]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1688761]: BUILD PASSED

Signed-off-by: Albert Wolant <awolant@nvidia.com>
Signed-off-by: Albert Wolant <awolant@nvidia.com>
@awolant
Copy link
Contributor Author

awolant commented Oct 10, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1691238]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1691238]: BUILD FAILED

Signed-off-by: Albert Wolant <awolant@nvidia.com>
pipe = Pipeline(batch_size=batch_size, num_threads=4, device_id=0)

with pipe:
input = fn.external_source(source = get_batch)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you just:

Suggested change
input = fn.external_source(source = get_batch)
input = fn.external_source(source = batch_fn)

Copy link
Contributor Author

@awolant awolant Oct 12, 2020

Choose a reason for hiding this comment

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

No. ExternalSource API for now does not work with some callables. I tried method and partial and it failed no a check inside. I think it could be reworked but not in this PR. For now I just wrapped it with ad hoc regular function so it works.

I put a comment about it.

Signed-off-by: Albert Wolant <awolant@nvidia.com>
@awolant
Copy link
Contributor Author

awolant commented Oct 12, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1693996]: BUILD STARTED

@awolant awolant changed the title CPU reductions: sum, min, max Reductions: sum, min, max Oct 12, 2020
template class SumGPU<uint16_t, uint16_t>;
template class SumGPU<uint8_t, uint8_t>;


Copy link
Contributor

@jantonguirao jantonguirao Oct 12, 2020

Choose a reason for hiding this comment

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

One crazy idea, if we plan to have many reductions that follow the same pattern we could have a:

#define REDUCTION_IMPL(Kernel, Impl)  \
  template <typename Out, typename In> \
  class Kernel<Out, In>::Impl : public Impl<Out, In> { \
  
  ...

Basically it'd cover all the repeated code (including template instantiation) and later you just do:

REDUCTION_IMPL(MinGPU, reduce_impl::MinImplGPU);
REDUCTION_IMPL(MaxGPU, reduce_impl::MaxImplGPU);
...

I have mixed feeling about having so much inside a macro, but on the other hand, now there's a lot of boiler-plate here. Second opinion maybe? @mzient ?

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1693996]: BUILD PASSED

Signed-off-by: Albert Wolant <awolant@nvidia.com>
@awolant awolant changed the title Reductions: sum, min, max Reductions: min, max Oct 13, 2020
Signed-off-by: Albert Wolant <awolant@nvidia.com>
Signed-off-by: Albert Wolant <awolant@nvidia.com>
@awolant
Copy link
Contributor Author

awolant commented Oct 13, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697300]: BUILD STARTED

@@ -1263,6 +1263,18 @@ class SumImplGPU : public ReduceImplGPU<Out, In, default_sum_acc_t<Out, In>, Sum
reductions::sum GetReduction() const { return {}; }
};

template <typename Out, typename In>
class MinImplGPU : public ReduceImplGPU<Out, In, default_sum_acc_t<Out, In>, MinImplGPU<Out, In>> {
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
class MinImplGPU : public ReduceImplGPU<Out, In, default_sum_acc_t<Out, In>, MinImplGPU<Out, In>> {
class MinImplGPU : public ReduceImplGPU<Out, In, In>, MinImplGPU<Out, In>> {

Signed-off-by: Albert Wolant <awolant@nvidia.com>
@awolant
Copy link
Contributor Author

awolant commented Oct 13, 2020

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697500]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697500]: BUILD PASSED

@NVIDIA NVIDIA deleted a comment from dali-automaton Oct 13, 2020
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1697500]: BUILD PASSED

@awolant awolant merged commit b28e866 into NVIDIA:master Oct 13, 2020
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

5 participants