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

Utils and prerequisities for NppRemapKernel implementation #4374

Merged
merged 1 commit into from
Oct 20, 2022

Conversation

szalpal
Copy link
Member

@szalpal szalpal commented Oct 19, 2022

Signed-off-by: szalpal mszolucha@nvidia.com

Category:

New feature (non-breaking change which adds functionality)
Refactoring (Redesign of existing code that doesn't affect functionality)
Other (e.g. Documentation, Tests, Configuration)

Description:

Since the #4365 PR grew significantly in size, I decided to extract parts of it into the separate PR to enhance review quality. This PR includes some utilities I've used for NppRemapKernel implementation. Specifically:

  1. Additional convenient make_tensor_list functions: creating TensorListView from a TensorView (just wrapping it) and form vector<TensorView>. The latter overload is possible, since we changed from contiguous memory pattern to non-contiguous one. The tests are included in tensor_view_test.cc.
  2. contains_v - convenient trait, that checks if a tuple has a given type. Surprisingly, such thing doesn't exist in std...
  3. Small update in tensor_to_mat function. It doesn't need StorageCPU. It just needs, that the memory is CPU-accessible.
  4. Refactoring Remap API and updating documentation.
  5. Utility functions ShapeFromRoi that return TensorShape that can be associated with given Roi. The functions that are already there don't cover the case, when there is no channel dimension. And such situation might happen for 1-channel images - channel dimension doesn't have to exist.

Additional information:

Affected modules and functionalities:

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: N/A

Signed-off-by: szalpal <mszolucha@nvidia.com>
@szalpal
Copy link
Member Author

szalpal commented Oct 19, 2022

!build

@szalpal szalpal marked this pull request as ready for review October 19, 2022 23:27
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6235052]: BUILD STARTED

@szalpal szalpal mentioned this pull request Oct 19, 2022
18 tasks
Comment on lines +484 to +499
/** @{ */
/** @brief Construction from contiguous memory */

TensorListView(std::nullptr_t, const std::vector<TensorShape<DynamicDimensions>> &shapes)
: Base(TensorListShape<DynamicDimensions>(shapes)) {}

template <int other_sample_ndim>
TensorListView(std::nullptr_t, const TensorListShape<other_sample_ndim> &shape)
: Base(shape) {}

template <int other_sample_ndim>
TensorListView(std::nullptr_t, TensorListShape<other_sample_ndim> &&shape)
: Base(std::move(shape)) {}

/** @} */

Copy link
Member Author

Choose a reason for hiding this comment

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

These constructors already exist in static_dim flavour of TensorListView. Here I'm adding them to DynamicDimensions flavour as well.

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6235052]: BUILD PASSED

Comment on lines +142 to +146
auto ridx = ndims;
for (size_t idx = 0; idx < ndims; idx++) {
ret[--ridx] = e[idx];
}
return ret;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You want to reverse the order here, right?

Suggested change
auto ridx = ndims;
for (size_t idx = 0; idx < ndims; idx++) {
ret[--ridx] = e[idx];
}
return ret;
std::reverse(e);
return TensorShape<ndims>(e.begin(), e.end());

this should work, I guess

Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe better:

TensorShape<ndim> ret;
std::reverse_copy(e.begin(), e.end(), ret.begin());
return ret;

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point. Followed up in #4375

namespace detail {

template<typename T, typename Tuple>
struct contains;
Copy link
Contributor

Choose a reason for hiding this comment

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

Tbh. I liked the old name has_type better but it is just a matter of preference, I guess. I know this name was suggested by other reviewer so no point in changing it back and forth :)

@szalpal szalpal merged commit 82e10e3 into NVIDIA:main Oct 20, 2022
@szalpal szalpal mentioned this pull request Oct 20, 2022
18 tasks
@JanuszL JanuszL mentioned this pull request Jan 11, 2023
@szalpal szalpal deleted the remap_kernel_prereq branch February 9, 2024 00:25
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.

4 participants