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

Enable named Slice arguments: start/rel_start, end/rel_end, shape/rel_shape #2625

Merged
merged 11 commits into from
Feb 9, 2021

Conversation

jantonguirao
Copy link
Contributor

@jantonguirao jantonguirao commented Jan 21, 2021

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

Why we need this PR?

  • Refactoring to improve usability of Slice operator

What happened in this PR?

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

  • What solution was applied:
    Introduced named arguments start, rel_start, end, rel_end, shape, rel_shape to define the slice parameters instead of the regular (positional) inputs anchor and shape
  • Affected modules and functionalities:
    Slice, ImageDecoderSlice
  • Key points relevant for the review:
    SliceAttr implementation, error checking
  • Validation and testing:
    Tests added
  • Documentation (including examples):
    Operator doc updated

JIRA TASK: [DALI-1544]

@jantonguirao jantonguirao changed the title [WIP] Enable named Slice arguments Enable named Slice arguments: start/rel_start, end/rel_end, shape/rel_shape Jan 22, 2021
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2005916]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2005916]: BUILD PASSED

@jantonguirao
Copy link
Contributor Author

image

@awolant awolant assigned awolant, banasraf and mzient and unassigned banasraf Jan 25, 2021
Comment on lines 37 to 39
Relative and absolute arguments can be used for different arguments (e.g. ``rel_start``
and ``shape``) but should not be specified for the same argument (e.g. ``start`` and ``rel_start``
should not be provided together).
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
Relative and absolute arguments can be used for different arguments (e.g. ``rel_start``
and ``shape``) but should not be specified for the same argument (e.g. ``start`` and ``rel_start``
should not be provided together).
Relative and absolute arguments can be mixed (for example, ``rel_start`` can be used with ``shape``) as long
as start and shape or end are uniquely defined.

if (has_end_ || has_shape_) { // ``start`` can be omitted
DALI_ENFORCE(!spec_.HasArgument("normalized_anchor")
&& !spec_.HasArgument("normalized_shape"),
"``normalized_anchor``/``normalized_shape`` is only relevant when using positional "
Copy link
Contributor

Choose a reason for hiding this comment

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

The fact that they are irrelevant doesn't mean they are forbidden (could be ignored, for example).

Suggested change
"``normalized_anchor``/``normalized_shape`` is only relevant when using positional "
"``normalized_anchor`` and ``normalized_shape`` can be used only with positional "

else if (rel_shape_.IsDefined())
rel_shape_.Acquire(spec_, ws, curr_batch_size, args_shape);

if (has_end_ || has_shape_) { // ``start`` can be omitted
Copy link
Contributor

@mzient mzient Jan 27, 2021

Choose a reason for hiding this comment

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

Food for thought: maybe we could live with only the start - which would work like a[start:]

@@ -122,14 +222,17 @@ class SliceAttr {
axes = GetDimIndices(shape_layout, axis_names_).to_vector();
}

constexpr double i64min = std::numeric_limits<int64_t>::min();
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
constexpr double i64min = std::numeric_limits<int64_t>::min();
constexpr double i64min = static_cast<double>(std::numeric_limits<int64_t>::min());

...or you'll fall victim to clang's warnings.

return GetInputShape<GPUBackend>(input_idx).num_samples();
}
return GetInputShape<CPUBackend>(input_idx).num_samples();
return GetInputShape(input_idx).num_samples();
Copy link
Contributor

Choose a reason for hiding this comment

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

This is extremely wasteful - the shape is returned by value, making a copy of an std::vector.

DALI_ENFORCE(NumInput() > 0, "No inputs found");
DALI_ENFORCE(input_idx >= 0 && input_idx < NumInput(),
make_string("Invalid input index: ", input_idx, "; while NumInput: ", NumInput()));
return GetInputShape(input_idx).sample_dim();
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise.

@mzient
Copy link
Contributor

mzient commented Feb 2, 2021

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2038719]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2038719]: BUILD FAILED

void ProcessPositionalInputArgs(int data_idx,
const AnchorT *slice_anchor_data,
const ShapeT *slice_shape_data,
const EndT *slice_end_data) {
Copy link
Contributor

Choose a reason for hiding this comment

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

It raised a warning in clang in the lambda - but slice_end_data is not used in this function at all. Do we need this argument at all here?

@mzient
Copy link
Contributor

mzient commented Feb 4, 2021

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2044839]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2044839]: BUILD FAILED

@mzient
Copy link
Contributor

mzient commented Feb 4, 2021

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2045077]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2045077]: BUILD FAILED

jantonguirao and others added 10 commits February 9, 2021 11:17
Signed-off-by: Joaquin Anton <janton@nvidia.com>
…hape

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
* This argument was captured by lambda but not used, which caused a warning in clang build

Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
…nalInputArgs.

Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2058496]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2058496]: BUILD FAILED

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2058664]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2058664]: BUILD PASSED

@jantonguirao jantonguirao merged commit 10ddecc into NVIDIA:master Feb 9, 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.

5 participants