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

IntelPython / dpctl / 42264307425

06 Nov 2026 05:43PM UTC coverage: 74.996% (+0.03%) from 74.963%
42264307425

Pull #2384

github

web-flow
Merge ec052193c into 6d9edf21b
Pull Request #2384: Enable AdaptiveCpp builds

1059 of 1490 branches covered (71.07%)

Branch coverage included in aggregate %.

47 of 66 new or added lines in 15 files covered. (71.21%)

18 existing lines in 3 files now uncovered.

4100 of 5389 relevant lines covered (76.08%)

285.8 hits per line

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

86.77
/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
#endif
124

125
namespace
126
{
127
#ifndef __ADAPTIVECPP__
128
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
129
              "The compiler does not meet minimum version requirement");
130
#endif
131

132
using namespace dpctl::syclinterface;
133

134
typedef struct complex
135
{
136
    std::uint64_t real;
137
    std::uint64_t imag;
138
} complexNumber;
139

140
#ifndef __ADAPTIVECPP__
141

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

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

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

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

278
#endif /* #ifndef __ADAPTIVECPP__ */
279

280
std::unique_ptr<property_list> create_property_list(int properties)
281
{
1,846 ✔
282
    std::unique_ptr<property_list> propList;
1,846 ✔
283
    int _prop = properties;
1,846 ✔
284
    if (_prop & DPCTL_ENABLE_PROFILING) {
1,846 ✔
285
        _prop = _prop ^ DPCTL_ENABLE_PROFILING;
86 ✔
286
        if (_prop & DPCTL_IN_ORDER) {
86 ✔
287
            _prop = _prop ^ DPCTL_IN_ORDER;
36 ✔
288
            propList = std::make_unique<property_list>(
36 ✔
289
                sycl::property::queue::enable_profiling(),
36 ✔
290
                sycl::property::queue::in_order());
36 ✔
291
        }
36 ✔
292
        else {
50 ✔
293
            propList = std::make_unique<property_list>(
50 ✔
294
                sycl::property::queue::enable_profiling());
50 ✔
295
        }
50 ✔
296
    }
86 ✔
297
    else if (_prop & DPCTL_IN_ORDER) {
1,760 ✔
298
        _prop = _prop ^ DPCTL_IN_ORDER;
552 ✔
299
        propList =
552 ✔
300
            std::make_unique<property_list>(sycl::property::queue::in_order());
552 ✔
301
    }
552 ✔
302
    else {
1,208 ✔
303
        propList = std::make_unique<property_list>();
1,208 ✔
304
    }
1,208 ✔
305

306
    if (_prop) {
1,846 ✔
307
        std::stringstream ss;
1 ✔
308
        ss << "Invalid queue property argument (" << std::hex << properties
1 ✔
309
           << "), interpreted as (" << (properties ^ _prop) << ").";
1 ✔
310
        error_handler(ss.str(), __FILE__, __func__, __LINE__);
1 ✔
311
    }
1 ✔
312
    return propList;
1,846 ✔
313
}
1,846 ✔
314

315
__dpctl_give DPCTLSyclQueueRef
316
getQueueImpl(__dpctl_keep DPCTLSyclContextRef cRef,
317
             __dpctl_keep DPCTLSyclDeviceRef dRef,
318
             error_handler_callback *handler,
319
             int properties)
320
{
209 ✔
321
    DPCTLSyclQueueRef qRef = nullptr;
209 ✔
322
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
209 ✔
323
    return qRef;
209 ✔
324
}
209 ✔
325

326
} /* end of anonymous namespace */
327

328
DPCTL_API
329
__dpctl_give DPCTLSyclQueueRef
330
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
331
                  __dpctl_keep const DPCTLSyclDeviceRef DRef,
332
                  error_handler_callback *handler,
333
                  int properties)
334
{
1,848 ✔
335
    DPCTLSyclQueueRef q = nullptr;
1,848 ✔
336
    auto dev = unwrap<device>(DRef);
1,848 ✔
337
    auto ctx = unwrap<context>(CRef);
1,848 ✔
338

339
    if (!(dev && ctx)) {
1,848 ✔
340
        error_handler("Cannot create queue from DPCTLSyclContextRef and "
2 ✔
341
                      "DPCTLSyclDeviceRef as input is a nullptr.",
2 ✔
342
                      __FILE__, __func__, __LINE__);
2 ✔
343
        return q;
2 ✔
344
    }
2 ✔
345
    auto propList = create_property_list(properties);
1,846 ✔
346

347
    if (handler) {
1,846 ✔
348
        try {
68 ✔
349
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
68 ✔
350
                                   *propList);
68 ✔
351
            q = wrap<queue>(Queue);
68 ✔
352
        } catch (std::exception const &e) {
68 ✔
353
            error_handler(e, __FILE__, __func__, __LINE__);
×
354
        }
×
355
    }
68 ✔
356
    else {
1,778 ✔
357
        try {
1,778 ✔
358
#ifdef __ADAPTIVECPP__
359
            // a queue with no handler of its own inherits the default handler
360
            // of the AdaptiveCpp context, which calls std::terminate
361
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(nullptr),
362
                                   *propList);
363
#else
364
            auto Queue = new queue(*ctx, *dev, *propList);
1,778 ✔
365
#endif
1,778 ✔
366
            q = wrap<queue>(Queue);
1,778 ✔
367
        } catch (std::exception const &e) {
1,778 ✔
368
            error_handler(e, __FILE__, __func__, __LINE__);
1 ✔
369
        }
1 ✔
370
    }
1,778 ✔
371

372
    return q;
1,846 ✔
373
}
1,846 ✔
374

375
__dpctl_give DPCTLSyclQueueRef
376
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
377
                           error_handler_callback *handler,
378
                           int properties)
379
{
491 ✔
380
    DPCTLSyclContextRef CRef = nullptr;
491 ✔
381
    DPCTLSyclQueueRef QRef = nullptr;
491 ✔
382
    auto Device = unwrap<device>(DRef);
491 ✔
383

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

413
/*!
414
 * Delete the passed in pointer after verifying it points to a sycl::queue.
415
 */
416
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef)
417
{
2,236 ✔
418
    delete unwrap<queue>(QRef);
2,236 ✔
419
}
2,236 ✔
420

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

444
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
445
                      __dpctl_keep const DPCTLSyclQueueRef QRef2)
446
{
13 ✔
447
    if (!(QRef1 && QRef2)) {
13 ✔
448
        error_handler("DPCTLSyclQueueRefs are nullptr.", __FILE__, __func__,
2 ✔
449
                      __LINE__);
2 ✔
450
        return false;
2 ✔
451
    }
2 ✔
452
    return (*unwrap<queue>(QRef1) == *unwrap<queue>(QRef2));
11 ✔
453
}
13 ✔
454

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

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

491
__dpctl_give DPCTLSyclContextRef
492
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
493
{
142 ✔
494
    auto Q = unwrap<queue>(QRef);
142 ✔
495
    DPCTLSyclContextRef CRef = nullptr;
142 ✔
496
    if (Q)
142 ✔
497
        CRef = wrap<context>(new context(Q->get_context()));
132 ✔
498
    else {
10 ✔
499
        error_handler("Could not get the context for this queue.", __FILE__,
10 ✔
500
                      __func__, __LINE__);
10 ✔
501
    }
10 ✔
502
    return CRef;
142 ✔
503
}
142 ✔
504

505
__dpctl_give DPCTLSyclEventRef
506
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
507
                       __dpctl_keep const DPCTLSyclQueueRef QRef,
508
                       __dpctl_keep void **Args,
509
                       __dpctl_keep const DPCTLKernelArgType *ArgTypes,
510
                       size_t NArgs,
511
                       __dpctl_keep const size_t Range[3],
512
                       size_t NDims,
513
                       __dpctl_keep const DPCTLSyclEventRef *DepEvents,
514
                       size_t NDepEvents)
515
{
65 ✔
516
    if (!KRef) {
65 ✔
517
        error_handler("Cannot submit the kernel as the kernel is a nullptr.",
2 ✔
518
                      __FILE__, __func__, __LINE__, error_level::error);
2 ✔
519
        return nullptr;
2 ✔
520
    }
2 ✔
521
    if (!QRef) {
63 ✔
522
        error_handler("Cannot submit the kernel as the queue is a nullptr.",
1 ✔
523
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
524
        return nullptr;
1 ✔
525
    }
1 ✔
526

527
#ifndef __ADAPTIVECPP__
62 ✔
528
    auto Kernel = unwrap<kernel>(KRef);
62 ✔
529
    auto Queue = unwrap<queue>(QRef);
62 ✔
530
    event e;
62 ✔
531

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

583
__dpctl_give DPCTLSyclEventRef
584
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
585
                         __dpctl_keep const DPCTLSyclQueueRef QRef,
586
                         __dpctl_keep void **Args,
587
                         __dpctl_keep const DPCTLKernelArgType *ArgTypes,
588
                         size_t NArgs,
589
                         __dpctl_keep const size_t gRange[3],
590
                         __dpctl_keep const size_t lRange[3],
591
                         size_t NDims,
592
                         __dpctl_keep const DPCTLSyclEventRef *DepEvents,
593
                         size_t NDepEvents)
594
{
116 ✔
595
    if (!KRef) {
116 ✔
596
        error_handler("Cannot submit the kernel as the kernel is a nullptr.",
1 ✔
597
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
598
        return nullptr;
1 ✔
599
    }
1 ✔
600
    if (!QRef) {
115 ✔
601
        error_handler("Cannot submit the kernel as the queue is a nullptr.",
1 ✔
602
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
603
        return nullptr;
1 ✔
604
    }
1 ✔
605

606
#ifndef __ADAPTIVECPP__
114 ✔
607
    auto Kernel = unwrap<kernel>(KRef);
114 ✔
608
    auto Queue = unwrap<queue>(QRef);
114 ✔
609
    event e;
114 ✔
610

611
    try {
114 ✔
612
        switch (NDims) {
114 ✔
613
        case 1:
100 ✔
614
        {
100 ✔
615
            e = Queue->submit([&](handler &cgh) {
100 ✔
616
                set_dependent_events(cgh, DepEvents, NDepEvents);
100 ✔
617
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
100 ✔
618
                cgh.parallel_for(nd_range<1>{{gRange[0]}, {lRange[0]}},
100 ✔
619
                                 *Kernel);
100 ✔
620
            });
100 ✔
621
            return wrap<event>(new event(std::move(e)));
100 ✔
622
        }
×
623
        case 2:
7 ✔
624
        {
7 ✔
625
            e = Queue->submit([&](handler &cgh) {
7 ✔
626
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
627
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
628
                cgh.parallel_for(
7 ✔
629
                    nd_range<2>{{gRange[0], gRange[1]}, {lRange[0], lRange[1]}},
7 ✔
630
                    *Kernel);
7 ✔
631
            });
7 ✔
632
            return wrap<event>(new event(std::move(e)));
7 ✔
633
        }
×
634
        case 3:
7 ✔
635
        {
7 ✔
636
            e = Queue->submit([&](handler &cgh) {
7 ✔
637
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
638
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
639
                cgh.parallel_for(nd_range<3>{{gRange[0], gRange[1], gRange[2]},
7 ✔
640
                                             {lRange[0], lRange[1], lRange[2]}},
7 ✔
641
                                 *Kernel);
7 ✔
642
            });
7 ✔
643
            return wrap<event>(new event(std::move(e)));
7 ✔
644
        }
×
645
        default:
×
NEW
646
            error_handler("Range cannot be greater than three dimensions.",
×
647
                          __FILE__, __func__, __LINE__, error_level::error);
×
648
            return nullptr;
×
649
        }
114 ✔
650
    } catch (std::exception const &e) {
114 ✔
651
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
1 ✔
652
        return nullptr;
1 ✔
653
    } catch (...) {
1 ✔
654
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
655
                      __LINE__, error_level::error);
×
656
        return nullptr;
×
657
    }
×
658
#else
659
    error_handler("Dynamic OpenCL-style kernel execution is not supported in "
660
                  "AdaptiveCpp.",
661
                  __FILE__, __func__, __LINE__, error_level::error);
662
    return nullptr;
663
#endif
664
}
114 ✔
665

666
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
667
{
2 ✔
668
    // \todo what happens if the QRef is null or a pointer to a valid sycl
669
    // queue
670
    if (QRef) {
2 !
671
        auto SyclQueue = unwrap<queue>(QRef);
2 ✔
672
        if (SyclQueue)
2 !
673
            SyclQueue->wait();
2 ✔
674
    }
2 ✔
675
    else {
×
676
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
×
677
    }
×
678
}
2 ✔
679

680
__dpctl_give DPCTLSyclEventRef
681
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
682
                  void *Dest,
683
                  const void *Src,
684
                  size_t Count)
685
{
206 ✔
686
    auto Q = unwrap<queue>(QRef);
206 ✔
687
    if (Q) {
206 ✔
688
        sycl::event ev;
205 ✔
689
        try {
205 ✔
690
            ev = Q->memcpy(Dest, Src, Count);
205 ✔
691
        } catch (std::exception const &e) {
205 ✔
692
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
693
            return nullptr;
8 ✔
694
        }
8 ✔
695
        return wrap<event>(new event(std::move(ev)));
197 ✔
696
    }
205 ✔
697
    else {
1 ✔
698
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
699
                      __LINE__);
1 ✔
700
        return nullptr;
1 ✔
701
    }
1 ✔
702
}
206 ✔
703

704
__dpctl_give DPCTLSyclEventRef
705
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
706
                            void *Dest,
707
                            const void *Src,
708
                            size_t Count,
709
                            const DPCTLSyclEventRef *DepEvents,
710
                            size_t DepEventsCount)
711
{
130 ✔
712
    event ev;
130 ✔
713
    auto Q = unwrap<queue>(QRef);
130 ✔
714
    if (Q) {
130 ✔
715
        try {
129 ✔
716
            ev = Q->submit([&](handler &cgh) {
129 ✔
717
                if (DepEvents)
129 ✔
718
                    for (size_t i = 0; i < DepEventsCount; ++i) {
329 ✔
719
                        event *ei = unwrap<event>(DepEvents[i]);
208 ✔
720
                        if (ei)
208 !
721
                            cgh.depends_on(*ei);
208 ✔
722
                    }
208 ✔
723

724
                cgh.memcpy(Dest, Src, Count);
129 ✔
725
            });
129 ✔
726
        } catch (const std::exception &ex) {
129 ✔
727
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
728
            return nullptr;
8 ✔
729
        }
8 ✔
730
    }
129 ✔
731
    else {
1 ✔
732
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
733
                      __LINE__);
1 ✔
734
        return nullptr;
1 ✔
735
    }
1 ✔
736

737
    return wrap<event>(new event(ev));
121 ✔
738
}
130 ✔
739

740
__dpctl_give DPCTLSyclEventRef
741
DPCTLQueue_CopyData(__dpctl_keep const DPCTLSyclQueueRef QRef,
742
                    void *Dest,
743
                    const void *Src,
744
                    size_t Count)
745
{
52 ✔
746
    auto Q = unwrap<queue>(QRef);
52 ✔
747
    if (Q) {
52 ✔
748
        sycl::event ev;
51 ✔
749
        try {
51 ✔
750
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
751
            ev = Q->copy(static_cast<const std::uint8_t *>(Src),
51 ✔
752
                         static_cast<std::uint8_t *>(Dest), Count);
51 ✔
753
        } catch (std::exception const &e) {
51 ✔
754
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
755
            return nullptr;
8 ✔
756
        }
8 ✔
757
        return wrap<event>(new event(std::move(ev)));
43 ✔
758
    }
51 ✔
759
    else {
1 ✔
760
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
761
                      __LINE__);
1 ✔
762
        return nullptr;
1 ✔
763
    }
1 ✔
764
}
52 ✔
765

766
__dpctl_give DPCTLSyclEventRef
767
DPCTLQueue_CopyDataWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
768
                              void *Dest,
769
                              const void *Src,
770
                              size_t Count,
771
                              const DPCTLSyclEventRef *DepEvents,
772
                              size_t DepEventsCount)
773
{
24 ✔
774
    auto Q = unwrap<queue>(QRef);
24 ✔
775
    if (Q) {
24 ✔
776
        try {
23 ✔
777
            std::vector<event> dep_events;
23 ✔
778
            if (DepEvents) {
23 ✔
779
                dep_events.reserve(DepEventsCount);
15 ✔
780
                for (size_t i = 0; i < DepEventsCount; ++i) {
30 ✔
781
                    event *ei = unwrap<event>(DepEvents[i]);
15 ✔
782
                    if (ei)
15 !
783
                        dep_events.push_back(*ei);
15 ✔
784
                }
15 ✔
785
            }
15 ✔
786

787
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
788
            auto ev =
23 ✔
789
                Q->copy(static_cast<const std::uint8_t *>(Src),
23 ✔
790
                        static_cast<std::uint8_t *>(Dest), Count, dep_events);
23 ✔
791
            return wrap<event>(new event(std::move(ev)));
23 ✔
792
        } catch (const std::exception &ex) {
23 ✔
793
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
794
            return nullptr;
8 ✔
795
        }
8 ✔
796
    }
23 ✔
797
    else {
1 ✔
798
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
799
                      __LINE__);
1 ✔
800
        return nullptr;
1 ✔
801
    }
1 ✔
802
}
24 ✔
803

804
__dpctl_give DPCTLSyclEventRef
805
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
806
                    const void *Ptr,
807
                    size_t Count)
808
{
16 ✔
809
    auto Q = unwrap<queue>(QRef);
16 ✔
810
    if (Q) {
16 ✔
811
        if (Ptr) {
15 ✔
812
            sycl::event ev;
7 ✔
813
            try {
7 ✔
814
                ev = Q->prefetch(Ptr, Count);
7 ✔
815
            } catch (std::exception const &e) {
7 ✔
816
                error_handler(e, __FILE__, __func__, __LINE__);
×
817
                return nullptr;
×
818
            }
×
819
            return wrap<event>(new event(std::move(ev)));
7 ✔
820
        }
7 ✔
821
        else {
8 ✔
822
            error_handler("Attempt to prefetch USM-allocation at nullptr.",
8 ✔
823
                          __FILE__, __func__, __LINE__);
8 ✔
824
            return nullptr;
8 ✔
825
        }
8 ✔
826
    }
15 ✔
827
    else {
1 ✔
828
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
829
                      __LINE__);
1 ✔
830
        return nullptr;
1 ✔
831
    }
1 ✔
832
}
16 ✔
833

834
__dpctl_give DPCTLSyclEventRef
835
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
836
                     const void *Ptr,
837
                     size_t Count,
838
                     int Advice)
839
{
16 ✔
840
    auto Q = unwrap<queue>(QRef);
16 ✔
841
    if (Q) {
16 ✔
842
        sycl::event ev;
15 ✔
843
        try {
15 ✔
844
            ev = Q->mem_advise(Ptr, Count, Advice);
15 ✔
845
        } catch (std::exception const &e) {
15 ✔
846
            error_handler(e, __FILE__, __func__, __LINE__);
×
847
            return nullptr;
×
848
        }
×
849
        return wrap<event>(new event(std::move(ev)));
15 ✔
850
    }
15 ✔
851
    else {
1 ✔
852
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
853
                      __LINE__);
1 ✔
854
        return nullptr;
1 ✔
855
    }
1 ✔
856
}
16 ✔
857

858
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
859
{
1,040 ✔
860
    auto Q = unwrap<queue>(QRef);
1,040 ✔
861
    if (Q) {
1,040 ✔
862
        return Q->is_in_order();
1,039 ✔
863
    }
1,039 ✔
864
    else
1 ✔
865
        return false;
1 ✔
866
}
1,040 ✔
867

868
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
869
{
67 ✔
870
    auto Q = unwrap<queue>(QRef);
67 ✔
871
    if (Q) {
67 ✔
872
        return Q->has_property<sycl::property::queue::enable_profiling>();
66 ✔
873
    }
66 ✔
874
    else
1 ✔
875
        return false;
1 ✔
876
}
67 ✔
877

878
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
879
{
32 ✔
880
    auto Q = unwrap<queue>(QRef);
32 ✔
881
    if (Q) {
32 ✔
882
        std::hash<queue> hash_fn;
29 ✔
883
        return hash_fn(*Q);
29 ✔
884
    }
29 ✔
885
    else {
3 ✔
886
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3 ✔
887
        return 0;
3 ✔
888
    }
3 ✔
889
}
32 ✔
890

891
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
892
    __dpctl_keep const DPCTLSyclQueueRef QRef,
893
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
894
    size_t NDepEvents)
895
{
116 ✔
896
    auto Q = unwrap<queue>(QRef);
116 ✔
897
    event e;
116 ✔
898
    if (Q) {
116 !
899
        try {
116 ✔
900
#ifdef __ADAPTIVECPP__
901
            // A kernel waits only for its dependencies, so depend on all prior
902
            // work
903
            auto prior = Q->get_wait_list();
904
#endif
905
            e = Q->submit([&](handler &cgh) {
116 ✔
906
                // Depend on any event that was specified by the caller.
907
                if (NDepEvents)
116 ✔
908
                    for (auto i = 0ul; i < NDepEvents; ++i)
18 ✔
909
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
12 ✔
910

911
#ifndef __ADAPTIVECPP__
116 ✔
912
                cgh.ext_oneapi_barrier();
116 ✔
913
#else
914
                cgh.depends_on(prior);
915
                class dpctl_barrier_task;
916
                cgh.single_task<dpctl_barrier_task>([=]() {});
917
#endif
918
            });
116 ✔
919
        } catch (std::exception const &e) {
116 ✔
920
            error_handler(e, __FILE__, __func__, __LINE__);
×
921
            return nullptr;
×
922
        }
×
923

924
        return wrap<event>(new event(std::move(e)));
116 ✔
925
    }
116 ✔
926
    else {
×
927
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
928
        return nullptr;
×
929
    }
×
930
}
116 ✔
931

932
__dpctl_give DPCTLSyclEventRef
933
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
934
{
1 ✔
935
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1 ✔
936
}
1 ✔
937

938
__dpctl_give DPCTLSyclEventRef
939
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
940
                  void *USMRef,
941
                  uint8_t Value,
942
                  size_t Count)
943
{
92 ✔
944
    auto Q = unwrap<queue>(QRef);
92 ✔
945
    if (Q && USMRef) {
92 !
946
        sycl::event ev;
91 ✔
947
        try {
91 ✔
948
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
91 ✔
949
        } catch (std::exception const &e) {
91 ✔
950
            error_handler(e, __FILE__, __func__, __LINE__);
×
951
            return nullptr;
×
952
        }
×
953
        return wrap<event>(new event(std::move(ev)));
91 ✔
954
    }
91 ✔
955
    else {
1 ✔
956
        error_handler("QRef or USMRef passed to memset were NULL.", __FILE__,
1 ✔
957
                      __func__, __LINE__);
1 ✔
958
        return nullptr;
1 ✔
959
    }
1 ✔
960
}
92 ✔
961

962
__dpctl_give DPCTLSyclEventRef
963
DPCTLQueue_MemsetWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
964
                            void *USMRef,
965
                            uint8_t Value,
966
                            size_t Count,
967
                            const DPCTLSyclEventRef *DepEvents,
968
                            size_t DepEventsCount)
969
{
10 ✔
970
    event ev;
10 ✔
971
    auto Q = unwrap<queue>(QRef);
10 ✔
972
    if (Q && USMRef) {
10 !
973
        try {
9 ✔
974
            ev = Q->submit([&](handler &cgh) {
9 ✔
975
                if (DepEvents)
9 !
976
                    for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
977
                        event *ei = unwrap<event>(DepEvents[i]);
9 ✔
978
                        if (ei)
9 !
979
                            cgh.depends_on(*ei);
9 ✔
980
                    }
9 ✔
981

982
                cgh.memset(USMRef, static_cast<int>(Value), Count);
9 ✔
983
            });
9 ✔
984
        } catch (const std::exception &ex) {
9 ✔
985
            error_handler(ex, __FILE__, __func__, __LINE__);
×
986
            return nullptr;
×
987
        }
×
988
    }
9 ✔
989
    else {
1 ✔
990
        error_handler("QRef or USMRef passed to memset_async were NULL.",
1 ✔
991
                      __FILE__, __func__, __LINE__);
1 ✔
992
        return nullptr;
1 ✔
993
    }
1 ✔
994

995
    return wrap<event>(new event(std::move(ev)));
9 ✔
996
}
10 ✔
997

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

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

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

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

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

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

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

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

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

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