-
Notifications
You must be signed in to change notification settings - Fork 621
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
Propagate layout in fn.reductions #4947
Conversation
!build |
CI MESSAGE: [9014738]: BUILD STARTED |
CI MESSAGE: [9014738]: BUILD FAILED |
int in_ndim = layout.size(); | ||
assert(in_ndim >= 0 && in_ndim <= 64); | ||
assert(axes.size() <= in_ndim); | ||
uint64_t mask = 0; | ||
for (auto a : axes) { | ||
assert(0 <= a && a < in_ndim); | ||
uint64_t a_mask = 1_u64 << a; | ||
assert(!(mask & a_mask)); // axes must be unique for the correct out layout dim | ||
mask |= a_mask; | ||
} |
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.
Instead of defensively double-checking the axes, you can simply do uint64_t mask = to_bit_mask(axes);
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.
done
int out_ndim = in_ndim - axes.size(); | ||
TensorLayout out_layout; | ||
if (out_ndim <= 0) { | ||
return out_layout; | ||
} | ||
out_layout.resize(out_ndim); | ||
for (int in_idx = 0, out_idx = 0; in_idx < in_ndim; in_idx++) { | ||
if (!(mask & (1_u64 << in_idx))) { | ||
out_layout[out_idx++] = layout[in_idx]; | ||
} | ||
} |
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.
Simpler:
int out_ndim = in_ndim - axes.size(); | |
TensorLayout out_layout; | |
if (out_ndim <= 0) { | |
return out_layout; | |
} | |
out_layout.resize(out_ndim); | |
for (int in_idx = 0, out_idx = 0; in_idx < in_ndim; in_idx++) { | |
if (!(mask & (1_u64 << in_idx))) { | |
out_layout[out_idx++] = layout[in_idx]; | |
} | |
} | |
TensorLayout out_layout; | |
for (int idx = 0; idx < layout.size(); idx++) { | |
if (!(mask & (1_u64 << idx))) { | |
out_layout += layout[idx]; | |
} | |
} |
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.
Nice. I missed that +=
op. It lets me drop the unique axes assumption.
} | ||
|
||
template <typename Input, typename Output, typename Axes> | ||
inline void PropagateLayout(const Input &input, Output &output, Axes &&axes, bool keep_dims) { |
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.
Just a nitpick, but we typically do (output, input, params)
.
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.
done
Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
109b9c0
to
e2a9c0b
Compare
!build |
CI MESSAGE: [9100773]: BUILD STARTED |
CI MESSAGE: [9100773]: BUILD PASSED |
Set layout to outputs of the family of fn.reductions (if not set already by the the specific implementation). --------- Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
Category:
Bug fix/New feature
Description:
Adds missing layout propagation to the family of
fn.reductions
. The layout propagation rules are simple:keep_dims
is True, the input layout is just copied to the output.Additional information:
Here's a real-life example of an augmentation that can benefit from the layout propagation, otherwise the
center = ..
line would not work.Affected modules and functionalities:
Key points relevant for the review:
Tests:
Checklist
Documentation
DALI team only
Requirements
REQ IDs: N/A
JIRA TASK: DALI-3554