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

IntelPython / dpctl / 12520577393

27 Dec 2024 08:50PM UTC coverage: 87.659%. Remained the same
12520577393

Pull #1950

github

web-flow
Merge 75f114513 into 39a19c159
Pull Request #1950: [MAINT] Use `std::size_t` from `cstddef` and use `dpctl::tensor::ssize_t` where `ssize_t` is used

3120 of 3640 branches covered (85.71%)

Branch coverage included in aggregate %.

11810 of 13392 relevant lines covered (88.19%)

7083.2 hits per line

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

82.74
/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 <stddef.h>
32
#include <sycl/sycl.hpp>
33
#include <utility>
34
#include <vector>
35

36
using namespace sycl;
37

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

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

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

66
    return CRef;
25✔
67
}
25✔
68

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

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

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

96
    return CRef;
10✔
97
}
10✔
98

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

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

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

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

176
void DPCTLContext_Delete(__dpctl_take DPCTLSyclContextRef CtxRef)
177
{
266,843✔
178
    delete unwrap<context>(CtxRef);
266,843✔
179
}
266,843✔
180

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

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

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

204
size_t DPCTLContext_Hash(__dpctl_keep const DPCTLSyclContextRef CtxRef)
205
{
50,002✔
206
    if (CtxRef) {
50,002✔
207
        auto C = unwrap<context>(CtxRef);
50,001✔
208
        std::hash<context> hash_fn;
50,001✔
209
        return hash_fn(*C);
50,001✔
210
    }
50,001✔
211
    else {
1✔
212
        error_handler("Argument CtxRef is null.", __FILE__, __func__, __LINE__);
1✔
213
        return 0;
1✔
214
    }
1✔
215
}
50,002✔
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

© 2026 Coveralls, Inc