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

Supporting "where" for unary operations #1061

Merged
merged 68 commits into from
Dec 3, 2023

Conversation

ipdemes
Copy link
Contributor

@ipdemes ipdemes commented Oct 18, 2023

No description provided.

@ipdemes ipdemes requested a review from manopapad October 18, 2023 17:10
@ipdemes ipdemes self-assigned this Oct 18, 2023
@ipdemes ipdemes added the category:new-feature PR introduces a new feature and will be classified as such in release notes label Oct 18, 2023
@ipdemes
Copy link
Contributor Author

ipdemes commented Oct 18, 2023

This PR also implements nanmean

src/cunumeric/unary/scalar_unary_red_template.inl Outdated Show resolved Hide resolved
src/cunumeric/unary/scalar_unary_red_template.inl Outdated Show resolved Hide resolved
src/cunumeric/unary/scalar_unary_red.h Outdated Show resolved Hide resolved
src/cunumeric/unary/scalar_unary_red_template.inl Outdated Show resolved Hide resolved
src/cunumeric/unary/scalar_unary_red_template.inl Outdated Show resolved Hide resolved
cunumeric/array.py Outdated Show resolved Hide resolved
cunumeric/array.py Outdated Show resolved Hide resolved
cunumeric/array.py Outdated Show resolved Hide resolved
cunumeric/array.py Outdated Show resolved Hide resolved
cunumeric/array.py Outdated Show resolved Hide resolved
struct ScalarUnaryRed {
ScalarUnaryRed(ScalarUnaryRedArgs& args) { assert(false); }

Choose a reason for hiding this comment

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

What is this trying to do? Bar the use of the general template? Or bar a non-const copy? If the point is to deny the use of the general template, prefer doing something like

template <typename T>
struct Foo {
  // Note tautological expression still dependent on template parameter
  static_assert(!std::is_same_v<T, T>);
};

If you'd like to instead bar the use of copy ctor, prefer the usual = delete:

template <typename T>
struct Foo {
  Foo(const Foo&) = delete;
};

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you, @Jacobfaib . This is not necessary anymore. the purpose for this was to "prevent the use of general template"

src/cunumeric/unary/scalar_unary_red_template.inl Outdated Show resolved Hide resolved
src/cunumeric/unary/scalar_unary_red_template.inl Outdated Show resolved Hide resolved
src/cunumeric/unary/scalar_unary_red_template.inl Outdated Show resolved Hide resolved
src/cunumeric/unary/scalar_unary_red_template.inl Outdated Show resolved Hide resolved
for (size_t o_idx = 0; o_idx < split.outer; ++o_idx)
for (size_t i_idx = 0; i_idx < split.inner; ++i_idx) {
auto point = splitter.combine(o_idx, i_idx, rect.lo);
auto identity = LG_OP::identity;

Choose a reason for hiding this comment

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

You can put this in the if

auto split = splitter.split(rect, collapsed_dim);

#pragma omp parallel for schedule(static)
for (size_t o_idx = 0; o_idx < split.outer; ++o_idx)

Choose a reason for hiding this comment

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

Minor nit, but consider adding the {} around the for's body. The code is correct as written, just makes it slightly easier to read.

cunumeric/module.py Outdated Show resolved Hide resolved
@marcinz marcinz changed the base branch from branch-23.11 to branch-24.01 November 9, 2023 17:11
Copy link

copy-pr-bot bot commented Nov 17, 2023

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@ipdemes
Copy link
Contributor Author

ipdemes commented Nov 17, 2023

But by doing it this way, the summation for np.int64 arrays happens using an intermediate of type np.int64, whereas the NumPy docs specifically note that "float64 intermediate and return values are used for integer inputs".

If this is important for the SLAC usecase, then I think the better solution would be to extend the template of UnaryRedImplBody with two "CODE" template parameters, one for the RHS (input array) type and one for the LHS (accumulator array) type. Then we can compute the sum of an np.int64 array directly into an array of np.float64 type, without converting the input to np.float64.

Makes sense, I will add back dtype to sum and create an issue to support 2 different types for RHS and LHS in UnaryImplBody

@ipdemes ipdemes requested a review from manopapad November 17, 2023 22:26
@manopapad
Copy link
Contributor

/ok to test

@manopapad
Copy link
Contributor

/ok to test

Copy link
Contributor

@manopapad manopapad left a comment

Choose a reason for hiding this comment

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

One minor comment, otherwise looks good

divisor = np.array(divisor, dtype=sum_array.dtype) # type: ignore [assignment] # noqa

if dtype.kind == "f" or dtype.kind == "c":
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can just get rid of the dtype parameter at this point, and just use sum_array.dtype everywhere in this function.

@ipdemes
Copy link
Contributor Author

ipdemes commented Dec 2, 2023

/ok to test

@ipdemes ipdemes merged commit 672e8c6 into nv-legate:branch-24.01 Dec 3, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:new-feature PR introduces a new feature and will be classified as such in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants