Skip to content

Commit ff45ca0

Browse files
authored
Merge branch 'master' into revert-gh-2912
2 parents dba592c + 1ebd2d3 commit ff45ca0

11 files changed

Lines changed: 80 additions & 52 deletions

File tree

‎.github/workflows/build-sphinx.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
sudo apt-get install -y nvidia-cuda-toolkit clinfo
9595
9696
- name: Checkout repo
97-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
97+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
9898
with:
9999
fetch-depth: 0
100100

@@ -263,7 +263,7 @@ jobs:
263263
timeout-minutes: 10
264264

265265
steps:
266-
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
266+
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
267267
with:
268268
fetch-depth: 0
269269

‎.github/workflows/check-onemath.yaml‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
access_token: ${{ github.token }}
4040

4141
- name: Checkout DPNP repo
42-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
42+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4343
with:
4444
fetch-depth: 0
4545

@@ -82,7 +82,7 @@ jobs:
8282

8383
steps:
8484
- name: Checkout DPNP repo
85-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
85+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
8686
with:
8787
fetch-depth: 0
8888

@@ -202,7 +202,7 @@ jobs:
202202

203203
steps:
204204
- name: Checkout DPNP repo
205-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
205+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
206206
with:
207207
fetch-depth: 0
208208

@@ -213,7 +213,7 @@ jobs:
213213
path: ${{ env.environment-file-loc }}
214214

215215
- name: Checkout oneMKL repo
216-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
216+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
217217
with:
218218
repository: 'oneapi-src/oneMKL'
219219
ref: 'develop'

‎.github/workflows/conda-package.yml‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
access_token: ${{ github.token }}
5555

5656
- name: Checkout DPNP repo
57-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
57+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
5858
with:
5959
fetch-depth: 0
6060

@@ -145,7 +145,7 @@ jobs:
145145
swap-size-gb: 8
146146

147147
- name: Checkout DPNP repo
148-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
148+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
149149
with:
150150
fetch-depth: ${{ env.fetch-depth }}
151151
path: ${{ env.dpnp-repo-path }}
@@ -295,7 +295,7 @@ jobs:
295295

296296
steps:
297297
- name: Checkout DPNP repo
298-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
298+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
299299
with:
300300
fetch-depth: ${{ env.fetch-depth }}
301301
path: ${{ env.dpnp-repo-path }}
@@ -403,7 +403,7 @@ jobs:
403403

404404
steps:
405405
- name: Checkout DPNP repo
406-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
406+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
407407
with:
408408
fetch-depth: ${{ env.fetch-depth }}
409409
path: ${{ env.dpnp-repo-path }}
@@ -583,7 +583,7 @@ jobs:
583583
584584
steps:
585585
- name: Checkout DPNP repo
586-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
586+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
587587
with:
588588
fetch-depth: ${{ env.fetch-depth }}
589589

@@ -667,7 +667,7 @@ jobs:
667667

668668
steps:
669669
- name: Checkout DPNP repo
670-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
670+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
671671
with:
672672
fetch-depth: ${{ env.fetch-depth }}
673673
path: ${{ env.dpnp-repo-path }}
@@ -740,7 +740,7 @@ jobs:
740740
python -c "import dpnp; print(dpnp.__version__)"
741741
742742
- name: Clone array API tests repo
743-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
743+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
744744
with:
745745
repository: 'data-apis/array-api-tests'
746746
path: ${{ env.array-api-tests-path }}
@@ -823,7 +823,7 @@ jobs:
823823

824824
steps:
825825
- name: Checkout DPNP repo
826-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
826+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
827827
with:
828828
fetch-depth: ${{ env.fetch-depth }}
829829

@@ -849,7 +849,7 @@ jobs:
849849
activate-environment: ${{ env.cleanup-env-name }}
850850

851851
- name: Checkout repo
852-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
852+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
853853
with:
854854
repository: IntelPython/devops-tools
855855
fetch-depth: ${{ env.fetch-depth }}

‎.github/workflows/generate_coverage.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
intel-oneapi-compiler-dpcpp-cpp
5959
6060
- name: Checkout repo
61-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
61+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
6262
with:
6363
fetch-depth: 0
6464

‎.github/workflows/openssf-scorecard.yml‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@ jobs:
3737

3838
steps:
3939
- name: "Checkout code"
40-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
40+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
4141
with:
4242
persist-credentials: false
4343

4444
- name: "Run analysis"
45-
uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # v2.4.3
45+
uses: ossf/scorecard-action@2d1146689b8cda280b9bc96326124645441f03bc # v2.4.4
4646
with:
4747
results_file: results.sarif
4848
results_format: sarif
@@ -72,6 +72,6 @@ jobs:
7272

7373
# Upload the results to GitHub's code scanning dashboard.
7474
- name: "Upload to code-scanning"
75-
uses: github/codeql-action/upload-sarif@7188fc363630916deb702c7fdcf4e481b751f97a # v4.37.1
75+
uses: github/codeql-action/upload-sarif@e4fba868fa4b1b91e1fdab776edc8cfbe6e9fb81 # v4.37.3
7676
with:
7777
sarif_file: results.sarif

‎.github/workflows/pre-commit.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ jobs:
2323
pylint
2424
2525
- name: Checkout DPNP repo
26-
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
26+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
2727
with:
2828
# use commit hash to make "no-commit-to-branch" check passing
2929
ref: ${{ github.sha }}
3030

3131
- name: Set up python
32-
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 # v6.3.0
32+
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
3333
with:
3434
python-version: '3.14'
3535

‎.pre-commit-config.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ repos:
128128
hooks:
129129
- id: actionlint
130130
- repo: https://github.com/BlankSpruce/gersemi-pre-commit
131-
rev: 0.27.7
131+
rev: 0.28.0
132132
hooks:
133133
- id: gersemi
134134
exclude: "dpnp/backend/cmake/Modules/"

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ This release is compatible with NumPy 2.5.
7070
* Fixed `__array_namespace_info__().devices()` and `.default_device()` to return Python array API compatible device objects [#2979](https://github.com/IntelPython/dpnp/pull/2979)
7171
* Fixed `dpnp.interp` with an empty input array `x` to return an empty array with the correct dtype [#2985](https://github.com/IntelPython/dpnp/pull/2985)
7272
* Fixed `dpnp.interp` returning `nan` when querying at an exact knot point whose adjacent `fp` value is `inf` [#2986](https://github.com/IntelPython/dpnp/pull/2986)
73+
* Fixed missing strides validation in `dpnp.tensor.usm_ndarray` constructor when allocating new memory [#2927](https://github.com/IntelPython/dpnp/pull/2927)
7374

7475
### Security
7576

‎dpnp/tensor/_usmarray.pyx‎

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -378,20 +378,19 @@ cdef class usm_ndarray:
378378
if (typenum < 0):
379379
if typenum == -2:
380380
raise ValueError(
381-
"Data type '" + str(dtype) +
382-
"' can only have native byteorder."
381+
f"Data type '{dtype}' can only have native byteorder."
383382
)
384383
elif typenum == -1:
385384
raise ValueError(
386-
"Data type '" + str(dtype) + "' is not understood."
385+
f"Data type '{dtype}' is not understood."
387386
)
388387
raise TypeError(
389388
f"Expected string or a dtype object, got {type(dtype)}"
390389
)
391390
itemsize = type_bytesize(typenum)
392391
if (itemsize < 1):
393392
raise TypeError(
394-
"dtype=" + np.dtype(dtype).name + " is not supported."
393+
f"dtype={np.dtype(dtype).name} is not supported."
395394
)
396395
# allocate host C-arrays for shape, strides
397396
err = _from_input_shape_strides(
@@ -406,11 +405,11 @@ cdef class usm_ndarray:
406405
"array failed.")
407406
elif err == ERROR_INCORRECT_ORDER:
408407
raise ValueError(
409-
"Unsupported order='{}' given. "
410-
"Supported values are 'C' or 'F'.".format(order))
408+
f"Unsupported order='{order}' given. "
409+
"Supported values are 'C' or 'F'.")
411410
elif err == ERROR_UNEXPECTED_STRIDES:
412411
raise ValueError(
413-
"strides={} is not understood".format(strides))
412+
f"strides={strides} is not understood")
414413
else:
415414
raise InternalUSMArrayError(
416415
" .. while processing shape and strides.")
@@ -421,6 +420,21 @@ cdef class usm_ndarray:
421420
elif isinstance(buffer, (str, bytes)):
422421
if isinstance(buffer, bytes):
423422
buffer = buffer.decode("UTF-8")
423+
if strides is not None and ary_min_displacement < 0:
424+
self._cleanup()
425+
raise ValueError(
426+
f"strides={strides} result in a negative memory "
427+
"displacement and are not allowed when allocating "
428+
"new memory")
429+
if strides is not None and (
430+
(ary_max_displacement - ary_min_displacement + 1) > ary_nelems
431+
):
432+
self._cleanup()
433+
raise ValueError(
434+
f"strides={strides} is incompatible with "
435+
f"shape={shape} when allocating new memory because "
436+
"the memory footprint exceeds the number of elements"
437+
)
424438
_offset = -ary_min_displacement
425439
if (buffer == "shared"):
426440
_buffer = dpmem.MemoryUSMShared(ary_nbytes,
@@ -434,24 +448,24 @@ cdef class usm_ndarray:
434448
else:
435449
self._cleanup()
436450
raise ValueError(
437-
"buffer='{}' is not understood. "
451+
f"buffer='{buffer}' is not understood. "
438452
"Recognized values are 'device', 'shared', 'host', "
439453
"an instance of `MemoryUSM*` object, or a usm_ndarray"
440-
"".format(buffer)
441454
)
442455
elif isinstance(buffer, usm_ndarray):
443456
if not buffer.flags.writable:
444457
writable_flag = 0
445458
_buffer = buffer.usm_data
446459
else:
447460
self._cleanup()
448-
raise ValueError("buffer='{}' was not understood.".format(buffer))
461+
raise ValueError(f"buffer='{buffer}' was not understood.")
449462
if (shape_to_elem_count(nd, shape_ptr) > 0 and
450463
(_offset + ary_min_displacement < 0 or
451464
(_offset + ary_max_displacement + 1) * itemsize > _buffer.nbytes)):
452465
self._cleanup()
453-
raise ValueError(("buffer='{}' can not accommodate "
454-
"the requested array.").format(buffer))
466+
raise ValueError(
467+
f"buffer='{buffer}' can not accommodate the requested array."
468+
)
455469
is_fp64 = (typenum == UAR_DOUBLE or typenum == UAR_CDOUBLE)
456470
is_fp16 = (typenum == UAR_HALF)
457471
if (is_fp64 or is_fp16):
@@ -640,9 +654,8 @@ cdef class usm_ndarray:
640654
if (not isinstance(self.base_, dpmem._memory._Memory)):
641655
raise InternalUSMArrayError(
642656
"Invalid instance of usm_ndarray encountered. "
643-
"Private field base_ has an unexpected type {}.".format(
644-
type(self.base_)
645-
)
657+
"Private field base_ has an unexpected type "
658+
f"{type(self.base_)}."
646659
)
647660
ary_iface = self.base_.__sycl_usm_array_interface__
648661
mem_ptr = <char *>(<size_t> ary_iface["data"][0])
@@ -803,7 +816,7 @@ cdef class usm_ndarray:
803816
self.strides_ = strides_ptr
804817
else:
805818
raise InternalUSMArrayError(
806-
"Encountered in shape setter, error code {err}".format(err)
819+
f"Encountered in shape setter, error code {err}"
807820
)
808821

809822
@property
@@ -1905,7 +1918,7 @@ cdef api object UsmNDArray_MakeSimpleFromPtr(
19051918
cdef int itemsize = type_bytesize(typenum)
19061919
if (itemsize < 1):
19071920
raise ValueError(
1908-
"dtype with typenum=" + str(typenum) + " is not supported."
1921+
f"dtype with typenum={typenum} is not supported."
19091922
)
19101923
cdef size_t nbytes = (<size_t> itemsize) * nelems
19111924
cdef c_dpmem._Memory mobj
@@ -1961,7 +1974,7 @@ cdef api object UsmNDArray_MakeFromPtr(
19611974

19621975
if (itemsize < 1):
19631976
raise ValueError(
1964-
"dtype with typenum=" + str(typenum) + " is not supported."
1977+
f"dtype with typenum={typenum} is not supported."
19651978
)
19661979
if (nd < 0):
19671980
raise ValueError("Dimensionality must be non-negative")

‎dpnp/tests/tensor/test_usm_ndarray_ctor.py‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ def test_usm_ndarray_flags():
124124
assert f.fc
125125
assert f.forc
126126
assert not dpt.usm_ndarray(
127-
(5, 1, 1), dtype="i4", strides=(2, 0, 1)
127+
(2, 3, 4), dtype="i4", strides=(4, 8, 1)
128128
).flags.forc
129129

130130
x = dpt.empty(5, dtype="u2")
@@ -1085,6 +1085,23 @@ def test_ctor_invalid():
10851085
dpt.usm_ndarray((4,), dtype="u1", buffer=m, strides={"not": "valid"})
10861086

10871087

1088+
def test_ctor_invalid_strides():
1089+
try:
1090+
dpt.usm_ndarray((1,), dtype="i4")
1091+
except dpctl.SyclDeviceCreationError:
1092+
pytest.skip("No SYCL devices available")
1093+
# negative displacement
1094+
with pytest.raises(
1095+
ValueError, match="result in a negative memory displacement"
1096+
):
1097+
dpt.usm_ndarray((2, 3, 4), dtype="i4", strides=(-1, 1, 1))
1098+
# oversized memory footprint
1099+
with pytest.raises(
1100+
ValueError, match="memory footprint exceeds the number of elements"
1101+
):
1102+
dpt.usm_ndarray((2, 3, 4), dtype="i4", strides=(1, 16, 128))
1103+
1104+
10881105
def test_reshape():
10891106
try:
10901107
X = dpt.usm_ndarray((5, 5), "i4")

0 commit comments

Comments
 (0)