Skip to content

Commit faf965c

Browse files
Merge pull request #1612 from IntelPython/backport-gh-1558-take2
Backport gh 1558 to 0.16.x maintenance branch
2 parents 983ff64 + 733bc32 commit faf965c

18 files changed

+622
-33
lines changed

dpctl/_backend.pxd

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ cdef extern from "syclinterface/dpctl_sycl_enum_types.h":
6767
_UINT64_T 'DPCTL_UINT64_T',
6868
_FLOAT 'DPCTL_FLOAT32_T',
6969
_DOUBLE 'DPCTL_FLOAT64_T',
70-
_VOID_PTR 'DPCTL_VOID_PTR'
70+
_VOID_PTR 'DPCTL_VOID_PTR',
71+
_LOCAL_ACCESSOR 'DPCTL_LOCAL_ACCESSOR'
7172

7273
ctypedef enum _queue_property_type 'DPCTLQueuePropertyType':
7374
_DEFAULT_PROPERTY 'DPCTL_DEFAULT_PROPERTY'

dpctl/_sycl_queue.pyx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,15 @@ cdef class _kernel_arg_type:
233233
_arg_data_type._VOID_PTR
234234
)
235235

236+
@property
237+
def dpctl_local_accessor(self):
238+
cdef str p_name = "dpctl_local_accessor"
239+
return kernel_arg_type_attribute(
240+
self._name,
241+
p_name,
242+
_arg_data_type._LOCAL_ACCESSOR
243+
)
244+
236245

237246
kernel_arg_type = _kernel_arg_type()
238247

dpctl/enum_types.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@
2222
"""
2323
from enum import Enum, auto
2424

25-
__all__ = [
26-
"device_type",
27-
"backend_type",
28-
"event_status_type",
29-
]
25+
__all__ = ["device_type", "backend_type", "event_status_type"]
3026

3127

3228
class device_type(Enum):

dpctl/tests/test_sycl_kernel_submit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,4 @@ def test_kernel_arg_type():
274274
_check_kernel_arg_type_instance(kernel_arg_type.dpctl_float32)
275275
_check_kernel_arg_type_instance(kernel_arg_type.dpctl_float64)
276276
_check_kernel_arg_type_instance(kernel_arg_type.dpctl_void_ptr)
277+
_check_kernel_arg_type_instance(kernel_arg_type.dpctl_local_accessor)

libsyclinterface/dbg_build.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ pushd build || exit 1
77
INSTALL_PREFIX=$(pwd)/../install
88
rm -rf ${INSTALL_PREFIX}
99

10+
# With DPC++ 2024.0 adn newer set these to ensure that
11+
# cmake can find llvm-cov and other utilities
12+
LLVM_TOOLS_HOME=${CMPLR_ROOT}/bin/compiler
13+
PATH=$PATH:${CMPLR_ROOT}/bin/compiler
14+
1015
cmake \
1116
-DCMAKE_BUILD_TYPE=Debug \
1217
-DCMAKE_C_COMPILER=icx \
@@ -16,13 +21,19 @@ cmake \
1621
-DCMAKE_PREFIX_PATH=${INSTALL_PREFIX} \
1722
-DDPCTL_ENABLE_L0_PROGRAM_CREATION=ON \
1823
-DDPCTL_BUILD_CAPI_TESTS=ON \
24+
-DDPCTL_GENERATE_COVERAGE=OFF \
1925
..
2026

21-
make V=1 -n -j 4 && make check && make install
27+
# build
28+
make V=1 -n -j 4
29+
# run ctest
30+
make check
31+
# install
32+
make install
2233

2334
# Turn on to generate coverage report html files reconfigure with
2435
# -DDPCTL_GENERATE_COVERAGE=ON and then
25-
# make lcov-genhtml
36+
# make llvm-cov-report
2637

2738
# For more verbose tests use:
2839
# cd tests

libsyclinterface/helper/include/dpctl_error_handlers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
///
2121
/// \file
2222
/// A functor to use for passing an error handler callback function to sycl
23-
/// context and queue contructors.
23+
/// context and queue constructors.
2424
//===----------------------------------------------------------------------===//
2525

2626
#pragma once

libsyclinterface/include/dpctl_sycl_enum_types.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ typedef enum
9898
DPCTL_FLOAT32_T,
9999
DPCTL_FLOAT64_T,
100100
DPCTL_VOID_PTR,
101+
DPCTL_LOCAL_ACCESSOR,
101102
DPCTL_UNSUPPORTED_KERNEL_ARG
102103
} DPCTLKernelArgType;
103104

libsyclinterface/include/dpctl_sycl_queue_interface.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,18 @@ DPCTL_API
171171
__dpctl_give DPCTLSyclDeviceRef
172172
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef);
173173

174+
/*! @brief Structure to be used to specify dimensionality and type of
175+
* local_accessor kernel type argument.
176+
*/
177+
typedef struct MDLocalAccessorTy
178+
{
179+
size_t ndim;
180+
DPCTLKernelArgType dpctl_type_id;
181+
size_t dim0;
182+
size_t dim1;
183+
size_t dim2;
184+
} MDLocalAccessor;
185+
174186
/*!
175187
* @brief Submits the kernel to the specified queue with the provided range
176188
* argument.

libsyclinterface/source/dpctl_sycl_kernel_bundle_interface.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ _GetKernel_ze_impl(const kernel_bundle<bundle_state::executable> &kb,
530530
else {
531531
error_handler("Kernel named " + std::string(kernel_name) +
532532
" could not be found.",
533-
__FILE__, __func__, __LINE__);
533+
__FILE__, __func__, __LINE__, error_level::error);
534534
return nullptr;
535535
}
536536
}
@@ -541,7 +541,7 @@ bool _HasKernel_ze_impl(const kernel_bundle<bundle_state::executable> &kb,
541541
auto zeKernelCreateFn = get_zeKernelCreate();
542542
if (zeKernelCreateFn == nullptr) {
543543
error_handler("Could not load zeKernelCreate function.", __FILE__,
544-
__func__, __LINE__);
544+
__func__, __LINE__, error_level::error);
545545
return false;
546546
}
547547

@@ -564,7 +564,7 @@ bool _HasKernel_ze_impl(const kernel_bundle<bundle_state::executable> &kb,
564564
if (ze_status != ZE_RESULT_ERROR_INVALID_KERNEL_NAME) {
565565
error_handler("zeKernelCreate failed: " +
566566
_GetErrorCode_ze_impl(ze_status),
567-
__FILE__, __func__, __LINE__);
567+
__FILE__, __func__, __LINE__, error_level::error);
568568
return false;
569569
}
570570
}

libsyclinterface/source/dpctl_sycl_queue_interface.cpp

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,76 @@
3838

3939
using namespace sycl;
4040

41+
#define SET_LOCAL_ACCESSOR_ARG(CGH, NDIM, ARGTY, R, IDX) \
42+
do { \
43+
switch ((ARGTY)) { \
44+
case DPCTL_INT8_T: \
45+
{ \
46+
auto la = local_accessor<int8_t, NDIM>(R, CGH); \
47+
CGH.set_arg(IDX, la); \
48+
return true; \
49+
} \
50+
case DPCTL_UINT8_T: \
51+
{ \
52+
auto la = local_accessor<uint8_t, NDIM>(R, CGH); \
53+
CGH.set_arg(IDX, la); \
54+
return true; \
55+
} \
56+
case DPCTL_INT16_T: \
57+
{ \
58+
auto la = local_accessor<int16_t, NDIM>(R, CGH); \
59+
CGH.set_arg(IDX, la); \
60+
return true; \
61+
} \
62+
case DPCTL_UINT16_T: \
63+
{ \
64+
auto la = local_accessor<uint16_t, NDIM>(R, CGH); \
65+
CGH.set_arg(IDX, la); \
66+
return true; \
67+
} \
68+
case DPCTL_INT32_T: \
69+
{ \
70+
auto la = local_accessor<int32_t, NDIM>(R, CGH); \
71+
CGH.set_arg(IDX, la); \
72+
return true; \
73+
} \
74+
case DPCTL_UINT32_T: \
75+
{ \
76+
auto la = local_accessor<uint32_t, NDIM>(R, CGH); \
77+
CGH.set_arg(IDX, la); \
78+
return true; \
79+
} \
80+
case DPCTL_INT64_T: \
81+
{ \
82+
auto la = local_accessor<int64_t, NDIM>(R, CGH); \
83+
CGH.set_arg(IDX, la); \
84+
return true; \
85+
} \
86+
case DPCTL_UINT64_T: \
87+
{ \
88+
auto la = local_accessor<uint64_t, NDIM>(R, CGH); \
89+
CGH.set_arg(IDX, la); \
90+
return true; \
91+
} \
92+
case DPCTL_FLOAT32_T: \
93+
{ \
94+
auto la = local_accessor<float, NDIM>(R, CGH); \
95+
CGH.set_arg(IDX, la); \
96+
return true; \
97+
} \
98+
case DPCTL_FLOAT64_T: \
99+
{ \
100+
auto la = local_accessor<double, NDIM>(R, CGH); \
101+
CGH.set_arg(IDX, la); \
102+
return true; \
103+
} \
104+
default: \
105+
error_handler("Kernel argument could not be created.", __FILE__, \
106+
__func__, __LINE__, error_level::error); \
107+
return false; \
108+
} \
109+
} while (0);
110+
41111
namespace
42112
{
43113
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
@@ -62,11 +132,39 @@ void set_dependent_events(handler &cgh,
62132
}
63133
}
64134

135+
bool set_local_accessor_arg(handler &cgh,
136+
size_t idx,
137+
const MDLocalAccessor *mdstruct)
138+
{
139+
switch (mdstruct->ndim) {
140+
case 1:
141+
{
142+
auto r = range<1>(mdstruct->dim0);
143+
SET_LOCAL_ACCESSOR_ARG(cgh, 1, mdstruct->dpctl_type_id, r, idx);
144+
}
145+
case 2:
146+
{
147+
auto r = range<2>(mdstruct->dim0, mdstruct->dim1);
148+
SET_LOCAL_ACCESSOR_ARG(cgh, 2, mdstruct->dpctl_type_id, r, idx);
149+
}
150+
case 3:
151+
{
152+
auto r = range<3>(mdstruct->dim0, mdstruct->dim1, mdstruct->dim2);
153+
SET_LOCAL_ACCESSOR_ARG(cgh, 3, mdstruct->dpctl_type_id, r, idx);
154+
}
155+
default:
156+
return false;
157+
}
158+
}
65159
/*!
66160
* @brief Set the kernel arg object
67161
*
68-
* @param cgh My Param doc
69-
* @param Arg My Param doc
162+
* @param cgh SYCL command group handler using which a kernel is going to
163+
* be submitted.
164+
* @param idx The position of the argument in the list of arguments passed
165+
* to a kernel.
166+
* @param Arg A void* representing a kernel argument.
167+
* @param Argty A typeid specifying the C++ type of the Arg parameter.
70168
*/
71169
bool set_kernel_arg(handler &cgh,
72170
size_t idx,
@@ -109,10 +207,11 @@ bool set_kernel_arg(handler &cgh,
109207
case DPCTL_VOID_PTR:
110208
cgh.set_arg(idx, Arg);
111209
break;
210+
case DPCTL_LOCAL_ACCESSOR:
211+
arg_set = set_local_accessor_arg(cgh, idx, (MDLocalAccessor *)Arg);
212+
break;
112213
default:
113214
arg_set = false;
114-
error_handler("Kernel argument could not be created.", __FILE__,
115-
__func__, __LINE__);
116215
break;
117216
}
118217
return arg_set;

0 commit comments

Comments
 (0)