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

IntelPython / dpctl / 42410101900

07 Nov 2026 08:14PM UTC coverage: 75.432% (+0.3%) from 75.137%
42410101900

Pull #2335

github

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

1104 of 1538 branches covered (71.78%)

Branch coverage included in aggregate %.

53 of 55 new or added lines in 2 files covered. (96.36%)

4177 of 5463 relevant lines covered (76.46%)

285.38 hits per line

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

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

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

53
using namespace sycl;
54

55
#define SET_LOCAL_ACCESSOR_ARG(CGH, NDIM, ARGTY, R, IDX)                       \
56
    do {                                                                       \
34 ✔
57
        switch ((ARGTY)) {                                                     \
34 ✔
58
        case DPCTL_INT8_T:                                                     \
3 ✔
59
        {                                                                      \
3 ✔
60
            auto la = local_accessor<std::int8_t, NDIM>(R, CGH);               \
3 ✔
61
            CGH.set_arg(IDX, la);                                              \
3 ✔
62
            return true;                                                       \
3 ✔
63
        }                                                                      \
×
64
        case DPCTL_UINT8_T:                                                    \
3 ✔
65
        {                                                                      \
3 ✔
66
            auto la = local_accessor<std::uint8_t, NDIM>(R, CGH);              \
3 ✔
67
            CGH.set_arg(IDX, la);                                              \
3 ✔
68
            return true;                                                       \
3 ✔
69
        }                                                                      \
×
70
        case DPCTL_INT16_T:                                                    \
3 ✔
71
        {                                                                      \
3 ✔
72
            auto la = local_accessor<std::int16_t, NDIM>(R, CGH);              \
3 ✔
73
            CGH.set_arg(IDX, la);                                              \
3 ✔
74
            return true;                                                       \
3 ✔
75
        }                                                                      \
×
76
        case DPCTL_UINT16_T:                                                   \
3 ✔
77
        {                                                                      \
3 ✔
78
            auto la = local_accessor<std::uint16_t, NDIM>(R, CGH);             \
3 ✔
79
            CGH.set_arg(IDX, la);                                              \
3 ✔
80
            return true;                                                       \
3 ✔
81
        }                                                                      \
×
82
        case DPCTL_INT32_T:                                                    \
3 ✔
83
        {                                                                      \
3 ✔
84
            auto la = local_accessor<std::int32_t, NDIM>(R, CGH);              \
3 ✔
85
            CGH.set_arg(IDX, la);                                              \
3 ✔
86
            return true;                                                       \
3 ✔
87
        }                                                                      \
×
88
        case DPCTL_UINT32_T:                                                   \
4 ✔
89
        {                                                                      \
4 ✔
90
            auto la = local_accessor<std::uint32_t, NDIM>(R, CGH);             \
4 ✔
91
            CGH.set_arg(IDX, la);                                              \
4 ✔
92
            return true;                                                       \
4 ✔
93
        }                                                                      \
×
94
        case DPCTL_INT64_T:                                                    \
3 ✔
95
        {                                                                      \
3 ✔
96
            auto la = local_accessor<std::int64_t, NDIM>(R, CGH);              \
3 ✔
97
            CGH.set_arg(IDX, la);                                              \
3 ✔
98
            return true;                                                       \
3 ✔
99
        }                                                                      \
×
100
        case DPCTL_UINT64_T:                                                   \
4 ✔
101
        {                                                                      \
4 ✔
102
            auto la = local_accessor<std::uint64_t, NDIM>(R, CGH);             \
4 ✔
103
            CGH.set_arg(IDX, la);                                              \
4 ✔
104
            return true;                                                       \
4 ✔
105
        }                                                                      \
×
106
        case DPCTL_FLOAT32_T:                                                  \
3 ✔
107
        {                                                                      \
3 ✔
108
            auto la = local_accessor<float, NDIM>(R, CGH);                     \
3 ✔
109
            CGH.set_arg(IDX, la);                                              \
3 ✔
110
            return true;                                                       \
3 ✔
111
        }                                                                      \
×
112
        case DPCTL_FLOAT64_T:                                                  \
3 ✔
113
        {                                                                      \
3 ✔
114
            auto la = local_accessor<double, NDIM>(R, CGH);                    \
3 ✔
115
            CGH.set_arg(IDX, la);                                              \
3 ✔
116
            return true;                                                       \
3 ✔
117
        }                                                                      \
×
118
        case DPCTL_BYTES16_T:                                                  \
1 ✔
119
        {                                                                      \
1 ✔
120
            auto la = local_accessor<complexNumber, NDIM>(R, CGH);             \
1 ✔
121
            CGH.set_arg(IDX, la);                                              \
1 ✔
122
            return true;                                                       \
1 ✔
NEW
123
        }                                                                      \
×
124
        default:                                                               \
1 ✔
125
            error_handler("Kernel argument could not be created.", __FILE__,   \
1 ✔
126
                          __func__, __LINE__, error_level::error);             \
1 ✔
127
            return false;                                                      \
1 ✔
128
        }                                                                      \
34 ✔
129
    } while (0);
34 !
130

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

136
using namespace dpctl::syclinterface;
137

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

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

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

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

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

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

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

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

333
} /* end of anonymous namespace */
334

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

731
    return wrap<event>(new event(ev));
137 ✔
732
}
146 ✔
733

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

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

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

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

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

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

862
bool DPCTLQueue_GetLastEvent_Available(void)
863
{
23 ✔
864
#ifdef SYCL_EXT_ONEAPI_IN_ORDER_QUEUE_EVENTS
23 ✔
865
    return true;
23 ✔
866
#else
867
    return false;
868
#endif
869
}
23 ✔
870

871
__dpctl_give DPCTLSyclEventRef
872
DPCTLQueue_GetLastEvent(__dpctl_keep const DPCTLSyclQueueRef QRef)
873
{
17 ✔
874
#ifdef SYCL_EXT_ONEAPI_IN_ORDER_QUEUE_EVENTS
17 ✔
875
    auto Q = unwrap<queue>(QRef);
17 ✔
876
    if (!Q) {
17 ✔
877
        error_handler("QRef passed to GetLastEvent was NULL.", __FILE__,
1 ✔
878
                      __func__, __LINE__);
1 ✔
879
        return nullptr;
1 ✔
880
    }
1 ✔
881
    if (!Q->is_in_order()) {
16 ✔
882
        error_handler("Queue passed to GetLastEvent is not in-order.", __FILE__,
1 ✔
883
                      __func__, __LINE__);
1 ✔
884
        return nullptr;
1 ✔
885
    }
1 ✔
886
    try {
15 ✔
887
        std::optional<event> ev = Q->ext_oneapi_get_last_event();
15 ✔
888
        if (!ev.has_value()) {
15 ✔
889
            return nullptr;
2 ✔
890
        }
2 ✔
891
        return wrap<event>(new event(std::move(*ev)));
13 ✔
892
    } catch (std::exception const &e) {
15 ✔
893
        error_handler(e, __FILE__, __func__, __LINE__);
×
894
        return nullptr;
×
895
    }
×
896
#else
897
    (void)QRef;
898
    return nullptr;
899
#endif
900
}
15 ✔
901

902
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
903
{
67 ✔
904
    auto Q = unwrap<queue>(QRef);
67 ✔
905
    if (Q) {
67 ✔
906
        return Q->has_property<sycl::property::queue::enable_profiling>();
66 ✔
907
    }
66 ✔
908
    else
1 ✔
909
        return false;
1 ✔
910
}
67 ✔
911

912
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
913
{
55 ✔
914
    auto Q = unwrap<queue>(QRef);
55 ✔
915
    if (Q) {
55 ✔
916
        std::hash<queue> hash_fn;
52 ✔
917
        return hash_fn(*Q);
52 ✔
918
    }
52 ✔
919
    else {
3 ✔
920
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3 ✔
921
        return 0;
3 ✔
922
    }
3 ✔
923
}
55 ✔
924

925
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
926
    __dpctl_keep const DPCTLSyclQueueRef QRef,
927
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
928
    size_t NDepEvents)
929
{
111 ✔
930
    auto Q = unwrap<queue>(QRef);
111 ✔
931
    event e;
111 ✔
932
    if (Q) {
111 !
933
        try {
111 ✔
934
            e = Q->submit([&](handler &cgh) {
111 ✔
935
                // Depend on any event that was specified by the caller.
936
                if (NDepEvents)
111 ✔
937
                    for (auto i = 0ul; i < NDepEvents; ++i)
18 ✔
938
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
12 ✔
939

940
                cgh.ext_oneapi_barrier();
111 ✔
941
            });
111 ✔
942
        } catch (std::exception const &e) {
111 ✔
943
            error_handler(e, __FILE__, __func__, __LINE__);
×
944
            return nullptr;
×
945
        }
×
946

947
        return wrap<event>(new event(std::move(e)));
111 ✔
948
    }
111 ✔
949
    else {
×
950
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
951
        return nullptr;
×
952
    }
×
953
}
111 ✔
954

955
__dpctl_give DPCTLSyclEventRef
956
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
957
{
1 ✔
958
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1 ✔
959
}
1 ✔
960

961
__dpctl_give DPCTLSyclEventRef
962
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
963
                  void *USMRef,
964
                  uint8_t Value,
965
                  size_t Count)
966
{
131 ✔
967
    auto Q = unwrap<queue>(QRef);
131 ✔
968
    if (Q && USMRef) {
131 !
969
        sycl::event ev;
130 ✔
970
        try {
130 ✔
971
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
130 ✔
972
        } catch (std::exception const &e) {
130 ✔
973
            error_handler(e, __FILE__, __func__, __LINE__);
×
974
            return nullptr;
×
975
        }
×
976
        return wrap<event>(new event(std::move(ev)));
130 ✔
977
    }
130 ✔
978
    else {
1 ✔
979
        error_handler("QRef or USMRef passed to memset were NULL.", __FILE__,
1 ✔
980
                      __func__, __LINE__);
1 ✔
981
        return nullptr;
1 ✔
982
    }
1 ✔
983
}
131 ✔
984

985
__dpctl_give DPCTLSyclEventRef
986
DPCTLQueue_MemsetWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
987
                            void *USMRef,
988
                            uint8_t Value,
989
                            size_t Count,
990
                            const DPCTLSyclEventRef *DepEvents,
991
                            size_t DepEventsCount)
992
{
110 ✔
993
    event ev;
110 ✔
994
    auto Q = unwrap<queue>(QRef);
110 ✔
995
    if (Q && USMRef) {
110 !
996
        try {
109 ✔
997
            ev = Q->submit([&](handler &cgh) {
109 ✔
998
                if (DepEvents)
109 !
999
                    for (size_t i = 0; i < DepEventsCount; ++i) {
218 ✔
1000
                        event *ei = unwrap<event>(DepEvents[i]);
109 ✔
1001
                        if (ei)
109 !
1002
                            cgh.depends_on(*ei);
109 ✔
1003
                    }
109 ✔
1004

1005
                cgh.memset(USMRef, static_cast<int>(Value), Count);
109 ✔
1006
            });
109 ✔
1007
        } catch (const std::exception &ex) {
109 ✔
1008
            error_handler(ex, __FILE__, __func__, __LINE__);
×
1009
            return nullptr;
×
1010
        }
×
1011
    }
109 ✔
1012
    else {
1 ✔
1013
        error_handler("QRef or USMRef passed to memset_async were NULL.",
1 ✔
1014
                      __FILE__, __func__, __LINE__);
1 ✔
1015
        return nullptr;
1 ✔
1016
    }
1 ✔
1017

1018
    return wrap<event>(new event(std::move(ev)));
109 ✔
1019
}
110 ✔
1020

1021
__dpctl_give DPCTLSyclEventRef
1022
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
1023
                 void *USMRef,
1024
                 uint8_t Value,
1025
                 size_t Count)
1026
{
30 ✔
1027
    auto Q = unwrap<queue>(QRef);
30 ✔
1028
    if (Q && USMRef) {
30 !
1029
        sycl::event ev;
29 ✔
1030
        try {
29 ✔
1031
            ev = Q->fill<uint8_t>(USMRef, Value, Count);
29 ✔
1032
        } catch (std::exception const &e) {
29 ✔
1033
            error_handler(e, __FILE__, __func__, __LINE__);
×
1034
            return nullptr;
×
1035
        }
×
1036
        return wrap<event>(new event(std::move(ev)));
29 ✔
1037
    }
29 ✔
1038
    else {
1 ✔
1039
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1 ✔
1040
                      __func__, __LINE__);
1 ✔
1041
        return nullptr;
1 ✔
1042
    }
1 ✔
1043
}
30 ✔
1044

1045
__dpctl_give DPCTLSyclEventRef
1046
DPCTLQueue_Fill8WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1047
                           void *USMRef,
1048
                           uint8_t Value,
1049
                           size_t Count,
1050
                           const DPCTLSyclEventRef *DepEvents,
1051
                           size_t DepEventsCount)
1052
{
10 ✔
1053
    auto Q = unwrap<queue>(QRef);
10 ✔
1054
    if (Q && USMRef) {
10 !
1055
        sycl::event ev;
9 ✔
1056
        try {
9 ✔
1057
            std::vector<event> dep_events;
9 ✔
1058
            if (DepEvents) {
9 !
1059
                dep_events.reserve(DepEventsCount);
9 ✔
1060
                for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
1061
                    event *ei = unwrap<event>(DepEvents[i]);
9 ✔
1062
                    if (ei)
9 !
1063
                        dep_events.push_back(*ei);
9 ✔
1064
                }
9 ✔
1065
            }
9 ✔
1066
            ev = Q->fill<uint8_t>(USMRef, Value, Count, dep_events);
9 ✔
1067
        } catch (std::exception const &e) {
9 ✔
1068
            error_handler(e, __FILE__, __func__, __LINE__);
×
1069
            return nullptr;
×
1070
        }
×
1071
        return wrap<event>(new event(std::move(ev)));
9 ✔
1072
    }
9 ✔
1073
    else {
1 ✔
1074
        error_handler("QRef or USMRef passed to fill8_async were NULL.",
1 ✔
1075
                      __FILE__, __func__, __LINE__);
1 ✔
1076
        return nullptr;
1 ✔
1077
    }
1 ✔
1078
}
10 ✔
1079

1080
__dpctl_give DPCTLSyclEventRef
1081
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
1082
                  void *USMRef,
1083
                  uint16_t Value,
1084
                  size_t Count)
1085
{
27 ✔
1086
    auto Q = unwrap<queue>(QRef);
27 ✔
1087
    if (Q && USMRef) {
27 !
1088
        sycl::event ev;
26 ✔
1089
        try {
26 ✔
1090
            ev = Q->fill<uint16_t>(USMRef, Value, Count);
26 ✔
1091
        } catch (std::exception const &e) {
26 ✔
1092
            error_handler(e, __FILE__, __func__, __LINE__);
×
1093
            return nullptr;
×
1094
        }
×
1095
        return wrap<event>(new event(std::move(ev)));
26 ✔
1096
    }
26 ✔
1097
    else {
1 ✔
1098
        error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__,
1 ✔
1099
                      __func__, __LINE__);
1 ✔
1100
        return nullptr;
1 ✔
1101
    }
1 ✔
1102
}
27 ✔
1103

1104
__dpctl_give DPCTLSyclEventRef
1105
DPCTLQueue_Fill16WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1106
                            void *USMRef,
1107
                            uint16_t Value,
1108
                            size_t Count,
1109
                            const DPCTLSyclEventRef *DepEvents,
1110
                            size_t DepEventsCount)
1111
{
9 ✔
1112
    auto Q = unwrap<queue>(QRef);
9 ✔
1113
    if (Q && USMRef) {
9 !
1114
        sycl::event ev;
8 ✔
1115
        try {
8 ✔
1116
            std::vector<event> dep_events;
8 ✔
1117
            if (DepEvents) {
8 !
1118
                dep_events.reserve(DepEventsCount);
8 ✔
1119
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1120
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1121
                    if (ei)
8 !
1122
                        dep_events.push_back(*ei);
8 ✔
1123
                }
8 ✔
1124
            }
8 ✔
1125
            ev = Q->fill<uint16_t>(USMRef, Value, Count, dep_events);
8 ✔
1126
        } catch (std::exception const &e) {
8 ✔
1127
            error_handler(e, __FILE__, __func__, __LINE__);
×
1128
            return nullptr;
×
1129
        }
×
1130
        return wrap<event>(new event(std::move(ev)));
8 ✔
1131
    }
8 ✔
1132
    else {
1 ✔
1133
        error_handler("QRef or USMRef passed to fill16_async were NULL.",
1 ✔
1134
                      __FILE__, __func__, __LINE__);
1 ✔
1135
        return nullptr;
1 ✔
1136
    }
1 ✔
1137
}
9 ✔
1138

1139
__dpctl_give DPCTLSyclEventRef
1140
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
1141
                  void *USMRef,
1142
                  uint32_t Value,
1143
                  size_t Count)
1144
{
32 ✔
1145
    auto Q = unwrap<queue>(QRef);
32 ✔
1146
    if (Q && USMRef) {
32 !
1147
        sycl::event ev;
31 ✔
1148
        try {
31 ✔
1149
            ev = Q->fill<uint32_t>(USMRef, Value, Count);
31 ✔
1150
        } catch (std::exception const &e) {
31 ✔
1151
            error_handler(e, __FILE__, __func__, __LINE__);
×
1152
            return nullptr;
×
1153
        }
×
1154
        return wrap<event>(new event(std::move(ev)));
31 ✔
1155
    }
31 ✔
1156
    else {
1 ✔
1157
        error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__,
1 ✔
1158
                      __func__, __LINE__);
1 ✔
1159
        return nullptr;
1 ✔
1160
    }
1 ✔
1161
}
32 ✔
1162

1163
__dpctl_give DPCTLSyclEventRef
1164
DPCTLQueue_Fill32WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1165
                            void *USMRef,
1166
                            uint32_t Value,
1167
                            size_t Count,
1168
                            const DPCTLSyclEventRef *DepEvents,
1169
                            size_t DepEventsCount)
1170
{
9 ✔
1171
    auto Q = unwrap<queue>(QRef);
9 ✔
1172
    if (Q && USMRef) {
9 !
1173
        sycl::event ev;
8 ✔
1174
        try {
8 ✔
1175
            std::vector<event> dep_events;
8 ✔
1176
            if (DepEvents) {
8 !
1177
                dep_events.reserve(DepEventsCount);
8 ✔
1178
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1179
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1180
                    if (ei)
8 !
1181
                        dep_events.push_back(*ei);
8 ✔
1182
                }
8 ✔
1183
            }
8 ✔
1184
            ev = Q->fill<uint32_t>(USMRef, Value, Count, dep_events);
8 ✔
1185
        } catch (std::exception const &e) {
8 ✔
1186
            error_handler(e, __FILE__, __func__, __LINE__);
×
1187
            return nullptr;
×
1188
        }
×
1189
        return wrap<event>(new event(std::move(ev)));
8 ✔
1190
    }
8 ✔
1191
    else {
1 ✔
1192
        error_handler("QRef or USMRef passed to fill32_async were NULL.",
1 ✔
1193
                      __FILE__, __func__, __LINE__);
1 ✔
1194
        return nullptr;
1 ✔
1195
    }
1 ✔
1196
}
9 ✔
1197

1198
__dpctl_give DPCTLSyclEventRef
1199
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
1200
                  void *USMRef,
1201
                  uint64_t Value,
1202
                  size_t Count)
1203
{
34 ✔
1204
    auto Q = unwrap<queue>(QRef);
34 ✔
1205
    if (Q && USMRef) {
34 !
1206
        sycl::event ev;
33 ✔
1207
        try {
33 ✔
1208
            ev = Q->fill<uint64_t>(USMRef, Value, Count);
33 ✔
1209
        } catch (std::exception const &e) {
33 ✔
1210
            error_handler(e, __FILE__, __func__, __LINE__);
×
1211
            return nullptr;
×
1212
        }
×
1213
        return wrap<event>(new event(std::move(ev)));
33 ✔
1214
    }
33 ✔
1215
    else {
1 ✔
1216
        error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__,
1 ✔
1217
                      __func__, __LINE__);
1 ✔
1218
        return nullptr;
1 ✔
1219
    }
1 ✔
1220
}
34 ✔
1221

1222
__dpctl_give DPCTLSyclEventRef
1223
DPCTLQueue_Fill64WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1224
                            void *USMRef,
1225
                            uint64_t Value,
1226
                            size_t Count,
1227
                            const DPCTLSyclEventRef *DepEvents,
1228
                            size_t DepEventsCount)
1229
{
9 ✔
1230
    auto Q = unwrap<queue>(QRef);
9 ✔
1231
    if (Q && USMRef) {
9 !
1232
        sycl::event ev;
8 ✔
1233
        try {
8 ✔
1234
            std::vector<event> dep_events;
8 ✔
1235
            if (DepEvents) {
8 !
1236
                dep_events.reserve(DepEventsCount);
8 ✔
1237
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1238
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1239
                    if (ei)
8 !
1240
                        dep_events.push_back(*ei);
8 ✔
1241
                }
8 ✔
1242
            }
8 ✔
1243
            ev = Q->fill<uint64_t>(USMRef, Value, Count, dep_events);
8 ✔
1244
        } catch (std::exception const &e) {
8 ✔
1245
            error_handler(e, __FILE__, __func__, __LINE__);
×
1246
            return nullptr;
×
1247
        }
×
1248
        return wrap<event>(new event(std::move(ev)));
8 ✔
1249
    }
8 ✔
1250
    else {
1 ✔
1251
        error_handler("QRef or USMRef passed to fill64_async were NULL.",
1 ✔
1252
                      __FILE__, __func__, __LINE__);
1 ✔
1253
        return nullptr;
1 ✔
1254
    }
1 ✔
1255
}
9 ✔
1256

1257
__dpctl_give DPCTLSyclEventRef
1258
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
1259
                   void *USMRef,
1260
                   uint64_t *Value,
1261
                   size_t Count)
1262
{
30 ✔
1263
    auto Q = unwrap<queue>(QRef);
30 ✔
1264
    if (Q && USMRef && Value) {
30 !
1265
        sycl::event ev;
21 ✔
1266
        try {
21 ✔
1267
            complexNumber Val;
21 ✔
1268
            Val.real = Value[0];
21 ✔
1269
            Val.imag = Value[1];
21 ✔
1270
            ev = Q->fill(USMRef, Val, Count);
21 ✔
1271
        } catch (std::exception const &e) {
21 ✔
1272
            error_handler(e, __FILE__, __func__, __LINE__);
×
1273
            return nullptr;
×
1274
        }
×
1275
        return wrap<event>(new event(std::move(ev)));
21 ✔
1276
    }
21 ✔
1277
    else {
9 ✔
1278
        error_handler("QRef, USMRef, or Value passed to fill128 were NULL.",
9 ✔
1279
                      __FILE__, __func__, __LINE__);
9 ✔
1280
        return nullptr;
9 ✔
1281
    }
9 ✔
1282
}
30 ✔
1283

1284
__dpctl_give DPCTLSyclEventRef
1285
DPCTLQueue_Fill128WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
1286
                             void *USMRef,
1287
                             uint64_t *Value,
1288
                             size_t Count,
1289
                             const DPCTLSyclEventRef *DepEvents,
1290
                             size_t DepEventsCount)
1291
{
17 ✔
1292
    auto Q = unwrap<queue>(QRef);
17 ✔
1293
    if (Q && USMRef && Value) {
17 !
1294
        sycl::event ev;
8 ✔
1295
        try {
8 ✔
1296
            std::vector<event> dep_events;
8 ✔
1297
            if (DepEvents) {
8 !
1298
                dep_events.reserve(DepEventsCount);
8 ✔
1299
                for (size_t i = 0; i < DepEventsCount; ++i) {
16 ✔
1300
                    event *ei = unwrap<event>(DepEvents[i]);
8 ✔
1301
                    if (ei)
8 !
1302
                        dep_events.push_back(*ei);
8 ✔
1303
                }
8 ✔
1304
            }
8 ✔
1305
            complexNumber Val;
8 ✔
1306
            Val.real = Value[0];
8 ✔
1307
            Val.imag = Value[1];
8 ✔
1308
            ev = Q->fill(USMRef, Val, Count, dep_events);
8 ✔
1309
        } catch (std::exception const &e) {
8 ✔
1310
            error_handler(e, __FILE__, __func__, __LINE__);
×
1311
            return nullptr;
×
1312
        }
×
1313
        return wrap<event>(new event(std::move(ev)));
8 ✔
1314
    }
8 ✔
1315
    else {
9 ✔
1316
        error_handler(
9 ✔
1317
            "QRef, USMRef, or Value passed to fill128_async were NULL.",
9 ✔
1318
            __FILE__, __func__, __LINE__);
9 ✔
1319
        return nullptr;
9 ✔
1320
    }
9 ✔
1321
}
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