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

IntelPython / dpctl / 6620553462

24 Oct 2023 12:17AM UTC coverage: 85.718% (+0.02%) from 85.701%
6620553462

push

github

web-flow
Merge pull request #1452 from IntelPython/improve-exception-parent-device

Use partition_type_property descriptor in DPCTLDevice_GetParentDevice

2472 of 2923 branches covered (0.0%)

Branch coverage included in aggregate %.

9 of 12 new or added lines in 1 file covered. (75.0%)

130 existing lines in 4 files now uncovered.

8799 of 10226 relevant lines covered (86.05%)

8009.21 hits per line

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

82.72
/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,950✔
127
    std::unique_ptr<property_list> propList;
26,950✔
128
    int _prop = properties;
26,950✔
129
    if (_prop & DPCTL_ENABLE_PROFILING) {
26,950✔
130
        _prop = _prop ^ DPCTL_ENABLE_PROFILING;
60✔
131
        if (_prop & DPCTL_IN_ORDER) {
60✔
132
            _prop = _prop ^ DPCTL_IN_ORDER;
24✔
133
            propList = std::make_unique<property_list>(
24✔
134
                sycl::property::queue::enable_profiling(),
24✔
135
                sycl::property::queue::in_order());
24✔
136
        }
24✔
137
        else {
36✔
138
            propList = std::make_unique<property_list>(
36✔
139
                sycl::property::queue::enable_profiling());
36✔
140
        }
36✔
141
    }
60✔
142
    else if (_prop & DPCTL_IN_ORDER) {
26,890✔
143
        _prop = _prop ^ DPCTL_IN_ORDER;
419✔
144
        propList =
419✔
145
            std::make_unique<property_list>(sycl::property::queue::in_order());
419✔
146
    }
419✔
147
    else {
26,471✔
148
        propList = std::make_unique<property_list>();
26,471✔
149
    }
26,471✔
150

151
    if (_prop) {
26,950✔
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,950✔
158
}
26,950✔
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
{
115✔
166
    DPCTLSyclQueueRef qRef = nullptr;
115✔
167
    qRef = DPCTLQueue_Create(cRef, dRef, handler, properties);
115✔
168
    return qRef;
115✔
169
}
115✔
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,950✔
180
    DPCTLSyclQueueRef q = nullptr;
26,950✔
181
    auto dev = unwrap<device>(DRef);
26,950✔
182
    auto ctx = unwrap<context>(CRef);
26,950✔
183

184
    if (!(dev && ctx)) {
26,950!
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,950✔
191

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

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

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

222
    if (!Device) {
301✔
223
        error_handler("Cannot create queue from NULL device reference.",
186✔
224
                      __FILE__, __func__, __LINE__);
186✔
225
        return QRef;
186✔
226
    }
186✔
227
    // Check if a cached default context exists for the device.
228
    CRef = DPCTLDeviceMgr_GetCachedContext(DRef);
115✔
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) {
115✔
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);
115✔
246
    // Free the context
247
    DPCTLContext_Delete(CRef);
115✔
248
    return QRef;
115✔
249
}
115✔
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
{
198,156✔
256
    delete unwrap<queue>(QRef);
198,156✔
257
}
198,156✔
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
{
426,255✔
265
    auto Queue = unwrap<queue>(QRef);
426,255✔
266
    if (Queue) {
426,255✔
267
        try {
426,254✔
268
            auto CopiedQueue = new queue(*Queue);
426,254✔
269
            return wrap<queue>(CopiedQueue);
426,254✔
270
        } catch (std::exception const &e) {
426,254✔
271
            error_handler(e, __FILE__, __func__, __LINE__);
×
272
            return nullptr;
×
273
        }
×
274
    }
426,254✔
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
}
426,255✔
281

282
bool DPCTLQueue_AreEq(__dpctl_keep const DPCTLSyclQueueRef QRef1,
283
                      __dpctl_keep const DPCTLSyclQueueRef QRef2)
284
{
24,216✔
285
    if (!(QRef1 && QRef2)) {
24,216✔
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));
24,214✔
291
}
24,216✔
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
{
85,526✔
312
    DPCTLSyclDeviceRef DRef = nullptr;
85,526✔
313
    auto Q = unwrap<queue>(QRef);
85,526✔
314
    if (Q) {
85,526✔
315
        try {
85,525✔
316
            auto Device = new device(Q->get_device());
85,525✔
317
            DRef = wrap<device>(Device);
85,525✔
318
        } catch (std::exception const &e) {
85,525✔
319
            error_handler(e, __FILE__, __func__, __LINE__);
×
320
        }
×
321
    }
85,525✔
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;
85,526✔
327
}
85,526✔
328

329
__dpctl_give DPCTLSyclContextRef
330
DPCTLQueue_GetContext(__dpctl_keep const DPCTLSyclQueueRef QRef)
331
{
87,200✔
332
    auto Q = unwrap<queue>(QRef);
87,200✔
333
    DPCTLSyclContextRef CRef = nullptr;
87,200✔
334
    if (Q)
87,200✔
335
        CRef = wrap<context>(new context(Q->get_context()));
87,190✔
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;
87,200✔
341
}
87,200✔
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 (DepEvents)
22!
414
                for (auto i = 0ul; i < NDepEvents; ++i) {
44✔
415
                    auto ei = unwrap<event>(DepEvents[i]);
22✔
416
                    if (ei)
22!
417
                        cgh.depends_on(*ei);
22✔
418
                }
22✔
419

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

450
    return wrap<event>(new event(std::move(e)));
22✔
451
}
22✔
452

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

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

491
__dpctl_give DPCTLSyclEventRef
492
DPCTLQueue_MemcpyWithEvents(__dpctl_keep const DPCTLSyclQueueRef QRef,
493
                            void *Dest,
494
                            const void *Src,
495
                            size_t Count,
496
                            const DPCTLSyclEventRef *DepEvents,
497
                            size_t DepEventsCount)
498
{
58✔
499
    event ev;
58✔
500
    auto Q = unwrap<queue>(QRef);
58✔
501
    if (Q) {
58✔
502
        try {
57✔
503
            ev = Q->submit([&](handler &cgh) {
57✔
504
                if (DepEvents)
57✔
505
                    for (size_t i = 0; i < DepEventsCount; ++i) {
98✔
506
                        event *ei = unwrap<event>(DepEvents[i]);
49✔
507
                        if (ei)
49!
508
                            cgh.depends_on(*ei);
49✔
509
                    }
49✔
510

511
                cgh.memcpy(Dest, Src, Count);
57✔
512
            });
57✔
513
        } catch (const std::exception &ex) {
57✔
514
            error_handler(ex, __FILE__, __func__, __LINE__);
8✔
515
            return nullptr;
8✔
516
        }
8✔
517
    }
57✔
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

524
    return wrap<event>(new event(ev));
49✔
525
}
58✔
526

527
__dpctl_give DPCTLSyclEventRef
528
DPCTLQueue_Prefetch(__dpctl_keep DPCTLSyclQueueRef QRef,
529
                    const void *Ptr,
530
                    size_t Count)
531
{
16✔
532
    auto Q = unwrap<queue>(QRef);
16✔
533
    if (Q) {
16✔
534
        if (Ptr) {
15✔
535
            sycl::event ev;
7✔
536
            try {
7✔
537
                ev = Q->prefetch(Ptr, Count);
7✔
538
            } catch (std::exception const &e) {
7✔
UNCOV
539
                error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
540
                return nullptr;
×
UNCOV
541
            }
×
542
            return wrap<event>(new event(std::move(ev)));
7✔
543
        }
7✔
544
        else {
8✔
545
            error_handler("Attempt to prefetch USM-allocation at nullptr.",
8✔
546
                          __FILE__, __func__, __LINE__);
8✔
547
            return nullptr;
8✔
548
        }
8✔
549
    }
15✔
550
    else {
1✔
551
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1✔
552
                      __LINE__);
1✔
553
        return nullptr;
1✔
554
    }
1✔
555
}
16✔
556

557
__dpctl_give DPCTLSyclEventRef
558
DPCTLQueue_MemAdvise(__dpctl_keep DPCTLSyclQueueRef QRef,
559
                     const void *Ptr,
560
                     size_t Count,
561
                     int Advice)
562
{
16✔
563
    auto Q = unwrap<queue>(QRef);
16✔
564
    if (Q) {
16✔
565
        sycl::event ev;
15✔
566
        try {
15✔
567
            ev = Q->mem_advise(Ptr, Count, Advice);
15✔
568
        } catch (std::exception const &e) {
15✔
UNCOV
569
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
570
            return nullptr;
×
UNCOV
571
        }
×
572
        return wrap<event>(new event(std::move(ev)));
15✔
573
    }
15✔
574
    else {
1✔
575
        error_handler("QRef passed to prefetch was NULL.", __FILE__, __func__,
1✔
576
                      __LINE__);
1✔
577
        return nullptr;
1✔
578
    }
1✔
579
}
16✔
580

581
bool DPCTLQueue_IsInOrder(__dpctl_keep const DPCTLSyclQueueRef QRef)
582
{
800✔
583
    auto Q = unwrap<queue>(QRef);
800✔
584
    if (Q) {
800✔
585
        return Q->is_in_order();
799✔
586
    }
799✔
587
    else
1✔
588
        return false;
1✔
589
}
800✔
590

591
bool DPCTLQueue_HasEnableProfiling(__dpctl_keep const DPCTLSyclQueueRef QRef)
592
{
56✔
593
    auto Q = unwrap<queue>(QRef);
56✔
594
    if (Q) {
56✔
595
        return Q->has_property<sycl::property::queue::enable_profiling>();
55✔
596
    }
55✔
597
    else
1✔
598
        return false;
1✔
599
}
56✔
600

601
size_t DPCTLQueue_Hash(__dpctl_keep const DPCTLSyclQueueRef QRef)
602
{
38✔
603
    auto Q = unwrap<queue>(QRef);
38✔
604
    if (Q) {
38✔
605
        std::hash<queue> hash_fn;
35✔
606
        return hash_fn(*Q);
35✔
607
    }
35✔
608
    else {
3✔
609
        error_handler("Argument QRef is NULL.", __FILE__, __func__, __LINE__);
3✔
610
        return 0;
3✔
611
    }
3✔
612
}
38✔
613

614
__dpctl_give DPCTLSyclEventRef DPCTLQueue_SubmitBarrierForEvents(
615
    __dpctl_keep const DPCTLSyclQueueRef QRef,
616
    __dpctl_keep const DPCTLSyclEventRef *DepEvents,
617
    size_t NDepEvents)
618
{
105✔
619
    auto Q = unwrap<queue>(QRef);
105✔
620
    event e;
105✔
621
    if (Q) {
105!
622
        try {
105✔
623
            e = Q->submit([&](handler &cgh) {
105✔
624
                // Depend on any event that was specified by the caller.
625
                if (NDepEvents)
105✔
626
                    for (auto i = 0ul; i < NDepEvents; ++i)
20✔
627
                        cgh.depends_on(*unwrap<event>(DepEvents[i]));
13✔
628

629
                cgh.ext_oneapi_barrier();
105✔
630
            });
105✔
631
        } catch (std::exception const &e) {
105✔
UNCOV
632
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
633
            return nullptr;
×
UNCOV
634
        }
×
635

636
        return wrap<event>(new event(std::move(e)));
105✔
637
    }
105✔
UNCOV
638
    else {
×
UNCOV
639
        error_handler("Argument QRef is NULL", __FILE__, __func__, __LINE__);
×
UNCOV
640
        return nullptr;
×
UNCOV
641
    }
×
642
}
105✔
643

644
__dpctl_give DPCTLSyclEventRef
645
DPCTLQueue_SubmitBarrier(__dpctl_keep const DPCTLSyclQueueRef QRef)
646
{
1✔
647
    return DPCTLQueue_SubmitBarrierForEvents(QRef, nullptr, 0);
1✔
648
}
1✔
649

650
__dpctl_give DPCTLSyclEventRef
651
DPCTLQueue_Memset(__dpctl_keep const DPCTLSyclQueueRef QRef,
652
                  void *USMRef,
653
                  uint8_t Value,
654
                  size_t Count)
655
{
3,099✔
656
    auto Q = unwrap<queue>(QRef);
3,099✔
657
    if (Q && USMRef) {
3,099!
658
        sycl::event ev;
3,098✔
659
        try {
3,098✔
660
            ev = Q->memset(USMRef, static_cast<int>(Value), Count);
3,098✔
661
        } catch (std::exception const &e) {
3,098✔
UNCOV
662
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
663
            return nullptr;
×
UNCOV
664
        }
×
665
        return wrap<event>(new event(std::move(ev)));
3,098✔
666
    }
3,098✔
667
    else {
1✔
668
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1✔
669
                      __func__, __LINE__);
1✔
670
        return nullptr;
1✔
671
    }
1✔
672
};
3,099✔
673

674
__dpctl_give DPCTLSyclEventRef
675
DPCTLQueue_Fill8(__dpctl_keep const DPCTLSyclQueueRef QRef,
676
                 void *USMRef,
677
                 uint8_t Value,
678
                 size_t Count)
679
{
9✔
680
    auto Q = unwrap<queue>(QRef);
9✔
681
    if (Q && USMRef) {
9!
682
        sycl::event ev;
8✔
683
        try {
8✔
684
            ev = Q->fill<uint8_t>(USMRef, Value, Count);
8✔
685
        } catch (std::exception const &e) {
8✔
UNCOV
686
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
687
            return nullptr;
×
UNCOV
688
        }
×
689
        return wrap<event>(new event(std::move(ev)));
8✔
690
    }
8✔
691
    else {
1✔
692
        error_handler("QRef or USMRef passed to fill8 were NULL.", __FILE__,
1✔
693
                      __func__, __LINE__);
1✔
694
        return nullptr;
1✔
695
    }
1✔
696
}
9✔
697

698
__dpctl_give DPCTLSyclEventRef
699
DPCTLQueue_Fill16(__dpctl_keep const DPCTLSyclQueueRef QRef,
700
                  void *USMRef,
701
                  uint16_t Value,
702
                  size_t Count)
703
{
9✔
704
    auto Q = unwrap<queue>(QRef);
9✔
705
    if (Q && USMRef) {
9!
706
        sycl::event ev;
8✔
707
        try {
8✔
708
            ev = Q->fill<uint16_t>(USMRef, Value, Count);
8✔
709
        } catch (std::exception const &e) {
8✔
UNCOV
710
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
711
            return nullptr;
×
UNCOV
712
        }
×
713
        return wrap<event>(new event(std::move(ev)));
8✔
714
    }
8✔
715
    else {
1✔
716
        error_handler("QRef or USMRef passed to fill16 were NULL.", __FILE__,
1✔
717
                      __func__, __LINE__);
1✔
718
        return nullptr;
1✔
719
    }
1✔
720
}
9✔
721

722
__dpctl_give DPCTLSyclEventRef
723
DPCTLQueue_Fill32(__dpctl_keep const DPCTLSyclQueueRef QRef,
724
                  void *USMRef,
725
                  uint32_t Value,
726
                  size_t Count)
727
{
9✔
728
    auto Q = unwrap<queue>(QRef);
9✔
729
    if (Q && USMRef) {
9!
730
        sycl::event ev;
8✔
731
        try {
8✔
732
            ev = Q->fill<uint32_t>(USMRef, Value, Count);
8✔
733
        } catch (std::exception const &e) {
8✔
UNCOV
734
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
735
            return nullptr;
×
UNCOV
736
        }
×
737
        return wrap<event>(new event(std::move(ev)));
8✔
738
    }
8✔
739
    else {
1✔
740
        error_handler("QRef or USMRef passed to fill32 were NULL.", __FILE__,
1✔
741
                      __func__, __LINE__);
1✔
742
        return nullptr;
1✔
743
    }
1✔
744
}
9✔
745

746
__dpctl_give DPCTLSyclEventRef
747
DPCTLQueue_Fill64(__dpctl_keep const DPCTLSyclQueueRef QRef,
748
                  void *USMRef,
749
                  uint64_t Value,
750
                  size_t Count)
751
{
9✔
752
    auto Q = unwrap<queue>(QRef);
9✔
753
    if (Q && USMRef) {
9!
754
        sycl::event ev;
8✔
755
        try {
8✔
756
            ev = Q->fill<uint64_t>(USMRef, Value, Count);
8✔
757
        } catch (std::exception const &e) {
8✔
UNCOV
758
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
759
            return nullptr;
×
UNCOV
760
        }
×
761
        return wrap<event>(new event(std::move(ev)));
8✔
762
    }
8✔
763
    else {
1✔
764
        error_handler("QRef or USMRef passed to fill64 were NULL.", __FILE__,
1✔
765
                      __func__, __LINE__);
1✔
766
        return nullptr;
1✔
767
    }
1✔
768
}
9✔
769

770
__dpctl_give DPCTLSyclEventRef
771
DPCTLQueue_Fill128(__dpctl_keep const DPCTLSyclQueueRef QRef,
772
                   void *USMRef,
773
                   uint64_t *Value,
774
                   size_t Count)
775
{
9✔
776
    auto Q = unwrap<queue>(QRef);
9✔
777
    if (Q && USMRef) {
9!
778
        sycl::event ev;
8✔
779
        try {
8✔
780
            complexNumber Val;
8✔
781
            Val.real = Value[0];
8✔
782
            Val.imag = Value[1];
8✔
783
            ev = Q->fill(USMRef, Val, Count);
8✔
784
        } catch (std::exception const &e) {
8✔
UNCOV
785
            error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
786
            return nullptr;
×
UNCOV
787
        }
×
788
        return wrap<event>(new event(std::move(ev)));
8✔
789
    }
8✔
790
    else {
1✔
791
        error_handler("QRef or USMRef passed to fill128 were NULL.", __FILE__,
1✔
792
                      __func__, __LINE__);
1✔
793
        return nullptr;
1✔
794
    }
1✔
795
}
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