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

IntelPython / dpctl / 42091724335

05 Nov 2026 07:12PM UTC coverage: 75.087% (+0.1%) from 74.963%
42091724335

Pull #2384

github

web-flow
Merge 98bc1d29b into ea89d1b9e
Pull Request #2384: Enable AdaptiveCpp builds

1058 of 1486 branches covered (71.2%)

Branch coverage included in aggregate %.

48 of 66 new or added lines in 15 files covered. (72.73%)

2 existing lines in 2 files now uncovered.

4099 of 5382 relevant lines covered (76.16%)

288.3 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
#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
{
176 ✔
154
    for (auto i = 0ul; i < NDepEvents; ++i) {
332 ✔
155
        auto ei = unwrap<event>(DepEvents[i]);
156 ✔
156
        if (ei)
156 !
157
            cgh.depends_on(*ei);
156 ✔
158
    }
156 ✔
159
}
176 ✔
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
{
498 ✔
200
    bool arg_set = true;
498 ✔
201

202
    switch (ArgTy) {
498 ✔
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:
327 ✔
234
        cgh.set_arg(idx, Arg);
327 ✔
235
        break;
327 ✔
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:
×
265
        arg_set = false;
×
266
        break;
×
267
    }
498 ✔
268
    return arg_set;
498 ✔
269
}
498 ✔
270

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

286
#endif /* #ifndef __ADAPTIVECPP__ */
287

288
std::unique_ptr<property_list> create_property_list(int properties)
289
{
1,867 ✔
290
    std::unique_ptr<property_list> propList;
1,867 ✔
291
    int _prop = properties;
1,867 ✔
292
    if (_prop & DPCTL_ENABLE_PROFILING) {
1,867 ✔
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,781 ✔
306
        _prop = _prop ^ DPCTL_IN_ORDER;
552 ✔
307
        propList =
552 ✔
308
            std::make_unique<property_list>(sycl::property::queue::in_order());
552 ✔
309
    }
552 ✔
310
    else {
1,229 ✔
311
        propList = std::make_unique<property_list>();
1,229 ✔
312
    }
1,229 ✔
313

314
    if (_prop) {
1,867 ✔
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,867 ✔
321
}
1,867 ✔
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
{
209 ✔
329
    DPCTLSyclQueueRef qRef = nullptr;
209 ✔
330
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
209 ✔
331
    return qRef;
209 ✔
332
}
209 ✔
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,869 ✔
343
    DPCTLSyclQueueRef q = nullptr;
1,869 ✔
344
    auto dev = unwrap<device>(DRef);
1,869 ✔
345
    auto ctx = unwrap<context>(CRef);
1,869 ✔
346

347
    if (!(dev && ctx)) {
1,869 ✔
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,867 ✔
354

355
    if (handler) {
1,867 ✔
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,799 ✔
365
        try {
1,799 ✔
366
#ifdef __ADAPTIVECPP__
367
            // a queue with no handler of its own inherits the default handler
368
            // of the AdaptiveCpp context, which calls std::terminate
369
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(nullptr),
370
                                   *propList);
371
#else
372
            auto Queue = new queue(*ctx, *dev, *propList);
1,799 ✔
373
#endif
1,799 ✔
374
            q = wrap<queue>(Queue);
1,799 ✔
375
        } catch (std::exception const &e) {
1,799 ✔
376
            error_handler(e, __FILE__, __func__, __LINE__);
1 ✔
377
        }
1 ✔
378
    }
1,799 ✔
379

380
    return q;
1,867 ✔
381
}
1,867 ✔
382

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

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

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

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

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

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

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

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

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

535
#ifndef __ADAPTIVECPP__
62 ✔
536
    auto Kernel = unwrap<kernel>(KRef);
62 ✔
537
    auto Queue = unwrap<queue>(QRef);
62 ✔
538
    event e;
62 ✔
539

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

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

614
#ifndef __ADAPTIVECPP__
114 ✔
615
    auto Kernel = unwrap<kernel>(KRef);
114 ✔
616
    auto Queue = unwrap<queue>(QRef);
114 ✔
617
    event e;
114 ✔
618

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

674
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
675
{
2 ✔
676
    // \todo what happens if the QRef is null or a pointer to a valid sycl
677
    // queue
678
    if (QRef) {
2 !
679
        auto SyclQueue = unwrap<queue>(QRef);
2 ✔
680
        if (SyclQueue)
2 !
681
            SyclQueue->wait();
2 ✔
682
    }
2 ✔
683
    else {
×
684
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
×
685
    }
×
686
}
2 ✔
687

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

712
__dpctl_give DPCTLSyclEventRef
713
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
714
                            void *Dest,
715
                            const void *Src,
716
                            size_t Count,
717
                            const DPCTLSyclEventRef *DepEvents,
718
                            size_t DepEventsCount)
719
{
129 ✔
720
    event ev;
129 ✔
721
    auto Q = unwrap<queue>(QRef);
129 ✔
722
    if (Q) {
129 ✔
723
        try {
128 ✔
724
            ev = Q->submit([&](handler &cgh) {
128 ✔
725
                if (DepEvents)
128 ✔
726
                    for (size_t i = 0; i < DepEventsCount; ++i) {
323 ✔
727
                        event *ei = unwrap<event>(DepEvents[i]);
203 ✔
728
                        if (ei)
203 !
729
                            cgh.depends_on(*ei);
203 ✔
730
                    }
203 ✔
731

732
                cgh.memcpy(Dest, Src, Count);
128 ✔
733
            });
128 ✔
734
        } catch (const std::exception &ex) {
128 ✔
735
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
736
            return nullptr;
8 ✔
737
        }
8 ✔
738
    }
128 ✔
739
    else {
1 ✔
740
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
741
                      __LINE__);
1 ✔
742
        return nullptr;
1 ✔
743
    }
1 ✔
744

745
    return wrap<event>(new event(ev));
120 ✔
746
}
129 ✔
747

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

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

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

812
__dpctl_give DPCTLSyclEventRef
813
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
814
                    const void *Ptr,
815
                    size_t Count)
816
{
16 ✔
817
    auto Q = unwrap<queue>(QRef);
16 ✔
818
    if (Q) {
16 ✔
819
        if (Ptr) {
15 ✔
820
            sycl::event ev;
7 ✔
821
            try {
7 ✔
822
                ev = Q->prefetch(Ptr, Count);
7 ✔
823
            } catch (std::exception const &e) {
7 ✔
824
                error_handler(e, __FILE__, __func__, __LINE__);
×
825
                return nullptr;
×
826
            }
×
827
            return wrap<event>(new event(std::move(ev)));
7 ✔
828
        }
7 ✔
829
        else {
8 ✔
830
            error_handler("Attempt to prefetch USM-allocation at nullptr.",
8 ✔
831
                          __FILE__, __func__, __LINE__);
8 ✔
832
            return nullptr;
8 ✔
833
        }
8 ✔
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
__dpctl_give DPCTLSyclEventRef
843
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
844
                     const void *Ptr,
845
                     size_t Count,
846
                     int Advice)
847
{
16 ✔
848
    auto Q = unwrap<queue>(QRef);
16 ✔
849
    if (Q) {
16 ✔
850
        sycl::event ev;
15 ✔
851
        try {
15 ✔
852
            ev = Q->mem_advise(Ptr, Count, Advice);
15 ✔
853
        } catch (std::exception const &e) {
15 ✔
854
            error_handler(e, __FILE__, __func__, __LINE__);
×
855
            return nullptr;
×
856
        }
×
857
        return wrap<event>(new event(std::move(ev)));
15 ✔
858
    }
15 ✔
859
    else {
1 ✔
860
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
861
                      __LINE__);
1 ✔
862
        return nullptr;
1 ✔
863
    }
1 ✔
864
}
16 ✔
865

866
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
867
{
1,040 ✔
868
    auto Q = unwrap<queue>(QRef);
1,040 ✔
869
    if (Q) {
1,040 ✔
870
        return Q->is_in_order();
1,039 ✔
871
    }
1,039 ✔
872
    else
1 ✔
873
        return false;
1 ✔
874
}
1,040 ✔
875

876
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
877
{
67 ✔
878
    auto Q = unwrap<queue>(QRef);
67 ✔
879
    if (Q) {
67 ✔
880
        return Q->has_property<sycl::property::queue::enable_profiling>();
66 ✔
881
    }
66 ✔
882
    else
1 ✔
883
        return false;
1 ✔
884
}
67 ✔
885

886
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
887
{
32 ✔
888
    auto Q = unwrap<queue>(QRef);
32 ✔
889
    if (Q) {
32 ✔
890
        std::hash<queue> hash_fn;
29 ✔
891
        return hash_fn(*Q);
29 ✔
892
    }
29 ✔
893
    else {
3 ✔
894
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3 ✔
895
        return 0;
3 ✔
896
    }
3 ✔
897
}
32 ✔
898

899
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
900
    __dpctl_keep const DPCTLSyclQueueRef QRef,
901
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
902
    size_t NDepEvents)
903
{
115 ✔
904
    auto Q = unwrap<queue>(QRef);
115 ✔
905
    event e;
115 ✔
906
    if (Q) {
115 !
907
        try {
115 ✔
908
            e = Q->submit([&](handler &cgh) {
115 ✔
909
                // Depend on any event that was specified by the caller.
910
                if (NDepEvents)
115 ✔
911
                    for (auto i = 0ul; i < NDepEvents; ++i)
18 ✔
912
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
12 ✔
913

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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