• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

IntelPython / dpctl / 47376819836

04 Dec 2026 04:30PM UTC coverage: 75.354% (+0.2%) from 75.182%
47376819836

Pull #2335

github

web-flow
Merge 58d6dee23 into 7fb677ad7
Pull Request #2335: Allow NumPy data types as arguments

1097 of 1532 branches covered (71.61%)

Branch coverage included in aggregate %.

41 of 43 new or added lines in 2 files covered. (95.35%)

4223 of 5528 relevant lines covered (76.39%)

300.33 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.91
/libsyclinterface/source/dpctl_sycl_queue_interface.cpp
1
//===----- dpctl_sycl_queue_interface.cpp - Implements C API for sycl::queue =//
2
//
3
//                      Data Parallel Control (dpctl)
4
//
5
// Copyright 2020 Intel Corporation
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
//    http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// distributed under the License is distributed on an "AS IS" BASIS,
15
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
// See the License for the specific language governing permissions and
17
// limitations under the License.
18
//
19
//===----------------------------------------------------------------------===//
20
///
21
/// \file
22
/// This file implements the data types and functions declared in
23
/// dpctl_sycl_queue_interface.h.
24
///
25
//===----------------------------------------------------------------------===//
26

27
#include "dpctl_sycl_queue_interface.h"
28
#include "Config/dpctl_config.h"
29
#include "dpctl_error_handlers.h"
30
#include "dpctl_sycl_context_interface.h"
31
#include "dpctl_sycl_device_interface.h"
32
#include "dpctl_sycl_device_manager.h"
33
#include "dpctl_sycl_type_casters.hpp"
34

35
#include <stddef.h>
36
#include <stdint.h>
37

38
#include <cstdint>
39
#include <cstring>
40
#include <exception>
41
#include <optional>
42
#include <sstream>
43
#include <stdexcept>
44
#include <sycl/sycl.hpp> /* SYCL headers   */
45
#include <utility>
46
#include <vector>
47

48
#if defined(SYCL_EXT_ONEAPI_WORK_GROUP_MEMORY) ||                              \
49
    defined(SYCL_EXT_ONEAPI_RAW_KERNEL_ARG)
50
#include "dpctl_sycl_extension_interface.h"
51
#endif
52

53
using namespace sycl;
54

55
#ifndef __ADAPTIVECPP__
56
#define SET_LOCAL_ACCESSOR_ARG(CGH, NDIM, ARGTY, R, IDX)                       \
57
    do {                                                                       \
37 ✔
58
        switch ((ARGTY)) {                                                     \
37 ✔
59
        case DPCTL_INT8_T:                                                     \
3 ✔
60
        {                                                                      \
3 ✔
61
            auto la = local_accessor<std::int8_t, NDIM>(R, CGH);               \
3 ✔
62
            CGH.set_arg(IDX, la);                                              \
3 ✔
63
            return true;                                                       \
3 ✔
64
        }                                                                      \
×
65
        case DPCTL_UINT8_T:                                                    \
3 ✔
66
        {                                                                      \
3 ✔
67
            auto la = local_accessor<std::uint8_t, NDIM>(R, CGH);              \
3 ✔
68
            CGH.set_arg(IDX, la);                                              \
3 ✔
69
            return true;                                                       \
3 ✔
70
        }                                                                      \
×
71
        case DPCTL_INT16_T:                                                    \
3 ✔
72
        {                                                                      \
3 ✔
73
            auto la = local_accessor<std::int16_t, NDIM>(R, CGH);              \
3 ✔
74
            CGH.set_arg(IDX, la);                                              \
3 ✔
75
            return true;                                                       \
3 ✔
76
        }                                                                      \
×
77
        case DPCTL_UINT16_T:                                                   \
3 ✔
78
        {                                                                      \
3 ✔
79
            auto la = local_accessor<std::uint16_t, NDIM>(R, CGH);             \
3 ✔
80
            CGH.set_arg(IDX, la);                                              \
3 ✔
81
            return true;                                                       \
3 ✔
82
        }                                                                      \
×
83
        case DPCTL_INT32_T:                                                    \
3 ✔
84
        {                                                                      \
3 ✔
85
            auto la = local_accessor<std::int32_t, NDIM>(R, CGH);              \
3 ✔
86
            CGH.set_arg(IDX, la);                                              \
3 ✔
87
            return true;                                                       \
3 ✔
88
        }                                                                      \
×
89
        case DPCTL_UINT32_T:                                                   \
7 ✔
90
        {                                                                      \
7 ✔
91
            auto la = local_accessor<std::uint32_t, NDIM>(R, CGH);             \
7 ✔
92
            CGH.set_arg(IDX, la);                                              \
7 ✔
93
            return true;                                                       \
7 ✔
94
        }                                                                      \
×
95
        case DPCTL_INT64_T:                                                    \
3 ✔
96
        {                                                                      \
3 ✔
97
            auto la = local_accessor<std::int64_t, NDIM>(R, CGH);              \
3 ✔
98
            CGH.set_arg(IDX, la);                                              \
3 ✔
99
            return true;                                                       \
3 ✔
100
        }                                                                      \
×
101
        case DPCTL_UINT64_T:                                                   \
4 ✔
102
        {                                                                      \
4 ✔
103
            auto la = local_accessor<std::uint64_t, NDIM>(R, CGH);             \
4 ✔
104
            CGH.set_arg(IDX, la);                                              \
4 ✔
105
            return true;                                                       \
4 ✔
106
        }                                                                      \
×
107
        case DPCTL_FLOAT32_T:                                                  \
3 ✔
108
        {                                                                      \
3 ✔
109
            auto la = local_accessor<float, NDIM>(R, CGH);                     \
3 ✔
110
            CGH.set_arg(IDX, la);                                              \
3 ✔
111
            return true;                                                       \
3 ✔
112
        }                                                                      \
×
113
        case DPCTL_FLOAT64_T:                                                  \
3 ✔
114
        {                                                                      \
3 ✔
115
            auto la = local_accessor<double, NDIM>(R, CGH);                    \
3 ✔
116
            CGH.set_arg(IDX, la);                                              \
3 ✔
117
            return true;                                                       \
3 ✔
118
        }                                                                      \
×
119
        case DPCTL_BYTES16_T:                                                  \
1 ✔
120
        {                                                                      \
1 ✔
121
            auto la = local_accessor<complexNumber, NDIM>(R, CGH);             \
1 ✔
122
            CGH.set_arg(IDX, la);                                              \
1 ✔
123
            return true;                                                       \
1 ✔
NEW
124
        }                                                                      \
×
125
        default:                                                               \
1 ✔
126
            error_handler("Kernel argument could not be created.", __FILE__,   \
1 ✔
127
                          __func__, __LINE__, error_level::error);             \
1 ✔
128
            return false;                                                      \
1 ✔
129
        }                                                                      \
37 ✔
130
    } while (0);
37 !
131
#endif
132

133
namespace
134
{
135
#ifndef __ADAPTIVECPP__
136
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
137
              "The compiler does not meet minimum version requirement");
138
#endif
139

140
using namespace dpctl::syclinterface;
141

142
typedef struct complex
143
{
144
    std::uint64_t real;
145
    std::uint64_t imag;
146
} complexNumber;
147

148
#ifndef __ADAPTIVECPP__
149

150
void set_dependent_events(handler &cgh,
151
                          __dpctl_keep const DPCTLSyclEventRef *DepEvents,
152
                          size_t NDepEvents)
153
{
202 ✔
154
    for (auto i = 0ul; i < NDepEvents; ++i) {
359 ✔
155
        auto ei = unwrap<event>(DepEvents[i]);
157 ✔
156
        if (ei)
157 !
157
            cgh.depends_on(*ei);
157 ✔
158
    }
157 ✔
159
}
202 ✔
160

161
bool set_local_accessor_arg(handler &cgh,
162
                            size_t idx,
163
                            const MDLocalAccessor *mdstruct)
164
{
37 ✔
165
    switch (mdstruct->ndim) {
37 ✔
166
    case 1:
17 ✔
167
    {
17 ✔
168
        auto r = range<1>(mdstruct->dim0);
17 ✔
169
        SET_LOCAL_ACCESSOR_ARG(cgh, 1, mdstruct->dpctl_type_id, r, idx);
17 ✔
170
    }
×
171
    case 2:
10 ✔
172
    {
10 ✔
173
        auto r = range<2>(mdstruct->dim0, mdstruct->dim1);
10 ✔
174
        SET_LOCAL_ACCESSOR_ARG(cgh, 2, mdstruct->dpctl_type_id, r, idx);
10 ✔
175
    }
×
176
    case 3:
10 ✔
177
    {
10 ✔
178
        auto r = range<3>(mdstruct->dim0, mdstruct->dim1, mdstruct->dim2);
10 ✔
179
        SET_LOCAL_ACCESSOR_ARG(cgh, 3, mdstruct->dpctl_type_id, r, idx);
10 ✔
180
    }
×
181
    default:
×
182
        return false;
×
183
    }
37 ✔
184
}
37 ✔
185
/*!
186
 * @brief Set the kernel arg object
187
 *
188
 * @param cgh   SYCL command group handler using which a kernel is going to
189
 * be submitted.
190
 * @param idx   The position of the argument in the list of arguments passed
191
 * to a kernel.
192
 * @param Arg   A void* representing a kernel argument.
193
 * @param Argty A typeid specifying the C++ type of the Arg parameter.
194
 */
195
bool set_kernel_arg(handler &cgh,
196
                    size_t idx,
197
                    __dpctl_keep void *Arg,
198
                    DPCTLKernelArgType ArgTy)
199
{
573 ✔
200
    bool arg_set = true;
573 ✔
201

202
    switch (ArgTy) {
573 ✔
203
    case DPCTL_INT8_T:
3 ✔
204
        cgh.set_arg(idx, *(std::int8_t *)Arg);
3 ✔
205
        break;
3 ✔
206
    case DPCTL_UINT8_T:
5 ✔
207
        cgh.set_arg(idx, *(std::uint8_t *)Arg);
5 ✔
208
        break;
5 ✔
209
    case DPCTL_INT16_T:
9 ✔
210
        cgh.set_arg(idx, *(std::int16_t *)Arg);
9 ✔
211
        break;
9 ✔
212
    case DPCTL_UINT16_T:
7 ✔
213
        cgh.set_arg(idx, *(std::uint16_t *)Arg);
7 ✔
214
        break;
7 ✔
215
    case DPCTL_INT32_T:
13 ✔
216
        cgh.set_arg(idx, *(std::int32_t *)Arg);
13 ✔
217
        break;
13 ✔
218
    case DPCTL_UINT32_T:
17 ✔
219
        cgh.set_arg(idx, *(std::uint32_t *)Arg);
17 ✔
220
        break;
17 ✔
221
    case DPCTL_INT64_T:
9 ✔
222
        cgh.set_arg(idx, *(std::int64_t *)Arg);
9 ✔
223
        break;
9 ✔
224
    case DPCTL_UINT64_T:
21 ✔
225
        cgh.set_arg(idx, *(std::uint64_t *)Arg);
21 ✔
226
        break;
21 ✔
227
    case DPCTL_FLOAT32_T:
9 ✔
228
        cgh.set_arg(idx, *(float *)Arg);
9 ✔
229
        break;
9 ✔
230
    case DPCTL_FLOAT64_T:
9 ✔
231
        cgh.set_arg(idx, *(double *)Arg);
9 ✔
232
        break;
9 ✔
233
    case DPCTL_BYTES16_T:
1 ✔
234
    {
1 ✔
235
        complexNumber Val;
1 ✔
236
        std::memcpy(&Val, Arg, sizeof(Val));
1 ✔
237
        cgh.set_arg(idx, Val);
1 ✔
238
        break;
1 ✔
NEW
239
    }
×
240
    case DPCTL_VOID_PTR:
371 ✔
241
        cgh.set_arg(idx, Arg);
371 ✔
242
        break;
371 ✔
243
    case DPCTL_LOCAL_ACCESSOR:
37 ✔
244
        arg_set = set_local_accessor_arg(cgh, idx, (MDLocalAccessor *)Arg);
37 ✔
245
        break;
37 ✔
246
#ifdef SYCL_EXT_ONEAPI_WORK_GROUP_MEMORY
×
247
    case DPCTL_WORK_GROUP_MEMORY:
31 ✔
248
    {
31 ✔
249
        auto ref = static_cast<DPCTLSyclWorkGroupMemoryRef>(Arg);
31 ✔
250
        RawWorkGroupMemory *raw_mem = unwrap<RawWorkGroupMemory>(ref);
31 ✔
251
        size_t num_bytes = raw_mem->nbytes;
31 ✔
252
        sycl::ext::oneapi::experimental::work_group_memory<char[]> mem{
31 ✔
253
            num_bytes, cgh};
31 ✔
254
        cgh.set_arg(idx, mem);
31 ✔
255
        break;
31 ✔
256
    }
×
257
#endif
×
258
#ifdef SYCL_EXT_ONEAPI_RAW_KERNEL_ARG
×
259
    case DPCTL_RAW_KERNEL_ARG:
31 ✔
260
    {
31 ✔
261
        auto ref = static_cast<DPCTLSyclRawKernelArgRef>(Arg);
31 ✔
262
        std::vector<unsigned char> *raw_arg =
31 ✔
263
            unwrap<std::vector<unsigned char>>(ref);
31 ✔
264
        void *bytes = raw_arg->data();
31 ✔
265
        size_t count = raw_arg->size();
31 ✔
266
        sycl::ext::oneapi::experimental::raw_kernel_arg arg{bytes, count};
31 ✔
267
        cgh.set_arg(idx, arg);
31 ✔
268
        break;
31 ✔
269
    }
×
270
#endif
×
271
    default:
×
272
        arg_set = false;
×
273
        break;
×
274
    }
573 ✔
275
    return arg_set;
573 ✔
276
}
573 ✔
277

278
void set_kernel_args(handler &cgh,
279
                     __dpctl_keep void **Args,
280
                     __dpctl_keep const DPCTLKernelArgType *ArgTypes,
281
                     size_t NArgs)
282
{
202 ✔
283
    for (auto i = 0ul; i < NArgs; ++i) {
774 ✔
284
        if (!set_kernel_arg(cgh, i, Args[i], ArgTypes[i])) {
573 ✔
285
            error_handler("Kernel argument could not be created.", __FILE__,
1 ✔
286
                          __func__, __LINE__);
1 ✔
287
            throw std::invalid_argument(
1 ✔
288
                "Kernel argument could not be created.");
1 ✔
289
        }
1 ✔
290
    }
573 ✔
291
}
202 ✔
292

293
#endif /* #ifndef __ADAPTIVECPP__ */
294

295
std::unique_ptr<property_list> create_property_list(int properties)
296
{
1,956 ✔
297
    std::unique_ptr<property_list> propList;
1,956 ✔
298
    int _prop = properties;
1,956 ✔
299
    if (_prop & DPCTL_ENABLE_PROFILING) {
1,956 ✔
300
        _prop = _prop ^ DPCTL_ENABLE_PROFILING;
90 ✔
301
        if (_prop & DPCTL_IN_ORDER) {
90 ✔
302
            _prop = _prop ^ DPCTL_IN_ORDER;
38 ✔
303
            propList = std::make_unique<property_list>(
38 ✔
304
                sycl::property::queue::enable_profiling(),
38 ✔
305
                sycl::property::queue::in_order());
38 ✔
306
        }
38 ✔
307
        else {
52 ✔
308
            propList = std::make_unique<property_list>(
52 ✔
309
                sycl::property::queue::enable_profiling());
52 ✔
310
        }
52 ✔
311
    }
90 ✔
312
    else if (_prop & DPCTL_IN_ORDER) {
1,866 ✔
313
        _prop = _prop ^ DPCTL_IN_ORDER;
577 ✔
314
        propList =
577 ✔
315
            std::make_unique<property_list>(sycl::property::queue::in_order());
577 ✔
316
    }
577 ✔
317
    else {
1,289 ✔
318
        propList = std::make_unique<property_list>();
1,289 ✔
319
    }
1,289 ✔
320

321
    if (_prop) {
1,956 ✔
322
        std::stringstream ss;
1 ✔
323
        ss << "Invalid queue property argument (" << std::hex << properties
1 ✔
324
           << "), interpreted as (" << (properties ^ _prop) << ").";
1 ✔
325
        error_handler(ss.str(), __FILE__, __func__, __LINE__);
1 ✔
326
    }
1 ✔
327
    return propList;
1,956 ✔
328
}
1,956 ✔
329

330
__dpctl_give DPCTLSyclQueueRef
331
getQueueImpl(__dpctl_keep DPCTLSyclContextRef cRef,
332
             __dpctl_keep DPCTLSyclDeviceRef dRef,
333
             error_handler_callback *handler,
334
             int properties)
335
{
211 ✔
336
    DPCTLSyclQueueRef qRef = nullptr;
211 ✔
337
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
211 ✔
338
    return qRef;
211 ✔
339
}
211 ✔
340

341
} /* end of anonymous namespace */
342

343
DPCTL_API
344
__dpctl_give DPCTLSyclQueueRef
345
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
346
                  __dpctl_keep const DPCTLSyclDeviceRef DRef,
347
                  error_handler_callback *handler,
348
                  int properties)
349
{
1,958 ✔
350
    DPCTLSyclQueueRef q = nullptr;
1,958 ✔
351
    auto dev = unwrap<device>(DRef);
1,958 ✔
352
    auto ctx = unwrap<context>(CRef);
1,958 ✔
353

354
    if (!(dev && ctx)) {
1,958 ✔
355
        error_handler("Cannot create queue from DPCTLSyclContextRef and "
2 ✔
356
                      "DPCTLSyclDeviceRef as input is a nullptr.",
2 ✔
357
                      __FILE__, __func__, __LINE__);
2 ✔
358
        return q;
2 ✔
359
    }
2 ✔
360
    auto propList = create_property_list(properties);
1,956 ✔
361

362
    if (handler) {
1,956 ✔
363
        try {
68 ✔
364
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
68 ✔
365
                                   *propList);
68 ✔
366
            q = wrap<queue>(Queue);
68 ✔
367
        } catch (std::exception const &e) {
68 ✔
368
            error_handler(e, __FILE__, __func__, __LINE__);
×
369
        }
×
370
    }
68 ✔
371
    else {
1,888 ✔
372
        try {
1,888 ✔
373
#ifdef __ADAPTIVECPP__
374
            // a queue with no handler of its own inherits the default handler
375
            // of the AdaptiveCpp context, which calls std::terminate
376
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(nullptr),
377
                                   *propList);
378
#else
379
            auto Queue = new queue(*ctx, *dev, *propList);
1,888 ✔
380
#endif
1,888 ✔
381
            q = wrap<queue>(Queue);
1,888 ✔
382
        } catch (std::exception const &e) {
1,888 ✔
383
            error_handler(e, __FILE__, __func__, __LINE__);
1 ✔
384
        }
1 ✔
385
    }
1,888 ✔
386

387
    return q;
1,956 ✔
388
}
1,956 ✔
389

390
__dpctl_give DPCTLSyclQueueRef
391
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
392
                           error_handler_callback *handler,
393
                           int properties)
394
{
493 ✔
395
    DPCTLSyclContextRef CRef = nullptr;
493 ✔
396
    DPCTLSyclQueueRef QRef = nullptr;
493 ✔
397
    auto Device = unwrap<device>(DRef);
493 ✔
398

399
    if (!Device) {
493 ✔
400
        error_handler("Cannot create queue from NULL device reference.",
282 ✔
401
                      __FILE__, __func__, __LINE__);
282 ✔
402
        return QRef;
282 ✔
403
    }
282 ✔
404
    // Check if a cached default context exists for the device.
405
    CRef = DPCTLDeviceMgr_GetCachedContext(DRef);
211 ✔
406
    // If a cached default context was found, that context will be used to use
407
    // create the new queue. When a default cached context was not found, as
408
    // will be the case for non-root devices, i.e., sub-devices, a new context
409
    // will be allocated. Note that any newly allocated context is not cached.
410
    if (!CRef) {
211 !
411
        context *ContextPtr = nullptr;
×
412
        try {
×
413
            ContextPtr = new context(*Device);
×
414
            CRef = wrap<context>(ContextPtr);
×
415
        } catch (std::exception const &e) {
×
416
            error_handler(e, __FILE__, __func__, __LINE__);
×
417
            delete ContextPtr;
×
418
            return QRef;
×
419
        }
×
420
    }
×
421
    // At this point we have a valid context and the queue can be allocated.
422
    QRef = getQueueImpl(CRef, DRef, handler, properties);
211 ✔
423
    // Free the context
424
    DPCTLContext_Delete(CRef);
211 ✔
425
    return QRef;
211 ✔
426
}
211 ✔
427

428
/*!
429
 * Delete the passed in pointer after verifying it points to a sycl::queue.
430
 */
431
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef)
432
{
2,346 ✔
433
    delete unwrap<queue>(QRef);
2,346 ✔
434
}
2,346 ✔
435

436
/*!
437
 * Make copy of sycl::queue referenced by passed pointer
438
 */
439
__dpctl_give DPCTLSyclQueueRef
440
DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef)
441
{
116 ✔
442
    auto Queue = unwrap<queue>(QRef);
116 ✔
443
    if (Queue) {
116 ✔
444
        try {
115 ✔
445
            auto CopiedQueue = new queue(*Queue);
115 ✔
446
            return wrap<queue>(CopiedQueue);
115 ✔
447
        } catch (std::exception const &e) {
115 ✔
448
            error_handler(e, __FILE__, __func__, __LINE__);
×
449
            return nullptr;
×
450
        }
×
451
    }
115 ✔
452
    else {
1 ✔
453
        error_handler("Cannot copy DPCTLSyclQueueRef as input is a nullptr",
1 ✔
454
                      __FILE__, __func__, __LINE__);
1 ✔
455
        return nullptr;
1 ✔
456
    }
1 ✔
457
}
116 ✔
458

459
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
460
                      __dpctl_keep const DPCTLSyclQueueRef QRef2)
461
{
27 ✔
462
    if (!(QRef1 && QRef2)) {
27 ✔
463
        error_handler("DPCTLSyclQueueRefs are nullptr.", __FILE__, __func__,
2 ✔
464
                      __LINE__);
2 ✔
465
        return false;
2 ✔
466
    }
2 ✔
467
    return (*unwrap<queue>(QRef1) == *unwrap<queue>(QRef2));
25 ✔
468
}
27 ✔
469

470
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
471
{
10 ✔
472
    auto Q = unwrap<queue>(QRef);
10 ✔
473
    if (Q) {
10 ✔
474
        try {
9 ✔
475
            auto C = Q->get_context();
9 ✔
476
            return DPCTLContext_GetBackend(wrap<context>(&C));
9 ✔
477
        } catch (std::exception const &e) {
9 ✔
478
            error_handler(e, __FILE__, __func__, __LINE__);
×
479
            return DPCTL_UNKNOWN_BACKEND;
×
480
        }
×
481
    }
9 ✔
482
    else
1 ✔
483
        return DPCTL_UNKNOWN_BACKEND;
1 ✔
484
}
10 ✔
485

486
__dpctl_give DPCTLSyclDeviceRef
487
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef)
488
{
74 ✔
489
    DPCTLSyclDeviceRef DRef = nullptr;
74 ✔
490
    auto Q = unwrap<queue>(QRef);
74 ✔
491
    if (Q) {
74 ✔
492
        try {
73 ✔
493
            auto Device = new device(Q->get_device());
73 ✔
494
            DRef = wrap<device>(Device);
73 ✔
495
        } catch (std::exception const &e) {
73 ✔
496
            error_handler(e, __FILE__, __func__, __LINE__);
×
497
        }
×
498
    }
73 ✔
499
    else {
1 ✔
500
        error_handler("Could not get the device for this queue.", __FILE__,
1 ✔
501
                      __func__, __LINE__);
1 ✔
502
    }
1 ✔
503
    return DRef;
74 ✔
504
}
74 ✔
505

506
__dpctl_give DPCTLSyclContextRef
507
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
508
{
142 ✔
509
    auto Q = unwrap<queue>(QRef);
142 ✔
510
    DPCTLSyclContextRef CRef = nullptr;
142 ✔
511
    if (Q)
142 ✔
512
        CRef = wrap<context>(new context(Q->get_context()));
132 ✔
513
    else {
10 ✔
514
        error_handler("Could not get the context for this queue.", __FILE__,
10 ✔
515
                      __func__, __LINE__);
10 ✔
516
    }
10 ✔
517
    return CRef;
142 ✔
518
}
142 ✔
519

520
__dpctl_give DPCTLSyclEventRef
521
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
522
                       __dpctl_keep const DPCTLSyclQueueRef QRef,
523
                       __dpctl_keep void **Args,
524
                       __dpctl_keep const DPCTLKernelArgType *ArgTypes,
525
                       size_t NArgs,
526
                       __dpctl_keep const size_t Range[3],
527
                       size_t NDims,
528
                       __dpctl_keep const DPCTLSyclEventRef *DepEvents,
529
                       size_t NDepEvents)
530
{
83 ✔
531
    if (!KRef) {
83 ✔
532
        error_handler("Cannot submit the kernel as the kernel is a nullptr.",
2 ✔
533
                      __FILE__, __func__, __LINE__, error_level::error);
2 ✔
534
        return nullptr;
2 ✔
535
    }
2 ✔
536
    if (!QRef) {
81 ✔
537
        error_handler("Cannot submit the kernel as the queue is a nullptr.",
1 ✔
538
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
539
        return nullptr;
1 ✔
540
    }
1 ✔
541

542
#ifndef __ADAPTIVECPP__
80 ✔
543
    auto Kernel = unwrap<kernel>(KRef);
80 ✔
544
    auto Queue = unwrap<queue>(QRef);
80 ✔
545
    event e;
80 ✔
546

547
    try {
80 ✔
548
        switch (NDims) {
80 ✔
549
        case 1:
46 ✔
550
        {
46 ✔
551
            e = Queue->submit([&](handler &cgh) {
46 ✔
552
                set_dependent_events(cgh, DepEvents, NDepEvents);
46 ✔
553
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
46 ✔
554
                cgh.parallel_for(range<1>{Range[0]}, *Kernel);
46 ✔
555
            });
46 ✔
556
            return wrap<event>(new event(std::move(e)));
46 ✔
557
        }
×
558
        case 2:
17 ✔
559
        {
17 ✔
560
            e = Queue->submit([&](handler &cgh) {
17 ✔
561
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
562
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
563
                cgh.parallel_for(range<2>{Range[0], Range[1]}, *Kernel);
17 ✔
564
            });
17 ✔
565
            return wrap<event>(new event(std::move(e)));
17 ✔
566
        }
×
567
        case 3:
17 ✔
568
        {
17 ✔
569
            e = Queue->submit([&](handler &cgh) {
17 ✔
570
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
571
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
572
                cgh.parallel_for(range<3>{Range[0], Range[1], Range[2]},
17 ✔
573
                                 *Kernel);
17 ✔
574
            });
17 ✔
575
            return wrap<event>(new event(std::move(e)));
17 ✔
576
        }
×
577
        default:
×
578
            error_handler("Range cannot be greater than three dimensions.",
×
579
                          __FILE__, __func__, __LINE__, error_level::error);
×
580
            return nullptr;
×
581
        }
80 ✔
582
    } catch (std::exception const &e) {
80 ✔
583
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
×
584
        return nullptr;
×
585
    } catch (...) {
×
586
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
587
                      __LINE__, error_level::error);
×
588
        return nullptr;
×
589
    }
×
590
#else
591
    error_handler("Dynamic OpenCL-style kernel execution is not supported in "
592
                  "AdaptiveCpp.",
593
                  __FILE__, __func__, __LINE__, error_level::error);
594
    return nullptr;
595
#endif
596
}
80 ✔
597

598
__dpctl_give DPCTLSyclEventRef
599
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
600
                         __dpctl_keep const DPCTLSyclQueueRef QRef,
601
                         __dpctl_keep void **Args,
602
                         __dpctl_keep const DPCTLKernelArgType *ArgTypes,
603
                         size_t NArgs,
604
                         __dpctl_keep const size_t gRange[3],
605
                         __dpctl_keep const size_t lRange[3],
606
                         size_t NDims,
607
                         __dpctl_keep const DPCTLSyclEventRef *DepEvents,
608
                         size_t NDepEvents)
609
{
124 ✔
610
    if (!KRef) {
124 ✔
611
        error_handler("Cannot submit the kernel as the kernel is a nullptr.",
1 ✔
612
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
613
        return nullptr;
1 ✔
614
    }
1 ✔
615
    if (!QRef) {
123 ✔
616
        error_handler("Cannot submit the kernel as the queue is a nullptr.",
1 ✔
617
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
618
        return nullptr;
1 ✔
619
    }
1 ✔
620

621
#ifndef __ADAPTIVECPP__
122 ✔
622
    auto Kernel = unwrap<kernel>(KRef);
122 ✔
623
    auto Queue = unwrap<queue>(QRef);
122 ✔
624
    event e;
122 ✔
625

626
    try {
122 ✔
627
        switch (NDims) {
122 ✔
628
        case 1:
108 ✔
629
        {
108 ✔
630
            e = Queue->submit([&](handler &cgh) {
108 ✔
631
                set_dependent_events(cgh, DepEvents, NDepEvents);
108 ✔
632
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
108 ✔
633
                cgh.parallel_for(nd_range<1>{{gRange[0]}, {lRange[0]}},
108 ✔
634
                                 *Kernel);
108 ✔
635
            });
108 ✔
636
            return wrap<event>(new event(std::move(e)));
108 ✔
637
        }
×
638
        case 2:
7 ✔
639
        {
7 ✔
640
            e = Queue->submit([&](handler &cgh) {
7 ✔
641
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
642
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
643
                cgh.parallel_for(
7 ✔
644
                    nd_range<2>{{gRange[0], gRange[1]}, {lRange[0], lRange[1]}},
7 ✔
645
                    *Kernel);
7 ✔
646
            });
7 ✔
647
            return wrap<event>(new event(std::move(e)));
7 ✔
648
        }
×
649
        case 3:
7 ✔
650
        {
7 ✔
651
            e = Queue->submit([&](handler &cgh) {
7 ✔
652
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
653
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
654
                cgh.parallel_for(nd_range<3>{{gRange[0], gRange[1], gRange[2]},
7 ✔
655
                                             {lRange[0], lRange[1], lRange[2]}},
7 ✔
656
                                 *Kernel);
7 ✔
657
            });
7 ✔
658
            return wrap<event>(new event(std::move(e)));
7 ✔
659
        }
×
660
        default:
×
661
            error_handler("Range cannot be greater than three dimensions.",
×
662
                          __FILE__, __func__, __LINE__, error_level::error);
×
663
            return nullptr;
×
664
        }
122 ✔
665
    } catch (std::exception const &e) {
122 ✔
666
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
2 ✔
667
        return nullptr;
2 ✔
668
    } catch (...) {
2 ✔
669
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
670
                      __LINE__, error_level::error);
×
671
        return nullptr;
×
672
    }
×
673
#else
674
    error_handler("Dynamic OpenCL-style kernel execution is not supported in "
675
                  "AdaptiveCpp.",
676
                  __FILE__, __func__, __LINE__, error_level::error);
677
    return nullptr;
678
#endif
679
}
122 ✔
680

681
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
682
{
37 ✔
683
    // \todo what happens if the QRef is null or a pointer to a valid sycl
684
    // queue
685
    if (QRef) {
37 !
686
        auto SyclQueue = unwrap<queue>(QRef);
37 ✔
687
        if (SyclQueue)
37 !
688
            SyclQueue->wait();
37 ✔
689
    }
37 ✔
690
    else {
×
691
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
×
692
    }
×
693
}
37 ✔
694

695
__dpctl_give DPCTLSyclEventRef
696
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
697
                  void *Dest,
698
                  const void *Src,
699
                  size_t Count)
700
{
295 ✔
701
    auto Q = unwrap<queue>(QRef);
295 ✔
702
    if (Q) {
295 ✔
703
        sycl::event ev;
294 ✔
704
        try {
294 ✔
705
            ev = Q->memcpy(Dest, Src, Count);
294 ✔
706
        } catch (std::exception const &e) {
294 ✔
707
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
708
            return nullptr;
8 ✔
709
        }
8 ✔
710
        return wrap<event>(new event(std::move(ev)));
286 ✔
711
    }
294 ✔
712
    else {
1 ✔
713
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
714
                      __LINE__);
1 ✔
715
        return nullptr;
1 ✔
716
    }
1 ✔
717
}
295 ✔
718

719
__dpctl_give DPCTLSyclEventRef
720
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
721
                            void *Dest,
722
                            const void *Src,
723
                            size_t Count,
724
                            const DPCTLSyclEventRef *DepEvents,
725
                            size_t DepEventsCount)
726
{
146 ✔
727
    event ev;
146 ✔
728
    auto Q = unwrap<queue>(QRef);
146 ✔
729
    if (Q) {
146 ✔
730
        try {
145 ✔
731
            ev = Q->submit([&](handler &cgh) {
145 ✔
732
                if (DepEvents)
145 ✔
733
                    for (size_t i = 0; i < DepEventsCount; ++i) {
417 ✔
734
                        event *ei = unwrap<event>(DepEvents[i]);
280 ✔
735
                        if (ei)
280 !
736
                            cgh.depends_on(*ei);
280 ✔
737
                    }
280 ✔
738

739
                cgh.memcpy(Dest, Src, Count);
145 ✔
740
            });
145 ✔
741
        } catch (const std::exception &ex) {
145 ✔
742
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
743
            return nullptr;
8 ✔
744
        }
8 ✔
745
    }
145 ✔
746
    else {
1 ✔
747
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
748
                      __LINE__);
1 ✔
749
        return nullptr;
1 ✔
750
    }
1 ✔
751

752
    return wrap<event>(new event(ev));
137 ✔
753
}
146 ✔
754

755
__dpctl_give DPCTLSyclEventRef
756
DPCTLQueue_CopyData(__dpctl_keep const DPCTLSyclQueueRef QRef,
757
                    void *Dest,
758
                    const void *Src,
759
                    size_t Count)
760
{
62 ✔
761
    auto Q = unwrap<queue>(QRef);
62 ✔
762
    if (Q) {
62 ✔
763
        sycl::event ev;
61 ✔
764
        try {
61 ✔
765
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
766
            ev = Q->copy(static_cast<const std::uint8_t *>(Src),
61 ✔
767
                         static_cast<std::uint8_t *>(Dest), Count);
61 ✔
768
        } catch (std::exception const &e) {
61 ✔
769
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
770
            return nullptr;
8 ✔
771
        }
8 ✔
772
        return wrap<event>(new event(std::move(ev)));
53 ✔
773
    }
61 ✔
774
    else {
1 ✔
775
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
776
                      __LINE__);
1 ✔
777
        return nullptr;
1 ✔
778
    }
1 ✔
779
}
62 ✔
780

781
__dpctl_give DPCTLSyclEventRef
782
DPCTLQueue_CopyDataWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
783
                              void *Dest,
784
                              const void *Src,
785
                              size_t Count,
786
                              const DPCTLSyclEventRef *DepEvents,
787
                              size_t DepEventsCount)
788
{
24 ✔
789
    auto Q = unwrap<queue>(QRef);
24 ✔
790
    if (Q) {
24 ✔
791
        try {
23 ✔
792
            std::vector<event> dep_events;
23 ✔
793
            if (DepEvents) {
23 ✔
794
                dep_events.reserve(DepEventsCount);
15 ✔
795
                for (size_t i = 0; i < DepEventsCount; ++i) {
30 ✔
796
                    event *ei = unwrap<event>(DepEvents[i]);
15 ✔
797
                    if (ei)
15 !
798
                        dep_events.push_back(*ei);
15 ✔
799
                }
15 ✔
800
            }
15 ✔
801

802
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
803
            auto ev =
23 ✔
804
                Q->copy(static_cast<const std::uint8_t *>(Src),
23 ✔
805
                        static_cast<std::uint8_t *>(Dest), Count, dep_events);
23 ✔
806
            return wrap<event>(new event(std::move(ev)));
23 ✔
807
        } catch (const std::exception &ex) {
23 ✔
808
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
809
            return nullptr;
8 ✔
810
        }
8 ✔
811
    }
23 ✔
812
    else {
1 ✔
813
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
814
                      __LINE__);
1 ✔
815
        return nullptr;
1 ✔
816
    }
1 ✔
817
}
24 ✔
818

819
__dpctl_give DPCTLSyclEventRef
820
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
821
                    const void *Ptr,
822
                    size_t Count)
823
{
16 ✔
824
    auto Q = unwrap<queue>(QRef);
16 ✔
825
    if (Q) {
16 ✔
826
        if (Ptr) {
15 ✔
827
            sycl::event ev;
7 ✔
828
            try {
7 ✔
829
                ev = Q->prefetch(Ptr, Count);
7 ✔
830
            } catch (std::exception const &e) {
7 ✔
831
                error_handler(e, __FILE__, __func__, __LINE__);
×
832
                return nullptr;
×
833
            }
×
834
            return wrap<event>(new event(std::move(ev)));
7 ✔
835
        }
7 ✔
836
        else {
8 ✔
837
            error_handler("Attempt to prefetch USM-allocation at nullptr.",
8 ✔
838
                          __FILE__, __func__, __LINE__);
8 ✔
839
            return nullptr;
8 ✔
840
        }
8 ✔
841
    }
15 ✔
842
    else {
1 ✔
843
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
844
                      __LINE__);
1 ✔
845
        return nullptr;
1 ✔
846
    }
1 ✔
847
}
16 ✔
848

849
__dpctl_give DPCTLSyclEventRef
850
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
851
                     const void *Ptr,
852
                     size_t Count,
853
                     int Advice)
854
{
16 ✔
855
    auto Q = unwrap<queue>(QRef);
16 ✔
856
    if (Q) {
16 ✔
857
        sycl::event ev;
15 ✔
858
        try {
15 ✔
859
            ev = Q->mem_advise(Ptr, Count, Advice);
15 ✔
860
        } catch (std::exception const &e) {
15 ✔
861
            error_handler(e, __FILE__, __func__, __LINE__);
×
862
            return nullptr;
×
863
        }
×
864
        return wrap<event>(new event(std::move(ev)));
15 ✔
865
    }
15 ✔
866
    else {
1 ✔
867
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
868
                      __LINE__);
1 ✔
869
        return nullptr;
1 ✔
870
    }
1 ✔
871
}
16 ✔
872

873
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
874
{
1,106 ✔
875
    auto Q = unwrap<queue>(QRef);
1,106 ✔
876
    if (Q) {
1,106 ✔
877
        return Q->is_in_order();
1,105 ✔
878
    }
1,105 ✔
879
    else
1 ✔
880
        return false;
1 ✔
881
}
1,106 ✔
882

883
bool DPCTLQueue_GetLastEvent_Available(void)
884
{
23 ✔
885
#ifdef SYCL_EXT_ONEAPI_IN_ORDER_QUEUE_EVENTS
23 ✔
886
    return true;
23 ✔
887
#else
888
    return false;
889
#endif
890
}
23 ✔
891

892
__dpctl_give DPCTLSyclEventRef
893
DPCTLQueue_GetLastEvent(__dpctl_keep const DPCTLSyclQueueRef QRef)
894
{
17 ✔
895
#ifdef SYCL_EXT_ONEAPI_IN_ORDER_QUEUE_EVENTS
17 ✔
896
    auto Q = unwrap<queue>(QRef);
17 ✔
897
    if (!Q) {
17 ✔
898
        error_handler("QRef passed to GetLastEvent was NULL.", __FILE__,
1 ✔
899
                      __func__, __LINE__);
1 ✔
900
        return nullptr;
1 ✔
901
    }
1 ✔
902
    if (!Q->is_in_order()) {
16 ✔
903
        error_handler("Queue passed to GetLastEvent is not in-order.", __FILE__,
1 ✔
904
                      __func__, __LINE__);
1 ✔
905
        return nullptr;
1 ✔
906
    }
1 ✔
907
    try {
15 ✔
908
        std::optional<event> ev = Q->ext_oneapi_get_last_event();
15 ✔
909
        if (!ev.has_value()) {
15 ✔
910
            return nullptr;
2 ✔
911
        }
2 ✔
912
        return wrap<event>(new event(std::move(*ev)));
13 ✔
913
    } catch (std::exception const &e) {
15 ✔
914
        error_handler(e, __FILE__, __func__, __LINE__);
×
915
        return nullptr;
×
916
    }
×
917
#else
918
    (void)QRef;
919
    return nullptr;
920
#endif
921
}
15 ✔
922

923
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
924
{
97 ✔
925
    auto Q = unwrap<queue>(QRef);
97 ✔
926
    if (Q) {
97 ✔
927
        return Q->has_property<sycl::property::queue::enable_profiling>();
96 ✔
928
    }
96 ✔
929
    else
1 ✔
930
        return false;
1 ✔
931
}
97 ✔
932

933
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
934
{
55 ✔
935
    auto Q = unwrap<queue>(QRef);
55 ✔
936
    if (Q) {
55 ✔
937
        std::hash<queue> hash_fn;
52 ✔
938
        return hash_fn(*Q);
52 ✔
939
    }
52 ✔
940
    else {
3 ✔
941
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3 ✔
942
        return 0;
3 ✔
943
    }
3 ✔
944
}
55 ✔
945

946
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
947
    __dpctl_keep const DPCTLSyclQueueRef QRef,
948
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
949
    size_t NDepEvents)
950
{
117 ✔
951
    auto Q = unwrap<queue>(QRef);
117 ✔
952
    event e;
117 ✔
953
    if (Q) {
117 !
954
        try {
117 ✔
955
#ifdef __ADAPTIVECPP__
956
            // A kernel waits only for its dependencies, so depend on all prior
957
            // work
958
            auto prior = Q->get_wait_list();
959
#endif
960
            e = Q->submit([&](handler &cgh) {
117 ✔
961
                // Depend on any event that was specified by the caller.
962
                if (NDepEvents)
117 ✔
963
                    for (auto i = 0ul; i < NDepEvents; ++i)
18 ✔
964
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
12 ✔
965

966
#ifndef __ADAPTIVECPP__
117 ✔
967
                cgh.ext_oneapi_barrier();
117 ✔
968
#else
969
                cgh.depends_on(prior);
970
                class dpctl_barrier_task;
971
                cgh.single_task<dpctl_barrier_task>([=]() {});
972
#endif
973
            });
117 ✔
974
        } catch (std::exception const &e) {
117 ✔
975
            error_handler(e, __FILE__, __func__, __LINE__);
×
976
            return nullptr;
×
977
        }
×
978

979
        return wrap<event>(new event(std::move(e)));
117 ✔
980
    }
117 ✔
981
    else {
×
982
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
983
        return nullptr;
×
984
    }
×
985
}
117 ✔
986

987
__dpctl_give DPCTLSyclEventRef
988
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
989
{
1 ✔
990
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1 ✔
991
}
1 ✔
992

993
__dpctl_give DPCTLSyclEventRef
994
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
995
                  void *USMRef,
996
                  uint8_t Value,
997
                  size_t Count)
998
{
131 ✔
999
    auto Q = unwrap<queue>(QRef);
131 ✔
1000
    if (Q && USMRef) {
131 !
1001
        sycl::event ev;
130 ✔
1002
        try {
130 ✔
1003
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
130 ✔
1004
        } catch (std::exception const &e) {
130 ✔
1005
            error_handler(e, __FILE__, __func__, __LINE__);
×
1006
            return nullptr;
×
1007
        }
×
1008
        return wrap<event>(new event(std::move(ev)));
130 ✔
1009
    }
130 ✔
1010
    else {
1 ✔
1011
        error_handler("QRef or USMRef passed to memset were NULL.", __FILE__,
1 ✔
1012
                      __func__, __LINE__);
1 ✔
1013
        return nullptr;
1 ✔
1014
    }
1 ✔
1015
}
131 ✔
1016

1017
__dpctl_give DPCTLSyclEventRef
1018
DPCTLQueue_MemsetWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1019
                            void *USMRef,
1020
                            uint8_t Value,
1021
                            size_t Count,
1022
                            const DPCTLSyclEventRef *DepEvents,
1023
                            size_t DepEventsCount)
1024
{
110 ✔
1025
    event ev;
110 ✔
1026
    auto Q = unwrap<queue>(QRef);
110 ✔
1027
    if (Q && USMRef) {
110 !
1028
        try {
109 ✔
1029
            ev = Q->submit([&](handler &cgh) {
109 ✔
1030
                if (DepEvents)
109 !
1031
                    for (size_t i = 0; i < DepEventsCount; ++i) {
218 ✔
1032
                        event *ei = unwrap<event>(DepEvents[i]);
109 ✔
1033
                        if (ei)
109 !
1034
                            cgh.depends_on(*ei);
109 ✔
1035
                    }
109 ✔
1036

1037
                cgh.memset(USMRef, static_cast<int>(Value), Count);
109 ✔
1038
            });
109 ✔
1039
        } catch (const std::exception &ex) {
109 ✔
1040
            error_handler(ex, __FILE__, __func__, __LINE__);
×
1041
            return nullptr;
×
1042
        }
×
1043
    }
109 ✔
1044
    else {
1 ✔
1045
        error_handler("QRef or USMRef passed to memset_async were NULL.",
1 ✔
1046
                      __FILE__, __func__, __LINE__);
1 ✔
1047
        return nullptr;
1 ✔
1048
    }
1 ✔
1049

1050
    return wrap<event>(new event(std::move(ev)));
109 ✔
1051
}
110 ✔
1052

1053
__dpctl_give DPCTLSyclEventRef
1054
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
1055
                 void *USMRef,
1056
                 uint8_t Value,
1057
                 size_t Count)
1058
{
30 ✔
1059
    auto Q = unwrap<queue>(QRef);
30 ✔
1060
    if (Q && USMRef) {
30 !
1061
        sycl::event ev;
29 ✔
1062
        try {
29 ✔
1063
            ev = Q->fill<uint8_t>(USMRef, Value, Count);
29 ✔
1064
        } catch (std::exception const &e) {
29 ✔
1065
            error_handler(e, __FILE__, __func__, __LINE__);
×
1066
            return nullptr;
×
1067
        }
×
1068
        return wrap<event>(new event(std::move(ev)));
29 ✔
1069
    }
29 ✔
1070
    else {
1 ✔
1071
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1 ✔
1072
                      __func__, __LINE__);
1 ✔
1073
        return nullptr;
1 ✔
1074
    }
1 ✔
1075
}
30 ✔
1076

1077
__dpctl_give DPCTLSyclEventRef
1078
DPCTLQueue_Fill8WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1079
                           void *USMRef,
1080
                           uint8_t Value,
1081
                           size_t Count,
1082
                           const DPCTLSyclEventRef *DepEvents,
1083
                           size_t DepEventsCount)
1084
{
10 ✔
1085
    auto Q = unwrap<queue>(QRef);
10 ✔
1086
    if (Q && USMRef) {
10 !
1087
        sycl::event ev;
9 ✔
1088
        try {
9 ✔
1089
            std::vector<event> dep_events;
9 ✔
1090
            if (DepEvents) {
9 !
1091
                dep_events.reserve(DepEventsCount);
9 ✔
1092
                for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
1093
                    event *ei = unwrap<event>(DepEvents[i]);
9 ✔
1094
                    if (ei)
9 !
1095
                        dep_events.push_back(*ei);
9 ✔
1096
                }
9 ✔
1097
            }
9 ✔
1098
            ev = Q->fill<uint8_t>(USMRef, Value, Count, dep_events);
9 ✔
1099
        } catch (std::exception const &e) {
9 ✔
1100
            error_handler(e, __FILE__, __func__, __LINE__);
×
1101
            return nullptr;
×
1102
        }
×
1103
        return wrap<event>(new event(std::move(ev)));
9 ✔
1104
    }
9 ✔
1105
    else {
1 ✔
1106
        error_handler("QRef or USMRef passed to fill8_async were NULL.",
1 ✔
1107
                      __FILE__, __func__, __LINE__);
1 ✔
1108
        return nullptr;
1 ✔
1109
    }
1 ✔
1110
}
10 ✔
1111

1112
__dpctl_give DPCTLSyclEventRef
1113
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
1114
                  void *USMRef,
1115
                  uint16_t Value,
1116
                  size_t Count)
1117
{
27 ✔
1118
    auto Q = unwrap<queue>(QRef);
27 ✔
1119
    if (Q && USMRef) {
27 !
1120
        sycl::event ev;
26 ✔
1121
        try {
26 ✔
1122
            ev = Q->fill<uint16_t>(USMRef, Value, Count);
26 ✔
1123
        } catch (std::exception const &e) {
26 ✔
1124
            error_handler(e, __FILE__, __func__, __LINE__);
×
1125
            return nullptr;
×
1126
        }
×
1127
        return wrap<event>(new event(std::move(ev)));
26 ✔
1128
    }
26 ✔
1129
    else {
1 ✔
1130
        error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__,
1 ✔
1131
                      __func__, __LINE__);
1 ✔
1132
        return nullptr;
1 ✔
1133
    }
1 ✔
1134
}
27 ✔
1135

1136
__dpctl_give DPCTLSyclEventRef
1137
DPCTLQueue_Fill16WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1138
                            void *USMRef,
1139
                            uint16_t Value,
1140
                            size_t Count,
1141
                            const DPCTLSyclEventRef *DepEvents,
1142
                            size_t DepEventsCount)
1143
{
9 ✔
1144
    auto Q = unwrap<queue>(QRef);
9 ✔
1145
    if (Q && USMRef) {
9 !
1146
        sycl::event ev;
8 ✔
1147
        try {
8 ✔
1148
            std::vector<event> dep_events;
8 ✔
1149
            if (DepEvents) {
8 !
1150
                dep_events.reserve(DepEventsCount);
8 ✔
1151
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1152
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1153
                    if (ei)
8 !
1154
                        dep_events.push_back(*ei);
8 ✔
1155
                }
8 ✔
1156
            }
8 ✔
1157
            ev = Q->fill<uint16_t>(USMRef, Value, Count, dep_events);
8 ✔
1158
        } catch (std::exception const &e) {
8 ✔
1159
            error_handler(e, __FILE__, __func__, __LINE__);
×
1160
            return nullptr;
×
1161
        }
×
1162
        return wrap<event>(new event(std::move(ev)));
8 ✔
1163
    }
8 ✔
1164
    else {
1 ✔
1165
        error_handler("QRef or USMRef passed to fill16_async were NULL.",
1 ✔
1166
                      __FILE__, __func__, __LINE__);
1 ✔
1167
        return nullptr;
1 ✔
1168
    }
1 ✔
1169
}
9 ✔
1170

1171
__dpctl_give DPCTLSyclEventRef
1172
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
1173
                  void *USMRef,
1174
                  uint32_t Value,
1175
                  size_t Count)
1176
{
32 ✔
1177
    auto Q = unwrap<queue>(QRef);
32 ✔
1178
    if (Q && USMRef) {
32 !
1179
        sycl::event ev;
31 ✔
1180
        try {
31 ✔
1181
            ev = Q->fill<uint32_t>(USMRef, Value, Count);
31 ✔
1182
        } catch (std::exception const &e) {
31 ✔
1183
            error_handler(e, __FILE__, __func__, __LINE__);
×
1184
            return nullptr;
×
1185
        }
×
1186
        return wrap<event>(new event(std::move(ev)));
31 ✔
1187
    }
31 ✔
1188
    else {
1 ✔
1189
        error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__,
1 ✔
1190
                      __func__, __LINE__);
1 ✔
1191
        return nullptr;
1 ✔
1192
    }
1 ✔
1193
}
32 ✔
1194

1195
__dpctl_give DPCTLSyclEventRef
1196
DPCTLQueue_Fill32WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1197
                            void *USMRef,
1198
                            uint32_t Value,
1199
                            size_t Count,
1200
                            const DPCTLSyclEventRef *DepEvents,
1201
                            size_t DepEventsCount)
1202
{
9 ✔
1203
    auto Q = unwrap<queue>(QRef);
9 ✔
1204
    if (Q && USMRef) {
9 !
1205
        sycl::event ev;
8 ✔
1206
        try {
8 ✔
1207
            std::vector<event> dep_events;
8 ✔
1208
            if (DepEvents) {
8 !
1209
                dep_events.reserve(DepEventsCount);
8 ✔
1210
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1211
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1212
                    if (ei)
8 !
1213
                        dep_events.push_back(*ei);
8 ✔
1214
                }
8 ✔
1215
            }
8 ✔
1216
            ev = Q->fill<uint32_t>(USMRef, Value, Count, dep_events);
8 ✔
1217
        } catch (std::exception const &e) {
8 ✔
1218
            error_handler(e, __FILE__, __func__, __LINE__);
×
1219
            return nullptr;
×
1220
        }
×
1221
        return wrap<event>(new event(std::move(ev)));
8 ✔
1222
    }
8 ✔
1223
    else {
1 ✔
1224
        error_handler("QRef or USMRef passed to fill32_async were NULL.",
1 ✔
1225
                      __FILE__, __func__, __LINE__);
1 ✔
1226
        return nullptr;
1 ✔
1227
    }
1 ✔
1228
}
9 ✔
1229

1230
__dpctl_give DPCTLSyclEventRef
1231
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
1232
                  void *USMRef,
1233
                  uint64_t Value,
1234
                  size_t Count)
1235
{
34 ✔
1236
    auto Q = unwrap<queue>(QRef);
34 ✔
1237
    if (Q && USMRef) {
34 !
1238
        sycl::event ev;
33 ✔
1239
        try {
33 ✔
1240
            ev = Q->fill<uint64_t>(USMRef, Value, Count);
33 ✔
1241
        } catch (std::exception const &e) {
33 ✔
1242
            error_handler(e, __FILE__, __func__, __LINE__);
×
1243
            return nullptr;
×
1244
        }
×
1245
        return wrap<event>(new event(std::move(ev)));
33 ✔
1246
    }
33 ✔
1247
    else {
1 ✔
1248
        error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__,
1 ✔
1249
                      __func__, __LINE__);
1 ✔
1250
        return nullptr;
1 ✔
1251
    }
1 ✔
1252
}
34 ✔
1253

1254
__dpctl_give DPCTLSyclEventRef
1255
DPCTLQueue_Fill64WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1256
                            void *USMRef,
1257
                            uint64_t Value,
1258
                            size_t Count,
1259
                            const DPCTLSyclEventRef *DepEvents,
1260
                            size_t DepEventsCount)
1261
{
9 ✔
1262
    auto Q = unwrap<queue>(QRef);
9 ✔
1263
    if (Q && USMRef) {
9 !
1264
        sycl::event ev;
8 ✔
1265
        try {
8 ✔
1266
            std::vector<event> dep_events;
8 ✔
1267
            if (DepEvents) {
8 !
1268
                dep_events.reserve(DepEventsCount);
8 ✔
1269
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1270
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1271
                    if (ei)
8 !
1272
                        dep_events.push_back(*ei);
8 ✔
1273
                }
8 ✔
1274
            }
8 ✔
1275
            ev = Q->fill<uint64_t>(USMRef, Value, Count, dep_events);
8 ✔
1276
        } catch (std::exception const &e) {
8 ✔
1277
            error_handler(e, __FILE__, __func__, __LINE__);
×
1278
            return nullptr;
×
1279
        }
×
1280
        return wrap<event>(new event(std::move(ev)));
8 ✔
1281
    }
8 ✔
1282
    else {
1 ✔
1283
        error_handler("QRef or USMRef passed to fill64_async were NULL.",
1 ✔
1284
                      __FILE__, __func__, __LINE__);
1 ✔
1285
        return nullptr;
1 ✔
1286
    }
1 ✔
1287
}
9 ✔
1288

1289
__dpctl_give DPCTLSyclEventRef
1290
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
1291
                   void *USMRef,
1292
                   uint64_t *Value,
1293
                   size_t Count)
1294
{
30 ✔
1295
    auto Q = unwrap<queue>(QRef);
30 ✔
1296
    if (Q && USMRef && Value) {
30 !
1297
        sycl::event ev;
21 ✔
1298
        try {
21 ✔
1299
            complexNumber Val;
21 ✔
1300
            Val.real = Value[0];
21 ✔
1301
            Val.imag = Value[1];
21 ✔
1302
            ev = Q->fill(USMRef, Val, Count);
21 ✔
1303
        } catch (std::exception const &e) {
21 ✔
1304
            error_handler(e, __FILE__, __func__, __LINE__);
×
1305
            return nullptr;
×
1306
        }
×
1307
        return wrap<event>(new event(std::move(ev)));
21 ✔
1308
    }
21 ✔
1309
    else {
9 ✔
1310
        error_handler("QRef, USMRef, or Value passed to fill128 were NULL.",
9 ✔
1311
                      __FILE__, __func__, __LINE__);
9 ✔
1312
        return nullptr;
9 ✔
1313
    }
9 ✔
1314
}
30 ✔
1315

1316
__dpctl_give DPCTLSyclEventRef
1317
DPCTLQueue_Fill128WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1318
                             void *USMRef,
1319
                             uint64_t *Value,
1320
                             size_t Count,
1321
                             const DPCTLSyclEventRef *DepEvents,
1322
                             size_t DepEventsCount)
1323
{
17 ✔
1324
    auto Q = unwrap<queue>(QRef);
17 ✔
1325
    if (Q && USMRef && Value) {
17 !
1326
        sycl::event ev;
8 ✔
1327
        try {
8 ✔
1328
            std::vector<event> dep_events;
8 ✔
1329
            if (DepEvents) {
8 !
1330
                dep_events.reserve(DepEventsCount);
8 ✔
1331
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1332
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1333
                    if (ei)
8 !
1334
                        dep_events.push_back(*ei);
8 ✔
1335
                }
8 ✔
1336
            }
8 ✔
1337
            complexNumber Val;
8 ✔
1338
            Val.real = Value[0];
8 ✔
1339
            Val.imag = Value[1];
8 ✔
1340
            ev = Q->fill(USMRef, Val, Count, dep_events);
8 ✔
1341
        } catch (std::exception const &e) {
8 ✔
1342
            error_handler(e, __FILE__, __func__, __LINE__);
×
1343
            return nullptr;
×
1344
        }
×
1345
        return wrap<event>(new event(std::move(ev)));
8 ✔
1346
    }
8 ✔
1347
    else {
9 ✔
1348
        error_handler(
9 ✔
1349
            "QRef, USMRef, or Value passed to fill128_async were NULL.",
9 ✔
1350
            __FILE__, __func__, __LINE__);
9 ✔
1351
        return nullptr;
9 ✔
1352
    }
9 ✔
1353
}
17 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc