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

IntelPython / dpctl / 41532559936

02 Nov 2026 09:54PM UTC coverage: 75.218% (+0.2%) from 74.989%
41532559936

Pull #2335

github

web-flow
Merge a69429984 into 2dfa6bbda
Pull Request #2335: Allow NumPy data types as arguments

1076 of 1504 branches covered (71.54%)

Branch coverage included in aggregate %.

49 of 51 new or added lines in 2 files covered. (96.08%)

4105 of 5384 relevant lines covered (76.24%)

283.26 hits per line

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

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

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

52
using namespace sycl;
53

54
#define SET_LOCAL_ACCESSOR_ARG(CGH, NDIM, ARGTY, R, IDX)                       \
55
    do {                                                                       \
34 ✔
56
        switch ((ARGTY)) {                                                     \
34 ✔
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:                                                   \
4 ✔
88
        {                                                                      \
4 ✔
89
            auto la = local_accessor<std::uint32_t, NDIM>(R, CGH);             \
4 ✔
90
            CGH.set_arg(IDX, la);                                              \
4 ✔
91
            return true;                                                       \
4 ✔
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:                                                   \
4 ✔
100
        {                                                                      \
4 ✔
101
            auto la = local_accessor<std::uint64_t, NDIM>(R, CGH);             \
4 ✔
102
            CGH.set_arg(IDX, la);                                              \
4 ✔
103
            return true;                                                       \
4 ✔
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
        case DPCTL_BYTES16_T:                                                  \
1 ✔
118
        {                                                                      \
1 ✔
119
            auto la = local_accessor<complexNumber, NDIM>(R, CGH);             \
1 ✔
120
            CGH.set_arg(IDX, la);                                              \
1 ✔
121
            return true;                                                       \
1 ✔
NEW
122
        }                                                                      \
×
123
        default:                                                               \
1 ✔
124
            error_handler("Kernel argument could not be created.", __FILE__,   \
1 ✔
125
                          __func__, __LINE__, error_level::error);             \
1 ✔
126
            return false;                                                      \
1 ✔
127
        }                                                                      \
34 ✔
128
    } while (0);
34 !
129

130
namespace
131
{
132
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
133
              "The compiler does not meet minimum version requirement");
134

135
using namespace dpctl::syclinterface;
136

137
typedef struct complex
138
{
139
    std::uint64_t real;
140
    std::uint64_t imag;
141
} complexNumber;
142

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

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

195
    switch (ArgTy) {
557 ✔
196
    case DPCTL_INT8_T:
3 ✔
197
        cgh.set_arg(idx, *(std::int8_t *)Arg);
3 ✔
198
        break;
3 ✔
199
    case DPCTL_UINT8_T:
6 ✔
200
        cgh.set_arg(idx, *(std::uint8_t *)Arg);
6 ✔
201
        break;
6 ✔
202
    case DPCTL_INT16_T:
9 ✔
203
        cgh.set_arg(idx, *(std::int16_t *)Arg);
9 ✔
204
        break;
9 ✔
205
    case DPCTL_UINT16_T:
6 ✔
206
        cgh.set_arg(idx, *(std::uint16_t *)Arg);
6 ✔
207
        break;
6 ✔
208
    case DPCTL_INT32_T:
9 ✔
209
        cgh.set_arg(idx, *(std::int32_t *)Arg);
9 ✔
210
        break;
9 ✔
211
    case DPCTL_UINT32_T:
15 ✔
212
        cgh.set_arg(idx, *(std::uint32_t *)Arg);
15 ✔
213
        break;
15 ✔
214
    case DPCTL_INT64_T:
9 ✔
215
        cgh.set_arg(idx, *(std::int64_t *)Arg);
9 ✔
216
        break;
9 ✔
217
    case DPCTL_UINT64_T:
20 ✔
218
        cgh.set_arg(idx, *(std::uint64_t *)Arg);
20 ✔
219
        break;
20 ✔
220
    case DPCTL_FLOAT32_T:
9 ✔
221
        cgh.set_arg(idx, *(float *)Arg);
9 ✔
222
        break;
9 ✔
223
    case DPCTL_FLOAT64_T:
9 ✔
224
        cgh.set_arg(idx, *(double *)Arg);
9 ✔
225
        break;
9 ✔
226
    case DPCTL_BYTES16_T:
2 ✔
227
    {
2 ✔
228
        complexNumber Val;
2 ✔
229
        std::memcpy(&Val, Arg, sizeof(Val));
2 ✔
230
        cgh.set_arg(idx, Val);
2 ✔
231
        break;
2 ✔
NEW
232
    }
×
233
    case DPCTL_VOID_PTR:
364 ✔
234
        cgh.set_arg(idx, Arg);
364 ✔
235
        break;
364 ✔
236
    case DPCTL_LOCAL_ACCESSOR:
34 ✔
237
        arg_set = set_local_accessor_arg(cgh, idx, (MDLocalAccessor *)Arg);
34 ✔
238
        break;
34 ✔
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:
31 ✔
253
    {
31 ✔
254
        auto ref = static_cast<DPCTLSyclRawKernelArgRef>(Arg);
31 ✔
255
        std::vector<unsigned char> *raw_arg =
31 ✔
256
            unwrap<std::vector<unsigned char>>(ref);
31 ✔
257
        void *bytes = raw_arg->data();
31 ✔
258
        size_t count = raw_arg->size();
31 ✔
259
        sycl::ext::oneapi::experimental::raw_kernel_arg arg{bytes, count};
31 ✔
260
        cgh.set_arg(idx, arg);
31 ✔
261
        break;
31 ✔
262
    }
×
263
#endif
×
264
    default:
×
265
        arg_set = false;
×
266
        break;
×
267
    }
557 ✔
268
    return arg_set;
557 ✔
269
}
557 ✔
270

271
void set_kernel_args(handler &cgh,
272
                     __dpctl_keep void **Args,
273
                     __dpctl_keep const DPCTLKernelArgType *ArgTypes,
274
                     size_t NArgs)
275
{
198 ✔
276
    for (auto i = 0ul; i < NArgs; ++i) {
754 ✔
277
        if (!set_kernel_arg(cgh, i, Args[i], ArgTypes[i])) {
557 ✔
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
    }
557 ✔
284
}
198 ✔
285

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

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

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

332
} /* end of anonymous namespace */
333

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

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

353
    if (handler) {
1,874 ✔
354
        try {
68 ✔
355
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
68 ✔
356
                                   *propList);
68 ✔
357
            q = wrap<queue>(Queue);
68 ✔
358
        } catch (std::exception const &e) {
68 ✔
359
            error_handler(e, __FILE__, __func__, __LINE__);
×
360
        }
×
361
    }
68 ✔
362
    else {
1,806 ✔
363
        try {
1,806 ✔
364
            auto Queue = new queue(*ctx, *dev, *propList);
1,806 ✔
365
            q = wrap<queue>(Queue);
1,806 ✔
366
        } catch (std::exception const &e) {
1,806 ✔
367
            error_handler(e, __FILE__, __func__, __LINE__);
1 ✔
368
        }
1 ✔
369
    }
1,806 ✔
370

371
    return q;
1,874 ✔
372
}
1,874 ✔
373

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

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

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

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

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

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

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

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

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

526
    auto Kernel = unwrap<kernel>(KRef);
80 ✔
527
    auto Queue = unwrap<queue>(QRef);
80 ✔
528
    event e;
80 ✔
529

530
    try {
80 ✔
531
        switch (NDims) {
80 ✔
532
        case 1:
46 ✔
533
        {
46 ✔
534
            e = Queue->submit([&](handler &cgh) {
46 ✔
535
                // Depend on any event that was specified by the caller.
536
                set_dependent_events(cgh, DepEvents, NDepEvents);
46 ✔
537
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
46 ✔
538
                cgh.parallel_for(range<1>{Range[0]}, *Kernel);
46 ✔
539
            });
46 ✔
540
            return wrap<event>(new event(std::move(e)));
46 ✔
541
        }
×
542
        case 2:
17 ✔
543
        {
17 ✔
544
            e = Queue->submit([&](handler &cgh) {
17 ✔
545
                // Depend on any event that was specified by the caller.
546
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
547
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
548
                cgh.parallel_for(range<2>{Range[0], Range[1]}, *Kernel);
17 ✔
549
            });
17 ✔
550
            return wrap<event>(new event(std::move(e)));
17 ✔
551
        }
×
552
        case 3:
17 ✔
553
        {
17 ✔
554
            e = Queue->submit([&](handler &cgh) {
17 ✔
555
                // Depend on any event that was specified by the caller.
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:
×
564
            error_handler("Range cannot be greater than three "
×
565
                          "dimensions.",
×
566
                          __FILE__, __func__, __LINE__, error_level::error);
×
567
            return nullptr;
×
568
        }
80 ✔
569
    } catch (std::exception const &e) {
80 ✔
570
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
×
571
        return nullptr;
×
572
    } catch (...) {
×
573
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
574
                      __LINE__, error_level::error);
×
575
        return nullptr;
×
576
    }
×
577
}
80 ✔
578

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

602
    auto Kernel = unwrap<kernel>(KRef);
118 ✔
603
    auto Queue = unwrap<queue>(QRef);
118 ✔
604
    event e;
118 ✔
605

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

659
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
660
{
1 ✔
661
    // \todo what happens if the QRef is null or a pointer to a valid sycl
662
    // queue
663
    if (QRef) {
1 !
664
        auto SyclQueue = unwrap<queue>(QRef);
1 ✔
665
        if (SyclQueue)
1 !
666
            SyclQueue->wait();
1 ✔
667
    }
1 ✔
668
    else {
×
669
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
×
670
    }
×
671
}
1 ✔
672

673
__dpctl_give DPCTLSyclEventRef
674
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
675
                  void *Dest,
676
                  const void *Src,
677
                  size_t Count)
678
{
265 ✔
679
    auto Q = unwrap<queue>(QRef);
265 ✔
680
    if (Q) {
265 ✔
681
        sycl::event ev;
264 ✔
682
        try {
264 ✔
683
            ev = Q->memcpy(Dest, Src, Count);
264 ✔
684
        } catch (std::exception const &e) {
264 ✔
685
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
686
            return nullptr;
8 ✔
687
        }
8 ✔
688
        return wrap<event>(new event(std::move(ev)));
256 ✔
689
    }
264 ✔
690
    else {
1 ✔
691
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
692
                      __LINE__);
1 ✔
693
        return nullptr;
1 ✔
694
    }
1 ✔
695
}
265 ✔
696

697
__dpctl_give DPCTLSyclEventRef
698
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
699
                            void *Dest,
700
                            const void *Src,
701
                            size_t Count,
702
                            const DPCTLSyclEventRef *DepEvents,
703
                            size_t DepEventsCount)
704
{
129 ✔
705
    event ev;
129 ✔
706
    auto Q = unwrap<queue>(QRef);
129 ✔
707
    if (Q) {
129 ✔
708
        try {
128 ✔
709
            ev = Q->submit([&](handler &cgh) {
128 ✔
710
                if (DepEvents)
128 ✔
711
                    for (size_t i = 0; i < DepEventsCount; ++i) {
335 ✔
712
                        event *ei = unwrap<event>(DepEvents[i]);
215 ✔
713
                        if (ei)
215 !
714
                            cgh.depends_on(*ei);
215 ✔
715
                    }
215 ✔
716

717
                cgh.memcpy(Dest, Src, Count);
128 ✔
718
            });
128 ✔
719
        } catch (const std::exception &ex) {
128 ✔
720
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
721
            return nullptr;
8 ✔
722
        }
8 ✔
723
    }
128 ✔
724
    else {
1 ✔
725
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
726
                      __LINE__);
1 ✔
727
        return nullptr;
1 ✔
728
    }
1 ✔
729

730
    return wrap<event>(new event(ev));
120 ✔
731
}
129 ✔
732

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

759
__dpctl_give DPCTLSyclEventRef
760
DPCTLQueue_CopyDataWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
761
                              void *Dest,
762
                              const void *Src,
763
                              size_t Count,
764
                              const DPCTLSyclEventRef *DepEvents,
765
                              size_t DepEventsCount)
766
{
10 ✔
767
    auto Q = unwrap<queue>(QRef);
10 ✔
768
    if (Q) {
10 ✔
769
        try {
9 ✔
770
            std::vector<event> dep_events;
9 ✔
771
            if (DepEvents) {
9 ✔
772
                dep_events.reserve(DepEventsCount);
1 ✔
773
                for (size_t i = 0; i < DepEventsCount; ++i) {
2 ✔
774
                    event *ei = unwrap<event>(DepEvents[i]);
1 ✔
775
                    if (ei)
1 !
776
                        dep_events.push_back(*ei);
1 ✔
777
                }
1 ✔
778
            }
1 ✔
779

780
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
781
            auto ev =
9 ✔
782
                Q->copy(static_cast<const std::uint8_t *>(Src),
9 ✔
783
                        static_cast<std::uint8_t *>(Dest), Count, dep_events);
9 ✔
784
            return wrap<event>(new event(std::move(ev)));
9 ✔
785
        } catch (const std::exception &ex) {
9 ✔
786
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
787
            return nullptr;
8 ✔
788
        }
8 ✔
789
    }
9 ✔
790
    else {
1 ✔
791
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
792
                      __LINE__);
1 ✔
793
        return nullptr;
1 ✔
794
    }
1 ✔
795
}
10 ✔
796

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

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

851
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
852
{
1,040 ✔
853
    auto Q = unwrap<queue>(QRef);
1,040 ✔
854
    if (Q) {
1,040 ✔
855
        return Q->is_in_order();
1,039 ✔
856
    }
1,039 ✔
857
    else
1 ✔
858
        return false;
1 ✔
859
}
1,040 ✔
860

861
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
862
{
67 ✔
863
    auto Q = unwrap<queue>(QRef);
67 ✔
864
    if (Q) {
67 ✔
865
        return Q->has_property<sycl::property::queue::enable_profiling>();
66 ✔
866
    }
66 ✔
867
    else
1 ✔
868
        return false;
1 ✔
869
}
67 ✔
870

871
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
872
{
24 ✔
873
    auto Q = unwrap<queue>(QRef);
24 ✔
874
    if (Q) {
24 ✔
875
        std::hash<queue> hash_fn;
21 ✔
876
        return hash_fn(*Q);
21 ✔
877
    }
21 ✔
878
    else {
3 ✔
879
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3 ✔
880
        return 0;
3 ✔
881
    }
3 ✔
882
}
24 ✔
883

884
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
885
    __dpctl_keep const DPCTLSyclQueueRef QRef,
886
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
887
    size_t NDepEvents)
888
{
107 ✔
889
    auto Q = unwrap<queue>(QRef);
107 ✔
890
    event e;
107 ✔
891
    if (Q) {
107 !
892
        try {
107 ✔
893
            e = Q->submit([&](handler &cgh) {
107 ✔
894
                // Depend on any event that was specified by the caller.
895
                if (NDepEvents)
107 ✔
896
                    for (auto i = 0ul; i < NDepEvents; ++i)
18 ✔
897
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
12 ✔
898

899
                cgh.ext_oneapi_barrier();
107 ✔
900
            });
107 ✔
901
        } catch (std::exception const &e) {
107 ✔
902
            error_handler(e, __FILE__, __func__, __LINE__);
×
903
            return nullptr;
×
904
        }
×
905

906
        return wrap<event>(new event(std::move(e)));
107 ✔
907
    }
107 ✔
908
    else {
×
909
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
910
        return nullptr;
×
911
    }
×
912
}
107 ✔
913

914
__dpctl_give DPCTLSyclEventRef
915
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
916
{
1 ✔
917
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1 ✔
918
}
1 ✔
919

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

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

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

977
    return wrap<event>(new event(std::move(ev)));
9 ✔
978
}
10 ✔
979

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

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

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

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

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

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

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

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

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

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