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

IntelPython / dpctl / 42077126821

05 Nov 2026 05:41PM UTC coverage: 75.127% (+0.2%) from 74.963%
42077126821

Pull #2384

github

web-flow
Merge 4dd89c6f6 into ea89d1b9e
Pull Request #2384: Enable AdaptiveCpp builds

1058 of 1484 branches covered (71.29%)

Branch coverage included in aggregate %.

47 of 61 new or added lines in 14 files covered. (77.05%)

2 existing lines in 2 files now uncovered.

4098 of 5379 relevant lines covered (76.19%)

288.28 hits per line

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

86.76
/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
            auto Queue = new queue(*ctx, *dev, *propList);
1,799 ✔
367
            q = wrap<queue>(Queue);
1,799 ✔
368
        } catch (std::exception const &e) {
1,799 ✔
369
            error_handler(e, __FILE__, __func__, __LINE__);
1 ✔
370
        }
1 ✔
371
    }
1,799 ✔
372

373
    return q;
1,867 ✔
374
}
1,867 ✔
375

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

738
    return wrap<event>(new event(ev));
120 ✔
739
}
129 ✔
740

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

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

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

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

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

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

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

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

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

907
#ifndef __ADAPTIVECPP__
115 ✔
908
                cgh.ext_oneapi_barrier();
115 ✔
909
#else
910
                class dpctl_barrier_task;
911
                cgh.single_task<dpctl_barrier_task>([=]() {});
912
#endif
913
            });
115 ✔
914
        } catch (std::exception const &e) {
115 ✔
915
            error_handler(e, __FILE__, __func__, __LINE__);
×
916
            return nullptr;
×
917
        }
×
918

919
        return wrap<event>(new event(std::move(e)));
115 ✔
920
    }
115 ✔
921
    else {
×
922
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
923
        return nullptr;
×
924
    }
×
925
}
115 ✔
926

927
__dpctl_give DPCTLSyclEventRef
928
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
929
{
1 ✔
930
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1 ✔
931
}
1 ✔
932

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

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

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

990
    return wrap<event>(new event(std::move(ev)));
9 ✔
991
}
10 ✔
992

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

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

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

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

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

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

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

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

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

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