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

IntelPython / dpctl / 6514458641

14 Oct 2023 12:43AM UTC coverage: 85.692% (+0.01%) from 85.68%
6514458641

push

github

web-flow
Merge pull request #1436 from IntelPython/do-not-use-wait-and-throw

2445 of 2893 branches covered (0.0%)

Branch coverage included in aggregate %.

3 of 3 new or added lines in 2 files covered. (100.0%)

2 existing lines in 1 file now uncovered.

8683 of 10093 relevant lines covered (86.03%)

7884.31 hits per line

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

82.02
/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-2022 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 <CL/sycl.hpp> /* SYCL headers   */
35
#include <exception>
36
#include <stdexcept>
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
/*!
55
 * @brief Set the kernel arg object
56
 *
57
 * @param    cgh            My Param doc
58
 * @param    Arg            My Param doc
59
 */
60
bool set_kernel_arg(handler &cgh,
61
                    size_t idx,
62
                    __dpctl_keep void *Arg,
63
                    DPCTLKernelArgType ArgTy)
64
{
189✔
65
    bool arg_set = true;
189✔
66

67
    switch (ArgTy) {
189✔
68
    case DPCTL_CHAR:
×
69
        cgh.set_arg(idx, *(char *)Arg);
×
70
        break;
×
71
    case DPCTL_SIGNED_CHAR:
×
72
        cgh.set_arg(idx, *(signed char *)Arg);
×
73
        break;
×
74
    case DPCTL_UNSIGNED_CHAR:
×
75
        cgh.set_arg(idx, *(unsigned char *)Arg);
×
76
        break;
×
77
    case DPCTL_SHORT:
6✔
78
        cgh.set_arg(idx, *(short *)Arg);
6✔
79
        break;
6✔
80
    case DPCTL_INT:
6✔
81
        cgh.set_arg(idx, *(int *)Arg);
6✔
82
        break;
6✔
83
    case DPCTL_UNSIGNED_INT:
8✔
84
        cgh.set_arg(idx, *(unsigned int *)Arg);
8✔
85
        break;
8✔
86
    case DPCTL_UNSIGNED_INT8:
×
87
        cgh.set_arg(idx, *(uint8_t *)Arg);
×
88
        break;
×
89
    case DPCTL_LONG:
6✔
90
        cgh.set_arg(idx, *(long *)Arg);
6✔
91
        break;
6✔
92
    case DPCTL_UNSIGNED_LONG:
6✔
93
        cgh.set_arg(idx, *(unsigned long *)Arg);
6✔
94
        break;
6✔
95
    case DPCTL_LONG_LONG:
×
96
        cgh.set_arg(idx, *(long long *)Arg);
×
97
        break;
×
98
    case DPCTL_UNSIGNED_LONG_LONG:
×
99
        cgh.set_arg(idx, *(unsigned long long *)Arg);
×
100
        break;
×
101
    case DPCTL_SIZE_T:
×
102
        cgh.set_arg(idx, *(size_t *)Arg);
×
103
        break;
×
104
    case DPCTL_FLOAT:
8✔
105
        cgh.set_arg(idx, *(float *)Arg);
8✔
106
        break;
8✔
107
    case DPCTL_DOUBLE:
6✔
108
        cgh.set_arg(idx, *(double *)Arg);
6✔
109
        break;
6✔
110
    case DPCTL_LONG_DOUBLE:
×
111
        cgh.set_arg(idx, *(long double *)Arg);
×
112
        break;
×
113
    case DPCTL_VOID_PTR:
143✔
114
        cgh.set_arg(idx, Arg);
143✔
115
        break;
143✔
116
    default:
×
117
        arg_set = false;
×
118
        error_handler("Kernel argument could not be created.", __FILE__,
×
119
                      __func__, __LINE__);
×
120
        break;
×
121
    }
189✔
122
    return arg_set;
189✔
123
}
189✔
124

125
std::unique_ptr<property_list> create_property_list(int properties)
126
{
26,334✔
127
    std::unique_ptr<property_list> propList;
26,334✔
128
    int _prop = properties;
26,334✔
129
    if (_prop & DPCTL_ENABLE_PROFILING) {
26,334✔
130
        _prop = _prop ^ DPCTL_ENABLE_PROFILING;
56✔
131
        if (_prop & DPCTL_IN_ORDER) {
56✔
132
            _prop = _prop ^ DPCTL_IN_ORDER;
22✔
133
            propList = std::make_unique<property_list>(
22✔
134
                sycl::property::queue::enable_profiling(),
22✔
135
                sycl::property::queue::in_order());
22✔
136
        }
22✔
137
        else {
34✔
138
            propList = std::make_unique<property_list>(
34✔
139
                sycl::property::queue::enable_profiling());
34✔
140
        }
34✔
141
    }
56✔
142
    else if (_prop & DPCTL_IN_ORDER) {
26,278✔
143
        _prop = _prop ^ DPCTL_IN_ORDER;
417✔
144
        propList =
417✔
145
            std::make_unique<property_list>(sycl::property::queue::in_order());
417✔
146
    }
417✔
147
    else {
25,861✔
148
        propList = std::make_unique<property_list>();
25,861✔
149
    }
25,861✔
150

151
    if (_prop) {
26,334✔
152
        std::stringstream ss;
1✔
153
        ss << "Invalid queue property argument (" << std::hex << properties
1✔
154
           << "), interpreted as (" << (properties ^ _prop) << ").";
1✔
155
        error_handler(ss.str(), __FILE__, __func__, __LINE__);
1✔
156
    }
1✔
157
    return propList;
26,334✔
158
}
26,334✔
159

160
__dpctl_give DPCTLSyclQueueRef
161
getQueueImpl(__dpctl_keep DPCTLSyclContextRef cRef,
162
             __dpctl_keep DPCTLSyclDeviceRef dRef,
163
             error_handler_callback *handler,
164
             int properties)
165
{
107✔
166
    DPCTLSyclQueueRef qRef = nullptr;
107✔
167
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
107✔
168
    return qRef;
107✔
169
}
107✔
170

171
} /* end of anonymous namespace */
172

173
DPCTL_API
174
__dpctl_give DPCTLSyclQueueRef
175
DPCTLQueue_Create(__dpctl_keep const DPCTLSyclContextRef CRef,
176
                  __dpctl_keep const DPCTLSyclDeviceRef DRef,
177
                  error_handler_callback *handler,
178
                  int properties)
179
{
26,334✔
180
    DPCTLSyclQueueRef q = nullptr;
26,334✔
181
    auto dev = unwrap<device>(DRef);
26,334✔
182
    auto ctx = unwrap<context>(CRef);
26,334✔
183

184
    if (!(dev && ctx)) {
26,334!
185
        error_handler("Cannot create queue from DPCTLSyclContextRef and "
×
186
                      "DPCTLSyclDeviceRef as input is a nullptr.",
×
187
                      __FILE__, __func__, __LINE__);
×
188
        return q;
×
189
    }
×
190
    auto propList = create_property_list(properties);
26,334✔
191

192
    if (handler) {
26,334✔
193
        try {
40✔
194
            auto Queue = new queue(*ctx, *dev, DPCTL_AsyncErrorHandler(handler),
40✔
195
                                   *propList);
40✔
196
            q = wrap<queue>(Queue);
40✔
197
        } catch (std::exception const &e) {
40✔
UNCOV
198
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
199
        }
×
200
    }
40✔
201
    else {
26,294✔
202
        try {
26,294✔
203
            auto Queue = new queue(*ctx, *dev, *propList);
26,294✔
204
            q = wrap<queue>(Queue);
26,294✔
205
        } catch (std::exception const &e) {
26,294✔
206
            error_handler(e, __FILE__, __func__, __LINE__);
1✔
207
        }
1✔
208
    }
26,294✔
209

210
    return q;
26,334✔
211
}
26,334✔
212

213
__dpctl_give DPCTLSyclQueueRef
214
DPCTLQueue_CreateForDevice(__dpctl_keep const DPCTLSyclDeviceRef DRef,
215
                           error_handler_callback *handler,
216
                           int properties)
217
{
277✔
218
    DPCTLSyclContextRef CRef = nullptr;
277✔
219
    DPCTLSyclQueueRef QRef = nullptr;
277✔
220
    auto Device = unwrap<device>(DRef);
277✔
221

222
    if (!Device) {
277✔
223
        error_handler("Cannot create queue from NULL device reference.",
170✔
224
                      __FILE__, __func__, __LINE__);
170✔
225
        return QRef;
170✔
226
    }
170✔
227
    // Check if a cached default context exists for the device.
228
    CRef = DPCTLDeviceMgr_GetCachedContext(DRef);
107✔
229
    // If a cached default context was found, that context will be used to use
230
    // create the new queue. When a default cached context was not found, as
231
    // will be the case for non-root devices, i.e., sub-devices, a new context
232
    // will be allocated. Note that any newly allocated context is not cached.
233
    if (!CRef) {
107✔
234
        context *ContextPtr = nullptr;
1✔
235
        try {
1✔
236
            ContextPtr = new context(*Device);
1✔
237
            CRef = wrap<context>(ContextPtr);
1✔
238
        } catch (std::exception const &e) {
1✔
239
            error_handler(e, __FILE__, __func__, __LINE__);
×
240
            delete ContextPtr;
×
241
            return QRef;
×
242
        }
×
243
    }
1✔
244
    // At this point we have a valid context and the queue can be allocated.
245
    QRef = getQueueImpl(CRef, DRef, handler, properties);
107✔
246
    // Free the context
247
    DPCTLContext_Delete(CRef);
107✔
248
    return QRef;
107✔
249
}
107✔
250

251
/*!
252
 * Delete the passed in pointer after verifying it points to a sycl::queue.
253
 */
254
void DPCTLQueue_Delete(__dpctl_take DPCTLSyclQueueRef QRef)
255
{
191,930✔
256
    delete unwrap<queue>(QRef);
191,930✔
257
}
191,930✔
258

259
/*!
260
 * Make copy of sycl::queue referenced by passed pointer
261
 */
262
__dpctl_give DPCTLSyclQueueRef
263
DPCTLQueue_Copy(__dpctl_keep const DPCTLSyclQueueRef QRef)
264
{
413,662✔
265
    auto Queue = unwrap<queue>(QRef);
413,662✔
266
    if (Queue) {
413,662✔
267
        try {
413,661✔
268
            auto CopiedQueue = new queue(*Queue);
413,661✔
269
            return wrap<queue>(CopiedQueue);
413,661✔
270
        } catch (std::exception const &e) {
413,661✔
271
            error_handler(e, __FILE__, __func__, __LINE__);
×
272
            return nullptr;
×
273
        }
×
274
    }
413,661✔
275
    else {
1✔
276
        error_handler("Cannot copy DPCTLSyclQueueRef as input is a nullptr",
1✔
277
                      __FILE__, __func__, __LINE__);
1✔
278
        return nullptr;
1✔
279
    }
1✔
280
}
413,662✔
281

282
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
283
                      __dpctl_keep const DPCTLSyclQueueRef QRef2)
284
{
23,677✔
285
    if (!(QRef1 && QRef2)) {
23,677✔
286
        error_handler("DPCTLSyclQueueRefs are nullptr.", __FILE__, __func__,
2✔
287
                      __LINE__);
2✔
288
        return false;
2✔
289
    }
2✔
290
    return (*unwrap<queue>(QRef1) == *unwrap<queue>(QRef2));
23,675✔
291
}
23,677✔
292

293
DPCTLSyclBackendType DPCTLQueue_GetBackend(__dpctl_keep DPCTLSyclQueueRef QRef)
294
{
11✔
295
    auto Q = unwrap<queue>(QRef);
11✔
296
    if (Q) {
11✔
297
        try {
10✔
298
            auto C = Q->get_context();
10✔
299
            return DPCTLContext_GetBackend(wrap<context>(&C));
10✔
300
        } catch (std::exception const &e) {
10✔
301
            error_handler(e, __FILE__, __func__, __LINE__);
×
302
            return DPCTL_UNKNOWN_BACKEND;
×
303
        }
×
304
    }
10✔
305
    else
1✔
306
        return DPCTL_UNKNOWN_BACKEND;
1✔
307
}
11✔
308

309
__dpctl_give DPCTLSyclDeviceRef
310
DPCTLQueue_GetDevice(__dpctl_keep const DPCTLSyclQueueRef QRef)
311
{
82,729✔
312
    DPCTLSyclDeviceRef DRef = nullptr;
82,729✔
313
    auto Q = unwrap<queue>(QRef);
82,729✔
314
    if (Q) {
82,729✔
315
        try {
82,728✔
316
            auto Device = new device(Q->get_device());
82,728✔
317
            DRef = wrap<device>(Device);
82,728✔
318
        } catch (std::exception const &e) {
82,728✔
319
            error_handler(e, __FILE__, __func__, __LINE__);
×
320
        }
×
321
    }
82,728✔
322
    else {
1✔
323
        error_handler("Could not get the device for this queue.", __FILE__,
1✔
324
                      __func__, __LINE__);
1✔
325
    }
1✔
326
    return DRef;
82,729✔
327
}
82,729✔
328

329
__dpctl_give DPCTLSyclContextRef
330
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
331
{
84,403✔
332
    auto Q = unwrap<queue>(QRef);
84,403✔
333
    DPCTLSyclContextRef CRef = nullptr;
84,403✔
334
    if (Q)
84,403✔
335
        CRef = wrap<context>(new context(Q->get_context()));
84,393✔
336
    else {
10✔
337
        error_handler("Could not get the context for this queue.", __FILE__,
10✔
338
                      __func__, __LINE__);
10✔
339
    }
10✔
340
    return CRef;
84,403✔
341
}
84,403✔
342

343
__dpctl_give DPCTLSyclEventRef
344
DPCTLQueue_SubmitRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
345
                       __dpctl_keep const DPCTLSyclQueueRef QRef,
346
                       __dpctl_keep void **Args,
347
                       __dpctl_keep const DPCTLKernelArgType *ArgTypes,
348
                       size_t NArgs,
349
                       __dpctl_keep const size_t Range[3],
350
                       size_t NDims,
351
                       __dpctl_keep const DPCTLSyclEventRef *DepEvents,
352
                       size_t NDepEvents)
353
{
31✔
354
    auto Kernel = unwrap<kernel>(KRef);
31✔
355
    auto Queue = unwrap<queue>(QRef);
31✔
356
    event e;
31✔
357

358
    try {
31✔
359
        e = Queue->submit([&](handler &cgh) {
31✔
360
            // Depend on any event that was specified by the caller.
361
            if (NDepEvents)
31✔
362
                for (auto i = 0ul; i < NDepEvents; ++i)
7✔
363
                    cgh.depends_on(*unwrap<event>(DepEvents[i]));
4✔
364

365
            for (auto i = 0ul; i < NArgs; ++i) {
132✔
366
                // \todo add support for Sycl buffers
367
                if (!set_kernel_arg(cgh, i, Args[i], ArgTypes[i]))
101!
368
                    exit(1);
×
369
            }
101✔
370
            switch (NDims) {
31✔
371
            case 1:
17✔
372
                cgh.parallel_for(range<1>{Range[0]}, *Kernel);
17✔
373
                break;
17✔
374
            case 2:
7✔
375
                cgh.parallel_for(range<2>{Range[0], Range[1]}, *Kernel);
7✔
376
                break;
7✔
377
            case 3:
7✔
378
                cgh.parallel_for(range<3>{Range[0], Range[1], Range[2]},
7✔
379
                                 *Kernel);
7✔
380
                break;
7✔
381
            default:
×
382
                throw std::runtime_error("Range cannot be greater than three "
×
383
                                         "dimensions.");
×
384
            }
31✔
385
        });
31✔
386
    } catch (std::exception const &e) {
31✔
387
        error_handler(e, __FILE__, __func__, __LINE__);
×
388
        return nullptr;
×
389
    }
×
390

391
    return wrap<event>(new event(std::move(e)));
31✔
392
}
31✔
393

394
__dpctl_give DPCTLSyclEventRef
395
DPCTLQueue_SubmitNDRange(__dpctl_keep const DPCTLSyclKernelRef KRef,
396
                         __dpctl_keep const DPCTLSyclQueueRef QRef,
397
                         __dpctl_keep void **Args,
398
                         __dpctl_keep const DPCTLKernelArgType *ArgTypes,
399
                         size_t NArgs,
400
                         __dpctl_keep const size_t gRange[3],
401
                         __dpctl_keep const size_t lRange[3],
402
                         size_t NDims,
403
                         __dpctl_keep const DPCTLSyclEventRef *DepEvents,
404
                         size_t NDepEvents)
405
{
22✔
406
    auto Kernel = unwrap<kernel>(KRef);
22✔
407
    auto Queue = unwrap<queue>(QRef);
22✔
408
    event e;
22✔
409

410
    try {
22✔
411
        e = Queue->submit([&](handler &cgh) {
22✔
412
            // Depend on any event that was specified by the caller.
413
            if (NDepEvents)
22!
414
                for (auto i = 0ul; i < NDepEvents; ++i)
44✔
415
                    cgh.depends_on(*unwrap<event>(DepEvents[i]));
22✔
416

417
            for (auto i = 0ul; i < NArgs; ++i) {
110✔
418
                // \todo add support for Sycl buffers
419
                if (!set_kernel_arg(cgh, i, Args[i], ArgTypes[i]))
88!
420
                    exit(1);
×
421
            }
88✔
422
            switch (NDims) {
22✔
423
            case 1:
7✔
424
                cgh.parallel_for(nd_range<1>{{gRange[0]}, {lRange[0]}},
7✔
425
                                 *Kernel);
7✔
426
                break;
7✔
427
            case 2:
7✔
428
                cgh.parallel_for(
7✔
429
                    nd_range<2>{{gRange[0], gRange[1]}, {lRange[0], lRange[1]}},
7✔
430
                    *Kernel);
7✔
431
                break;
7✔
432
            case 3:
8✔
433
                cgh.parallel_for(nd_range<3>{{gRange[0], gRange[1], gRange[2]},
8✔
434
                                             {lRange[0], lRange[1], lRange[2]}},
8✔
435
                                 *Kernel);
8✔
436
                break;
8✔
437
            default:
×
438
                throw std::runtime_error("Range cannot be greater than three "
×
439
                                         "dimensions.");
×
440
            }
22✔
441
        });
22✔
442
    } catch (std::exception const &e) {
22✔
443
        error_handler(e, __FILE__, __func__, __LINE__);
×
444
        return nullptr;
×
445
    }
×
446

447
    return wrap<event>(new event(std::move(e)));
22✔
448
}
22✔
449

450
void DPCTLQueue_Wait(__dpctl_keep DPCTLSyclQueueRef QRef)
451
{
3✔
452
    // \todo what happens if the QRef is null or a pointer to a valid sycl
453
    // queue
454
    if (QRef) {
3!
455
        auto SyclQueue = unwrap<queue>(QRef);
3✔
456
        if (SyclQueue)
3!
457
            SyclQueue->wait();
3✔
458
    }
3✔
459
    else {
×
460
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
×
461
    }
×
462
}
3✔
463

464
__dpctl_give DPCTLSyclEventRef
465
DPCTLQueue_Memcpy(__dpctl_keep const DPCTLSyclQueueRef QRef,
466
                  void *Dest,
467
                  const void *Src,
468
                  size_t Count)
469
{
81,119✔
470
    auto Q = unwrap<queue>(QRef);
81,119✔
471
    if (Q) {
81,119✔
472
        sycl::event ev;
81,118✔
473
        try {
81,118✔
474
            ev = Q->memcpy(Dest, Src, Count);
81,118✔
475
        } catch (std::exception const &e) {
81,118✔
476
            error_handler(e, __FILE__, __func__, __LINE__);
8✔
477
            return nullptr;
8✔
478
        }
8✔
479
        return wrap<event>(new event(std::move(ev)));
81,110✔
480
    }
81,118✔
481
    else {
1✔
482
        error_handler("QRef passed to memcpy was NULL.", __FILE__, __func__,
1✔
483
                      __LINE__);
1✔
484
        return nullptr;
1✔
485
    }
1✔
486
}
81,119✔
487

488
__dpctl_give DPCTLSyclEventRef
489
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
490
                    const void *Ptr,
491
                    size_t Count)
492
{
16✔
493
    auto Q = unwrap<queue>(QRef);
16✔
494
    if (Q) {
16✔
495
        if (Ptr) {
15✔
496
            sycl::event ev;
7✔
497
            try {
7✔
498
                ev = Q->prefetch(Ptr, Count);
7✔
499
            } catch (std::exception const &e) {
7✔
500
                error_handler(e, __FILE__, __func__, __LINE__);
×
501
                return nullptr;
×
502
            }
×
503
            return wrap<event>(new event(std::move(ev)));
7✔
504
        }
7✔
505
        else {
8✔
506
            error_handler("Attempt to prefetch USM-allocation at nullptr.",
8✔
507
                          __FILE__, __func__, __LINE__);
8✔
508
            return nullptr;
8✔
509
        }
8✔
510
    }
15✔
511
    else {
1✔
512
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1✔
513
                      __LINE__);
1✔
514
        return nullptr;
1✔
515
    }
1✔
516
}
16✔
517

518
__dpctl_give DPCTLSyclEventRef
519
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
520
                     const void *Ptr,
521
                     size_t Count,
522
                     int Advice)
523
{
16✔
524
    auto Q = unwrap<queue>(QRef);
16✔
525
    if (Q) {
16✔
526
        sycl::event ev;
15✔
527
        try {
15✔
528
            ev = Q->mem_advise(Ptr, Count, Advice);
15✔
529
        } catch (std::exception const &e) {
15✔
530
            error_handler(e, __FILE__, __func__, __LINE__);
×
531
            return nullptr;
×
532
        }
×
533
        return wrap<event>(new event(std::move(ev)));
15✔
534
    }
15✔
535
    else {
1✔
536
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1✔
537
                      __LINE__);
1✔
538
        return nullptr;
1✔
539
    }
1✔
540
}
16✔
541

542
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
543
{
800✔
544
    auto Q = unwrap<queue>(QRef);
800✔
545
    if (Q) {
800✔
546
        return Q->is_in_order();
799✔
547
    }
799✔
548
    else
1✔
549
        return false;
1✔
550
}
800✔
551

552
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
553
{
56✔
554
    auto Q = unwrap<queue>(QRef);
56✔
555
    if (Q) {
56✔
556
        return Q->has_property<sycl::property::queue::enable_profiling>();
55✔
557
    }
55✔
558
    else
1✔
559
        return false;
1✔
560
}
56✔
561

562
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
563
{
38✔
564
    auto Q = unwrap<queue>(QRef);
38✔
565
    if (Q) {
38✔
566
        std::hash<queue> hash_fn;
35✔
567
        return hash_fn(*Q);
35✔
568
    }
35✔
569
    else {
3✔
570
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3✔
571
        return 0;
3✔
572
    }
3✔
573
}
38✔
574

575
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
576
    __dpctl_keep const DPCTLSyclQueueRef QRef,
577
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
578
    size_t NDepEvents)
579
{
105✔
580
    auto Q = unwrap<queue>(QRef);
105✔
581
    event e;
105✔
582
    if (Q) {
105!
583
        try {
105✔
584
            e = Q->submit([&](handler &cgh) {
105✔
585
                // Depend on any event that was specified by the caller.
586
                if (NDepEvents)
105✔
587
                    for (auto i = 0ul; i < NDepEvents; ++i)
20✔
588
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
13✔
589

590
                cgh.ext_oneapi_barrier();
105✔
591
            });
105✔
592
        } catch (std::exception const &e) {
105✔
593
            error_handler(e, __FILE__, __func__, __LINE__);
×
594
            return nullptr;
×
595
        }
×
596

597
        return wrap<event>(new event(std::move(e)));
105✔
598
    }
105✔
599
    else {
×
600
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
601
        return nullptr;
×
602
    }
×
603
}
105✔
604

605
__dpctl_give DPCTLSyclEventRef
606
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
607
{
1✔
608
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1✔
609
}
1✔
610

611
__dpctl_give DPCTLSyclEventRef
612
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
613
                  void *USMRef,
614
                  uint8_t Value,
615
                  size_t Count)
616
{
3,091✔
617
    auto Q = unwrap<queue>(QRef);
3,091✔
618
    if (Q && USMRef) {
3,091!
619
        sycl::event ev;
3,090✔
620
        try {
3,090✔
621
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
3,090✔
622
        } catch (std::exception const &e) {
3,090✔
623
            error_handler(e, __FILE__, __func__, __LINE__);
×
624
            return nullptr;
×
625
        }
×
626
        return wrap<event>(new event(std::move(ev)));
3,090✔
627
    }
3,090✔
628
    else {
1✔
629
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1✔
630
                      __func__, __LINE__);
1✔
631
        return nullptr;
1✔
632
    }
1✔
633
};
3,091✔
634

635
__dpctl_give DPCTLSyclEventRef
636
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
637
                 void *USMRef,
638
                 uint8_t Value,
639
                 size_t Count)
640
{
9✔
641
    auto Q = unwrap<queue>(QRef);
9✔
642
    if (Q && USMRef) {
9!
643
        sycl::event ev;
8✔
644
        try {
8✔
645
            ev = Q->fill<uint8_t>(USMRef, Value, Count);
8✔
646
        } catch (std::exception const &e) {
8✔
647
            error_handler(e, __FILE__, __func__, __LINE__);
×
648
            return nullptr;
×
649
        }
×
650
        return wrap<event>(new event(std::move(ev)));
8✔
651
    }
8✔
652
    else {
1✔
653
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1✔
654
                      __func__, __LINE__);
1✔
655
        return nullptr;
1✔
656
    }
1✔
657
}
9✔
658

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

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

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

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