Skip to content

Update implementation of dpnp.putmask - #3014

Open
vlad-perevezentsev wants to merge 8 commits into
masterfrom
add_putmask_impl
Open

Update implementation of dpnp.putmask#3014
vlad-perevezentsev wants to merge 8 commits into
masterfrom
add_putmask_impl

Conversation

@vlad-perevezentsev

@vlad-perevezentsev vlad-perevezentsev commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This PR proposes a new implementation of dpnp.putmask replacing the legacy dpnp_putmask implementation with dedicated SYCL kernels : a vectorized contiguous kernel and a strided kernel for F-contiguous/transposed arrays.
It also fully reworks the putmask tests by adding TestPutMask

Performance results on PVC are below:

image
  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@vlad-perevezentsev vlad-perevezentsev self-assigned this Aug 6, 2026
@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/3014/index.html

@vlad-perevezentsev
vlad-perevezentsev marked this pull request as ready for review August 7, 2026 12:25
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Array API standard conformance tests for dpnp=0.21.0dev3=py314h509198e_43 ran successfully.
Passed: 1376
Failed: 1
Skipped: 5

@coveralls

Copy link
Copy Markdown
Collaborator

Coverage Status

coverage: 78.443% (+0.03%) from 78.414% — add_putmask_impl into master

@antonwolfy antonwolfy added this to the 0.21.0 release milestone Aug 19, 2026
# -*- coding: utf-8 -*-
# *****************************************************************************
# Copyright (c) 2025, Intel Corporation
# Copyright (c) 2026, Intel Corporation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's year when file was created, no need to update

Suggested change
# Copyright (c) 2026, Intel Corporation
# Copyright (c) 2025, Intel Corporation

# values must always be flattened in C-order.
values_1d = values.ravel(order="C")
if a.dtype != values_1d.dtype:
values_1d = dpnp.astype(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems no test is covering that

@@ -1,5 +1,5 @@
//*****************************************************************************
// Copyright (c) 2025, Intel Corporation
// Copyright (c) 2026, Intel Corporation

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Copyright (c) 2026, Intel Corporation
// Copyright (c) 2025, Intel Corporation

array([[ 0, 1, 2],
[ 9, 16, 25]])

If `values` is smaller than `x1` it is repeated:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
If `values` is smaller than `x1` it is repeated:
If `values` is smaller than `a` it is repeated:

:obj:`dpnp.take` : Take elements from an array along an axis.
:obj:`dpnp.copyto` : Copies values from one array to another.


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Double blank like:

Suggested change

for xp in (numpy, cupy):
a = xp.array([1, 2, 3])
mask = xp.array([True, False])
with pytest.raises((ValueError, IndexError)):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can be aligned now:

Suggested change
with pytest.raises(ValueError):

const std::size_t values_size = values.get_size();

// the contig kernel cycles `values` by the memory-linear index, which
// matches numpy's C-order `values.flat` only for C-contiguous data

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

but no check here that values.is_c_contiguous() has to be true

Comment on lines +106 to +107
std::size_t nelems,
std::size_t val_size)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
std::size_t nelems,
std::size_t val_size)
const std::size_t nelems,
const std::size_t val_size)

elems_per_wi * (ndit.get_group(0) * ndit.get_local_range(0) +
sg.get_group_id()[0] * sgSize);

const bool values_no_repeat = (val_size_ >= nelems_);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

can be moved away of if-else block to reduce duplication

#pragma unroll
for (std::uint8_t vec_id = 0; vec_id < vec_sz; ++vec_id) {
out_vec[vec_id] =
(mask_vec[vec_id] != static_cast<std::uint8_t>(0))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

for consistency with other places in the kernel:

Suggested change
(mask_vec[vec_id] != static_cast<std::uint8_t>(0))
(mask_vec[vec_id])

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.

3 participants