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

IntelPython / dpctl / 8177422685

06 Mar 2024 07:08PM UTC coverage: 87.717% (+0.3%) from 87.449%
8177422685

Pull #1581

github

web-flow
Merge 554541ffa into e69d26872
Pull Request #1581: Updated the DPCTLKernelArgType enum values to be aligned with C++11 types

3276 of 3753 branches covered (87.29%)

Branch coverage included in aggregate %.

106 of 132 new or added lines in 3 files covered. (80.3%)

1 existing line in 1 file now uncovered.

10350 of 11781 relevant lines covered (87.85%)

8145.08 hits per line

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

86.79
/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-2024 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
#include <exception>
35
#include <stdexcept>
36
#include <sycl/sycl.hpp> /* SYCL headers   */
37
#include <utility>
38

39
using namespace sycl;
40

41
namespace
42
{
43
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
44
              "The compiler does not meet minimum version requirement");
45

46
using namespace dpctl::syclinterface;
47

48
typedef struct complex
49
{
50
    uint64_t real;
51
    uint64_t imag;
52
} complexNumber;
53

54
void set_dependent_events(handler &cgh,
55
                          __dpctl_keep const DPCTLSyclEventRef *DepEvents,
56
                          size_t NDepEvents)
57
{
62✔
58
    for (auto i = 0ul; i < NDepEvents; ++i) {
87✔
59
        auto ei = unwrap<event>(DepEvents[i]);
25✔
60
        if (ei)
25!
61
            cgh.depends_on(*ei);
25✔
62
    }
25✔
63
}
62✔
64

65
/*!
66
 * @brief Set the kernel arg object
67
 *
68
 * @param    cgh            My Param doc
69
 * @param    Arg            My Param doc
70
 */
71
bool set_kernel_arg(handler &cgh,
72
                    size_t idx,
73
                    __dpctl_keep void *Arg,
74
                    DPCTLKernelArgType ArgTy)
75
{
225✔
76
    bool arg_set = true;
225✔
77

78
    switch (ArgTy) {
225✔
79
    case DPCTL_INT8_T:
1✔
80
        cgh.set_arg(idx, *(int8_t *)Arg);
1✔
81
        break;
1✔
82
    case DPCTL_UINT8_T:
1✔
83
        cgh.set_arg(idx, *(uint8_t *)Arg);
1✔
84
        break;
1✔
85
    case DPCTL_INT16_T:
7✔
86
        cgh.set_arg(idx, *(int16_t *)Arg);
7✔
87
        break;
7✔
88
    case DPCTL_UINT16_T:
1✔
89
        cgh.set_arg(idx, *(uint16_t *)Arg);
1✔
90
        break;
1✔
91
    case DPCTL_INT32_T:
7✔
92
        cgh.set_arg(idx, *(int32_t *)Arg);
7✔
93
        break;
7✔
94
    case DPCTL_UINT32_T:
9✔
95
        cgh.set_arg(idx, *(uint32_t *)Arg);
9✔
96
        break;
9✔
97
    case DPCTL_INT64_T:
7✔
98
        cgh.set_arg(idx, *(int64_t *)Arg);
7✔
99
        break;
7✔
100
    case DPCTL_UINT64_T:
7✔
101
        cgh.set_arg(idx, *(uint64_t *)Arg);
7✔
102
        break;
7✔
103
    case DPCTL_FLOAT32_T:
7✔
104
        cgh.set_arg(idx, *(float *)Arg);
7✔
105
        break;
7✔
106
    case DPCTL_FLOAT64_T:
7✔
107
        cgh.set_arg(idx, *(double *)Arg);
7✔
108
        break;
7✔
109
    case DPCTL_VOID_PTR:
170✔
110
        cgh.set_arg(idx, Arg);
170✔
111
        break;
170✔
112
    default:
1✔
113
        arg_set = false;
1✔
114
        error_handler("Kernel argument could not be created.", __FILE__,
1✔
115
                      __func__, __LINE__);
1✔
116
        break;
1✔
117
    }
225✔
118
    return arg_set;
225✔
119
}
225✔
120

121
void set_kernel_args(handler &cgh,
122
                     __dpctl_keep void **Args,
123
                     __dpctl_keep const DPCTLKernelArgType *ArgTypes,
124
                     size_t NArgs)
125
{
62✔
126
    for (auto i = 0ul; i < NArgs; ++i) {
286✔
127
        if (!set_kernel_arg(cgh, i, Args[i], ArgTypes[i])) {
225✔
128
            error_handler("Kernel argument could not be created.", __FILE__,
1✔
129
                          __func__, __LINE__);
1✔
130
            throw std::invalid_argument(
1✔
131
                "Kernel argument could not be created.");
1✔
132
        }
1✔
133
    }
225✔
134
}
62✔
135

136
std::unique_ptr<property_list> create_property_list(int properties)
137
{
38,734✔
138
    std::unique_ptr<property_list> propList;
38,734✔
139
    int _prop = properties;
38,734✔
140
    if (_prop & DPCTL_ENABLE_PROFILING) {
38,734✔
141
        _prop = _prop ^ DPCTL_ENABLE_PROFILING;
61✔
142
        if (_prop & DPCTL_IN_ORDER) {
61✔
143
            _prop = _prop ^ DPCTL_IN_ORDER;
24✔
144
            propList = std::make_unique<property_list>(
24✔
145
                sycl::property::queue::enable_profiling(),
24✔
146
                sycl::property::queue::in_order());
24✔
147
        }
24✔
148
        else {
37✔
149
            propList = std::make_unique<property_list>(
37✔
150
                sycl::property::queue::enable_profiling());
37✔
151
        }
37✔
152
    }
61✔
153
    else if (_prop & DPCTL_IN_ORDER) {
38,673✔
154
        _prop = _prop ^ DPCTL_IN_ORDER;
430✔
155
        propList =
430✔
156
            std::make_unique<property_list>(sycl::property::queue::in_order());
430✔
157
    }
430✔
158
    else {
38,243✔
159
        propList = std::make_unique<property_list>();
38,243✔
160
    }
38,243✔
161

162
    if (_prop) {
38,734✔
163
        std::stringstream ss;
1✔
164
        ss << "Invalid queue property argument (" << std::hex << properties
1✔
165
           << "), interpreted as (" << (properties ^ _prop) << ").";
1✔
166
        error_handler(ss.str(), __FILE__, __func__, __LINE__);
1✔
167
    }
1✔
168
    return propList;
38,734✔
169
}
38,734✔
170

171
__dpctl_give DPCTLSyclQueueRef
172
getQueueImpl(__dpctl_keep DPCTLSyclContextRef cRef,
173
             __dpctl_keep DPCTLSyclDeviceRef dRef,
174
             error_handler_callback *handler,
175
             int properties)
176
{
124✔
177
    DPCTLSyclQueueRef qRef = nullptr;
124✔
178
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
124✔
179
    return qRef;
124✔
180
}
124✔
181

182
} /* end of anonymous namespace */
183

184
DPCTL_API
185
__dpctl_give DPCTLSyclQueueRef
186
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
187
                  __dpctl_keep const DPCTLSyclDeviceRef DRef,
188
                  error_handler_callback *handler,
189
                  int properties)
190
{
38,734✔
191
    DPCTLSyclQueueRef q = nullptr;
38,734✔
192
    auto dev = unwrap<device>(DRef);
38,734✔
193
    auto ctx = unwrap<context>(CRef);
38,734✔
194

195
    if (!(dev && ctx)) {
38,734!
196
        error_handler("Cannot create queue from DPCTLSyclContextRef and "
×
197
                      "DPCTLSyclDeviceRef as input is a nullptr.",
×
198
                      __FILE__, __func__, __LINE__);
×
199
        return q;
×
200
    }
×
201
    auto propList = create_property_list(properties);
38,734✔
202

203
    if (handler) {
38,734✔
204
        try {
44✔
205
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
44✔
206
                                   *propList);
44✔
207
            q = wrap<queue>(Queue);
44✔
208
        } catch (std::exception const &e) {
44✔
209
            error_handler(e, __FILE__, __func__, __LINE__);
×
210
        }
×
211
    }
44✔
212
    else {
38,690✔
213
        try {
38,690✔
214
            auto Queue = new queue(*ctx, *dev, *propList);
38,690✔
215
            q = wrap<queue>(Queue);
38,690✔
216
        } catch (std::exception const &e) {
38,690✔
217
            error_handler(e, __FILE__, __func__, __LINE__);
2✔
218
        }
2✔
219
    }
38,690✔
220

221
    return q;
38,734✔
222
}
38,734✔
223

224
__dpctl_give DPCTLSyclQueueRef
225
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
226
                           error_handler_callback *handler,
227
                           int properties)
228
{
310✔
229
    DPCTLSyclContextRef CRef = nullptr;
310✔
230
    DPCTLSyclQueueRef QRef = nullptr;
310✔
231
    auto Device = unwrap<device>(DRef);
310✔
232

233
    if (!Device) {
310✔
234
        error_handler("Cannot create queue from NULL device reference.",
186✔
235
                      __FILE__, __func__, __LINE__);
186✔
236
        return QRef;
186✔
237
    }
186✔
238
    // Check if a cached default context exists for the device.
239
    CRef = DPCTLDeviceMgr_GetCachedContext(DRef);
124✔
240
    // If a cached default context was found, that context will be used to use
241
    // create the new queue. When a default cached context was not found, as
242
    // will be the case for non-root devices, i.e., sub-devices, a new context
243
    // will be allocated. Note that any newly allocated context is not cached.
244
    if (!CRef) {
124✔
245
        context *ContextPtr = nullptr;
1✔
246
        try {
1✔
247
            ContextPtr = new context(*Device);
1✔
248
            CRef = wrap<context>(ContextPtr);
1✔
249
        } catch (std::exception const &e) {
1✔
250
            error_handler(e, __FILE__, __func__, __LINE__);
×
251
            delete ContextPtr;
×
252
            return QRef;
×
253
        }
×
254
    }
1✔
255
    // At this point we have a valid context and the queue can be allocated.
256
    QRef = getQueueImpl(CRef, DRef, handler, properties);
124✔
257
    // Free the context
258
    DPCTLContext_Delete(CRef);
124✔
259
    return QRef;
124✔
260
}
124✔
261

262
/*!
263
 * Delete the passed in pointer after verifying it points to a sycl::queue.
264
 */
265
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef)
266
{
226,967✔
267
    delete unwrap<queue>(QRef);
226,967✔
268
}
226,967✔
269

270
/*!
271
 * Make copy of sycl::queue referenced by passed pointer
272
 */
273
__dpctl_give DPCTLSyclQueueRef
274
DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef)
275
{
540,888✔
276
    auto Queue = unwrap<queue>(QRef);
540,888✔
277
    if (Queue) {
540,888✔
278
        try {
540,887✔
279
            auto CopiedQueue = new queue(*Queue);
540,887✔
280
            return wrap<queue>(CopiedQueue);
540,887✔
281
        } catch (std::exception const &e) {
540,887✔
282
            error_handler(e, __FILE__, __func__, __LINE__);
×
283
            return nullptr;
×
284
        }
×
285
    }
540,887✔
286
    else {
1✔
287
        error_handler("Cannot copy DPCTLSyclQueueRef as input is a nullptr",
1✔
288
                      __FILE__, __func__, __LINE__);
1✔
289
        return nullptr;
1✔
290
    }
1✔
291
}
540,888✔
292

293
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
294
                      __dpctl_keep const DPCTLSyclQueueRef QRef2)
295
{
40,749✔
296
    if (!(QRef1 && QRef2)) {
40,749✔
297
        error_handler("DPCTLSyclQueueRefs are nullptr.", __FILE__, __func__,
2✔
298
                      __LINE__);
2✔
299
        return false;
2✔
300
    }
2✔
301
    return (*unwrap<queue>(QRef1) == *unwrap<queue>(QRef2));
40,747✔
302
}
40,749✔
303

304
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
305
{
11✔
306
    auto Q = unwrap<queue>(QRef);
11✔
307
    if (Q) {
11✔
308
        try {
10✔
309
            auto C = Q->get_context();
10✔
310
            return DPCTLContext_GetBackend(wrap<context>(&C));
10✔
311
        } catch (std::exception const &e) {
10✔
312
            error_handler(e, __FILE__, __func__, __LINE__);
×
313
            return DPCTL_UNKNOWN_BACKEND;
×
314
        }
×
315
    }
10✔
316
    else
1✔
317
        return DPCTL_UNKNOWN_BACKEND;
1✔
318
}
11✔
319

320
__dpctl_give DPCTLSyclDeviceRef
321
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef)
322
{
94,042✔
323
    DPCTLSyclDeviceRef DRef = nullptr;
94,042✔
324
    auto Q = unwrap<queue>(QRef);
94,042✔
325
    if (Q) {
94,042✔
326
        try {
94,041✔
327
            auto Device = new device(Q->get_device());
94,041✔
328
            DRef = wrap<device>(Device);
94,041✔
329
        } catch (std::exception const &e) {
94,041✔
330
            error_handler(e, __FILE__, __func__, __LINE__);
×
331
        }
×
332
    }
94,041✔
333
    else {
1✔
334
        error_handler("Could not get the device for this queue.", __FILE__,
1✔
335
                      __func__, __LINE__);
1✔
336
    }
1✔
337
    return DRef;
94,042✔
338
}
94,042✔
339

340
__dpctl_give DPCTLSyclContextRef
341
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
342
{
95,728✔
343
    auto Q = unwrap<queue>(QRef);
95,728✔
344
    DPCTLSyclContextRef CRef = nullptr;
95,728✔
345
    if (Q)
95,728✔
346
        CRef = wrap<context>(new context(Q->get_context()));
95,718✔
347
    else {
10✔
348
        error_handler("Could not get the context for this queue.", __FILE__,
10✔
349
                      __func__, __LINE__);
10✔
350
    }
10✔
351
    return CRef;
95,728✔
352
}
95,728✔
353

354
__dpctl_give DPCTLSyclEventRef
355
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
356
                       __dpctl_keep const DPCTLSyclQueueRef QRef,
357
                       __dpctl_keep void **Args,
358
                       __dpctl_keep const DPCTLKernelArgType *ArgTypes,
359
                       size_t NArgs,
360
                       __dpctl_keep const size_t Range[3],
361
                       size_t NDims,
362
                       __dpctl_keep const DPCTLSyclEventRef *DepEvents,
363
                       size_t NDepEvents)
364
{
41✔
365
    auto Kernel = unwrap<kernel>(KRef);
41✔
366
    auto Queue = unwrap<queue>(QRef);
41✔
367
    event e;
41✔
368

369
    try {
41✔
370
        switch (NDims) {
41✔
371
        case 1:
27✔
372
        {
27✔
373
            e = Queue->submit([&](handler &cgh) {
27✔
374
                // Depend on any event that was specified by the caller.
375
                set_dependent_events(cgh, DepEvents, NDepEvents);
27✔
376
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
27✔
377
                cgh.parallel_for(range<1>{Range[0]}, *Kernel);
27✔
378
            });
27✔
379
            return wrap<event>(new event(std::move(e)));
27✔
NEW
380
        }
×
381
        case 2:
7✔
382
        {
7✔
383
            e = Queue->submit([&](handler &cgh) {
7✔
384
                // Depend on any event that was specified by the caller.
385
                set_dependent_events(cgh, DepEvents, NDepEvents);
7✔
386
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7✔
387
                cgh.parallel_for(range<2>{Range[0], Range[1]}, *Kernel);
7✔
388
            });
7✔
389
            return wrap<event>(new event(std::move(e)));
7✔
NEW
390
        }
×
391
        case 3:
7✔
392
        {
7✔
393
            e = Queue->submit([&](handler &cgh) {
7✔
394
                // Depend on any event that was specified by the caller.
395
                set_dependent_events(cgh, DepEvents, NDepEvents);
7✔
396
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7✔
397
                cgh.parallel_for(range<3>{Range[0], Range[1], Range[2]},
7✔
398
                                 *Kernel);
7✔
399
            });
7✔
400
            return wrap<event>(new event(std::move(e)));
7✔
NEW
401
        }
×
NEW
402
        default:
×
NEW
403
            error_handler("Range cannot be greater than three "
×
NEW
404
                          "dimensions.",
×
NEW
405
                          __FILE__, __func__, __LINE__, error_level::error);
×
NEW
406
            return nullptr;
×
407
        }
41✔
408
    } catch (std::exception const &e) {
41✔
409
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
1✔
410
        return nullptr;
1✔
411
    } catch (...) {
1✔
NEW
412
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
NEW
413
                      __LINE__, error_level::error);
×
414
        return nullptr;
×
415
    }
×
416
}
41✔
417

418
__dpctl_give DPCTLSyclEventRef
419
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
420
                         __dpctl_keep const DPCTLSyclQueueRef QRef,
421
                         __dpctl_keep void **Args,
422
                         __dpctl_keep const DPCTLKernelArgType *ArgTypes,
423
                         size_t NArgs,
424
                         __dpctl_keep const size_t gRange[3],
425
                         __dpctl_keep const size_t lRange[3],
426
                         size_t NDims,
427
                         __dpctl_keep const DPCTLSyclEventRef *DepEvents,
428
                         size_t NDepEvents)
429
{
21✔
430
    auto Kernel = unwrap<kernel>(KRef);
21✔
431
    auto Queue = unwrap<queue>(QRef);
21✔
432
    event e;
21✔
433

434
    try {
21✔
435
        switch (NDims) {
21✔
436
        case 1:
7✔
437
        {
7✔
438
            e = Queue->submit([&](handler &cgh) {
7✔
439
                // Depend on any event that was specified by the caller.
440
                set_dependent_events(cgh, DepEvents, NDepEvents);
7✔
441
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7✔
442
                cgh.parallel_for(nd_range<1>{{gRange[0]}, {lRange[0]}},
7✔
443
                                 *Kernel);
7✔
444
            });
7✔
445
            return wrap<event>(new event(std::move(e)));
7✔
NEW
446
        }
×
447
        case 2:
7✔
448
        {
7✔
449
            e = Queue->submit([&](handler &cgh) {
7✔
450
                // Depend on any event that was specified by the caller.
451
                set_dependent_events(cgh, DepEvents, NDepEvents);
7✔
452
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7✔
453
                cgh.parallel_for(
7✔
454
                    nd_range<2>{{gRange[0], gRange[1]}, {lRange[0], lRange[1]}},
7✔
455
                    *Kernel);
7✔
456
            });
7✔
457
            return wrap<event>(new event(std::move(e)));
7✔
NEW
458
        }
×
459
        case 3:
7✔
460
        {
7✔
461
            e = Queue->submit([&](handler &cgh) {
7✔
462
                // Depend on any event that was specified by the caller.
463
                set_dependent_events(cgh, DepEvents, NDepEvents);
7✔
464
                set_kernel_args(cgh, Args, ArgTypes, NArgs);
7✔
465
                cgh.parallel_for(nd_range<3>{{gRange[0], gRange[1], gRange[2]},
7✔
466
                                             {lRange[0], lRange[1], lRange[2]}},
7✔
467
                                 *Kernel);
7✔
468
            });
7✔
469
            return wrap<event>(new event(std::move(e)));
7✔
NEW
470
        }
×
NEW
471
        default:
×
NEW
472
            error_handler("Range cannot be greater than three "
×
NEW
473
                          "dimensions.",
×
NEW
474
                          __FILE__, __func__, __LINE__, error_level::error);
×
NEW
475
            return nullptr;
×
476
        }
21✔
477
    } catch (std::exception const &e) {
21✔
NEW
478
        error_handler(e, __FILE__, __func__, __LINE__, error_level::error);
×
NEW
479
        return nullptr;
×
NEW
480
    } catch (...) {
×
NEW
481
        error_handler("Unknown exception encountered", __FILE__, __func__,
×
NEW
482
                      __LINE__, error_level::error);
×
483
        return nullptr;
×
484
    }
×
485
}
21✔
486

487
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
488
{
11✔
489
    // \todo what happens if the QRef is null or a pointer to a valid sycl
490
    // queue
491
    if (QRef) {
11!
492
        auto SyclQueue = unwrap<queue>(QRef);
11✔
493
        if (SyclQueue)
11!
494
            SyclQueue->wait();
11✔
495
    }
11✔
496
    else {
×
497
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
×
498
    }
×
499
}
11✔
500

501
__dpctl_give DPCTLSyclEventRef
502
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
503
                  void *Dest,
504
                  const void *Src,
505
                  size_t Count)
506
{
92,388✔
507
    auto Q = unwrap<queue>(QRef);
92,388✔
508
    if (Q) {
92,388✔
509
        sycl::event ev;
92,387✔
510
        try {
92,387✔
511
            ev = Q->memcpy(Dest, Src, Count);
92,387✔
512
        } catch (std::exception const &e) {
92,387✔
513
            error_handler(e, __FILE__, __func__, __LINE__);
8✔
514
            return nullptr;
8✔
515
        }
8✔
516
        return wrap<event>(new event(std::move(ev)));
92,379✔
517
    }
92,387✔
518
    else {
1✔
519
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1✔
520
                      __LINE__);
1✔
521
        return nullptr;
1✔
522
    }
1✔
523
}
92,388✔
524

525
__dpctl_give DPCTLSyclEventRef
526
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
527
                            void *Dest,
528
                            const void *Src,
529
                            size_t Count,
530
                            const DPCTLSyclEventRef *DepEvents,
531
                            size_t DepEventsCount)
532
{
58✔
533
    event ev;
58✔
534
    auto Q = unwrap<queue>(QRef);
58✔
535
    if (Q) {
58✔
536
        try {
57✔
537
            ev = Q->submit([&](handler &cgh) {
57✔
538
                if (DepEvents)
57✔
539
                    for (size_t i = 0; i < DepEventsCount; ++i) {
98✔
540
                        event *ei = unwrap<event>(DepEvents[i]);
49✔
541
                        if (ei)
49!
542
                            cgh.depends_on(*ei);
49✔
543
                    }
49✔
544

545
                cgh.memcpy(Dest, Src, Count);
57✔
546
            });
57✔
547
        } catch (const std::exception &ex) {
57✔
548
            error_handler(ex, __FILE__, __func__, __LINE__);
8✔
549
            return nullptr;
8✔
550
        }
8✔
551
    }
57✔
552
    else {
1✔
553
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1✔
554
                      __LINE__);
1✔
555
        return nullptr;
1✔
556
    }
1✔
557

558
    return wrap<event>(new event(ev));
49✔
559
}
58✔
560

561
__dpctl_give DPCTLSyclEventRef
562
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
563
                    const void *Ptr,
564
                    size_t Count)
565
{
16✔
566
    auto Q = unwrap<queue>(QRef);
16✔
567
    if (Q) {
16✔
568
        if (Ptr) {
15✔
569
            sycl::event ev;
7✔
570
            try {
7✔
571
                ev = Q->prefetch(Ptr, Count);
7✔
572
            } catch (std::exception const &e) {
7✔
573
                error_handler(e, __FILE__, __func__, __LINE__);
×
574
                return nullptr;
×
575
            }
×
576
            return wrap<event>(new event(std::move(ev)));
7✔
577
        }
7✔
578
        else {
8✔
579
            error_handler("Attempt to prefetch USM-allocation at nullptr.",
8✔
580
                          __FILE__, __func__, __LINE__);
8✔
581
            return nullptr;
8✔
582
        }
8✔
583
    }
15✔
584
    else {
1✔
585
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1✔
586
                      __LINE__);
1✔
587
        return nullptr;
1✔
588
    }
1✔
589
}
16✔
590

591
__dpctl_give DPCTLSyclEventRef
592
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
593
                     const void *Ptr,
594
                     size_t Count,
595
                     int Advice)
596
{
16✔
597
    auto Q = unwrap<queue>(QRef);
16✔
598
    if (Q) {
16✔
599
        sycl::event ev;
15✔
600
        try {
15✔
601
            ev = Q->mem_advise(Ptr, Count, Advice);
15✔
602
        } catch (std::exception const &e) {
15✔
603
            error_handler(e, __FILE__, __func__, __LINE__);
×
604
            return nullptr;
×
605
        }
×
606
        return wrap<event>(new event(std::move(ev)));
15✔
607
    }
15✔
608
    else {
1✔
609
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1✔
610
                      __LINE__);
1✔
611
        return nullptr;
1✔
612
    }
1✔
613
}
16✔
614

615
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
616
{
820✔
617
    auto Q = unwrap<queue>(QRef);
820✔
618
    if (Q) {
820✔
619
        return Q->is_in_order();
819✔
620
    }
819✔
621
    else
1✔
622
        return false;
1✔
623
}
820✔
624

625
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
626
{
56✔
627
    auto Q = unwrap<queue>(QRef);
56✔
628
    if (Q) {
56✔
629
        return Q->has_property<sycl::property::queue::enable_profiling>();
55✔
630
    }
55✔
631
    else
1✔
632
        return false;
1✔
633
}
56✔
634

635
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
636
{
38✔
637
    auto Q = unwrap<queue>(QRef);
38✔
638
    if (Q) {
38✔
639
        std::hash<queue> hash_fn;
35✔
640
        return hash_fn(*Q);
35✔
641
    }
35✔
642
    else {
3✔
643
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3✔
644
        return 0;
3✔
645
    }
3✔
646
}
38✔
647

648
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
649
    __dpctl_keep const DPCTLSyclQueueRef QRef,
650
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
651
    size_t NDepEvents)
652
{
105✔
653
    auto Q = unwrap<queue>(QRef);
105✔
654
    event e;
105✔
655
    if (Q) {
105!
656
        try {
105✔
657
            e = Q->submit([&](handler &cgh) {
105✔
658
                // Depend on any event that was specified by the caller.
659
                if (NDepEvents)
105✔
660
                    for (auto i = 0ul; i < NDepEvents; ++i)
20✔
661
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
13✔
662

663
                cgh.ext_oneapi_barrier();
105✔
664
            });
105✔
665
        } catch (std::exception const &e) {
105✔
666
            error_handler(e, __FILE__, __func__, __LINE__);
×
667
            return nullptr;
×
668
        }
×
669

670
        return wrap<event>(new event(std::move(e)));
105✔
671
    }
105✔
672
    else {
×
673
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
674
        return nullptr;
×
675
    }
×
676
}
105✔
677

678
__dpctl_give DPCTLSyclEventRef
679
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
680
{
1✔
681
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1✔
682
}
1✔
683

684
__dpctl_give DPCTLSyclEventRef
685
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
686
                  void *USMRef,
687
                  uint8_t Value,
688
                  size_t Count)
689
{
3,400✔
690
    auto Q = unwrap<queue>(QRef);
3,400✔
691
    if (Q && USMRef) {
3,400!
692
        sycl::event ev;
3,399✔
693
        try {
3,399✔
694
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
3,399✔
695
        } catch (std::exception const &e) {
3,399✔
696
            error_handler(e, __FILE__, __func__, __LINE__);
×
697
            return nullptr;
×
698
        }
×
699
        return wrap<event>(new event(std::move(ev)));
3,399✔
700
    }
3,399✔
701
    else {
1✔
702
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1✔
703
                      __func__, __LINE__);
1✔
704
        return nullptr;
1✔
705
    }
1✔
706
};
3,400✔
707

708
__dpctl_give DPCTLSyclEventRef
709
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
710
                 void *USMRef,
711
                 uint8_t Value,
712
                 size_t Count)
713
{
9✔
714
    auto Q = unwrap<queue>(QRef);
9✔
715
    if (Q && USMRef) {
9!
716
        sycl::event ev;
8✔
717
        try {
8✔
718
            ev = Q->fill<uint8_t>(USMRef, Value, Count);
8✔
719
        } catch (std::exception const &e) {
8✔
720
            error_handler(e, __FILE__, __func__, __LINE__);
×
721
            return nullptr;
×
722
        }
×
723
        return wrap<event>(new event(std::move(ev)));
8✔
724
    }
8✔
725
    else {
1✔
726
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1✔
727
                      __func__, __LINE__);
1✔
728
        return nullptr;
1✔
729
    }
1✔
730
}
9✔
731

732
__dpctl_give DPCTLSyclEventRef
733
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
734
                  void *USMRef,
735
                  uint16_t Value,
736
                  size_t Count)
737
{
9✔
738
    auto Q = unwrap<queue>(QRef);
9✔
739
    if (Q && USMRef) {
9!
740
        sycl::event ev;
8✔
741
        try {
8✔
742
            ev = Q->fill<uint16_t>(USMRef, Value, Count);
8✔
743
        } catch (std::exception const &e) {
8✔
744
            error_handler(e, __FILE__, __func__, __LINE__);
×
745
            return nullptr;
×
746
        }
×
747
        return wrap<event>(new event(std::move(ev)));
8✔
748
    }
8✔
749
    else {
1✔
750
        error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__,
1✔
751
                      __func__, __LINE__);
1✔
752
        return nullptr;
1✔
753
    }
1✔
754
}
9✔
755

756
__dpctl_give DPCTLSyclEventRef
757
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
758
                  void *USMRef,
759
                  uint32_t Value,
760
                  size_t Count)
761
{
9✔
762
    auto Q = unwrap<queue>(QRef);
9✔
763
    if (Q && USMRef) {
9!
764
        sycl::event ev;
8✔
765
        try {
8✔
766
            ev = Q->fill<uint32_t>(USMRef, Value, Count);
8✔
767
        } catch (std::exception const &e) {
8✔
768
            error_handler(e, __FILE__, __func__, __LINE__);
×
769
            return nullptr;
×
770
        }
×
771
        return wrap<event>(new event(std::move(ev)));
8✔
772
    }
8✔
773
    else {
1✔
774
        error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__,
1✔
775
                      __func__, __LINE__);
1✔
776
        return nullptr;
1✔
777
    }
1✔
778
}
9✔
779

780
__dpctl_give DPCTLSyclEventRef
781
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
782
                  void *USMRef,
783
                  uint64_t Value,
784
                  size_t Count)
785
{
9✔
786
    auto Q = unwrap<queue>(QRef);
9✔
787
    if (Q && USMRef) {
9!
788
        sycl::event ev;
8✔
789
        try {
8✔
790
            ev = Q->fill<uint64_t>(USMRef, Value, Count);
8✔
791
        } catch (std::exception const &e) {
8✔
792
            error_handler(e, __FILE__, __func__, __LINE__);
×
793
            return nullptr;
×
794
        }
×
795
        return wrap<event>(new event(std::move(ev)));
8✔
796
    }
8✔
797
    else {
1✔
798
        error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__,
1✔
799
                      __func__, __LINE__);
1✔
800
        return nullptr;
1✔
801
    }
1✔
802
}
9✔
803

804
__dpctl_give DPCTLSyclEventRef
805
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
806
                   void *USMRef,
807
                   uint64_t *Value,
808
                   size_t Count)
809
{
9✔
810
    auto Q = unwrap<queue>(QRef);
9✔
811
    if (Q && USMRef) {
9!
812
        sycl::event ev;
8✔
813
        try {
8✔
814
            complexNumber Val;
8✔
815
            Val.real = Value[0];
8✔
816
            Val.imag = Value[1];
8✔
817
            ev = Q->fill(USMRef, Val, Count);
8✔
818
        } catch (std::exception const &e) {
8✔
819
            error_handler(e, __FILE__, __func__, __LINE__);
×
820
            return nullptr;
×
821
        }
×
822
        return wrap<event>(new event(std::move(ev)));
8✔
823
    }
8✔
824
    else {
1✔
825
        error_handler("QRef or USMRef passed to fill128 were NULL.", __FILE__,
1✔
826
                      __func__, __LINE__);
1✔
827
        return nullptr;
1✔
828
    }
1✔
829
}
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc