Skip to content

Commit ff43ac7

Browse files
committed
Merge branch 'master' into add-md-local-accessor
2 parents 7588d61 + 7e2b69e commit ff43ac7

11 files changed

+121
-41
lines changed

.github/CODEOWNERS

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
* @oleksandr-pavlyk @ndgrigorian
1+
* @ndgrigorian @antonwolfy @vlad-perevezentsev @vtavana

.github/workflows/conda-package.yml

+11-5
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
run: echo $CONDA/bin >> $GITHUB_PATH
4949
- name: Install conda-build
5050
# FIXME: unpin when conda-build fixes issues with lief
51-
run: conda install conda-build -c conda-forge --override-channels
51+
run: conda install conda-build"<25.1.2" -c conda-forge --override-channels
5252
- name: Store conda paths as envs
5353
shell: bash -l {0}
5454
run: |
@@ -100,7 +100,7 @@ jobs:
100100
# FIXME: unpin when conda-build fixes issues with lief
101101
run: |
102102
conda activate
103-
conda install -y conda-build
103+
conda install -y conda-build"<25.1.2"
104104
conda list -n base
105105
106106
- name: Cache conda packages
@@ -167,7 +167,9 @@ jobs:
167167
run: echo $CONDA/bin >> $GITHUB_PATH
168168
- name: Install conda-index
169169
# Needed to be able to run conda index
170-
run: conda install conda-index -c conda-forge --override-channels
170+
run: |
171+
conda update -n base --all
172+
conda install conda-index -c conda-forge --override-channels
171173
- name: Create conda channel
172174
run: |
173175
mkdir -p $GITHUB_WORKSPACE/channel/linux-64
@@ -508,7 +510,9 @@ jobs:
508510
echo ${{ env.CHANNELS }}
509511
- name: Install conda-index
510512
# Needed to be able to run conda index
511-
run: conda install conda-index -c conda-forge --override-channels
513+
run: |
514+
conda update -n base --all
515+
conda install conda-index -c conda-forge --override-channels
512516
- name: Checkout dpctl repo
513517
uses: actions/[email protected]
514518
with:
@@ -696,7 +700,9 @@ jobs:
696700
run: echo $CONDA/bin >> $GITHUB_PATH
697701
- name: Install conda-index
698702
# Needed to be able to run conda index
699-
run: conda install conda-index -c conda-forge --override-channels
703+
run: |
704+
conda update -n base --all
705+
conda install conda-index -c conda-forge --override-channels
700706
- name: Create conda channel
701707
run: |
702708
mkdir -p $GITHUB_WORKSPACE/channel/linux-64

conda-recipe/meta.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ about:
8080
8181
extra:
8282
recipe-maintainers:
83-
- diptorupd
84-
- oleksandr-pavlyk
8583
- ndgrigorian
86-
- ZzEeKkAa
84+
- antonwolfy
85+
- vtavana
86+
- vlad-perevezentsev

dpctl/tensor/_copy_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def from_numpy(np_ary, /, *, device=None, usm_type="device", sycl_queue=None):
126126
arg:
127127
Input convertible to :class:`numpy.ndarray`
128128
device (object): array API specification of device where the
129-
output array is created. Device can be specified by a
129+
output array is created. Device can be specified by
130130
a filter selector string, an instance of
131131
:class:`dpctl.SyclDevice`, an instance of
132132
:class:`dpctl.SyclQueue`, or an instance of
@@ -620,7 +620,7 @@ def astype(
620620
If this keyword is set to `False`, a view of the input array
621621
may be returned when possible.
622622
device (object): array API specification of device where the
623-
output array is created. Device can be specified by a
623+
output array is created. Device can be specified by
624624
a filter selector string, an instance of
625625
:class:`dpctl.SyclDevice`, an instance of
626626
:class:`dpctl.SyclQueue`, or an instance of

dpctl/tensor/_usmarray.pyx

+8-4
Original file line numberDiff line numberDiff line change
@@ -1777,8 +1777,10 @@ cdef api object UsmNDArray_MakeSimpleFromPtr(
17771777
Returns:
17781778
Created usm_ndarray instance
17791779
"""
1780-
cdef size_t itemsize = type_bytesize(typenum)
1781-
cdef size_t nbytes = itemsize * nelems
1780+
cdef int itemsize = type_bytesize(typenum)
1781+
if (itemsize < 1):
1782+
raise ValueError("dtype with typenum=" + str(typenum) + " is not supported.")
1783+
cdef size_t nbytes = (<size_t> itemsize) * nelems
17821784
cdef c_dpmem._Memory mobj = c_dpmem._Memory.create_from_usm_pointer_size_qref(
17831785
ptr, nbytes, QRef, memory_owner=owner
17841786
)
@@ -1817,7 +1819,7 @@ cdef api object UsmNDArray_MakeFromPtr(
18171819
Returns:
18181820
Created usm_ndarray instance
18191821
"""
1820-
cdef size_t itemsize = type_bytesize(typenum)
1822+
cdef int itemsize = type_bytesize(typenum)
18211823
cdef int err = 0
18221824
cdef size_t nelems = 1
18231825
cdef Py_ssize_t min_disp = 0
@@ -1830,6 +1832,8 @@ cdef api object UsmNDArray_MakeFromPtr(
18301832
cdef object obj_shape
18311833
cdef object obj_strides
18321834

1835+
if (itemsize < 1):
1836+
raise ValueError("dtype with typenum=" + str(typenum) + " is not supported.")
18331837
if (nd < 0):
18341838
raise ValueError("Dimensionality must be non-negative")
18351839
if (ptr is NULL or QRef is NULL):
@@ -1881,7 +1885,7 @@ cdef api object UsmNDArray_MakeFromPtr(
18811885
raise ValueError(
18821886
"Given shape, strides and offset reference out-of-bound memory"
18831887
)
1884-
nbytes = itemsize * (offset + max_disp + 1)
1888+
nbytes = (<size_t> itemsize) * (offset + max_disp + 1)
18851889
mobj = c_dpmem._Memory.create_from_usm_pointer_size_qref(
18861890
ptr, nbytes, QRef, memory_owner=owner
18871891
)

dpctl/tensor/libtensor/source/accumulators.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ std::size_t py_mask_positions(const dpctl::tensor::usm_ndarray &mask,
210210
sycl::event::wait(host_task_events);
211211

212212
// ensure deleter of smart pointer is invoked with GIL released
213-
shape_strides_owner.release();
213+
shape_strides_owner.reset(nullptr);
214214
}
215215
throw std::runtime_error("Unexpected error");
216216
}
@@ -231,7 +231,7 @@ std::size_t py_mask_positions(const dpctl::tensor::usm_ndarray &mask,
231231

232232
sycl::event::wait(host_task_events);
233233
// ensure deleter of smart pointer is invoked with GIL released
234-
shape_strides_owner.release();
234+
shape_strides_owner.reset(nullptr);
235235
}
236236

237237
return total_set;
@@ -367,7 +367,7 @@ std::size_t py_cumsum_1d(const dpctl::tensor::usm_ndarray &src,
367367
sycl::event::wait(host_task_events);
368368

369369
// ensure USM deleter is called with GIL released
370-
shape_strides_owner.release();
370+
shape_strides_owner.reset(nullptr);
371371
}
372372
throw std::runtime_error("Unexpected error");
373373
}
@@ -387,7 +387,7 @@ std::size_t py_cumsum_1d(const dpctl::tensor::usm_ndarray &src,
387387
sycl::event::wait(host_task_events);
388388

389389
// ensure USM deleter is called with GIL released
390-
shape_strides_owner.release();
390+
shape_strides_owner.reset(nullptr);
391391
}
392392

393393
return total;

dpctl/tensor/libtensor/source/copy_numpy_ndarray_into_usm_ndarray.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ void copy_numpy_ndarray_into_usm_ndarray(
325325
dst_offset, depends, {copy_shape_ev});
326326

327327
// invoke USM deleter in smart pointer while GIL is held
328-
shape_strides_owner.release();
328+
shape_strides_owner.reset(nullptr);
329329
}
330330

331331
return;

dpctl/tests/test_usm_ndarray_ctor.py

+69
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,75 @@ def test_pyx_capi_make_general():
963963
assert zd_arr._pointer == mat._pointer
964964

965965

966+
def test_pyx_capi_make_fns_invalid_typenum():
967+
q = get_queue_or_skip()
968+
usm_ndarray = dpt.empty(tuple(), dtype="i4", sycl_queue=q)
969+
970+
make_simple_from_ptr = _pyx_capi_fnptr_to_callable(
971+
usm_ndarray,
972+
"UsmNDArray_MakeSimpleFromPtr",
973+
b"PyObject *(size_t, int, DPCTLSyclUSMRef, "
974+
b"DPCTLSyclQueueRef, PyObject *)",
975+
fn_restype=ctypes.py_object,
976+
fn_argtypes=(
977+
ctypes.c_size_t,
978+
ctypes.c_int,
979+
ctypes.c_void_p,
980+
ctypes.c_void_p,
981+
ctypes.py_object,
982+
),
983+
)
984+
985+
nelems = 10
986+
dtype = dpt.int64
987+
arr = dpt.arange(nelems, dtype=dtype, sycl_queue=q)
988+
989+
with pytest.raises(ValueError):
990+
make_simple_from_ptr(
991+
ctypes.c_size_t(nelems),
992+
-1,
993+
arr._pointer,
994+
arr.sycl_queue.addressof_ref(),
995+
arr,
996+
)
997+
998+
make_from_ptr = _pyx_capi_fnptr_to_callable(
999+
usm_ndarray,
1000+
"UsmNDArray_MakeFromPtr",
1001+
b"PyObject *(int, Py_ssize_t const *, int, Py_ssize_t const *, "
1002+
b"DPCTLSyclUSMRef, DPCTLSyclQueueRef, Py_ssize_t, PyObject *)",
1003+
fn_restype=ctypes.py_object,
1004+
fn_argtypes=(
1005+
ctypes.c_int,
1006+
ctypes.POINTER(ctypes.c_ssize_t),
1007+
ctypes.c_int,
1008+
ctypes.POINTER(ctypes.c_ssize_t),
1009+
ctypes.c_void_p,
1010+
ctypes.c_void_p,
1011+
ctypes.c_ssize_t,
1012+
ctypes.py_object,
1013+
),
1014+
)
1015+
c_shape = (ctypes.c_ssize_t * 1)(
1016+
nelems,
1017+
)
1018+
c_strides = (ctypes.c_ssize_t * 1)(
1019+
1,
1020+
)
1021+
with pytest.raises(ValueError):
1022+
make_from_ptr(
1023+
ctypes.c_int(1),
1024+
c_shape,
1025+
-1,
1026+
c_strides,
1027+
arr._pointer,
1028+
arr.sycl_queue.addressof_ref(),
1029+
ctypes.c_ssize_t(0),
1030+
arr,
1031+
)
1032+
del arr
1033+
1034+
9661035
def _pyx_capi_int(X, pyx_capi_name, caps_name=b"int", val_restype=ctypes.c_int):
9671036
import sys
9681037

libsyclinterface/tests/test_sycl_device_interface.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ TEST_P(TestDPCTLSyclDeviceInterface, ChkGetSubGroupSizes)
208208
else
209209
EXPECT_TRUE(sg_sizes_len > 0);
210210
for (size_t i = 0; i < sg_sizes_len; ++i) {
211-
EXPECT_TRUE(sg_sizes > 0);
211+
EXPECT_TRUE(sg_sizes[i] > 0);
212212
}
213213
EXPECT_NO_FATAL_FAILURE(DPCTLSize_t_Array_Delete(sg_sizes));
214214
}

libsyclinterface/tests/test_sycl_queue_submit_local_accessor_arg.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@
3737

3838
#include <filesystem>
3939
#include <fstream>
40+
#include <utility>
41+
4042
#include <gtest/gtest.h>
4143
#include <sycl/sycl.hpp>
42-
#include <utility>
4344

4445
namespace
4546
{
46-
constexpr std::size_t SIZE = 100;
47+
constexpr std::size_t SIZE = 320;
48+
49+
static_assert(SIZE % 10 == 0);
4750

4851
using namespace dpctl::syclinterface;
4952

@@ -69,11 +72,13 @@ void submit_kernel(DPCTLSyclQueueRef QRef,
6972
a_ptr[i] = 0;
7073
}
7174

72-
auto la1 = MDLocalAccessor{1, kernelArgTy, SIZE / 10, 1, 1};
75+
std::size_t lws = SIZE / 10;
76+
77+
auto la1 = MDLocalAccessor{1, kernelArgTy, lws, 1, 1};
7378

7479
// Create kernel args for vector_add
7580
std::size_t gRange[] = {SIZE};
76-
std::size_t lRange[] = {SIZE / 10};
81+
std::size_t lRange[] = {lws};
7782
void *args_1d[NARGS] = {unwrap<void>(a), (void *)&la1};
7883
DPCTLKernelArgType addKernelArgTypes[] = {DPCTL_VOID_PTR,
7984
DPCTL_LOCAL_ACCESSOR};
@@ -84,7 +89,7 @@ void submit_kernel(DPCTLSyclQueueRef QRef,
8489
ASSERT_TRUE(E1Ref != nullptr);
8590

8691
DPCTLSyclEventRef DepEv1[] = {E1Ref};
87-
auto la2 = MDLocalAccessor{2, kernelArgTy, SIZE / 10, 1, 1};
92+
auto la2 = MDLocalAccessor{2, kernelArgTy, lws, 1, 1};
8893
void *args_2d[NARGS] = {unwrap<void>(a), (void *)&la2};
8994

9095
DPCTLSyclEventRef E2Ref =
@@ -93,7 +98,7 @@ void submit_kernel(DPCTLSyclQueueRef QRef,
9398
ASSERT_TRUE(E2Ref != nullptr);
9499

95100
DPCTLSyclEventRef DepEv2[] = {E1Ref, E2Ref};
96-
auto la3 = MDLocalAccessor{3, kernelArgTy, SIZE / 10, 1, 1};
101+
auto la3 = MDLocalAccessor{3, kernelArgTy, lws, 1, 1};
97102
void *args_3d[NARGS] = {unwrap<void>(a), (void *)&la3};
98103

99104
DPCTLSyclEventRef E3Ref =
@@ -103,10 +108,7 @@ void submit_kernel(DPCTLSyclQueueRef QRef,
103108

104109
DPCTLEvent_Wait(E3Ref);
105110

106-
if (kernelArgTy != DPCTL_FLOAT32_T && kernelArgTy != DPCTL_FLOAT64_T)
107-
ASSERT_TRUE(a_ptr[0] == 20);
108-
else
109-
ASSERT_TRUE(a_ptr[0] == 20.0);
111+
ASSERT_TRUE(a_ptr[0] == T(lws * 2));
110112

111113
// clean ups
112114
DPCTLEvent_Delete(E1Ref);
@@ -133,9 +135,9 @@ void submit_kernel(DPCTLSyclQueueRef QRef,
133135
// figure which SPV file contains the kernels, use `spirv-dis` from the
134136
// spirv-tools package to translate the SPV binary format to a human-readable
135137
// textual format.
136-
#include <CL/sycl.hpp>
137138
#include <iostream>
138139
#include <sstream>
140+
#include <sycl/sycl.hpp>
139141
140142
template <typename T>
141143
class SyclKernel_SLM
@@ -195,7 +197,7 @@ int main(int argc, const char **argv)
195197
driver<int8_t>(N);
196198
driver<uint8_t>(N);
197199
driver<int16_t>(N);
198-
driver<int32_t>(N);
200+
driver<uint16_t>(N);
199201
driver<int32_t>(N);
200202
driver<uint32_t>(N);
201203
driver<int64_t>(N);
@@ -220,11 +222,10 @@ struct TestQueueSubmitWithLocalAccessor : public ::testing::Test
220222
{
221223
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
222224
DPCTLSyclDeviceRef DRef = nullptr;
225+
const char *test_spv_fn = "./local_accessor_kernel_inttys_fp32.spv";
223226

224-
spirvFile.open("./local_accessor_kernel_inttys_fp32.spv",
225-
std::ios::binary | std::ios::ate);
226-
spirvFileSize_ = std::filesystem::file_size(
227-
"./local_accessor_kernel_inttys_fp32.spv");
227+
spirvFile.open(test_spv_fn, std::ios::binary | std::ios::ate);
228+
spirvFileSize_ = std::filesystem::file_size(test_spv_fn);
228229
spirvBuffer_.reserve(spirvFileSize_);
229230
spirvFile.seekg(0, std::ios::beg);
230231
spirvFile.read(spirvBuffer_.data(), spirvFileSize_);
@@ -261,11 +262,10 @@ struct TestQueueSubmitWithLocalAccessorFP64 : public ::testing::Test
261262
TestQueueSubmitWithLocalAccessorFP64()
262263
{
263264
DPCTLSyclDeviceSelectorRef DSRef = nullptr;
265+
const char *test_spv_fn = "./local_accessor_kernel_fp64.spv";
264266

265-
spirvFile.open("./local_accessor_kernel_fp64.spv",
266-
std::ios::binary | std::ios::ate);
267-
spirvFileSize_ =
268-
std::filesystem::file_size("./local_accessor_kernel_fp64.spv");
267+
spirvFile.open(test_spv_fn, std::ios::binary | std::ios::ate);
268+
spirvFileSize_ = std::filesystem::file_size(test_spv_fn);
269269
spirvBuffer_.reserve(spirvFileSize_);
270270
spirvFile.seekg(0, std::ios::beg);
271271
spirvFile.read(spirvBuffer_.data(), spirvFileSize_);

pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ classifiers = [
2727
"Programming Language :: Python :: 3.9",
2828
"Programming Language :: Python :: 3.10",
2929
"Programming Language :: Python :: 3.11",
30+
"Programming Language :: Python :: 3.12",
3031
"Programming Language :: Python :: Implementation :: CPython",
3132
"Topic :: Software Development",
3233
"Topic :: Scientific/Engineering",

0 commit comments

Comments
 (0)