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

IntelPython / dpctl / 35424644453

19 Sep 2026 05:41AM UTC coverage: 75.167% (+0.2%) from 74.959%
35424644453

Pull #2384

github

web-flow
Merge cee555b34 into 3799508da
Pull Request #2384: Enable AdaptiveCpp builds

1053 of 1482 branches covered (71.05%)

Branch coverage included in aggregate %.

81 of 101 new or added lines in 17 files covered. (80.2%)

2 existing lines in 2 files now uncovered.

4111 of 5388 relevant lines covered (76.3%)

286.17 hits per line

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

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

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

51
using namespace sycl;
52

53
#ifndef __ADAPTIVECPP__
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
#else
124
#define SET_LOCAL_ACCESSOR_ARG(CGH, NDIM, ARGTY, R, IDX)                       \
125
    do {                                                                       \
126
        error_handler("Local accessors and dynamic kernel args are not "       \
127
                      "supported in AdaptiveCpp.",                             \
128
                      __FILE__, __func__, __LINE__, error_level::error);       \
129
        return false;                                                          \
130
    } while (0);
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
{
177 ✔
154
    for (auto i = 0ul; i < NDepEvents; ++i) {
333 ✔
155
        auto ei = unwrap<event>(DepEvents[i]);
156 ✔
156
        if (ei)
156 !
157
            cgh.depends_on(*ei);
156 ✔
158
    }
156 ✔
159
}
177 ✔
160

161
bool set_local_accessor_arg(handler &cgh,
162
                            size_t idx,
163
                            const MDLocalAccessor *mdstruct)
164
{
31 ✔
165
    switch (mdstruct->ndim) {
31 ✔
166
    case 1:
11 ✔
167
    {
11 ✔
168
        auto r = range<1>(mdstruct->dim0);
11 ✔
169
        SET_LOCAL_ACCESSOR_ARG(cgh, 1, mdstruct->dpctl_type_id, r, idx);
11 ✔
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
    }
31 ✔
184
}
31 ✔
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
{
502 ✔
200
    bool arg_set = true;
502 ✔
201

202
    switch (ArgTy) {
502 ✔
203
    case DPCTL_INT8_T:
3 ✔
204
        cgh.set_arg(idx, *(std::int8_t *)Arg);
3 ✔
205
        break;
3 ✔
206
    case DPCTL_UINT8_T:
3 ✔
207
        cgh.set_arg(idx, *(std::uint8_t *)Arg);
3 ✔
208
        break;
3 ✔
209
    case DPCTL_INT16_T:
9 ✔
210
        cgh.set_arg(idx, *(std::int16_t *)Arg);
9 ✔
211
        break;
9 ✔
212
    case DPCTL_UINT16_T:
3 ✔
213
        cgh.set_arg(idx, *(std::uint16_t *)Arg);
3 ✔
214
        break;
3 ✔
215
    case DPCTL_INT32_T:
9 ✔
216
        cgh.set_arg(idx, *(std::int32_t *)Arg);
9 ✔
217
        break;
9 ✔
218
    case DPCTL_UINT32_T:
11 ✔
219
        cgh.set_arg(idx, *(std::uint32_t *)Arg);
11 ✔
220
        break;
11 ✔
221
    case DPCTL_INT64_T:
9 ✔
222
        cgh.set_arg(idx, *(std::int64_t *)Arg);
9 ✔
223
        break;
9 ✔
224
    case DPCTL_UINT64_T:
14 ✔
225
        cgh.set_arg(idx, *(std::uint64_t *)Arg);
14 ✔
226
        break;
14 ✔
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_VOID_PTR:
330 ✔
234
        cgh.set_arg(idx, Arg);
330 ✔
235
        break;
330 ✔
236
    case DPCTL_LOCAL_ACCESSOR:
31 ✔
237
        arg_set = set_local_accessor_arg(cgh, idx, (MDLocalAccessor *)Arg);
31 ✔
238
        break;
31 ✔
239
#ifdef SYCL_EXT_ONEAPI_WORK_GROUP_MEMORY
×
240
    case DPCTL_WORK_GROUP_MEMORY:
31 ✔
241
    {
31 ✔
242
        auto ref = static_cast<DPCTLSyclWorkGroupMemoryRef>(Arg);
31 ✔
243
        RawWorkGroupMemory *raw_mem = unwrap<RawWorkGroupMemory>(ref);
31 ✔
244
        size_t num_bytes = raw_mem->nbytes;
31 ✔
245
        sycl::ext::oneapi::experimental::work_group_memory<char[]> mem{
31 ✔
246
            num_bytes, cgh};
31 ✔
247
        cgh.set_arg(idx, mem);
31 ✔
248
        break;
31 ✔
249
    }
×
250
#endif
×
251
#ifdef SYCL_EXT_ONEAPI_RAW_KERNEL_ARG
×
252
    case DPCTL_RAW_KERNEL_ARG:
30 ✔
253
    {
30 ✔
254
        auto ref = static_cast<DPCTLSyclRawKernelArgRef>(Arg);
30 ✔
255
        std::vector<unsigned char> *raw_arg =
30 ✔
256
            unwrap<std::vector<unsigned char>>(ref);
30 ✔
257
        void *bytes = raw_arg->data();
30 ✔
258
        size_t count = raw_arg->size();
30 ✔
259
        sycl::ext::oneapi::experimental::raw_kernel_arg arg{bytes, count};
30 ✔
260
        cgh.set_arg(idx, arg);
30 ✔
261
        break;
30 ✔
262
    }
×
263
#endif
×
264
    default:
1 ✔
265
        arg_set = false;
1 ✔
266
        break;
1 ✔
267
    }
502 ✔
268
    return arg_set;
502 ✔
269
}
502 ✔
270

271
void set_kernel_args(handler &cgh,
272
                     __dpctl_keep void **Args,
273
                     __dpctl_keep const DPCTLKernelArgType *ArgTypes,
274
                     size_t NArgs)
275
{
177 ✔
276
    for (auto i = 0ul; i < NArgs; ++i) {
677 ✔
277
        if (!set_kernel_arg(cgh, i, Args[i], ArgTypes[i])) {
502 ✔
278
            error_handler("Kernel argument could not be created.", __FILE__,
2 ✔
279
                          __func__, __LINE__);
2 ✔
280
            throw std::invalid_argument(
2 ✔
281
                "Kernel argument could not be created.");
2 ✔
282
        }
2 ✔
283
    }
502 ✔
284
}
177 ✔
285

286
#endif /* #ifndef __ADAPTIVECPP__ */
287

288
std::unique_ptr<property_list> create_property_list(int properties)
289
{
1,855 ✔
290
    std::unique_ptr<property_list> propList;
1,855 ✔
291
    int _prop = properties;
1,855 ✔
292
    if (_prop & DPCTL_ENABLE_PROFILING) {
1,855 ✔
293
        _prop = _prop ^ DPCTL_ENABLE_PROFILING;
86 ✔
294
        if (_prop & DPCTL_IN_ORDER) {
86 ✔
295
            _prop = _prop ^ DPCTL_IN_ORDER;
36 ✔
296
            propList = std::make_unique<property_list>(
36 ✔
297
                sycl::property::queue::enable_profiling(),
36 ✔
298
                sycl::property::queue::in_order());
36 ✔
299
        }
36 ✔
300
        else {
50 ✔
301
            propList = std::make_unique<property_list>(
50 ✔
302
                sycl::property::queue::enable_profiling());
50 ✔
303
        }
50 ✔
304
    }
86 ✔
305
    else if (_prop & DPCTL_IN_ORDER) {
1,769 ✔
306
        _prop = _prop ^ DPCTL_IN_ORDER;
551 ✔
307
        propList =
551 ✔
308
            std::make_unique<property_list>(sycl::property::queue::in_order());
551 ✔
309
    }
551 ✔
310
    else {
1,218 ✔
311
        propList = std::make_unique<property_list>();
1,218 ✔
312
    }
1,218 ✔
313

314
    if (_prop) {
1,855 ✔
315
        std::stringstream ss;
1 ✔
316
        ss << "Invalid queue property argument (" << std::hex << properties
1 ✔
317
           << "), interpreted as (" << (properties ^ _prop) << ").";
1 ✔
318
        error_handler(ss.str(), __FILE__, __func__, __LINE__);
1 ✔
319
    }
1 ✔
320
    return propList;
1,855 ✔
321
}
1,855 ✔
322

323
__dpctl_give DPCTLSyclQueueRef
324
getQueueImpl(__dpctl_keep DPCTLSyclContextRef cRef,
325
             __dpctl_keep DPCTLSyclDeviceRef dRef,
326
             error_handler_callback *handler,
327
             int properties)
328
{
207 ✔
329
    DPCTLSyclQueueRef qRef = nullptr;
207 ✔
330
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
207 ✔
331
    return qRef;
207 ✔
332
}
207 ✔
333

334
} /* end of anonymous namespace */
335

336
DPCTL_API
337
__dpctl_give DPCTLSyclQueueRef
338
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
339
                  __dpctl_keep const DPCTLSyclDeviceRef DRef,
340
                  error_handler_callback *handler,
341
                  int properties)
342
{
1,857 ✔
343
    DPCTLSyclQueueRef q = nullptr;
1,857 ✔
344
    auto dev = unwrap<device>(DRef);
1,857 ✔
345
    auto ctx = unwrap<context>(CRef);
1,857 ✔
346

347
    if (!(dev && ctx)) {
1,857 ✔
348
        error_handler("Cannot create queue from DPCTLSyclContextRef and "
2 ✔
349
                      "DPCTLSyclDeviceRef as input is a nullptr.",
2 ✔
350
                      __FILE__, __func__, __LINE__);
2 ✔
351
        return q;
2 ✔
352
    }
2 ✔
353
    auto propList = create_property_list(properties);
1,855 ✔
354

355
    if (handler) {
1,855 ✔
356
        try {
68 ✔
357
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
68 ✔
358
                                   *propList);
68 ✔
359
            q = wrap<queue>(Queue);
68 ✔
360
        } catch (std::exception const &e) {
68 ✔
361
            error_handler(e, __FILE__, __func__, __LINE__);
×
362
        }
×
363
    }
68 ✔
364
    else {
1,787 ✔
365
        try {
1,787 ✔
366
#ifdef __ADAPTIVECPP__
367
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(nullptr),
368
                                   *propList);
369
#else
370
            auto Queue = new queue(*ctx, *dev, *propList);
1,787 ✔
371
#endif
1,787 ✔
372
            q = wrap<queue>(Queue);
1,787 ✔
373
        } catch (std::exception const &e) {
1,787 ✔
374
            error_handler(e, __FILE__, __func__, __LINE__);
1 ✔
375
        }
1 ✔
376
    }
1,787 ✔
377

378
    return q;
1,855 ✔
379
}
1,855 ✔
380

381
__dpctl_give DPCTLSyclQueueRef
382
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
383
                           error_handler_callback *handler,
384
                           int properties)
385
{
489 ✔
386
    DPCTLSyclContextRef CRef = nullptr;
489 ✔
387
    DPCTLSyclQueueRef QRef = nullptr;
489 ✔
388
    auto Device = unwrap<device>(DRef);
489 ✔
389

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

419
/*!
420
 * Delete the passed in pointer after verifying it points to a sycl::queue.
421
 */
422
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef)
423
{
2,247 ✔
424
    delete unwrap<queue>(QRef);
2,247 ✔
425
}
2,247 ✔
426

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

450
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
451
                      __dpctl_keep const DPCTLSyclQueueRef QRef2)
452
{
13 ✔
453
    if (!(QRef1 && QRef2)) {
13 ✔
454
        error_handler("DPCTLSyclQueueRefs are nullptr.", __FILE__, __func__,
2 ✔
455
                      __LINE__);
2 ✔
456
        return false;
2 ✔
457
    }
2 ✔
458
    return (*unwrap<queue>(QRef1) == *unwrap<queue>(QRef2));
11 ✔
459
}
13 ✔
460

461
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
462
{
10 ✔
463
    auto Q = unwrap<queue>(QRef);
10 ✔
464
    if (Q) {
10 ✔
465
        try {
9 ✔
466
            auto C = Q->get_context();
9 ✔
467
            return DPCTLContext_GetBackend(wrap<context>(&C));
9 ✔
468
        } catch (std::exception const &e) {
9 ✔
469
            error_handler(e, __FILE__, __func__, __LINE__);
×
470
            return DPCTL_UNKNOWN_BACKEND;
×
471
        }
×
472
    }
9 ✔
473
    else
1 ✔
474
        return DPCTL_UNKNOWN_BACKEND;
1 ✔
475
}
10 ✔
476

477
__dpctl_give DPCTLSyclDeviceRef
478
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef)
479
{
74 ✔
480
    DPCTLSyclDeviceRef DRef = nullptr;
74 ✔
481
    auto Q = unwrap<queue>(QRef);
74 ✔
482
    if (Q) {
74 ✔
483
        try {
73 ✔
484
            auto Device = new device(Q->get_device());
73 ✔
485
            DRef = wrap<device>(Device);
73 ✔
486
        } catch (std::exception const &e) {
73 ✔
487
            error_handler(e, __FILE__, __func__, __LINE__);
×
488
        }
×
489
    }
73 ✔
490
    else {
1 ✔
491
        error_handler("Could not get the device for this queue.", __FILE__,
1 ✔
492
                      __func__, __LINE__);
1 ✔
493
    }
1 ✔
494
    return DRef;
74 ✔
495
}
74 ✔
496

497
__dpctl_give DPCTLSyclContextRef
498
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
499
{
140 ✔
500
    auto Q = unwrap<queue>(QRef);
140 ✔
501
    DPCTLSyclContextRef CRef = nullptr;
140 ✔
502
    if (Q)
140 ✔
503
        CRef = wrap<context>(new context(Q->get_context()));
130 ✔
504
    else {
10 ✔
505
        error_handler("Could not get the context for this queue.", __FILE__,
10 ✔
506
                      __func__, __LINE__);
10 ✔
507
    }
10 ✔
508
    return CRef;
140 ✔
509
}
140 ✔
510

511
__dpctl_give DPCTLSyclEventRef
512
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
513
                       __dpctl_keep const DPCTLSyclQueueRef QRef,
514
                       __dpctl_keep void **Args,
515
                       __dpctl_keep const DPCTLKernelArgType *ArgTypes,
516
                       size_t NArgs,
517
                       __dpctl_keep const size_t Range[3],
518
                       size_t NDims,
519
                       __dpctl_keep const DPCTLSyclEventRef *DepEvents,
520
                       size_t NDepEvents)
521
{
63 ✔
522
#ifndef __ADAPTIVECPP__
63 ✔
523
    auto Kernel = unwrap<kernel>(KRef);
63 ✔
524
    auto Queue = unwrap<queue>(QRef);
63 ✔
525
    event e;
63 ✔
526

527
    try {
63 ✔
528
        switch (NDims) {
63 ✔
529
        case 1:
29 ✔
530
        {
29 ✔
531
            e = Queue->submit([&](handler &cgh) {
29 ✔
532
                set_dependent_events(cgh, DepEvents, NDepEvents);
29 ✔
533
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
29 ✔
534
                cgh.parallel_for(range<1>{Range[0]}, *Kernel);
29 ✔
535
            });
29 ✔
536
            return wrap<event>(new event(std::move(e)));
29 ✔
537
        }
×
538
        case 2:
17 ✔
539
        {
17 ✔
540
            e = Queue->submit([&](handler &cgh) {
17 ✔
541
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
542
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
543
                cgh.parallel_for(range<2>{Range[0], Range[1]}, *Kernel);
17 ✔
544
            });
17 ✔
545
            return wrap<event>(new event(std::move(e)));
17 ✔
546
        }
×
547
        case 3:
17 ✔
548
        {
17 ✔
549
            e = Queue->submit([&](handler &cgh) {
17 ✔
550
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
551
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
552
                cgh.parallel_for(range<3>{Range[0], Range[1], Range[2]},
17 ✔
553
                                 *Kernel);
17 ✔
554
            });
17 ✔
555
            return wrap<event>(new event(std::move(e)));
17 ✔
556
        }
×
557
        default:
×
NEW
558
            error_handler("Range cannot be greater than three dimensions.",
×
559
                          __FILE__, __func__, __LINE__, error_level::error);
×
560
            return nullptr;
×
561
        }
63 ✔
562
    } catch (std::exception const &e) {
63 ✔
563
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
1 ✔
564
        return nullptr;
1 ✔
565
    } catch (...) {
1 ✔
566
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
567
                      __LINE__, error_level::error);
×
568
        return nullptr;
×
569
    }
×
570
#else
571
    error_handler("Dynamic OpenCL-style kernel execution is not supported in "
572
                  "AdaptiveCpp.",
573
                  __FILE__, __func__, __LINE__, error_level::error);
574
    return nullptr;
575
#endif
576
}
63 ✔
577

578
__dpctl_give DPCTLSyclEventRef
579
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
580
                         __dpctl_keep const DPCTLSyclQueueRef QRef,
581
                         __dpctl_keep void **Args,
582
                         __dpctl_keep const DPCTLKernelArgType *ArgTypes,
583
                         size_t NArgs,
584
                         __dpctl_keep const size_t gRange[3],
585
                         __dpctl_keep const size_t lRange[3],
586
                         size_t NDims,
587
                         __dpctl_keep const DPCTLSyclEventRef *DepEvents,
588
                         size_t NDepEvents)
589
{
114 ✔
590
#ifndef __ADAPTIVECPP__
114 ✔
591
    auto Kernel = unwrap<kernel>(KRef);
114 ✔
592
    auto Queue = unwrap<queue>(QRef);
114 ✔
593
    event e;
114 ✔
594

595
    try {
114 ✔
596
        switch (NDims) {
114 ✔
597
        case 1:
100 ✔
598
        {
100 ✔
599
            e = Queue->submit([&](handler &cgh) {
100 ✔
600
                set_dependent_events(cgh, DepEvents, NDepEvents);
100 ✔
601
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
100 ✔
602
                cgh.parallel_for(nd_range<1>{{gRange[0]}, {lRange[0]}},
100 ✔
603
                                 *Kernel);
100 ✔
604
            });
100 ✔
605
            return wrap<event>(new event(std::move(e)));
100 ✔
606
        }
×
607
        case 2:
7 ✔
608
        {
7 ✔
609
            e = Queue->submit([&](handler &cgh) {
7 ✔
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
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
622
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
623
                cgh.parallel_for(nd_range<3>{{gRange[0], gRange[1], gRange[2]},
7 ✔
624
                                             {lRange[0], lRange[1], lRange[2]}},
7 ✔
625
                                 *Kernel);
7 ✔
626
            });
7 ✔
627
            return wrap<event>(new event(std::move(e)));
7 ✔
628
        }
×
629
        default:
×
NEW
630
            error_handler("Range cannot be greater than three dimensions.",
×
631
                          __FILE__, __func__, __LINE__, error_level::error);
×
632
            return nullptr;
×
633
        }
114 ✔
634
    } catch (std::exception const &e) {
114 ✔
635
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
1 ✔
636
        return nullptr;
1 ✔
637
    } catch (...) {
1 ✔
638
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
639
                      __LINE__, error_level::error);
×
640
        return nullptr;
×
641
    }
×
642
#else
643
    error_handler("Dynamic OpenCL-style kernel execution is not supported in "
644
                  "AdaptiveCpp.",
645
                  __FILE__, __func__, __LINE__, error_level::error);
646
    return nullptr;
647
#endif
648
}
114 ✔
649

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

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

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

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

721
    return wrap<event>(new event(ev));
120 ✔
722
}
129 ✔
723

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

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

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

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

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

842
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
843
{
1,040 ✔
844
    auto Q = unwrap<queue>(QRef);
1,040 ✔
845
    if (Q) {
1,040 ✔
846
        return Q->is_in_order();
1,039 ✔
847
    }
1,039 ✔
848
    else
1 ✔
849
        return false;
1 ✔
850
}
1,040 ✔
851

852
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
853
{
67 ✔
854
    auto Q = unwrap<queue>(QRef);
67 ✔
855
    if (Q) {
67 ✔
856
        return Q->has_property<sycl::property::queue::enable_profiling>();
66 ✔
857
    }
66 ✔
858
    else
1 ✔
859
        return false;
1 ✔
860
}
67 ✔
861

862
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
863
{
30 ✔
864
    auto Q = unwrap<queue>(QRef);
30 ✔
865
    if (Q) {
30 ✔
866
        std::hash<queue> hash_fn;
27 ✔
867
        return hash_fn(*Q);
27 ✔
868
    }
27 ✔
869
    else {
3 ✔
870
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3 ✔
871
        return 0;
3 ✔
872
    }
3 ✔
873
}
30 ✔
874

875
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
876
    __dpctl_keep const DPCTLSyclQueueRef QRef,
877
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
878
    size_t NDepEvents)
879
{
111 ✔
880
    auto Q = unwrap<queue>(QRef);
111 ✔
881
    event e;
111 ✔
882
    if (Q) {
111 !
883
        try {
111 ✔
884
            e = Q->submit([&](handler &cgh) {
111 ✔
885
                // Depend on any event that was specified by the caller.
886
                if (NDepEvents)
111 ✔
887
                    for (auto i = 0ul; i < NDepEvents; ++i)
18 ✔
888
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
12 ✔
889

890
#ifndef __ADAPTIVECPP__
111 ✔
891
                cgh.ext_oneapi_barrier();
111 ✔
892
#else
893
                class dpctl_barrier_task;
894
                cgh.single_task<dpctl_barrier_task>([=]() {});
895
#endif
896
            });
111 ✔
897
        } catch (std::exception const &e) {
111 ✔
898
            error_handler(e, __FILE__, __func__, __LINE__);
×
899
            return nullptr;
×
900
        }
×
901

902
        return wrap<event>(new event(std::move(e)));
111 ✔
903
    }
111 ✔
904
    else {
×
905
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
906
        return nullptr;
×
907
    }
×
908
}
111 ✔
909

910
__dpctl_give DPCTLSyclEventRef
911
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
912
{
1 ✔
913
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1 ✔
914
}
1 ✔
915

916
__dpctl_give DPCTLSyclEventRef
917
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
918
                  void *USMRef,
919
                  uint8_t Value,
920
                  size_t Count)
921
{
92 ✔
922
    auto Q = unwrap<queue>(QRef);
92 ✔
923
    if (Q && USMRef) {
92 !
924
        sycl::event ev;
91 ✔
925
        try {
91 ✔
926
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
91 ✔
927
        } catch (std::exception const &e) {
91 ✔
928
            error_handler(e, __FILE__, __func__, __LINE__);
×
929
            return nullptr;
×
930
        }
×
931
        return wrap<event>(new event(std::move(ev)));
91 ✔
932
    }
91 ✔
933
    else {
1 ✔
934
        error_handler("QRef or USMRef passed to memset were NULL.", __FILE__,
1 ✔
935
                      __func__, __LINE__);
1 ✔
936
        return nullptr;
1 ✔
937
    }
1 ✔
938
}
92 ✔
939

940
__dpctl_give DPCTLSyclEventRef
941
DPCTLQueue_MemsetWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
942
                            void *USMRef,
943
                            uint8_t Value,
944
                            size_t Count,
945
                            const DPCTLSyclEventRef *DepEvents,
946
                            size_t DepEventsCount)
947
{
10 ✔
948
    event ev;
10 ✔
949
    auto Q = unwrap<queue>(QRef);
10 ✔
950
    if (Q && USMRef) {
10 !
951
        try {
9 ✔
952
            ev = Q->submit([&](handler &cgh) {
9 ✔
953
                if (DepEvents)
9 !
954
                    for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
955
                        event *ei = unwrap<event>(DepEvents[i]);
9 ✔
956
                        if (ei)
9 !
957
                            cgh.depends_on(*ei);
9 ✔
958
                    }
9 ✔
959

960
                cgh.memset(USMRef, static_cast<int>(Value), Count);
9 ✔
961
            });
9 ✔
962
        } catch (const std::exception &ex) {
9 ✔
963
            error_handler(ex, __FILE__, __func__, __LINE__);
×
964
            return nullptr;
×
965
        }
×
966
    }
9 ✔
967
    else {
1 ✔
968
        error_handler("QRef or USMRef passed to memset_async were NULL.",
1 ✔
969
                      __FILE__, __func__, __LINE__);
1 ✔
970
        return nullptr;
1 ✔
971
    }
1 ✔
972

973
    return wrap<event>(new event(std::move(ev)));
9 ✔
974
}
10 ✔
975

976
__dpctl_give DPCTLSyclEventRef
977
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
978
                 void *USMRef,
979
                 uint8_t Value,
980
                 size_t Count)
981
{
29 ✔
982
    auto Q = unwrap<queue>(QRef);
29 ✔
983
    if (Q && USMRef) {
29 !
984
        sycl::event ev;
28 ✔
985
        try {
28 ✔
986
            ev = Q->fill<uint8_t>(USMRef, Value, Count);
28 ✔
987
        } catch (std::exception const &e) {
28 ✔
988
            error_handler(e, __FILE__, __func__, __LINE__);
×
989
            return nullptr;
×
990
        }
×
991
        return wrap<event>(new event(std::move(ev)));
28 ✔
992
    }
28 ✔
993
    else {
1 ✔
994
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1 ✔
995
                      __func__, __LINE__);
1 ✔
996
        return nullptr;
1 ✔
997
    }
1 ✔
998
}
29 ✔
999

1000
__dpctl_give DPCTLSyclEventRef
1001
DPCTLQueue_Fill8WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1002
                           void *USMRef,
1003
                           uint8_t Value,
1004
                           size_t Count,
1005
                           const DPCTLSyclEventRef *DepEvents,
1006
                           size_t DepEventsCount)
1007
{
10 ✔
1008
    auto Q = unwrap<queue>(QRef);
10 ✔
1009
    if (Q && USMRef) {
10 !
1010
        sycl::event ev;
9 ✔
1011
        try {
9 ✔
1012
            std::vector<event> dep_events;
9 ✔
1013
            if (DepEvents) {
9 !
1014
                dep_events.reserve(DepEventsCount);
9 ✔
1015
                for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
1016
                    event *ei = unwrap<event>(DepEvents[i]);
9 ✔
1017
                    if (ei)
9 !
1018
                        dep_events.push_back(*ei);
9 ✔
1019
                }
9 ✔
1020
            }
9 ✔
1021
            ev = Q->fill<uint8_t>(USMRef, Value, Count, dep_events);
9 ✔
1022
        } catch (std::exception const &e) {
9 ✔
1023
            error_handler(e, __FILE__, __func__, __LINE__);
×
1024
            return nullptr;
×
1025
        }
×
1026
        return wrap<event>(new event(std::move(ev)));
9 ✔
1027
    }
9 ✔
1028
    else {
1 ✔
1029
        error_handler("QRef or USMRef passed to fill8_async were NULL.",
1 ✔
1030
                      __FILE__, __func__, __LINE__);
1 ✔
1031
        return nullptr;
1 ✔
1032
    }
1 ✔
1033
}
10 ✔
1034

1035
__dpctl_give DPCTLSyclEventRef
1036
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
1037
                  void *USMRef,
1038
                  uint16_t Value,
1039
                  size_t Count)
1040
{
24 ✔
1041
    auto Q = unwrap<queue>(QRef);
24 ✔
1042
    if (Q && USMRef) {
24 !
1043
        sycl::event ev;
23 ✔
1044
        try {
23 ✔
1045
            ev = Q->fill<uint16_t>(USMRef, Value, Count);
23 ✔
1046
        } catch (std::exception const &e) {
23 ✔
1047
            error_handler(e, __FILE__, __func__, __LINE__);
×
1048
            return nullptr;
×
1049
        }
×
1050
        return wrap<event>(new event(std::move(ev)));
23 ✔
1051
    }
23 ✔
1052
    else {
1 ✔
1053
        error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__,
1 ✔
1054
                      __func__, __LINE__);
1 ✔
1055
        return nullptr;
1 ✔
1056
    }
1 ✔
1057
}
24 ✔
1058

1059
__dpctl_give DPCTLSyclEventRef
1060
DPCTLQueue_Fill16WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1061
                            void *USMRef,
1062
                            uint16_t Value,
1063
                            size_t Count,
1064
                            const DPCTLSyclEventRef *DepEvents,
1065
                            size_t DepEventsCount)
1066
{
9 ✔
1067
    auto Q = unwrap<queue>(QRef);
9 ✔
1068
    if (Q && USMRef) {
9 !
1069
        sycl::event ev;
8 ✔
1070
        try {
8 ✔
1071
            std::vector<event> dep_events;
8 ✔
1072
            if (DepEvents) {
8 !
1073
                dep_events.reserve(DepEventsCount);
8 ✔
1074
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1075
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1076
                    if (ei)
8 !
1077
                        dep_events.push_back(*ei);
8 ✔
1078
                }
8 ✔
1079
            }
8 ✔
1080
            ev = Q->fill<uint16_t>(USMRef, Value, Count, dep_events);
8 ✔
1081
        } catch (std::exception const &e) {
8 ✔
1082
            error_handler(e, __FILE__, __func__, __LINE__);
×
1083
            return nullptr;
×
1084
        }
×
1085
        return wrap<event>(new event(std::move(ev)));
8 ✔
1086
    }
8 ✔
1087
    else {
1 ✔
1088
        error_handler("QRef or USMRef passed to fill16_async were NULL.",
1 ✔
1089
                      __FILE__, __func__, __LINE__);
1 ✔
1090
        return nullptr;
1 ✔
1091
    }
1 ✔
1092
}
9 ✔
1093

1094
__dpctl_give DPCTLSyclEventRef
1095
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
1096
                  void *USMRef,
1097
                  uint32_t Value,
1098
                  size_t Count)
1099
{
27 ✔
1100
    auto Q = unwrap<queue>(QRef);
27 ✔
1101
    if (Q && USMRef) {
27 !
1102
        sycl::event ev;
26 ✔
1103
        try {
26 ✔
1104
            ev = Q->fill<uint32_t>(USMRef, Value, Count);
26 ✔
1105
        } catch (std::exception const &e) {
26 ✔
1106
            error_handler(e, __FILE__, __func__, __LINE__);
×
1107
            return nullptr;
×
1108
        }
×
1109
        return wrap<event>(new event(std::move(ev)));
26 ✔
1110
    }
26 ✔
1111
    else {
1 ✔
1112
        error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__,
1 ✔
1113
                      __func__, __LINE__);
1 ✔
1114
        return nullptr;
1 ✔
1115
    }
1 ✔
1116
}
27 ✔
1117

1118
__dpctl_give DPCTLSyclEventRef
1119
DPCTLQueue_Fill32WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1120
                            void *USMRef,
1121
                            uint32_t Value,
1122
                            size_t Count,
1123
                            const DPCTLSyclEventRef *DepEvents,
1124
                            size_t DepEventsCount)
1125
{
9 ✔
1126
    auto Q = unwrap<queue>(QRef);
9 ✔
1127
    if (Q && USMRef) {
9 !
1128
        sycl::event ev;
8 ✔
1129
        try {
8 ✔
1130
            std::vector<event> dep_events;
8 ✔
1131
            if (DepEvents) {
8 !
1132
                dep_events.reserve(DepEventsCount);
8 ✔
1133
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1134
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1135
                    if (ei)
8 !
1136
                        dep_events.push_back(*ei);
8 ✔
1137
                }
8 ✔
1138
            }
8 ✔
1139
            ev = Q->fill<uint32_t>(USMRef, Value, Count, dep_events);
8 ✔
1140
        } catch (std::exception const &e) {
8 ✔
1141
            error_handler(e, __FILE__, __func__, __LINE__);
×
1142
            return nullptr;
×
1143
        }
×
1144
        return wrap<event>(new event(std::move(ev)));
8 ✔
1145
    }
8 ✔
1146
    else {
1 ✔
1147
        error_handler("QRef or USMRef passed to fill32_async were NULL.",
1 ✔
1148
                      __FILE__, __func__, __LINE__);
1 ✔
1149
        return nullptr;
1 ✔
1150
    }
1 ✔
1151
}
9 ✔
1152

1153
__dpctl_give DPCTLSyclEventRef
1154
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
1155
                  void *USMRef,
1156
                  uint64_t Value,
1157
                  size_t Count)
1158
{
33 ✔
1159
    auto Q = unwrap<queue>(QRef);
33 ✔
1160
    if (Q && USMRef) {
33 !
1161
        sycl::event ev;
32 ✔
1162
        try {
32 ✔
1163
            ev = Q->fill<uint64_t>(USMRef, Value, Count);
32 ✔
1164
        } catch (std::exception const &e) {
32 ✔
1165
            error_handler(e, __FILE__, __func__, __LINE__);
×
1166
            return nullptr;
×
1167
        }
×
1168
        return wrap<event>(new event(std::move(ev)));
32 ✔
1169
    }
32 ✔
1170
    else {
1 ✔
1171
        error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__,
1 ✔
1172
                      __func__, __LINE__);
1 ✔
1173
        return nullptr;
1 ✔
1174
    }
1 ✔
1175
}
33 ✔
1176

1177
__dpctl_give DPCTLSyclEventRef
1178
DPCTLQueue_Fill64WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1179
                            void *USMRef,
1180
                            uint64_t Value,
1181
                            size_t Count,
1182
                            const DPCTLSyclEventRef *DepEvents,
1183
                            size_t DepEventsCount)
1184
{
9 ✔
1185
    auto Q = unwrap<queue>(QRef);
9 ✔
1186
    if (Q && USMRef) {
9 !
1187
        sycl::event ev;
8 ✔
1188
        try {
8 ✔
1189
            std::vector<event> dep_events;
8 ✔
1190
            if (DepEvents) {
8 !
1191
                dep_events.reserve(DepEventsCount);
8 ✔
1192
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1193
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1194
                    if (ei)
8 !
1195
                        dep_events.push_back(*ei);
8 ✔
1196
                }
8 ✔
1197
            }
8 ✔
1198
            ev = Q->fill<uint64_t>(USMRef, Value, Count, dep_events);
8 ✔
1199
        } catch (std::exception const &e) {
8 ✔
1200
            error_handler(e, __FILE__, __func__, __LINE__);
×
1201
            return nullptr;
×
1202
        }
×
1203
        return wrap<event>(new event(std::move(ev)));
8 ✔
1204
    }
8 ✔
1205
    else {
1 ✔
1206
        error_handler("QRef or USMRef passed to fill64_async were NULL.",
1 ✔
1207
                      __FILE__, __func__, __LINE__);
1 ✔
1208
        return nullptr;
1 ✔
1209
    }
1 ✔
1210
}
9 ✔
1211

1212
__dpctl_give DPCTLSyclEventRef
1213
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
1214
                   void *USMRef,
1215
                   uint64_t *Value,
1216
                   size_t Count)
1217
{
29 ✔
1218
    auto Q = unwrap<queue>(QRef);
29 ✔
1219
    if (Q && USMRef && Value) {
29 !
1220
        sycl::event ev;
20 ✔
1221
        try {
20 ✔
1222
            complexNumber Val;
20 ✔
1223
            Val.real = Value[0];
20 ✔
1224
            Val.imag = Value[1];
20 ✔
1225
            ev = Q->fill(USMRef, Val, Count);
20 ✔
1226
        } catch (std::exception const &e) {
20 ✔
1227
            error_handler(e, __FILE__, __func__, __LINE__);
×
1228
            return nullptr;
×
1229
        }
×
1230
        return wrap<event>(new event(std::move(ev)));
20 ✔
1231
    }
20 ✔
1232
    else {
9 ✔
1233
        error_handler("QRef, USMRef, or Value passed to fill128 were NULL.",
9 ✔
1234
                      __FILE__, __func__, __LINE__);
9 ✔
1235
        return nullptr;
9 ✔
1236
    }
9 ✔
1237
}
29 ✔
1238

1239
__dpctl_give DPCTLSyclEventRef
1240
DPCTLQueue_Fill128WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1241
                             void *USMRef,
1242
                             uint64_t *Value,
1243
                             size_t Count,
1244
                             const DPCTLSyclEventRef *DepEvents,
1245
                             size_t DepEventsCount)
1246
{
17 ✔
1247
    auto Q = unwrap<queue>(QRef);
17 ✔
1248
    if (Q && USMRef && Value) {
17 !
1249
        sycl::event ev;
8 ✔
1250
        try {
8 ✔
1251
            std::vector<event> dep_events;
8 ✔
1252
            if (DepEvents) {
8 !
1253
                dep_events.reserve(DepEventsCount);
8 ✔
1254
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1255
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1256
                    if (ei)
8 !
1257
                        dep_events.push_back(*ei);
8 ✔
1258
                }
8 ✔
1259
            }
8 ✔
1260
            complexNumber Val;
8 ✔
1261
            Val.real = Value[0];
8 ✔
1262
            Val.imag = Value[1];
8 ✔
1263
            ev = Q->fill(USMRef, Val, Count, dep_events);
8 ✔
1264
        } catch (std::exception const &e) {
8 ✔
1265
            error_handler(e, __FILE__, __func__, __LINE__);
×
1266
            return nullptr;
×
1267
        }
×
1268
        return wrap<event>(new event(std::move(ev)));
8 ✔
1269
    }
8 ✔
1270
    else {
9 ✔
1271
        error_handler(
9 ✔
1272
            "QRef, USMRef, or Value passed to fill128_async were NULL.",
9 ✔
1273
            __FILE__, __func__, __LINE__);
9 ✔
1274
        return nullptr;
9 ✔
1275
    }
9 ✔
1276
}
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