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

IntelPython / dpctl / 47405022849

04 Dec 2026 07:07PM UTC coverage: 76.45% (+1.3%) from 75.182%
47405022849

Pull #2440

github

web-flow
Merge 90ec03eae into aacf76633
Pull Request #2440: Add kernel bundle states, kernel ids and SYCL library loading

1203 of 1660 branches covered (72.47%)

Branch coverage included in aggregate %.

761 of 957 new or added lines in 4 files covered. (79.52%)

13 existing lines in 2 files now uncovered.

4809 of 6204 relevant lines covered (77.51%)

281.06 hits per line

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

88.89
/libsyclinterface/source/dpctl_sycl_kernel_interface.cpp
1
//===--- dpctl_sycl_kernel_interface.cpp - Implements C API for sycl::kernel =//
2
//
3
//                      Data Parallel Control (dpctl)
4
//
5
// Copyright 2020 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 functions declared in
23
/// dpctl_sycl_kernel_interface.h.
24
///
25
//===----------------------------------------------------------------------===//
26

27
#include "dpctl_sycl_kernel_interface.h"
28
#include "Config/dpctl_config.h"
29
#include "dpctl_error_handlers.h"
30
#include "dpctl_string_utils.hpp"
31
#include "dpctl_sycl_type_casters.hpp"
32
#include <algorithm>
33
#include <cstdint>
34
#include <memory>
35
#include <stddef.h>
36
#include <sycl/sycl.hpp> /* Sycl headers */
37
#include <vector>
38

39
using namespace sycl;
40

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

48
using namespace dpctl::syclinterface;
49

50
std::vector<device> kernel_devices(const kernel &Kernel)
51
{
186 ✔
52
#ifndef __ADAPTIVECPP__
186 ✔
53
    return Kernel.get_kernel_bundle().get_devices();
186 ✔
54
#else
55
    return Kernel.get_context().get_devices();
56
#endif
57
}
186 ✔
58

59
template <typename Param, typename RetT>
60
RetT get_device_specific_info(DPCTLSyclKernelRef KRef,
61
                              DPCTLSyclDeviceRef DRef,
62
                              bool RequireDevice,
63
                              const char *Fn)
64
{
178 ✔
65
    if (!KRef) {
178 ✔
66
        error_handler("Input DPCTKSyclKernelRef is nullptr.", __FILE__, Fn,
15 ✔
67
                      __LINE__);
15 ✔
68
        return 0;
15 ✔
69
    }
15 ✔
70
    if (RequireDevice && !DRef) {
163 ✔
71
        error_handler("Input DPCTLSyclDeviceRef is nullptr.", __FILE__, Fn,
1 ✔
72
                      __LINE__);
1 ✔
73
        return 0;
1 ✔
74
    }
1 ✔
75
    auto sycl_kern = unwrap<kernel>(KRef);
162 ✔
76
    try {
162 ✔
77
        auto devs = kernel_devices(*sycl_kern);
162 ✔
78
        if (devs.empty()) {
162 !
NEW
79
            error_handler("Input DPCTKSyclKernelRef has no associated device.",
×
NEW
80
                          __FILE__, Fn, __LINE__);
×
NEW
81
            return 0;
×
NEW
82
        }
×
83
        if (!DRef)
162 ✔
84
            return static_cast<RetT>(sycl_kern->get_info<Param>(devs[0]));
124 ✔
85
        const device &Dev = *unwrap<device>(DRef);
38 ✔
86
        // the SYCL runtime does not check the device, and a device of another
87
        // backend can crash it
88
        if (std::find(devs.begin(), devs.end(), Dev) == devs.end()) {
38 !
NEW
89
            error_handler("The device is not a device of the kernel bundle of "
×
NEW
90
                          "the kernel.",
×
NEW
91
                          __FILE__, Fn, __LINE__);
×
NEW
92
            return 0;
×
NEW
93
        }
×
94
        return static_cast<RetT>(sycl_kern->get_info<Param>(Dev));
38 ✔
95
    } catch (std::exception const &e) {
38 ✔
NEW
96
        error_handler(e, __FILE__, Fn, __LINE__);
×
NEW
97
        return 0;
×
NEW
98
    }
×
99
}
162 ✔
100
} // end of anonymous namespace
101

102
size_t DPCTLKernel_GetNumArgs(__dpctl_keep const DPCTLSyclKernelRef KRef)
103
{
122 ✔
104
    if (!KRef) {
122 ✔
105
        error_handler("Cannot get the number of arguments from "
1 ✔
106
                      "DPCTLSyclKernelRef as input is a nullptr.",
1 ✔
107
                      __FILE__, __func__, __LINE__);
1 ✔
108
        return -1;
1 ✔
109
    }
1 ✔
110

111
    auto sycl_kernel = unwrap<kernel>(KRef);
121 ✔
112
    try {
121 ✔
113
        auto num_args = sycl_kernel->get_info<info::kernel::num_args>();
121 ✔
114
        return static_cast<size_t>(num_args);
121 ✔
115
    } catch (std::exception const &e) {
121 ✔
116
        error_handler(e, __FILE__, __func__, __LINE__);
2 ✔
117
        return -1;
2 ✔
118
    }
2 ✔
119
}
121 ✔
120

121
void DPCTLKernel_Delete(__dpctl_take DPCTLSyclKernelRef KRef)
122
{
160 ✔
123
    delete unwrap<kernel>(KRef);
160 ✔
124
}
160 ✔
125

126
__dpctl_give DPCTLSyclKernelRef
127
DPCTLKernel_Copy(__dpctl_keep const DPCTLSyclKernelRef KRef)
128
{
14 ✔
129
    auto Kernel = unwrap<kernel>(KRef);
14 ✔
130
    if (!Kernel) {
14 ✔
131
        error_handler("Cannot copy DPCTLSyclKernelRef as input is a nullptr",
1 ✔
132
                      __FILE__, __func__, __LINE__);
1 ✔
133
        return nullptr;
1 ✔
134
    }
1 ✔
135
    try {
13 ✔
136
        auto CopiedKernel = new kernel(*Kernel);
13 ✔
137
        return wrap<kernel>(CopiedKernel);
13 ✔
138
    } catch (std::exception const &e) {
13 ✔
139
        error_handler(e, __FILE__, __func__, __LINE__);
×
140
        return nullptr;
×
141
    }
×
142
}
13 ✔
143

144
__dpctl_give DPCTLDeviceVectorRef
145
DPCTLKernel_GetDevices(__dpctl_keep const DPCTLSyclKernelRef KRef)
146
{
25 ✔
147
    if (!KRef) {
25 ✔
148
        error_handler("Input DPCTKSyclKernelRef is nullptr.", __FILE__,
1 ✔
149
                      __func__, __LINE__);
1 ✔
150
        return nullptr;
1 ✔
151
    }
1 ✔
152
    try {
24 ✔
153
        auto devs = kernel_devices(*unwrap<kernel>(KRef));
24 ✔
154
        auto DV = std::make_unique<std::vector<DPCTLSyclDeviceRef>>();
24 ✔
155
        DV->reserve(devs.size());
24 ✔
156
        for (const auto &D : devs)
24 ✔
157
            DV->push_back(wrap<device>(new device(D)));
24 ✔
158
        return wrap<std::vector<DPCTLSyclDeviceRef>>(DV.release());
24 ✔
159
    } catch (std::exception const &e) {
24 ✔
NEW
160
        error_handler(e, __FILE__, __func__, __LINE__);
×
NEW
161
        return nullptr;
×
UNCOV
162
    }
×
163
}
24 ✔
164

165
size_t DPCTLKernel_GetWorkGroupSize(__dpctl_keep const DPCTLSyclKernelRef KRef)
166
{
41 ✔
167
    return get_device_specific_info<
41 ✔
168
        info::kernel_device_specific::work_group_size, size_t>(KRef, nullptr,
41 ✔
169
                                                               false, __func__);
41 ✔
170
}
41 ✔
171

172
size_t DPCTLKernel_GetWorkGroupSizeForDevice(
173
    __dpctl_keep const DPCTLSyclKernelRef KRef,
174
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
175
{
10 ✔
176
    return get_device_specific_info<
10 ✔
177
        info::kernel_device_specific::work_group_size, size_t>(KRef, DRef, true,
10 ✔
178
                                                               __func__);
10 ✔
179
}
10 ✔
180

181
size_t DPCTLKernel_GetPreferredWorkGroupSizeMultiple(
182
    __dpctl_keep const DPCTLSyclKernelRef KRef)
183
{
15 ✔
184
    return get_device_specific_info<
15 ✔
185
        info::kernel_device_specific::preferred_work_group_size_multiple,
15 ✔
186
        size_t>(KRef, nullptr, false, __func__);
15 ✔
187
}
15 ✔
188

189
size_t DPCTLKernel_GetPreferredWorkGroupSizeMultipleForDevice(
190
    __dpctl_keep const DPCTLSyclKernelRef KRef,
191
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
192
{
6 ✔
193
    return get_device_specific_info<
6 ✔
194
        info::kernel_device_specific::preferred_work_group_size_multiple,
6 ✔
195
        size_t>(KRef, DRef, true, __func__);
6 ✔
196
}
6 ✔
197

198
size_t DPCTLKernel_GetPrivateMemSize(__dpctl_keep const DPCTLSyclKernelRef KRef)
199
{
15 ✔
200
    return get_device_specific_info<
15 ✔
201
        info::kernel_device_specific::private_mem_size, size_t>(
15 ✔
202
        KRef, nullptr, false, __func__);
15 ✔
203
}
15 ✔
204

205
size_t DPCTLKernel_GetPrivateMemSizeForDevice(
206
    __dpctl_keep const DPCTLSyclKernelRef KRef,
207
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
208
{
6 ✔
209
    return get_device_specific_info<
6 ✔
210
        info::kernel_device_specific::private_mem_size, size_t>(KRef, DRef,
6 ✔
211
                                                                true, __func__);
6 ✔
212
}
6 ✔
213

214
uint32_t
215
DPCTLKernel_GetMaxNumSubGroups(__dpctl_keep const DPCTLSyclKernelRef KRef)
216
{
15 ✔
217
    return get_device_specific_info<
15 ✔
218
        info::kernel_device_specific::max_num_sub_groups, uint32_t>(
15 ✔
219
        KRef, nullptr, false, __func__);
15 ✔
220
}
15 ✔
221

222
uint32_t DPCTLKernel_GetMaxNumSubGroupsForDevice(
223
    __dpctl_keep const DPCTLSyclKernelRef KRef,
224
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
225
{
6 ✔
226
    return get_device_specific_info<
6 ✔
227
        info::kernel_device_specific::max_num_sub_groups, uint32_t>(
6 ✔
228
        KRef, DRef, true, __func__);
6 ✔
229
}
6 ✔
230

231
uint32_t
232
DPCTLKernel_GetMaxSubGroupSize(__dpctl_keep const DPCTLSyclKernelRef KRef)
233
{
15 ✔
234
    return get_device_specific_info<
15 ✔
235
        info::kernel_device_specific::max_sub_group_size, uint32_t>(
15 ✔
236
        KRef, nullptr, false, __func__);
15 ✔
237
}
15 ✔
238

239
uint32_t DPCTLKernel_GetMaxSubGroupSizeForDevice(
240
    __dpctl_keep const DPCTLSyclKernelRef KRef,
241
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
242
{
7 ✔
243
    return get_device_specific_info<
7 ✔
244
        info::kernel_device_specific::max_sub_group_size, uint32_t>(
7 ✔
245
        KRef, DRef, true, __func__);
7 ✔
246
}
7 ✔
247

248
uint32_t
249
DPCTLKernel_GetCompileNumSubGroups(__dpctl_keep const DPCTLSyclKernelRef KRef)
250
{
15 ✔
251
    return get_device_specific_info<
15 ✔
252
        info::kernel_device_specific::compile_num_sub_groups, uint32_t>(
15 ✔
253
        KRef, nullptr, false, __func__);
15 ✔
254
}
15 ✔
255

256
uint32_t DPCTLKernel_GetCompileNumSubGroupsForDevice(
257
    __dpctl_keep const DPCTLSyclKernelRef KRef,
258
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
259
{
6 ✔
260
    return get_device_specific_info<
6 ✔
261
        info::kernel_device_specific::compile_num_sub_groups, uint32_t>(
6 ✔
262
        KRef, DRef, true, __func__);
6 ✔
263
}
6 ✔
264

265
uint32_t
266
DPCTLKernel_GetCompileSubGroupSize(__dpctl_keep const DPCTLSyclKernelRef KRef)
267
{
15 ✔
268
    return get_device_specific_info<
15 ✔
269
        info::kernel_device_specific::compile_sub_group_size, uint32_t>(
15 ✔
270
        KRef, nullptr, false, __func__);
15 ✔
271
}
15 ✔
272

273
uint32_t DPCTLKernel_GetCompileSubGroupSizeForDevice(
274
    __dpctl_keep const DPCTLSyclKernelRef KRef,
275
    __dpctl_keep const DPCTLSyclDeviceRef DRef)
276
{
6 ✔
277
    return get_device_specific_info<
6 ✔
278
        info::kernel_device_specific::compile_sub_group_size, uint32_t>(
6 ✔
279
        KRef, DRef, true, __func__);
6 ✔
280
}
6 ✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc