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

IntelPython / dpctl / 9703092705

27 Jun 2024 08:21PM UTC coverage: 87.902% (-0.2%) from 88.057%
9703092705

push

github

web-flow
Merge pull request #1720 from IntelPython/fix-broadcast-arrays-no-args

Improve exception raised by `broadcast_arrays` with no arguments

3275 of 3767 branches covered (86.94%)

Branch coverage included in aggregate %.

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

24 existing lines in 7 files now uncovered.

11191 of 12690 relevant lines covered (88.19%)

7379.88 hits per line

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

84.15
/libsyclinterface/source/dpctl_sycl_context_interface.cpp
1
//===- dpctl_sycl_context_interface.cpp - Implements C API for sycl::context =//
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_context_interface.h.
24
///
25
//===----------------------------------------------------------------------===//
26

27
#include "dpctl_sycl_context_interface.h"
28
#include "Config/dpctl_config.h"
29
#include "dpctl_error_handlers.h"
30
#include "dpctl_sycl_type_casters.hpp"
31
#include <sycl/sycl.hpp>
32
#include <utility>
33
#include <vector>
34

35
using namespace sycl;
36

37
namespace
38
{
39
static_assert(__SYCL_COMPILER_VERSION >= __SYCL_COMPILER_VERSION_REQUIRED,
40
              "The compiler does not meet minimum version requirement");
41

42
using namespace dpctl::syclinterface;
43
} // end of anonymous namespace
44

45
__dpctl_give DPCTLSyclContextRef
46
DPCTLContext_Create(__dpctl_keep const DPCTLSyclDeviceRef DRef,
47
                    error_handler_callback *handler,
48
                    int /**/)
49
{
26✔
50
    DPCTLSyclContextRef CRef = nullptr;
26✔
51
    auto Device = unwrap<device>(DRef);
26✔
52
    if (!Device) {
26✔
53
        error_handler("Cannot create device from DPCTLSyclDeviceRef"
1✔
54
                      "as input is a nullptr.",
1✔
55
                      __FILE__, __func__, __LINE__);
1✔
56
        return nullptr;
1✔
57
    }
1✔
58
    try {
25✔
59
        CRef = wrap<context>(
25✔
60
            new context(*Device, DPCTL_AsyncErrorHandler(handler)));
25✔
61
    } catch (std::exception const &e) {
25✔
62
        error_handler(e, __FILE__, __func__, __LINE__);
×
63
    }
×
64

65
    return CRef;
25✔
66
}
25✔
67

68
__dpctl_give DPCTLSyclContextRef
69
DPCTLContext_CreateFromDevices(__dpctl_keep const DPCTLDeviceVectorRef DVRef,
70
                               error_handler_callback *handler,
71
                               int /**/)
72
{
11✔
73
    DPCTLSyclContextRef CRef = nullptr;
11✔
74
    std::vector<device> Devices;
11✔
75
    auto DeviceRefs = unwrap<std::vector<DPCTLSyclDeviceRef>>(DVRef);
11✔
76
    if (!DeviceRefs) {
11✔
77
        error_handler("Cannot create device reference from DPCTLDeviceVectorRef"
1✔
78
                      "as input is a nullptr.",
1✔
79
                      __FILE__, __func__, __LINE__);
1✔
80
        return CRef;
1✔
81
    }
1✔
82
    Devices.reserve(DeviceRefs->size());
10✔
83

84
    for (auto const &DRef : *DeviceRefs) {
21✔
85
        Devices.emplace_back(*unwrap<device>(DRef));
21✔
86
    }
21✔
87

88
    try {
10✔
89
        CRef = wrap<context>(
10✔
90
            new context(std::move(Devices), DPCTL_AsyncErrorHandler(handler)));
10✔
91
    } catch (std::exception const &e) {
10✔
UNCOV
92
        error_handler(e, __FILE__, __func__, __LINE__);
×
UNCOV
93
    }
×
94

95
    return CRef;
10✔
96
}
10✔
97

98
bool DPCTLContext_AreEq(__dpctl_keep const DPCTLSyclContextRef CtxRef1,
99
                        __dpctl_keep const DPCTLSyclContextRef CtxRef2)
100
{
131,576✔
101
    if (!(CtxRef1 && CtxRef2)) {
131,576!
102
        error_handler("DPCTLSyclContextRefs are nullptr.", __FILE__, __func__,
1✔
103
                      __LINE__);
1✔
104
        return false;
1✔
105
    }
1✔
106
    return (*unwrap<context>(CtxRef1) == *unwrap<context>(CtxRef2));
131,575✔
107
}
131,576✔
108

109
__dpctl_give DPCTLSyclContextRef
110
DPCTLContext_Copy(__dpctl_keep const DPCTLSyclContextRef CRef)
111
{
129,398✔
112
    auto Context = unwrap<context>(CRef);
129,398✔
113
    if (!Context) {
129,398✔
114
        error_handler("Cannot copy DPCTLSyclContextRef as input is a nullptr.",
1✔
115
                      __FILE__, __func__, __LINE__);
1✔
116
        return nullptr;
1✔
117
    }
1✔
118
    try {
129,397✔
119
        auto CopiedContext = new context(*Context);
129,397✔
120
        return wrap<context>(CopiedContext);
129,397✔
121
    } catch (std::exception const &e) {
129,397✔
122
        error_handler(e, __FILE__, __func__, __LINE__);
×
123
        return nullptr;
×
124
    }
×
125
}
129,397✔
126

127
__dpctl_give DPCTLDeviceVectorRef
128
DPCTLContext_GetDevices(__dpctl_keep const DPCTLSyclContextRef CRef)
129
{
23✔
130
    auto Context = unwrap<context>(CRef);
23✔
131
    if (!Context) {
23✔
132
        error_handler("Cannot retrieve devices from DPCTLSyclContextRef as "
1✔
133
                      "input is a nullptr.",
1✔
134
                      __FILE__, __func__, __LINE__);
1✔
135
        return nullptr;
1✔
136
    }
1✔
137
    using vecTy = std::vector<DPCTLSyclDeviceRef>;
22✔
138
    vecTy *DevicesVectorPtr = nullptr;
22✔
139
    try {
22✔
140
        DevicesVectorPtr = new vecTy();
22✔
141
    } catch (std::exception const &e) {
22✔
142
        delete DevicesVectorPtr;
×
143
        error_handler(e, __FILE__, __func__, __LINE__);
×
144
        return nullptr;
×
145
    }
×
146
    try {
22✔
147
        auto Devices = Context->get_devices();
22✔
148
        DevicesVectorPtr->reserve(Devices.size());
22✔
149
        for (const auto &Dev : Devices) {
26✔
150
            DevicesVectorPtr->emplace_back(
26✔
151
                wrap<device>(new device(std::move(Dev))));
26✔
152
        }
26✔
153
        return wrap<vecTy>(DevicesVectorPtr);
22✔
154
    } catch (std::exception const &e) {
22✔
155
        delete DevicesVectorPtr;
×
156
        error_handler(e, __FILE__, __func__, __LINE__);
×
157
        return nullptr;
×
158
    }
×
159
}
22✔
160

161
size_t DPCTLContext_DeviceCount(__dpctl_keep const DPCTLSyclContextRef CRef)
162
{
15✔
163
    auto Context = unwrap<context>(CRef);
15✔
164
    if (!Context) {
15✔
165
        error_handler("Cannot retrieve devices from DPCTLSyclContextRef as "
1✔
166
                      "input is a nullptr.",
1✔
167
                      __FILE__, __func__, __LINE__);
1✔
168
        return 0;
1✔
169
    }
1✔
170
    const auto Devices = Context->get_devices();
14✔
171
    return Devices.size();
14✔
172
}
15✔
173

174
void DPCTLContext_Delete(__dpctl_take DPCTLSyclContextRef CtxRef)
175
{
259,965✔
176
    delete unwrap<context>(CtxRef);
259,965✔
177
}
259,965✔
178

179
DPCTLSyclBackendType
180
DPCTLContext_GetBackend(__dpctl_keep const DPCTLSyclContextRef CtxRef)
181
{
14✔
182
    if (!CtxRef) {
14✔
183
        return DPCTL_UNKNOWN_BACKEND;
1✔
184
    }
1✔
185

186
    auto BE = unwrap<context>(CtxRef)->get_platform().get_backend();
13✔
187

188
    switch (BE) {
13✔
189
    case backend::opencl:
13!
190
        return DPCTL_OPENCL;
13✔
191
    case backend::ext_oneapi_level_zero:
×
192
        return DPCTL_LEVEL_ZERO;
×
193
    case backend::ext_oneapi_cuda:
×
194
        return DPCTL_CUDA;
×
195
    default:
×
196
        return DPCTL_UNKNOWN_BACKEND;
×
197
    }
13✔
198
}
13✔
199

200
size_t DPCTLContext_Hash(__dpctl_keep const DPCTLSyclContextRef CtxRef)
201
{
47,848✔
202
    if (CtxRef) {
47,848✔
203
        auto C = unwrap<context>(CtxRef);
47,847✔
204
        std::hash<context> hash_fn;
47,847✔
205
        return hash_fn(*C);
47,847✔
206
    }
47,847✔
207
    else {
1✔
208
        error_handler("Argument CtxRef is null.", __FILE__, __func__, __LINE__);
1✔
209
        return 0;
1✔
210
    }
1✔
211
}
47,848✔
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