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

IntelPython / dpctl / 41412202358

02 Nov 2026 08:19AM UTC coverage: 75.26% (+0.3%) from 74.989%
41412202358

Pull #2299

github

web-flow
Merge 2d6d8ea3d into 2dfa6bbda
Pull Request #2299: Use a no-op order manager for in-order queues

1073 of 1502 branches covered (71.44%)

Branch coverage included in aggregate %.

77 of 81 new or added lines in 2 files covered. (95.06%)

4129 of 5410 relevant lines covered (76.32%)

278.81 hits per line

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

86.7
/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 <exception>
40
#include <optional>
41
#include <sstream>
42
#include <stdexcept>
43
#include <sycl/sycl.hpp> /* SYCL headers   */
44
#include <utility>
45
#include <vector>
46

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

52
using namespace sycl;
53

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

124
namespace
125
{
126
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
127
              "The compiler does not meet minimum version requirement");
128

129
using namespace dpctl::syclinterface;
130

131
typedef struct complex
132
{
133
    std::uint64_t real;
134
    std::uint64_t imag;
135
} complexNumber;
136

137
void set_dependent_events(handler &cgh,
138
                          __dpctl_keep const DPCTLSyclEventRef *DepEvents,
139
                          size_t NDepEvents)
140
{
176 ✔
141
    for (auto i = 0ul; i < NDepEvents; ++i) {
332 ✔
142
        auto ei = unwrap<event>(DepEvents[i]);
156 ✔
143
        if (ei)
156 !
144
            cgh.depends_on(*ei);
156 ✔
145
    }
156 ✔
146
}
176 ✔
147

148
bool set_local_accessor_arg(handler &cgh,
149
                            size_t idx,
150
                            const MDLocalAccessor *mdstruct)
151
{
31 ✔
152
    switch (mdstruct->ndim) {
31 ✔
153
    case 1:
11 ✔
154
    {
11 ✔
155
        auto r = range<1>(mdstruct->dim0);
11 ✔
156
        SET_LOCAL_ACCESSOR_ARG(cgh, 1, mdstruct->dpctl_type_id, r, idx);
11 ✔
157
    }
×
158
    case 2:
10 ✔
159
    {
10 ✔
160
        auto r = range<2>(mdstruct->dim0, mdstruct->dim1);
10 ✔
161
        SET_LOCAL_ACCESSOR_ARG(cgh, 2, mdstruct->dpctl_type_id, r, idx);
10 ✔
162
    }
×
163
    case 3:
10 ✔
164
    {
10 ✔
165
        auto r = range<3>(mdstruct->dim0, mdstruct->dim1, mdstruct->dim2);
10 ✔
166
        SET_LOCAL_ACCESSOR_ARG(cgh, 3, mdstruct->dpctl_type_id, r, idx);
10 ✔
167
    }
×
168
    default:
×
169
        return false;
×
170
    }
31 ✔
171
}
31 ✔
172
/*!
173
 * @brief Set the kernel arg object
174
 *
175
 * @param cgh   SYCL command group handler using which a kernel is going to
176
 *              be submitted.
177
 * @param idx   The position of the argument in the list of arguments passed
178
 * to a kernel.
179
 * @param Arg   A void* representing a kernel argument.
180
 * @param Argty A typeid specifying the C++ type of the Arg parameter.
181
 */
182
bool set_kernel_arg(handler &cgh,
183
                    size_t idx,
184
                    __dpctl_keep void *Arg,
185
                    DPCTLKernelArgType ArgTy)
186
{
498 ✔
187
    bool arg_set = true;
498 ✔
188

189
    switch (ArgTy) {
498 ✔
190
    case DPCTL_INT8_T:
3 ✔
191
        cgh.set_arg(idx, *(std::int8_t *)Arg);
3 ✔
192
        break;
3 ✔
193
    case DPCTL_UINT8_T:
3 ✔
194
        cgh.set_arg(idx, *(std::uint8_t *)Arg);
3 ✔
195
        break;
3 ✔
196
    case DPCTL_INT16_T:
9 ✔
197
        cgh.set_arg(idx, *(std::int16_t *)Arg);
9 ✔
198
        break;
9 ✔
199
    case DPCTL_UINT16_T:
3 ✔
200
        cgh.set_arg(idx, *(std::uint16_t *)Arg);
3 ✔
201
        break;
3 ✔
202
    case DPCTL_INT32_T:
9 ✔
203
        cgh.set_arg(idx, *(std::int32_t *)Arg);
9 ✔
204
        break;
9 ✔
205
    case DPCTL_UINT32_T:
11 ✔
206
        cgh.set_arg(idx, *(std::uint32_t *)Arg);
11 ✔
207
        break;
11 ✔
208
    case DPCTL_INT64_T:
9 ✔
209
        cgh.set_arg(idx, *(std::int64_t *)Arg);
9 ✔
210
        break;
9 ✔
211
    case DPCTL_UINT64_T:
14 ✔
212
        cgh.set_arg(idx, *(std::uint64_t *)Arg);
14 ✔
213
        break;
14 ✔
214
    case DPCTL_FLOAT32_T:
9 ✔
215
        cgh.set_arg(idx, *(float *)Arg);
9 ✔
216
        break;
9 ✔
217
    case DPCTL_FLOAT64_T:
9 ✔
218
        cgh.set_arg(idx, *(double *)Arg);
9 ✔
219
        break;
9 ✔
220
    case DPCTL_VOID_PTR:
327 ✔
221
        cgh.set_arg(idx, Arg);
327 ✔
222
        break;
327 ✔
223
    case DPCTL_LOCAL_ACCESSOR:
31 ✔
224
        arg_set = set_local_accessor_arg(cgh, idx, (MDLocalAccessor *)Arg);
31 ✔
225
        break;
31 ✔
226
#ifdef SYCL_EXT_ONEAPI_WORK_GROUP_MEMORY
×
227
    case DPCTL_WORK_GROUP_MEMORY:
31 ✔
228
    {
31 ✔
229
        auto ref = static_cast<DPCTLSyclWorkGroupMemoryRef>(Arg);
31 ✔
230
        RawWorkGroupMemory *raw_mem = unwrap<RawWorkGroupMemory>(ref);
31 ✔
231
        size_t num_bytes = raw_mem->nbytes;
31 ✔
232
        sycl::ext::oneapi::experimental::work_group_memory<char[]> mem{
31 ✔
233
            num_bytes, cgh};
31 ✔
234
        cgh.set_arg(idx, mem);
31 ✔
235
        break;
31 ✔
236
    }
×
237
#endif
×
238
#ifdef SYCL_EXT_ONEAPI_RAW_KERNEL_ARG
×
239
    case DPCTL_RAW_KERNEL_ARG:
30 ✔
240
    {
30 ✔
241
        auto ref = static_cast<DPCTLSyclRawKernelArgRef>(Arg);
30 ✔
242
        std::vector<unsigned char> *raw_arg =
30 ✔
243
            unwrap<std::vector<unsigned char>>(ref);
30 ✔
244
        void *bytes = raw_arg->data();
30 ✔
245
        size_t count = raw_arg->size();
30 ✔
246
        sycl::ext::oneapi::experimental::raw_kernel_arg arg{bytes, count};
30 ✔
247
        cgh.set_arg(idx, arg);
30 ✔
248
        break;
30 ✔
249
    }
×
250
#endif
×
251
    default:
×
252
        arg_set = false;
×
253
        break;
×
254
    }
498 ✔
255
    return arg_set;
498 ✔
256
}
498 ✔
257

258
void set_kernel_args(handler &cgh,
259
                     __dpctl_keep void **Args,
260
                     __dpctl_keep const DPCTLKernelArgType *ArgTypes,
261
                     size_t NArgs)
262
{
176 ✔
263
    for (auto i = 0ul; i < NArgs; ++i) {
673 ✔
264
        if (!set_kernel_arg(cgh, i, Args[i], ArgTypes[i])) {
498 ✔
265
            error_handler("Kernel argument could not be created.", __FILE__,
1 ✔
266
                          __func__, __LINE__);
1 ✔
267
            throw std::invalid_argument(
1 ✔
268
                "Kernel argument could not be created.");
1 ✔
269
        }
1 ✔
270
    }
498 ✔
271
}
176 ✔
272

273
std::unique_ptr<property_list> create_property_list(int properties)
274
{
1,845 ✔
275
    std::unique_ptr<property_list> propList;
1,845 ✔
276
    int _prop = properties;
1,845 ✔
277
    if (_prop & DPCTL_ENABLE_PROFILING) {
1,845 ✔
278
        _prop = _prop ^ DPCTL_ENABLE_PROFILING;
86 ✔
279
        if (_prop & DPCTL_IN_ORDER) {
86 ✔
280
            _prop = _prop ^ DPCTL_IN_ORDER;
36 ✔
281
            propList = std::make_unique<property_list>(
36 ✔
282
                sycl::property::queue::enable_profiling(),
36 ✔
283
                sycl::property::queue::in_order());
36 ✔
284
        }
36 ✔
285
        else {
50 ✔
286
            propList = std::make_unique<property_list>(
50 ✔
287
                sycl::property::queue::enable_profiling());
50 ✔
288
        }
50 ✔
289
    }
86 ✔
290
    else if (_prop & DPCTL_IN_ORDER) {
1,759 ✔
291
        _prop = _prop ^ DPCTL_IN_ORDER;
560 ✔
292
        propList =
560 ✔
293
            std::make_unique<property_list>(sycl::property::queue::in_order());
560 ✔
294
    }
560 ✔
295
    else {
1,199 ✔
296
        propList = std::make_unique<property_list>();
1,199 ✔
297
    }
1,199 ✔
298

299
    if (_prop) {
1,845 ✔
300
        std::stringstream ss;
1 ✔
301
        ss << "Invalid queue property argument (" << std::hex << properties
1 ✔
302
           << "), interpreted as (" << (properties ^ _prop) << ").";
1 ✔
303
        error_handler(ss.str(), __FILE__, __func__, __LINE__);
1 ✔
304
    }
1 ✔
305
    return propList;
1,845 ✔
306
}
1,845 ✔
307

308
__dpctl_give DPCTLSyclQueueRef
309
getQueueImpl(__dpctl_keep DPCTLSyclContextRef cRef,
310
             __dpctl_keep DPCTLSyclDeviceRef dRef,
311
             error_handler_callback *handler,
312
             int properties)
313
{
211 ✔
314
    DPCTLSyclQueueRef qRef = nullptr;
211 ✔
315
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
211 ✔
316
    return qRef;
211 ✔
317
}
211 ✔
318

319
} /* end of anonymous namespace */
320

321
DPCTL_API
322
__dpctl_give DPCTLSyclQueueRef
323
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
324
                  __dpctl_keep const DPCTLSyclDeviceRef DRef,
325
                  error_handler_callback *handler,
326
                  int properties)
327
{
1,847 ✔
328
    DPCTLSyclQueueRef q = nullptr;
1,847 ✔
329
    auto dev = unwrap<device>(DRef);
1,847 ✔
330
    auto ctx = unwrap<context>(CRef);
1,847 ✔
331

332
    if (!(dev && ctx)) {
1,847 ✔
333
        error_handler("Cannot create queue from DPCTLSyclContextRef and "
2 ✔
334
                      "DPCTLSyclDeviceRef as input is a nullptr.",
2 ✔
335
                      __FILE__, __func__, __LINE__);
2 ✔
336
        return q;
2 ✔
337
    }
2 ✔
338
    auto propList = create_property_list(properties);
1,845 ✔
339

340
    if (handler) {
1,845 ✔
341
        try {
68 ✔
342
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
68 ✔
343
                                   *propList);
68 ✔
344
            q = wrap<queue>(Queue);
68 ✔
345
        } catch (std::exception const &e) {
68 ✔
346
            error_handler(e, __FILE__, __func__, __LINE__);
×
347
        }
×
348
    }
68 ✔
349
    else {
1,777 ✔
350
        try {
1,777 ✔
351
            auto Queue = new queue(*ctx, *dev, *propList);
1,777 ✔
352
            q = wrap<queue>(Queue);
1,777 ✔
353
        } catch (std::exception const &e) {
1,777 ✔
354
            error_handler(e, __FILE__, __func__, __LINE__);
1 ✔
355
        }
1 ✔
356
    }
1,777 ✔
357

358
    return q;
1,845 ✔
359
}
1,845 ✔
360

361
__dpctl_give DPCTLSyclQueueRef
362
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
363
                           error_handler_callback *handler,
364
                           int properties)
365
{
493 ✔
366
    DPCTLSyclContextRef CRef = nullptr;
493 ✔
367
    DPCTLSyclQueueRef QRef = nullptr;
493 ✔
368
    auto Device = unwrap<device>(DRef);
493 ✔
369

370
    if (!Device) {
493 ✔
371
        error_handler("Cannot create queue from NULL device reference.",
282 ✔
372
                      __FILE__, __func__, __LINE__);
282 ✔
373
        return QRef;
282 ✔
374
    }
282 ✔
375
    // Check if a cached default context exists for the device.
376
    CRef = DPCTLDeviceMgr_GetCachedContext(DRef);
211 ✔
377
    // If a cached default context was found, that context will be used to use
378
    // create the new queue. When a default cached context was not found, as
379
    // will be the case for non-root devices, i.e., sub-devices, a new context
380
    // will be allocated. Note that any newly allocated context is not cached.
381
    if (!CRef) {
211 !
382
        context *ContextPtr = nullptr;
×
383
        try {
×
384
            ContextPtr = new context(*Device);
×
385
            CRef = wrap<context>(ContextPtr);
×
386
        } catch (std::exception const &e) {
×
387
            error_handler(e, __FILE__, __func__, __LINE__);
×
388
            delete ContextPtr;
×
389
            return QRef;
×
390
        }
×
391
    }
×
392
    // At this point we have a valid context and the queue can be allocated.
393
    QRef = getQueueImpl(CRef, DRef, handler, properties);
211 ✔
394
    // Free the context
395
    DPCTLContext_Delete(CRef);
211 ✔
396
    return QRef;
211 ✔
397
}
211 ✔
398

399
/*!
400
 * Delete the passed in pointer after verifying it points to a sycl::queue.
401
 */
402
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef)
403
{
2,237 ✔
404
    delete unwrap<queue>(QRef);
2,237 ✔
405
}
2,237 ✔
406

407
/*!
408
 * Make copy of sycl::queue referenced by passed pointer
409
 */
410
__dpctl_give DPCTLSyclQueueRef
411
DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef)
412
{
116 ✔
413
    auto Queue = unwrap<queue>(QRef);
116 ✔
414
    if (Queue) {
116 ✔
415
        try {
115 ✔
416
            auto CopiedQueue = new queue(*Queue);
115 ✔
417
            return wrap<queue>(CopiedQueue);
115 ✔
418
        } catch (std::exception const &e) {
115 ✔
419
            error_handler(e, __FILE__, __func__, __LINE__);
×
420
            return nullptr;
×
421
        }
×
422
    }
115 ✔
423
    else {
1 ✔
424
        error_handler("Cannot copy DPCTLSyclQueueRef as input is a nullptr",
1 ✔
425
                      __FILE__, __func__, __LINE__);
1 ✔
426
        return nullptr;
1 ✔
427
    }
1 ✔
428
}
116 ✔
429

430
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
431
                      __dpctl_keep const DPCTLSyclQueueRef QRef2)
432
{
13 ✔
433
    if (!(QRef1 && QRef2)) {
13 ✔
434
        error_handler("DPCTLSyclQueueRefs are nullptr.", __FILE__, __func__,
2 ✔
435
                      __LINE__);
2 ✔
436
        return false;
2 ✔
437
    }
2 ✔
438
    return (*unwrap<queue>(QRef1) == *unwrap<queue>(QRef2));
11 ✔
439
}
13 ✔
440

441
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
442
{
10 ✔
443
    auto Q = unwrap<queue>(QRef);
10 ✔
444
    if (Q) {
10 ✔
445
        try {
9 ✔
446
            auto C = Q->get_context();
9 ✔
447
            return DPCTLContext_GetBackend(wrap<context>(&C));
9 ✔
448
        } catch (std::exception const &e) {
9 ✔
449
            error_handler(e, __FILE__, __func__, __LINE__);
×
450
            return DPCTL_UNKNOWN_BACKEND;
×
451
        }
×
452
    }
9 ✔
453
    else
1 ✔
454
        return DPCTL_UNKNOWN_BACKEND;
1 ✔
455
}
10 ✔
456

457
__dpctl_give DPCTLSyclDeviceRef
458
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef)
459
{
74 ✔
460
    DPCTLSyclDeviceRef DRef = nullptr;
74 ✔
461
    auto Q = unwrap<queue>(QRef);
74 ✔
462
    if (Q) {
74 ✔
463
        try {
73 ✔
464
            auto Device = new device(Q->get_device());
73 ✔
465
            DRef = wrap<device>(Device);
73 ✔
466
        } catch (std::exception const &e) {
73 ✔
467
            error_handler(e, __FILE__, __func__, __LINE__);
×
468
        }
×
469
    }
73 ✔
470
    else {
1 ✔
471
        error_handler("Could not get the device for this queue.", __FILE__,
1 ✔
472
                      __func__, __LINE__);
1 ✔
473
    }
1 ✔
474
    return DRef;
74 ✔
475
}
74 ✔
476

477
__dpctl_give DPCTLSyclContextRef
478
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
479
{
142 ✔
480
    auto Q = unwrap<queue>(QRef);
142 ✔
481
    DPCTLSyclContextRef CRef = nullptr;
142 ✔
482
    if (Q)
142 ✔
483
        CRef = wrap<context>(new context(Q->get_context()));
132 ✔
484
    else {
10 ✔
485
        error_handler("Could not get the context for this queue.", __FILE__,
10 ✔
486
                      __func__, __LINE__);
10 ✔
487
    }
10 ✔
488
    return CRef;
142 ✔
489
}
142 ✔
490

491
__dpctl_give DPCTLSyclEventRef
492
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
493
                       __dpctl_keep const DPCTLSyclQueueRef QRef,
494
                       __dpctl_keep void **Args,
495
                       __dpctl_keep const DPCTLKernelArgType *ArgTypes,
496
                       size_t NArgs,
497
                       __dpctl_keep const size_t Range[3],
498
                       size_t NDims,
499
                       __dpctl_keep const DPCTLSyclEventRef *DepEvents,
500
                       size_t NDepEvents)
501
{
65 ✔
502
    if (!KRef) {
65 ✔
503
        error_handler("Cannot submit the kernel as the kernel is a nullptr.",
2 ✔
504
                      __FILE__, __func__, __LINE__, error_level::error);
2 ✔
505
        return nullptr;
2 ✔
506
    }
2 ✔
507
    if (!QRef) {
63 ✔
508
        error_handler("Cannot submit the kernel as the queue is a nullptr.",
1 ✔
509
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
510
        return nullptr;
1 ✔
511
    }
1 ✔
512

513
    auto Kernel = unwrap<kernel>(KRef);
62 ✔
514
    auto Queue = unwrap<queue>(QRef);
62 ✔
515
    event e;
62 ✔
516

517
    try {
62 ✔
518
        switch (NDims) {
62 ✔
519
        case 1:
28 ✔
520
        {
28 ✔
521
            e = Queue->submit([&](handler &cgh) {
28 ✔
522
                // Depend on any event that was specified by the caller.
523
                set_dependent_events(cgh, DepEvents, NDepEvents);
28 ✔
524
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
28 ✔
525
                cgh.parallel_for(range<1>{Range[0]}, *Kernel);
28 ✔
526
            });
28 ✔
527
            return wrap<event>(new event(std::move(e)));
28 ✔
528
        }
×
529
        case 2:
17 ✔
530
        {
17 ✔
531
            e = Queue->submit([&](handler &cgh) {
17 ✔
532
                // Depend on any event that was specified by the caller.
533
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
534
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
535
                cgh.parallel_for(range<2>{Range[0], Range[1]}, *Kernel);
17 ✔
536
            });
17 ✔
537
            return wrap<event>(new event(std::move(e)));
17 ✔
538
        }
×
539
        case 3:
17 ✔
540
        {
17 ✔
541
            e = Queue->submit([&](handler &cgh) {
17 ✔
542
                // Depend on any event that was specified by the caller.
543
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
544
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
545
                cgh.parallel_for(range<3>{Range[0], Range[1], Range[2]},
17 ✔
546
                                 *Kernel);
17 ✔
547
            });
17 ✔
548
            return wrap<event>(new event(std::move(e)));
17 ✔
549
        }
×
550
        default:
×
551
            error_handler("Range cannot be greater than three "
×
552
                          "dimensions.",
×
553
                          __FILE__, __func__, __LINE__, error_level::error);
×
554
            return nullptr;
×
555
        }
62 ✔
556
    } catch (std::exception const &e) {
62 ✔
557
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
×
558
        return nullptr;
×
559
    } catch (...) {
×
560
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
561
                      __LINE__, error_level::error);
×
562
        return nullptr;
×
563
    }
×
564
}
62 ✔
565

566
__dpctl_give DPCTLSyclEventRef
567
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
568
                         __dpctl_keep const DPCTLSyclQueueRef QRef,
569
                         __dpctl_keep void **Args,
570
                         __dpctl_keep const DPCTLKernelArgType *ArgTypes,
571
                         size_t NArgs,
572
                         __dpctl_keep const size_t gRange[3],
573
                         __dpctl_keep const size_t lRange[3],
574
                         size_t NDims,
575
                         __dpctl_keep const DPCTLSyclEventRef *DepEvents,
576
                         size_t NDepEvents)
577
{
116 ✔
578
    if (!KRef) {
116 ✔
579
        error_handler("Cannot submit the kernel as the kernel is a nullptr.",
1 ✔
580
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
581
        return nullptr;
1 ✔
582
    }
1 ✔
583
    if (!QRef) {
115 ✔
584
        error_handler("Cannot submit the kernel as the queue is a nullptr.",
1 ✔
585
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
586
        return nullptr;
1 ✔
587
    }
1 ✔
588

589
    auto Kernel = unwrap<kernel>(KRef);
114 ✔
590
    auto Queue = unwrap<queue>(QRef);
114 ✔
591
    event e;
114 ✔
592

593
    try {
114 ✔
594
        switch (NDims) {
114 ✔
595
        case 1:
100 ✔
596
        {
100 ✔
597
            e = Queue->submit([&](handler &cgh) {
100 ✔
598
                // Depend on any event that was specified by the caller.
599
                set_dependent_events(cgh, DepEvents, NDepEvents);
100 ✔
600
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
100 ✔
601
                cgh.parallel_for(nd_range<1>{{gRange[0]}, {lRange[0]}},
100 ✔
602
                                 *Kernel);
100 ✔
603
            });
100 ✔
604
            return wrap<event>(new event(std::move(e)));
100 ✔
605
        }
×
606
        case 2:
7 ✔
607
        {
7 ✔
608
            e = Queue->submit([&](handler &cgh) {
7 ✔
609
                // Depend on any event that was specified by the caller.
610
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
611
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
612
                cgh.parallel_for(
7 ✔
613
                    nd_range<2>{{gRange[0], gRange[1]}, {lRange[0], lRange[1]}},
7 ✔
614
                    *Kernel);
7 ✔
615
            });
7 ✔
616
            return wrap<event>(new event(std::move(e)));
7 ✔
617
        }
×
618
        case 3:
7 ✔
619
        {
7 ✔
620
            e = Queue->submit([&](handler &cgh) {
7 ✔
621
                // Depend on any event that was specified by the caller.
622
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
623
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
624
                cgh.parallel_for(nd_range<3>{{gRange[0], gRange[1], gRange[2]},
7 ✔
625
                                             {lRange[0], lRange[1], lRange[2]}},
7 ✔
626
                                 *Kernel);
7 ✔
627
            });
7 ✔
628
            return wrap<event>(new event(std::move(e)));
7 ✔
629
        }
×
630
        default:
×
631
            error_handler("Range cannot be greater than three "
×
632
                          "dimensions.",
×
633
                          __FILE__, __func__, __LINE__, error_level::error);
×
634
            return nullptr;
×
635
        }
114 ✔
636
    } catch (std::exception const &e) {
114 ✔
637
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
1 ✔
638
        return nullptr;
1 ✔
639
    } catch (...) {
1 ✔
640
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
641
                      __LINE__, error_level::error);
×
642
        return nullptr;
×
643
    }
×
644
}
114 ✔
645

646
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
647
{
21 ✔
648
    // \todo what happens if the QRef is null or a pointer to a valid sycl
649
    // queue
650
    if (QRef) {
21 !
651
        auto SyclQueue = unwrap<queue>(QRef);
21 ✔
652
        if (SyclQueue)
21 !
653
            SyclQueue->wait();
21 ✔
654
    }
21 ✔
655
    else {
×
656
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
×
657
    }
×
658
}
21 ✔
659

660
__dpctl_give DPCTLSyclEventRef
661
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
662
                  void *Dest,
663
                  const void *Src,
664
                  size_t Count)
665
{
207 ✔
666
    auto Q = unwrap<queue>(QRef);
207 ✔
667
    if (Q) {
207 ✔
668
        sycl::event ev;
206 ✔
669
        try {
206 ✔
670
            ev = Q->memcpy(Dest, Src, Count);
206 ✔
671
        } catch (std::exception const &e) {
206 ✔
672
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
673
            return nullptr;
8 ✔
674
        }
8 ✔
675
        return wrap<event>(new event(std::move(ev)));
198 ✔
676
    }
206 ✔
677
    else {
1 ✔
678
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
679
                      __LINE__);
1 ✔
680
        return nullptr;
1 ✔
681
    }
1 ✔
682
}
207 ✔
683

684
__dpctl_give DPCTLSyclEventRef
685
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
686
                            void *Dest,
687
                            const void *Src,
688
                            size_t Count,
689
                            const DPCTLSyclEventRef *DepEvents,
690
                            size_t DepEventsCount)
691
{
134 ✔
692
    event ev;
134 ✔
693
    auto Q = unwrap<queue>(QRef);
134 ✔
694
    if (Q) {
134 ✔
695
        try {
133 ✔
696
            ev = Q->submit([&](handler &cgh) {
133 ✔
697
                if (DepEvents)
133 ✔
698
                    for (size_t i = 0; i < DepEventsCount; ++i) {
344 ✔
699
                        event *ei = unwrap<event>(DepEvents[i]);
219 ✔
700
                        if (ei)
219 !
701
                            cgh.depends_on(*ei);
219 ✔
702
                    }
219 ✔
703

704
                cgh.memcpy(Dest, Src, Count);
133 ✔
705
            });
133 ✔
706
        } catch (const std::exception &ex) {
133 ✔
707
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
708
            return nullptr;
8 ✔
709
        }
8 ✔
710
    }
133 ✔
711
    else {
1 ✔
712
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
713
                      __LINE__);
1 ✔
714
        return nullptr;
1 ✔
715
    }
1 ✔
716

717
    return wrap<event>(new event(ev));
125 ✔
718
}
134 ✔
719

720
__dpctl_give DPCTLSyclEventRef
721
DPCTLQueue_CopyData(__dpctl_keep const DPCTLSyclQueueRef QRef,
722
                    void *Dest,
723
                    const void *Src,
724
                    size_t Count)
725
{
50 ✔
726
    auto Q = unwrap<queue>(QRef);
50 ✔
727
    if (Q) {
50 ✔
728
        sycl::event ev;
49 ✔
729
        try {
49 ✔
730
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
731
            ev = Q->copy(static_cast<const std::uint8_t *>(Src),
49 ✔
732
                         static_cast<std::uint8_t *>(Dest), Count);
49 ✔
733
        } catch (std::exception const &e) {
49 ✔
734
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
735
            return nullptr;
8 ✔
736
        }
8 ✔
737
        return wrap<event>(new event(std::move(ev)));
41 ✔
738
    }
49 ✔
739
    else {
1 ✔
740
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
741
                      __LINE__);
1 ✔
742
        return nullptr;
1 ✔
743
    }
1 ✔
744
}
50 ✔
745

746
__dpctl_give DPCTLSyclEventRef
747
DPCTLQueue_CopyDataWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
748
                              void *Dest,
749
                              const void *Src,
750
                              size_t Count,
751
                              const DPCTLSyclEventRef *DepEvents,
752
                              size_t DepEventsCount)
753
{
10 ✔
754
    auto Q = unwrap<queue>(QRef);
10 ✔
755
    if (Q) {
10 ✔
756
        try {
9 ✔
757
            std::vector<event> dep_events;
9 ✔
758
            if (DepEvents) {
9 ✔
759
                dep_events.reserve(DepEventsCount);
1 ✔
760
                for (size_t i = 0; i < DepEventsCount; ++i) {
2 ✔
761
                    event *ei = unwrap<event>(DepEvents[i]);
1 ✔
762
                    if (ei)
1 !
763
                        dep_events.push_back(*ei);
1 ✔
764
                }
1 ✔
765
            }
1 ✔
766

767
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
768
            auto ev =
9 ✔
769
                Q->copy(static_cast<const std::uint8_t *>(Src),
9 ✔
770
                        static_cast<std::uint8_t *>(Dest), Count, dep_events);
9 ✔
771
            return wrap<event>(new event(std::move(ev)));
9 ✔
772
        } catch (const std::exception &ex) {
9 ✔
773
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
774
            return nullptr;
8 ✔
775
        }
8 ✔
776
    }
9 ✔
777
    else {
1 ✔
778
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
779
                      __LINE__);
1 ✔
780
        return nullptr;
1 ✔
781
    }
1 ✔
782
}
10 ✔
783

784
__dpctl_give DPCTLSyclEventRef
785
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
786
                    const void *Ptr,
787
                    size_t Count)
788
{
16 ✔
789
    auto Q = unwrap<queue>(QRef);
16 ✔
790
    if (Q) {
16 ✔
791
        if (Ptr) {
15 ✔
792
            sycl::event ev;
7 ✔
793
            try {
7 ✔
794
                ev = Q->prefetch(Ptr, Count);
7 ✔
795
            } catch (std::exception const &e) {
7 ✔
796
                error_handler(e, __FILE__, __func__, __LINE__);
×
797
                return nullptr;
×
798
            }
×
799
            return wrap<event>(new event(std::move(ev)));
7 ✔
800
        }
7 ✔
801
        else {
8 ✔
802
            error_handler("Attempt to prefetch USM-allocation at nullptr.",
8 ✔
803
                          __FILE__, __func__, __LINE__);
8 ✔
804
            return nullptr;
8 ✔
805
        }
8 ✔
806
    }
15 ✔
807
    else {
1 ✔
808
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
809
                      __LINE__);
1 ✔
810
        return nullptr;
1 ✔
811
    }
1 ✔
812
}
16 ✔
813

814
__dpctl_give DPCTLSyclEventRef
815
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
816
                     const void *Ptr,
817
                     size_t Count,
818
                     int Advice)
819
{
16 ✔
820
    auto Q = unwrap<queue>(QRef);
16 ✔
821
    if (Q) {
16 ✔
822
        sycl::event ev;
15 ✔
823
        try {
15 ✔
824
            ev = Q->mem_advise(Ptr, Count, Advice);
15 ✔
825
        } catch (std::exception const &e) {
15 ✔
826
            error_handler(e, __FILE__, __func__, __LINE__);
×
827
            return nullptr;
×
828
        }
×
829
        return wrap<event>(new event(std::move(ev)));
15 ✔
830
    }
15 ✔
831
    else {
1 ✔
832
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
833
                      __LINE__);
1 ✔
834
        return nullptr;
1 ✔
835
    }
1 ✔
836
}
16 ✔
837

838
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
839
{
1,064 ✔
840
    auto Q = unwrap<queue>(QRef);
1,064 ✔
841
    if (Q) {
1,064 ✔
842
        return Q->is_in_order();
1,063 ✔
843
    }
1,063 ✔
844
    else
1 ✔
845
        return false;
1 ✔
846
}
1,064 ✔
847

848
bool DPCTLQueue_GetLastEvent_Available(void)
849
{
23 ✔
850
#ifdef SYCL_EXT_ONEAPI_IN_ORDER_QUEUE_EVENTS
23 ✔
851
    return true;
23 ✔
852
#else
853
    return false;
854
#endif
855
}
23 ✔
856

857
__dpctl_give DPCTLSyclEventRef
858
DPCTLQueue_GetLastEvent(__dpctl_keep const DPCTLSyclQueueRef QRef)
859
{
17 ✔
860
#ifdef SYCL_EXT_ONEAPI_IN_ORDER_QUEUE_EVENTS
17 ✔
861
    auto Q = unwrap<queue>(QRef);
17 ✔
862
    if (!Q) {
17 ✔
863
        error_handler("QRef passed to GetLastEvent was NULL.", __FILE__,
1 ✔
864
                      __func__, __LINE__);
1 ✔
865
        return nullptr;
1 ✔
866
    }
1 ✔
867
    if (!Q->is_in_order()) {
16 ✔
868
        error_handler("Queue passed to GetLastEvent is not in-order.", __FILE__,
1 ✔
869
                      __func__, __LINE__);
1 ✔
870
        return nullptr;
1 ✔
871
    }
1 ✔
872
    try {
15 ✔
873
        std::optional<event> ev = Q->ext_oneapi_get_last_event();
15 ✔
874
        if (!ev.has_value()) {
15 ✔
875
            return nullptr;
7 ✔
876
        }
7 ✔
877
        return wrap<event>(new event(std::move(*ev)));
8 ✔
878
    } catch (std::exception const &e) {
15 ✔
NEW
879
        error_handler(e, __FILE__, __func__, __LINE__);
×
NEW
880
        return nullptr;
×
NEW
881
    }
×
882
#else
883
    (void)QRef;
884
    return nullptr;
885
#endif
886
}
15 ✔
887

888
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
889
{
67 ✔
890
    auto Q = unwrap<queue>(QRef);
67 ✔
891
    if (Q) {
67 ✔
892
        return Q->has_property<sycl::property::queue::enable_profiling>();
66 ✔
893
    }
66 ✔
894
    else
1 ✔
895
        return false;
1 ✔
896
}
67 ✔
897

898
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
899
{
40 ✔
900
    auto Q = unwrap<queue>(QRef);
40 ✔
901
    if (Q) {
40 ✔
902
        std::hash<queue> hash_fn;
37 ✔
903
        return hash_fn(*Q);
37 ✔
904
    }
37 ✔
905
    else {
3 ✔
906
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3 ✔
907
        return 0;
3 ✔
908
    }
3 ✔
909
}
40 ✔
910

911
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
912
    __dpctl_keep const DPCTLSyclQueueRef QRef,
913
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
914
    size_t NDepEvents)
915
{
107 ✔
916
    auto Q = unwrap<queue>(QRef);
107 ✔
917
    event e;
107 ✔
918
    if (Q) {
107 !
919
        try {
107 ✔
920
            e = Q->submit([&](handler &cgh) {
107 ✔
921
                // Depend on any event that was specified by the caller.
922
                if (NDepEvents)
107 ✔
923
                    for (auto i = 0ul; i < NDepEvents; ++i)
18 ✔
924
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
12 ✔
925

926
                cgh.ext_oneapi_barrier();
107 ✔
927
            });
107 ✔
928
        } catch (std::exception const &e) {
107 ✔
929
            error_handler(e, __FILE__, __func__, __LINE__);
×
930
            return nullptr;
×
931
        }
×
932

933
        return wrap<event>(new event(std::move(e)));
107 ✔
934
    }
107 ✔
935
    else {
×
936
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
937
        return nullptr;
×
938
    }
×
939
}
107 ✔
940

941
__dpctl_give DPCTLSyclEventRef
942
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
943
{
1 ✔
944
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1 ✔
945
}
1 ✔
946

947
__dpctl_give DPCTLSyclEventRef
948
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
949
                  void *USMRef,
950
                  uint8_t Value,
951
                  size_t Count)
952
{
152 ✔
953
    auto Q = unwrap<queue>(QRef);
152 ✔
954
    if (Q && USMRef) {
152 !
955
        sycl::event ev;
151 ✔
956
        try {
151 ✔
957
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
151 ✔
958
        } catch (std::exception const &e) {
151 ✔
959
            error_handler(e, __FILE__, __func__, __LINE__);
×
960
            return nullptr;
×
961
        }
×
962
        return wrap<event>(new event(std::move(ev)));
151 ✔
963
    }
151 ✔
964
    else {
1 ✔
965
        error_handler("QRef or USMRef passed to memset were NULL.", __FILE__,
1 ✔
966
                      __func__, __LINE__);
1 ✔
967
        return nullptr;
1 ✔
968
    }
1 ✔
969
}
152 ✔
970

971
__dpctl_give DPCTLSyclEventRef
972
DPCTLQueue_MemsetWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
973
                            void *USMRef,
974
                            uint8_t Value,
975
                            size_t Count,
976
                            const DPCTLSyclEventRef *DepEvents,
977
                            size_t DepEventsCount)
978
{
10 ✔
979
    event ev;
10 ✔
980
    auto Q = unwrap<queue>(QRef);
10 ✔
981
    if (Q && USMRef) {
10 !
982
        try {
9 ✔
983
            ev = Q->submit([&](handler &cgh) {
9 ✔
984
                if (DepEvents)
9 !
985
                    for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
986
                        event *ei = unwrap<event>(DepEvents[i]);
9 ✔
987
                        if (ei)
9 !
988
                            cgh.depends_on(*ei);
9 ✔
989
                    }
9 ✔
990

991
                cgh.memset(USMRef, static_cast<int>(Value), Count);
9 ✔
992
            });
9 ✔
993
        } catch (const std::exception &ex) {
9 ✔
994
            error_handler(ex, __FILE__, __func__, __LINE__);
×
995
            return nullptr;
×
996
        }
×
997
    }
9 ✔
998
    else {
1 ✔
999
        error_handler("QRef or USMRef passed to memset_async were NULL.",
1 ✔
1000
                      __FILE__, __func__, __LINE__);
1 ✔
1001
        return nullptr;
1 ✔
1002
    }
1 ✔
1003

1004
    return wrap<event>(new event(std::move(ev)));
9 ✔
1005
}
10 ✔
1006

1007
__dpctl_give DPCTLSyclEventRef
1008
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
1009
                 void *USMRef,
1010
                 uint8_t Value,
1011
                 size_t Count)
1012
{
29 ✔
1013
    auto Q = unwrap<queue>(QRef);
29 ✔
1014
    if (Q && USMRef) {
29 !
1015
        sycl::event ev;
28 ✔
1016
        try {
28 ✔
1017
            ev = Q->fill<uint8_t>(USMRef, Value, Count);
28 ✔
1018
        } catch (std::exception const &e) {
28 ✔
1019
            error_handler(e, __FILE__, __func__, __LINE__);
×
1020
            return nullptr;
×
1021
        }
×
1022
        return wrap<event>(new event(std::move(ev)));
28 ✔
1023
    }
28 ✔
1024
    else {
1 ✔
1025
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1 ✔
1026
                      __func__, __LINE__);
1 ✔
1027
        return nullptr;
1 ✔
1028
    }
1 ✔
1029
}
29 ✔
1030

1031
__dpctl_give DPCTLSyclEventRef
1032
DPCTLQueue_Fill8WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1033
                           void *USMRef,
1034
                           uint8_t Value,
1035
                           size_t Count,
1036
                           const DPCTLSyclEventRef *DepEvents,
1037
                           size_t DepEventsCount)
1038
{
10 ✔
1039
    auto Q = unwrap<queue>(QRef);
10 ✔
1040
    if (Q && USMRef) {
10 !
1041
        sycl::event ev;
9 ✔
1042
        try {
9 ✔
1043
            std::vector<event> dep_events;
9 ✔
1044
            if (DepEvents) {
9 !
1045
                dep_events.reserve(DepEventsCount);
9 ✔
1046
                for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
1047
                    event *ei = unwrap<event>(DepEvents[i]);
9 ✔
1048
                    if (ei)
9 !
1049
                        dep_events.push_back(*ei);
9 ✔
1050
                }
9 ✔
1051
            }
9 ✔
1052
            ev = Q->fill<uint8_t>(USMRef, Value, Count, dep_events);
9 ✔
1053
        } catch (std::exception const &e) {
9 ✔
1054
            error_handler(e, __FILE__, __func__, __LINE__);
×
1055
            return nullptr;
×
1056
        }
×
1057
        return wrap<event>(new event(std::move(ev)));
9 ✔
1058
    }
9 ✔
1059
    else {
1 ✔
1060
        error_handler("QRef or USMRef passed to fill8_async were NULL.",
1 ✔
1061
                      __FILE__, __func__, __LINE__);
1 ✔
1062
        return nullptr;
1 ✔
1063
    }
1 ✔
1064
}
10 ✔
1065

1066
__dpctl_give DPCTLSyclEventRef
1067
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
1068
                  void *USMRef,
1069
                  uint16_t Value,
1070
                  size_t Count)
1071
{
24 ✔
1072
    auto Q = unwrap<queue>(QRef);
24 ✔
1073
    if (Q && USMRef) {
24 !
1074
        sycl::event ev;
23 ✔
1075
        try {
23 ✔
1076
            ev = Q->fill<uint16_t>(USMRef, Value, Count);
23 ✔
1077
        } catch (std::exception const &e) {
23 ✔
1078
            error_handler(e, __FILE__, __func__, __LINE__);
×
1079
            return nullptr;
×
1080
        }
×
1081
        return wrap<event>(new event(std::move(ev)));
23 ✔
1082
    }
23 ✔
1083
    else {
1 ✔
1084
        error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__,
1 ✔
1085
                      __func__, __LINE__);
1 ✔
1086
        return nullptr;
1 ✔
1087
    }
1 ✔
1088
}
24 ✔
1089

1090
__dpctl_give DPCTLSyclEventRef
1091
DPCTLQueue_Fill16WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1092
                            void *USMRef,
1093
                            uint16_t Value,
1094
                            size_t Count,
1095
                            const DPCTLSyclEventRef *DepEvents,
1096
                            size_t DepEventsCount)
1097
{
9 ✔
1098
    auto Q = unwrap<queue>(QRef);
9 ✔
1099
    if (Q && USMRef) {
9 !
1100
        sycl::event ev;
8 ✔
1101
        try {
8 ✔
1102
            std::vector<event> dep_events;
8 ✔
1103
            if (DepEvents) {
8 !
1104
                dep_events.reserve(DepEventsCount);
8 ✔
1105
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1106
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1107
                    if (ei)
8 !
1108
                        dep_events.push_back(*ei);
8 ✔
1109
                }
8 ✔
1110
            }
8 ✔
1111
            ev = Q->fill<uint16_t>(USMRef, Value, Count, dep_events);
8 ✔
1112
        } catch (std::exception const &e) {
8 ✔
1113
            error_handler(e, __FILE__, __func__, __LINE__);
×
1114
            return nullptr;
×
1115
        }
×
1116
        return wrap<event>(new event(std::move(ev)));
8 ✔
1117
    }
8 ✔
1118
    else {
1 ✔
1119
        error_handler("QRef or USMRef passed to fill16_async were NULL.",
1 ✔
1120
                      __FILE__, __func__, __LINE__);
1 ✔
1121
        return nullptr;
1 ✔
1122
    }
1 ✔
1123
}
9 ✔
1124

1125
__dpctl_give DPCTLSyclEventRef
1126
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
1127
                  void *USMRef,
1128
                  uint32_t Value,
1129
                  size_t Count)
1130
{
27 ✔
1131
    auto Q = unwrap<queue>(QRef);
27 ✔
1132
    if (Q && USMRef) {
27 !
1133
        sycl::event ev;
26 ✔
1134
        try {
26 ✔
1135
            ev = Q->fill<uint32_t>(USMRef, Value, Count);
26 ✔
1136
        } catch (std::exception const &e) {
26 ✔
1137
            error_handler(e, __FILE__, __func__, __LINE__);
×
1138
            return nullptr;
×
1139
        }
×
1140
        return wrap<event>(new event(std::move(ev)));
26 ✔
1141
    }
26 ✔
1142
    else {
1 ✔
1143
        error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__,
1 ✔
1144
                      __func__, __LINE__);
1 ✔
1145
        return nullptr;
1 ✔
1146
    }
1 ✔
1147
}
27 ✔
1148

1149
__dpctl_give DPCTLSyclEventRef
1150
DPCTLQueue_Fill32WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1151
                            void *USMRef,
1152
                            uint32_t Value,
1153
                            size_t Count,
1154
                            const DPCTLSyclEventRef *DepEvents,
1155
                            size_t DepEventsCount)
1156
{
9 ✔
1157
    auto Q = unwrap<queue>(QRef);
9 ✔
1158
    if (Q && USMRef) {
9 !
1159
        sycl::event ev;
8 ✔
1160
        try {
8 ✔
1161
            std::vector<event> dep_events;
8 ✔
1162
            if (DepEvents) {
8 !
1163
                dep_events.reserve(DepEventsCount);
8 ✔
1164
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1165
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1166
                    if (ei)
8 !
1167
                        dep_events.push_back(*ei);
8 ✔
1168
                }
8 ✔
1169
            }
8 ✔
1170
            ev = Q->fill<uint32_t>(USMRef, Value, Count, dep_events);
8 ✔
1171
        } catch (std::exception const &e) {
8 ✔
1172
            error_handler(e, __FILE__, __func__, __LINE__);
×
1173
            return nullptr;
×
1174
        }
×
1175
        return wrap<event>(new event(std::move(ev)));
8 ✔
1176
    }
8 ✔
1177
    else {
1 ✔
1178
        error_handler("QRef or USMRef passed to fill32_async were NULL.",
1 ✔
1179
                      __FILE__, __func__, __LINE__);
1 ✔
1180
        return nullptr;
1 ✔
1181
    }
1 ✔
1182
}
9 ✔
1183

1184
__dpctl_give DPCTLSyclEventRef
1185
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
1186
                  void *USMRef,
1187
                  uint64_t Value,
1188
                  size_t Count)
1189
{
33 ✔
1190
    auto Q = unwrap<queue>(QRef);
33 ✔
1191
    if (Q && USMRef) {
33 !
1192
        sycl::event ev;
32 ✔
1193
        try {
32 ✔
1194
            ev = Q->fill<uint64_t>(USMRef, Value, Count);
32 ✔
1195
        } catch (std::exception const &e) {
32 ✔
1196
            error_handler(e, __FILE__, __func__, __LINE__);
×
1197
            return nullptr;
×
1198
        }
×
1199
        return wrap<event>(new event(std::move(ev)));
32 ✔
1200
    }
32 ✔
1201
    else {
1 ✔
1202
        error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__,
1 ✔
1203
                      __func__, __LINE__);
1 ✔
1204
        return nullptr;
1 ✔
1205
    }
1 ✔
1206
}
33 ✔
1207

1208
__dpctl_give DPCTLSyclEventRef
1209
DPCTLQueue_Fill64WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1210
                            void *USMRef,
1211
                            uint64_t Value,
1212
                            size_t Count,
1213
                            const DPCTLSyclEventRef *DepEvents,
1214
                            size_t DepEventsCount)
1215
{
9 ✔
1216
    auto Q = unwrap<queue>(QRef);
9 ✔
1217
    if (Q && USMRef) {
9 !
1218
        sycl::event ev;
8 ✔
1219
        try {
8 ✔
1220
            std::vector<event> dep_events;
8 ✔
1221
            if (DepEvents) {
8 !
1222
                dep_events.reserve(DepEventsCount);
8 ✔
1223
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1224
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1225
                    if (ei)
8 !
1226
                        dep_events.push_back(*ei);
8 ✔
1227
                }
8 ✔
1228
            }
8 ✔
1229
            ev = Q->fill<uint64_t>(USMRef, Value, Count, dep_events);
8 ✔
1230
        } catch (std::exception const &e) {
8 ✔
1231
            error_handler(e, __FILE__, __func__, __LINE__);
×
1232
            return nullptr;
×
1233
        }
×
1234
        return wrap<event>(new event(std::move(ev)));
8 ✔
1235
    }
8 ✔
1236
    else {
1 ✔
1237
        error_handler("QRef or USMRef passed to fill64_async were NULL.",
1 ✔
1238
                      __FILE__, __func__, __LINE__);
1 ✔
1239
        return nullptr;
1 ✔
1240
    }
1 ✔
1241
}
9 ✔
1242

1243
__dpctl_give DPCTLSyclEventRef
1244
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
1245
                   void *USMRef,
1246
                   uint64_t *Value,
1247
                   size_t Count)
1248
{
29 ✔
1249
    auto Q = unwrap<queue>(QRef);
29 ✔
1250
    if (Q && USMRef && Value) {
29 !
1251
        sycl::event ev;
20 ✔
1252
        try {
20 ✔
1253
            complexNumber Val;
20 ✔
1254
            Val.real = Value[0];
20 ✔
1255
            Val.imag = Value[1];
20 ✔
1256
            ev = Q->fill(USMRef, Val, Count);
20 ✔
1257
        } catch (std::exception const &e) {
20 ✔
1258
            error_handler(e, __FILE__, __func__, __LINE__);
×
1259
            return nullptr;
×
1260
        }
×
1261
        return wrap<event>(new event(std::move(ev)));
20 ✔
1262
    }
20 ✔
1263
    else {
9 ✔
1264
        error_handler("QRef, USMRef, or Value passed to fill128 were NULL.",
9 ✔
1265
                      __FILE__, __func__, __LINE__);
9 ✔
1266
        return nullptr;
9 ✔
1267
    }
9 ✔
1268
}
29 ✔
1269

1270
__dpctl_give DPCTLSyclEventRef
1271
DPCTLQueue_Fill128WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1272
                             void *USMRef,
1273
                             uint64_t *Value,
1274
                             size_t Count,
1275
                             const DPCTLSyclEventRef *DepEvents,
1276
                             size_t DepEventsCount)
1277
{
17 ✔
1278
    auto Q = unwrap<queue>(QRef);
17 ✔
1279
    if (Q && USMRef && Value) {
17 !
1280
        sycl::event ev;
8 ✔
1281
        try {
8 ✔
1282
            std::vector<event> dep_events;
8 ✔
1283
            if (DepEvents) {
8 !
1284
                dep_events.reserve(DepEventsCount);
8 ✔
1285
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1286
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1287
                    if (ei)
8 !
1288
                        dep_events.push_back(*ei);
8 ✔
1289
                }
8 ✔
1290
            }
8 ✔
1291
            complexNumber Val;
8 ✔
1292
            Val.real = Value[0];
8 ✔
1293
            Val.imag = Value[1];
8 ✔
1294
            ev = Q->fill(USMRef, Val, Count, dep_events);
8 ✔
1295
        } catch (std::exception const &e) {
8 ✔
1296
            error_handler(e, __FILE__, __func__, __LINE__);
×
1297
            return nullptr;
×
1298
        }
×
1299
        return wrap<event>(new event(std::move(ev)));
8 ✔
1300
    }
8 ✔
1301
    else {
9 ✔
1302
        error_handler(
9 ✔
1303
            "QRef, USMRef, or Value passed to fill128_async were NULL.",
9 ✔
1304
            __FILE__, __func__, __LINE__);
9 ✔
1305
        return nullptr;
9 ✔
1306
    }
9 ✔
1307
}
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