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

IntelPython / dpctl / 36873499906

01 Oct 2026 02:04PM UTC coverage: 74.989% (+0.03%) from 74.959%
36873499906

Pull #2382

github

web-flow
Merge d96c08787 into 283d709d6
Pull Request #2382: Fix bugs in kernel submission and creation

1056 of 1484 branches covered (71.16%)

Branch coverage included in aggregate %.

20 of 20 new or added lines in 1 file covered. (100.0%)

6 existing lines in 1 file now uncovered.

4056 of 5333 relevant lines covered (76.05%)

280.32 hits per line

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

86.58
/libsyclinterface/source/dpctl_sycl_queue_interface.cpp
1
//===----- dpctl_sycl_queue_interface.cpp - Implements C API for sycl::queue =//
2
//
3
//                      Data Parallel Control (dpctl)
4
//
5
// Copyright 2020 Intel Corporation
6
//
7
// Licensed under the Apache License, Version 2.0 (the "License");
8
// you may not use this file except in compliance with the License.
9
// You may obtain a copy of the License at
10
//
11
//    http://www.apache.org/licenses/LICENSE-2.0
12
//
13
// Unless required by applicable law or agreed to in writing, software
14
// distributed under the License is distributed on an "AS IS" BASIS,
15
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
// See the License for the specific language governing permissions and
17
// limitations under the License.
18
//
19
//===----------------------------------------------------------------------===//
20
///
21
/// \file
22
/// This file implements the data types and functions declared in
23
/// dpctl_sycl_queue_interface.h.
24
///
25
//===----------------------------------------------------------------------===//
26

27
#include "dpctl_sycl_queue_interface.h"
28
#include "Config/dpctl_config.h"
29
#include "dpctl_error_handlers.h"
30
#include "dpctl_sycl_context_interface.h"
31
#include "dpctl_sycl_device_interface.h"
32
#include "dpctl_sycl_device_manager.h"
33
#include "dpctl_sycl_type_casters.hpp"
34

35
#include <stddef.h>
36
#include <stdint.h>
37

38
#include <cstdint>
39
#include <exception>
40
#include <sstream>
41
#include <stdexcept>
42
#include <sycl/sycl.hpp> /* SYCL headers   */
43
#include <utility>
44
#include <vector>
45

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

51
using namespace sycl;
52

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

123
namespace
124
{
125
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
126
              "The compiler does not meet minimum version requirement");
127

128
using namespace dpctl::syclinterface;
129

130
typedef struct complex
131
{
132
    std::uint64_t real;
133
    std::uint64_t imag;
134
} complexNumber;
135

136
void set_dependent_events(handler &cgh,
137
                          __dpctl_keep const DPCTLSyclEventRef *DepEvents,
138
                          size_t NDepEvents)
139
{
176 ✔
140
    for (auto i = 0ul; i < NDepEvents; ++i) {
332 ✔
141
        auto ei = unwrap<event>(DepEvents[i]);
156 ✔
142
        if (ei)
156 !
143
            cgh.depends_on(*ei);
156 ✔
144
    }
156 ✔
145
}
176 ✔
146

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

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

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

272
std::unique_ptr<property_list> create_property_list(int properties)
273
{
1,832 ✔
274
    std::unique_ptr<property_list> propList;
1,832 ✔
275
    int _prop = properties;
1,832 ✔
276
    if (_prop & DPCTL_ENABLE_PROFILING) {
1,832 ✔
277
        _prop = _prop ^ DPCTL_ENABLE_PROFILING;
86 ✔
278
        if (_prop & DPCTL_IN_ORDER) {
86 ✔
279
            _prop = _prop ^ DPCTL_IN_ORDER;
36 ✔
280
            propList = std::make_unique<property_list>(
36 ✔
281
                sycl::property::queue::enable_profiling(),
36 ✔
282
                sycl::property::queue::in_order());
36 ✔
283
        }
36 ✔
284
        else {
50 ✔
285
            propList = std::make_unique<property_list>(
50 ✔
286
                sycl::property::queue::enable_profiling());
50 ✔
287
        }
50 ✔
288
    }
86 ✔
289
    else if (_prop & DPCTL_IN_ORDER) {
1,746 ✔
290
        _prop = _prop ^ DPCTL_IN_ORDER;
551 ✔
291
        propList =
551 ✔
292
            std::make_unique<property_list>(sycl::property::queue::in_order());
551 ✔
293
    }
551 ✔
294
    else {
1,195 ✔
295
        propList = std::make_unique<property_list>();
1,195 ✔
296
    }
1,195 ✔
297

298
    if (_prop) {
1,832 ✔
299
        std::stringstream ss;
1 ✔
300
        ss << "Invalid queue property argument (" << std::hex << properties
1 ✔
301
           << "), interpreted as (" << (properties ^ _prop) << ").";
1 ✔
302
        error_handler(ss.str(), __FILE__, __func__, __LINE__);
1 ✔
303
    }
1 ✔
304
    return propList;
1,832 ✔
305
}
1,832 ✔
306

307
__dpctl_give DPCTLSyclQueueRef
308
getQueueImpl(__dpctl_keep DPCTLSyclContextRef cRef,
309
             __dpctl_keep DPCTLSyclDeviceRef dRef,
310
             error_handler_callback *handler,
311
             int properties)
312
{
209 ✔
313
    DPCTLSyclQueueRef qRef = nullptr;
209 ✔
314
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
209 ✔
315
    return qRef;
209 ✔
316
}
209 ✔
317

318
} /* end of anonymous namespace */
319

320
DPCTL_API
321
__dpctl_give DPCTLSyclQueueRef
322
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
323
                  __dpctl_keep const DPCTLSyclDeviceRef DRef,
324
                  error_handler_callback *handler,
325
                  int properties)
326
{
1,834 ✔
327
    DPCTLSyclQueueRef q = nullptr;
1,834 ✔
328
    auto dev = unwrap<device>(DRef);
1,834 ✔
329
    auto ctx = unwrap<context>(CRef);
1,834 ✔
330

331
    if (!(dev && ctx)) {
1,834 ✔
332
        error_handler("Cannot create queue from DPCTLSyclContextRef and "
2 ✔
333
                      "DPCTLSyclDeviceRef as input is a nullptr.",
2 ✔
334
                      __FILE__, __func__, __LINE__);
2 ✔
335
        return q;
2 ✔
336
    }
2 ✔
337
    auto propList = create_property_list(properties);
1,832 ✔
338

339
    if (handler) {
1,832 ✔
340
        try {
68 ✔
341
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
68 ✔
342
                                   *propList);
68 ✔
343
            q = wrap<queue>(Queue);
68 ✔
344
        } catch (std::exception const &e) {
68 ✔
345
            error_handler(e, __FILE__, __func__, __LINE__);
×
346
        }
×
347
    }
68 ✔
348
    else {
1,764 ✔
349
        try {
1,764 ✔
350
            auto Queue = new queue(*ctx, *dev, *propList);
1,764 ✔
351
            q = wrap<queue>(Queue);
1,764 ✔
352
        } catch (std::exception const &e) {
1,764 ✔
353
            error_handler(e, __FILE__, __func__, __LINE__);
1 ✔
354
        }
1 ✔
355
    }
1,764 ✔
356

357
    return q;
1,832 ✔
358
}
1,832 ✔
359

360
__dpctl_give DPCTLSyclQueueRef
361
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
362
                           error_handler_callback *handler,
363
                           int properties)
364
{
491 ✔
365
    DPCTLSyclContextRef CRef = nullptr;
491 ✔
366
    DPCTLSyclQueueRef QRef = nullptr;
491 ✔
367
    auto Device = unwrap<device>(DRef);
491 ✔
368

369
    if (!Device) {
491 ✔
370
        error_handler("Cannot create queue from NULL device reference.",
282 ✔
371
                      __FILE__, __func__, __LINE__);
282 ✔
372
        return QRef;
282 ✔
373
    }
282 ✔
374
    // Check if a cached default context exists for the device.
375
    CRef = DPCTLDeviceMgr_GetCachedContext(DRef);
209 ✔
376
    // If a cached default context was found, that context will be used to use
377
    // create the new queue. When a default cached context was not found, as
378
    // will be the case for non-root devices, i.e., sub-devices, a new context
379
    // will be allocated. Note that any newly allocated context is not cached.
380
    if (!CRef) {
209 !
381
        context *ContextPtr = nullptr;
×
382
        try {
×
383
            ContextPtr = new context(*Device);
×
384
            CRef = wrap<context>(ContextPtr);
×
385
        } catch (std::exception const &e) {
×
386
            error_handler(e, __FILE__, __func__, __LINE__);
×
387
            delete ContextPtr;
×
388
            return QRef;
×
389
        }
×
390
    }
×
391
    // At this point we have a valid context and the queue can be allocated.
392
    QRef = getQueueImpl(CRef, DRef, handler, properties);
209 ✔
393
    // Free the context
394
    DPCTLContext_Delete(CRef);
209 ✔
395
    return QRef;
209 ✔
396
}
209 ✔
397

398
/*!
399
 * Delete the passed in pointer after verifying it points to a sycl::queue.
400
 */
401
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef)
402
{
2,224 ✔
403
    delete unwrap<queue>(QRef);
2,224 ✔
404
}
2,224 ✔
405

406
/*!
407
 * Make copy of sycl::queue referenced by passed pointer
408
 */
409
__dpctl_give DPCTLSyclQueueRef
410
DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef)
411
{
116 ✔
412
    auto Queue = unwrap<queue>(QRef);
116 ✔
413
    if (Queue) {
116 ✔
414
        try {
115 ✔
415
            auto CopiedQueue = new queue(*Queue);
115 ✔
416
            return wrap<queue>(CopiedQueue);
115 ✔
417
        } catch (std::exception const &e) {
115 ✔
418
            error_handler(e, __FILE__, __func__, __LINE__);
×
419
            return nullptr;
×
420
        }
×
421
    }
115 ✔
422
    else {
1 ✔
423
        error_handler("Cannot copy DPCTLSyclQueueRef as input is a nullptr",
1 ✔
424
                      __FILE__, __func__, __LINE__);
1 ✔
425
        return nullptr;
1 ✔
426
    }
1 ✔
427
}
116 ✔
428

429
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
430
                      __dpctl_keep const DPCTLSyclQueueRef QRef2)
431
{
13 ✔
432
    if (!(QRef1 && QRef2)) {
13 ✔
433
        error_handler("DPCTLSyclQueueRefs are nullptr.", __FILE__, __func__,
2 ✔
434
                      __LINE__);
2 ✔
435
        return false;
2 ✔
436
    }
2 ✔
437
    return (*unwrap<queue>(QRef1) == *unwrap<queue>(QRef2));
11 ✔
438
}
13 ✔
439

440
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
441
{
10 ✔
442
    auto Q = unwrap<queue>(QRef);
10 ✔
443
    if (Q) {
10 ✔
444
        try {
9 ✔
445
            auto C = Q->get_context();
9 ✔
446
            return DPCTLContext_GetBackend(wrap<context>(&C));
9 ✔
447
        } catch (std::exception const &e) {
9 ✔
448
            error_handler(e, __FILE__, __func__, __LINE__);
×
449
            return DPCTL_UNKNOWN_BACKEND;
×
450
        }
×
451
    }
9 ✔
452
    else
1 ✔
453
        return DPCTL_UNKNOWN_BACKEND;
1 ✔
454
}
10 ✔
455

456
__dpctl_give DPCTLSyclDeviceRef
457
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef)
458
{
74 ✔
459
    DPCTLSyclDeviceRef DRef = nullptr;
74 ✔
460
    auto Q = unwrap<queue>(QRef);
74 ✔
461
    if (Q) {
74 ✔
462
        try {
73 ✔
463
            auto Device = new device(Q->get_device());
73 ✔
464
            DRef = wrap<device>(Device);
73 ✔
465
        } catch (std::exception const &e) {
73 ✔
466
            error_handler(e, __FILE__, __func__, __LINE__);
×
467
        }
×
468
    }
73 ✔
469
    else {
1 ✔
470
        error_handler("Could not get the device for this queue.", __FILE__,
1 ✔
471
                      __func__, __LINE__);
1 ✔
472
    }
1 ✔
473
    return DRef;
74 ✔
474
}
74 ✔
475

476
__dpctl_give DPCTLSyclContextRef
477
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
478
{
142 ✔
479
    auto Q = unwrap<queue>(QRef);
142 ✔
480
    DPCTLSyclContextRef CRef = nullptr;
142 ✔
481
    if (Q)
142 ✔
482
        CRef = wrap<context>(new context(Q->get_context()));
132 ✔
483
    else {
10 ✔
484
        error_handler("Could not get the context for this queue.", __FILE__,
10 ✔
485
                      __func__, __LINE__);
10 ✔
486
    }
10 ✔
487
    return CRef;
142 ✔
488
}
142 ✔
489

490
__dpctl_give DPCTLSyclEventRef
491
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
492
                       __dpctl_keep const DPCTLSyclQueueRef QRef,
493
                       __dpctl_keep void **Args,
494
                       __dpctl_keep const DPCTLKernelArgType *ArgTypes,
495
                       size_t NArgs,
496
                       __dpctl_keep const size_t Range[3],
497
                       size_t NDims,
498
                       __dpctl_keep const DPCTLSyclEventRef *DepEvents,
499
                       size_t NDepEvents)
500
{
65 ✔
501
    if (!KRef) {
65 ✔
502
        error_handler("Cannot submit the kernel as the kernel is a nullptr.",
2 ✔
503
                      __FILE__, __func__, __LINE__, error_level::error);
2 ✔
504
        return nullptr;
2 ✔
505
    }
2 ✔
506
    if (!QRef) {
63 ✔
507
        error_handler("Cannot submit the kernel as the queue is a nullptr.",
1 ✔
508
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
509
        return nullptr;
1 ✔
510
    }
1 ✔
511

512
    auto Kernel = unwrap<kernel>(KRef);
62 ✔
513
    auto Queue = unwrap<queue>(QRef);
62 ✔
514
    event e;
62 ✔
515

516
    try {
62 ✔
517
        switch (NDims) {
62 ✔
518
        case 1:
28 ✔
519
        {
28 ✔
520
            e = Queue->submit([&](handler &cgh) {
28 ✔
521
                // Depend on any event that was specified by the caller.
522
                set_dependent_events(cgh, DepEvents, NDepEvents);
28 ✔
523
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
28 ✔
524
                cgh.parallel_for(range<1>{Range[0]}, *Kernel);
28 ✔
525
            });
28 ✔
526
            return wrap<event>(new event(std::move(e)));
28 ✔
527
        }
×
528
        case 2:
17 ✔
529
        {
17 ✔
530
            e = Queue->submit([&](handler &cgh) {
17 ✔
531
                // Depend on any event that was specified by the caller.
532
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
533
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
534
                cgh.parallel_for(range<2>{Range[0], Range[1]}, *Kernel);
17 ✔
535
            });
17 ✔
536
            return wrap<event>(new event(std::move(e)));
17 ✔
537
        }
×
538
        case 3:
17 ✔
539
        {
17 ✔
540
            e = Queue->submit([&](handler &cgh) {
17 ✔
541
                // Depend on any event that was specified by the caller.
542
                set_dependent_events(cgh, DepEvents, NDepEvents);
17 ✔
543
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
17 ✔
544
                cgh.parallel_for(range<3>{Range[0], Range[1], Range[2]},
17 ✔
545
                                 *Kernel);
17 ✔
546
            });
17 ✔
547
            return wrap<event>(new event(std::move(e)));
17 ✔
548
        }
×
549
        default:
×
550
            error_handler("Range cannot be greater than three "
×
551
                          "dimensions.",
×
552
                          __FILE__, __func__, __LINE__, error_level::error);
×
553
            return nullptr;
×
554
        }
62 ✔
555
    } catch (std::exception const &e) {
62 ✔
UNCOV
556
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
×
UNCOV
557
        return nullptr;
×
UNCOV
558
    } catch (...) {
×
559
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
560
                      __LINE__, error_level::error);
×
561
        return nullptr;
×
562
    }
×
563
}
62 ✔
564

565
__dpctl_give DPCTLSyclEventRef
566
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
567
                         __dpctl_keep const DPCTLSyclQueueRef QRef,
568
                         __dpctl_keep void **Args,
569
                         __dpctl_keep const DPCTLKernelArgType *ArgTypes,
570
                         size_t NArgs,
571
                         __dpctl_keep const size_t gRange[3],
572
                         __dpctl_keep const size_t lRange[3],
573
                         size_t NDims,
574
                         __dpctl_keep const DPCTLSyclEventRef *DepEvents,
575
                         size_t NDepEvents)
576
{
116 ✔
577
    if (!KRef) {
116 ✔
578
        error_handler("Cannot submit the kernel as the kernel is a nullptr.",
1 ✔
579
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
580
        return nullptr;
1 ✔
581
    }
1 ✔
582
    if (!QRef) {
115 ✔
583
        error_handler("Cannot submit the kernel as the queue is a nullptr.",
1 ✔
584
                      __FILE__, __func__, __LINE__, error_level::error);
1 ✔
585
        return nullptr;
1 ✔
586
    }
1 ✔
587

588
    auto Kernel = unwrap<kernel>(KRef);
114 ✔
589
    auto Queue = unwrap<queue>(QRef);
114 ✔
590
    event e;
114 ✔
591

592
    try {
114 ✔
593
        switch (NDims) {
114 ✔
594
        case 1:
100 ✔
595
        {
100 ✔
596
            e = Queue->submit([&](handler &cgh) {
100 ✔
597
                // Depend on any event that was specified by the caller.
598
                set_dependent_events(cgh, DepEvents, NDepEvents);
100 ✔
599
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
100 ✔
600
                cgh.parallel_for(nd_range<1>{{gRange[0]}, {lRange[0]}},
100 ✔
601
                                 *Kernel);
100 ✔
602
            });
100 ✔
603
            return wrap<event>(new event(std::move(e)));
100 ✔
604
        }
×
605
        case 2:
7 ✔
606
        {
7 ✔
607
            e = Queue->submit([&](handler &cgh) {
7 ✔
608
                // Depend on any event that was specified by the caller.
609
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
610
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
611
                cgh.parallel_for(
7 ✔
612
                    nd_range<2>{{gRange[0], gRange[1]}, {lRange[0], lRange[1]}},
7 ✔
613
                    *Kernel);
7 ✔
614
            });
7 ✔
615
            return wrap<event>(new event(std::move(e)));
7 ✔
616
        }
×
617
        case 3:
7 ✔
618
        {
7 ✔
619
            e = Queue->submit([&](handler &cgh) {
7 ✔
620
                // Depend on any event that was specified by the caller.
621
                set_dependent_events(cgh, DepEvents, NDepEvents);
7 ✔
622
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7 ✔
623
                cgh.parallel_for(nd_range<3>{{gRange[0], gRange[1], gRange[2]},
7 ✔
624
                                             {lRange[0], lRange[1], lRange[2]}},
7 ✔
625
                                 *Kernel);
7 ✔
626
            });
7 ✔
627
            return wrap<event>(new event(std::move(e)));
7 ✔
628
        }
×
629
        default:
×
630
            error_handler("Range cannot be greater than three "
×
631
                          "dimensions.",
×
632
                          __FILE__, __func__, __LINE__, error_level::error);
×
633
            return nullptr;
×
634
        }
114 ✔
635
    } catch (std::exception const &e) {
114 ✔
636
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
1 ✔
637
        return nullptr;
1 ✔
638
    } catch (...) {
1 ✔
639
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
640
                      __LINE__, error_level::error);
×
641
        return nullptr;
×
642
    }
×
643
}
114 ✔
644

645
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
646
{
1 ✔
647
    // \todo what happens if the QRef is null or a pointer to a valid sycl
648
    // queue
649
    if (QRef) {
1 !
650
        auto SyclQueue = unwrap<queue>(QRef);
1 ✔
651
        if (SyclQueue)
1 !
652
            SyclQueue->wait();
1 ✔
653
    }
1 ✔
654
    else {
×
655
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
×
656
    }
×
657
}
1 ✔
658

659
__dpctl_give DPCTLSyclEventRef
660
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
661
                  void *Dest,
662
                  const void *Src,
663
                  size_t Count)
664
{
207 ✔
665
    auto Q = unwrap<queue>(QRef);
207 ✔
666
    if (Q) {
207 ✔
667
        sycl::event ev;
206 ✔
668
        try {
206 ✔
669
            ev = Q->memcpy(Dest, Src, Count);
206 ✔
670
        } catch (std::exception const &e) {
206 ✔
671
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
672
            return nullptr;
8 ✔
673
        }
8 ✔
674
        return wrap<event>(new event(std::move(ev)));
198 ✔
675
    }
206 ✔
676
    else {
1 ✔
677
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
678
                      __LINE__);
1 ✔
679
        return nullptr;
1 ✔
680
    }
1 ✔
681
}
207 ✔
682

683
__dpctl_give DPCTLSyclEventRef
684
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
685
                            void *Dest,
686
                            const void *Src,
687
                            size_t Count,
688
                            const DPCTLSyclEventRef *DepEvents,
689
                            size_t DepEventsCount)
690
{
128 ✔
691
    event ev;
128 ✔
692
    auto Q = unwrap<queue>(QRef);
128 ✔
693
    if (Q) {
128 ✔
694
        try {
127 ✔
695
            ev = Q->submit([&](handler &cgh) {
127 ✔
696
                if (DepEvents)
127 ✔
697
                    for (size_t i = 0; i < DepEventsCount; ++i) {
302 ✔
698
                        event *ei = unwrap<event>(DepEvents[i]);
183 ✔
699
                        if (ei)
183 !
700
                            cgh.depends_on(*ei);
183 ✔
701
                    }
183 ✔
702

703
                cgh.memcpy(Dest, Src, Count);
127 ✔
704
            });
127 ✔
705
        } catch (const std::exception &ex) {
127 ✔
706
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
707
            return nullptr;
8 ✔
708
        }
8 ✔
709
    }
127 ✔
710
    else {
1 ✔
711
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1 ✔
712
                      __LINE__);
1 ✔
713
        return nullptr;
1 ✔
714
    }
1 ✔
715

716
    return wrap<event>(new event(ev));
119 ✔
717
}
128 ✔
718

719
__dpctl_give DPCTLSyclEventRef
720
DPCTLQueue_CopyData(__dpctl_keep const DPCTLSyclQueueRef QRef,
721
                    void *Dest,
722
                    const void *Src,
723
                    size_t Count)
724
{
50 ✔
725
    auto Q = unwrap<queue>(QRef);
50 ✔
726
    if (Q) {
50 ✔
727
        sycl::event ev;
49 ✔
728
        try {
49 ✔
729
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
730
            ev = Q->copy(static_cast<const std::uint8_t *>(Src),
49 ✔
731
                         static_cast<std::uint8_t *>(Dest), Count);
49 ✔
732
        } catch (std::exception const &e) {
49 ✔
733
            error_handler(e, __FILE__, __func__, __LINE__);
8 ✔
734
            return nullptr;
8 ✔
735
        }
8 ✔
736
        return wrap<event>(new event(std::move(ev)));
41 ✔
737
    }
49 ✔
738
    else {
1 ✔
739
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
740
                      __LINE__);
1 ✔
741
        return nullptr;
1 ✔
742
    }
1 ✔
743
}
50 ✔
744

745
__dpctl_give DPCTLSyclEventRef
746
DPCTLQueue_CopyDataWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
747
                              void *Dest,
748
                              const void *Src,
749
                              size_t Count,
750
                              const DPCTLSyclEventRef *DepEvents,
751
                              size_t DepEventsCount)
752
{
10 ✔
753
    auto Q = unwrap<queue>(QRef);
10 ✔
754
    if (Q) {
10 ✔
755
        try {
9 ✔
756
            std::vector<event> dep_events;
9 ✔
757
            if (DepEvents) {
9 ✔
758
                dep_events.reserve(DepEventsCount);
1 ✔
759
                for (size_t i = 0; i < DepEventsCount; ++i) {
2 ✔
760
                    event *ei = unwrap<event>(DepEvents[i]);
1 ✔
761
                    if (ei)
1 !
762
                        dep_events.push_back(*ei);
1 ✔
763
                }
1 ✔
764
            }
1 ✔
765

766
            // Copy uint8_t elements (1 byte each), so Count is a byte count.
767
            auto ev =
9 ✔
768
                Q->copy(static_cast<const std::uint8_t *>(Src),
9 ✔
769
                        static_cast<std::uint8_t *>(Dest), Count, dep_events);
9 ✔
770
            return wrap<event>(new event(std::move(ev)));
9 ✔
771
        } catch (const std::exception &ex) {
9 ✔
772
            error_handler(ex, __FILE__, __func__, __LINE__);
8 ✔
773
            return nullptr;
8 ✔
774
        }
8 ✔
775
    }
9 ✔
776
    else {
1 ✔
777
        error_handler("QRef passed to copy was NULL.", __FILE__, __func__,
1 ✔
778
                      __LINE__);
1 ✔
779
        return nullptr;
1 ✔
780
    }
1 ✔
781
}
10 ✔
782

783
__dpctl_give DPCTLSyclEventRef
784
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
785
                    const void *Ptr,
786
                    size_t Count)
787
{
16 ✔
788
    auto Q = unwrap<queue>(QRef);
16 ✔
789
    if (Q) {
16 ✔
790
        if (Ptr) {
15 ✔
791
            sycl::event ev;
7 ✔
792
            try {
7 ✔
793
                ev = Q->prefetch(Ptr, Count);
7 ✔
794
            } catch (std::exception const &e) {
7 ✔
795
                error_handler(e, __FILE__, __func__, __LINE__);
×
796
                return nullptr;
×
797
            }
×
798
            return wrap<event>(new event(std::move(ev)));
7 ✔
799
        }
7 ✔
800
        else {
8 ✔
801
            error_handler("Attempt to prefetch USM-allocation at nullptr.",
8 ✔
802
                          __FILE__, __func__, __LINE__);
8 ✔
803
            return nullptr;
8 ✔
804
        }
8 ✔
805
    }
15 ✔
806
    else {
1 ✔
807
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
808
                      __LINE__);
1 ✔
809
        return nullptr;
1 ✔
810
    }
1 ✔
811
}
16 ✔
812

813
__dpctl_give DPCTLSyclEventRef
814
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
815
                     const void *Ptr,
816
                     size_t Count,
817
                     int Advice)
818
{
16 ✔
819
    auto Q = unwrap<queue>(QRef);
16 ✔
820
    if (Q) {
16 ✔
821
        sycl::event ev;
15 ✔
822
        try {
15 ✔
823
            ev = Q->mem_advise(Ptr, Count, Advice);
15 ✔
824
        } catch (std::exception const &e) {
15 ✔
825
            error_handler(e, __FILE__, __func__, __LINE__);
×
826
            return nullptr;
×
827
        }
×
828
        return wrap<event>(new event(std::move(ev)));
15 ✔
829
    }
15 ✔
830
    else {
1 ✔
831
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1 ✔
832
                      __LINE__);
1 ✔
833
        return nullptr;
1 ✔
834
    }
1 ✔
835
}
16 ✔
836

837
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
838
{
1,040 ✔
839
    auto Q = unwrap<queue>(QRef);
1,040 ✔
840
    if (Q) {
1,040 ✔
841
        return Q->is_in_order();
1,039 ✔
842
    }
1,039 ✔
843
    else
1 ✔
844
        return false;
1 ✔
845
}
1,040 ✔
846

847
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
848
{
67 ✔
849
    auto Q = unwrap<queue>(QRef);
67 ✔
850
    if (Q) {
67 ✔
851
        return Q->has_property<sycl::property::queue::enable_profiling>();
66 ✔
852
    }
66 ✔
853
    else
1 ✔
854
        return false;
1 ✔
855
}
67 ✔
856

857
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
858
{
24 ✔
859
    auto Q = unwrap<queue>(QRef);
24 ✔
860
    if (Q) {
24 ✔
861
        std::hash<queue> hash_fn;
21 ✔
862
        return hash_fn(*Q);
21 ✔
863
    }
21 ✔
864
    else {
3 ✔
865
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3 ✔
866
        return 0;
3 ✔
867
    }
3 ✔
868
}
24 ✔
869

870
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
871
    __dpctl_keep const DPCTLSyclQueueRef QRef,
872
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
873
    size_t NDepEvents)
874
{
107 ✔
875
    auto Q = unwrap<queue>(QRef);
107 ✔
876
    event e;
107 ✔
877
    if (Q) {
107 !
878
        try {
107 ✔
879
            e = Q->submit([&](handler &cgh) {
107 ✔
880
                // Depend on any event that was specified by the caller.
881
                if (NDepEvents)
107 ✔
882
                    for (auto i = 0ul; i < NDepEvents; ++i)
18 ✔
883
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
12 ✔
884

885
                cgh.ext_oneapi_barrier();
107 ✔
886
            });
107 ✔
887
        } catch (std::exception const &e) {
107 ✔
888
            error_handler(e, __FILE__, __func__, __LINE__);
×
889
            return nullptr;
×
890
        }
×
891

892
        return wrap<event>(new event(std::move(e)));
107 ✔
893
    }
107 ✔
894
    else {
×
895
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
896
        return nullptr;
×
897
    }
×
898
}
107 ✔
899

900
__dpctl_give DPCTLSyclEventRef
901
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
902
{
1 ✔
903
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1 ✔
904
}
1 ✔
905

906
__dpctl_give DPCTLSyclEventRef
907
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
908
                  void *USMRef,
909
                  uint8_t Value,
910
                  size_t Count)
911
{
92 ✔
912
    auto Q = unwrap<queue>(QRef);
92 ✔
913
    if (Q && USMRef) {
92 !
914
        sycl::event ev;
91 ✔
915
        try {
91 ✔
916
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
91 ✔
917
        } catch (std::exception const &e) {
91 ✔
918
            error_handler(e, __FILE__, __func__, __LINE__);
×
919
            return nullptr;
×
920
        }
×
921
        return wrap<event>(new event(std::move(ev)));
91 ✔
922
    }
91 ✔
923
    else {
1 ✔
924
        error_handler("QRef or USMRef passed to memset were NULL.", __FILE__,
1 ✔
925
                      __func__, __LINE__);
1 ✔
926
        return nullptr;
1 ✔
927
    }
1 ✔
928
}
92 ✔
929

930
__dpctl_give DPCTLSyclEventRef
931
DPCTLQueue_MemsetWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
932
                            void *USMRef,
933
                            uint8_t Value,
934
                            size_t Count,
935
                            const DPCTLSyclEventRef *DepEvents,
936
                            size_t DepEventsCount)
937
{
10 ✔
938
    event ev;
10 ✔
939
    auto Q = unwrap<queue>(QRef);
10 ✔
940
    if (Q && USMRef) {
10 !
941
        try {
9 ✔
942
            ev = Q->submit([&](handler &cgh) {
9 ✔
943
                if (DepEvents)
9 !
944
                    for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
945
                        event *ei = unwrap<event>(DepEvents[i]);
9 ✔
946
                        if (ei)
9 !
947
                            cgh.depends_on(*ei);
9 ✔
948
                    }
9 ✔
949

950
                cgh.memset(USMRef, static_cast<int>(Value), Count);
9 ✔
951
            });
9 ✔
952
        } catch (const std::exception &ex) {
9 ✔
953
            error_handler(ex, __FILE__, __func__, __LINE__);
×
954
            return nullptr;
×
955
        }
×
956
    }
9 ✔
957
    else {
1 ✔
958
        error_handler("QRef or USMRef passed to memset_async were NULL.",
1 ✔
959
                      __FILE__, __func__, __LINE__);
1 ✔
960
        return nullptr;
1 ✔
961
    }
1 ✔
962

963
    return wrap<event>(new event(std::move(ev)));
9 ✔
964
}
10 ✔
965

966
__dpctl_give DPCTLSyclEventRef
967
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
968
                 void *USMRef,
969
                 uint8_t Value,
970
                 size_t Count)
971
{
29 ✔
972
    auto Q = unwrap<queue>(QRef);
29 ✔
973
    if (Q && USMRef) {
29 !
974
        sycl::event ev;
28 ✔
975
        try {
28 ✔
976
            ev = Q->fill<uint8_t>(USMRef, Value, Count);
28 ✔
977
        } catch (std::exception const &e) {
28 ✔
978
            error_handler(e, __FILE__, __func__, __LINE__);
×
979
            return nullptr;
×
980
        }
×
981
        return wrap<event>(new event(std::move(ev)));
28 ✔
982
    }
28 ✔
983
    else {
1 ✔
984
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1 ✔
985
                      __func__, __LINE__);
1 ✔
986
        return nullptr;
1 ✔
987
    }
1 ✔
988
}
29 ✔
989

990
__dpctl_give DPCTLSyclEventRef
991
DPCTLQueue_Fill8WithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
992
                           void *USMRef,
993
                           uint8_t Value,
994
                           size_t Count,
995
                           const DPCTLSyclEventRef *DepEvents,
996
                           size_t DepEventsCount)
997
{
10 ✔
998
    auto Q = unwrap<queue>(QRef);
10 ✔
999
    if (Q && USMRef) {
10 !
1000
        sycl::event ev;
9 ✔
1001
        try {
9 ✔
1002
            std::vector<event> dep_events;
9 ✔
1003
            if (DepEvents) {
9 !
1004
                dep_events.reserve(DepEventsCount);
9 ✔
1005
                for (size_t i = 0; i < DepEventsCount; ++i) {
18 ✔
1006
                    event *ei = unwrap<event>(DepEvents[i]);
9 ✔
1007
                    if (ei)
9 !
1008
                        dep_events.push_back(*ei);
9 ✔
1009
                }
9 ✔
1010
            }
9 ✔
1011
            ev = Q->fill<uint8_t>(USMRef, Value, Count, dep_events);
9 ✔
1012
        } catch (std::exception const &e) {
9 ✔
1013
            error_handler(e, __FILE__, __func__, __LINE__);
×
1014
            return nullptr;
×
1015
        }
×
1016
        return wrap<event>(new event(std::move(ev)));
9 ✔
1017
    }
9 ✔
1018
    else {
1 ✔
1019
        error_handler("QRef or USMRef passed to fill8_async were NULL.",
1 ✔
1020
                      __FILE__, __func__, __LINE__);
1 ✔
1021
        return nullptr;
1 ✔
1022
    }
1 ✔
1023
}
10 ✔
1024

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

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

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

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

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

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

1202
__dpctl_give DPCTLSyclEventRef
1203
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
1204
                   void *USMRef,
1205
                   uint64_t *Value,
1206
                   size_t Count)
1207
{
29 ✔
1208
    auto Q = unwrap<queue>(QRef);
29 ✔
1209
    if (Q && USMRef && Value) {
29 !
1210
        sycl::event ev;
20 ✔
1211
        try {
20 ✔
1212
            complexNumber Val;
20 ✔
1213
            Val.real = Value[0];
20 ✔
1214
            Val.imag = Value[1];
20 ✔
1215
            ev = Q->fill(USMRef, Val, Count);
20 ✔
1216
        } catch (std::exception const &e) {
20 ✔
1217
            error_handler(e, __FILE__, __func__, __LINE__);
×
1218
            return nullptr;
×
1219
        }
×
1220
        return wrap<event>(new event(std::move(ev)));
20 ✔
1221
    }
20 ✔
1222
    else {
9 ✔
1223
        error_handler("QRef, USMRef, or Value passed to fill128 were NULL.",
9 ✔
1224
                      __FILE__, __func__, __LINE__);
9 ✔
1225
        return nullptr;
9 ✔
1226
    }
9 ✔
1227
}
29 ✔
1228

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