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

IntelPython / dpctl / 4094432397

pending completion
4094432397

push

github

GitHub
Merge pull request #1061 from IntelPython/fix/DPCTLUSM_GetPointerType

1566 of 1978 branches covered (79.17%)

Branch coverage included in aggregate %.

14 of 16 new or added lines in 2 files covered. (87.5%)

1 existing line in 1 file now uncovered.

6885 of 8302 relevant lines covered (82.93%)

600.35 hits per line

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

88.57
/libsyclinterface/source/dpctl_sycl_usm_interface.cpp
1
//===------ dpctl_sycl_usm_interface.cpp - Implements C API for USM ops    ===//
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_usm_interface.h.
24
///
25
//===----------------------------------------------------------------------===//
26

27
#include "dpctl_sycl_usm_interface.h"
28
#include "Config/dpctl_config.h"
29
#include "dpctl_error_handlers.h"
30
#include "dpctl_sycl_device_interface.h"
31
#include "dpctl_sycl_type_casters.hpp"
32
#include <CL/sycl.hpp> /* SYCL headers   */
33

34
using namespace sycl;
35

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

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

44
__dpctl_give DPCTLSyclUSMRef
45
DPCTLmalloc_shared(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef)
46
{
827✔
47
    if (!QRef) {
827✔
48
        error_handler("Input QRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
49
        return nullptr;
1✔
50
    }
1✔
51
    try {
826✔
52
        auto Q = unwrap<queue>(QRef);
826✔
53
        auto Ptr = malloc_shared(size, *Q);
826✔
54
        return wrap<void>(Ptr);
826✔
55
    } catch (std::exception const &e) {
826✔
56
        error_handler(e, __FILE__, __func__, __LINE__);
×
57
        return nullptr;
×
58
    }
×
59
}
826✔
60

61
__dpctl_give DPCTLSyclUSMRef
62
DPCTLaligned_alloc_shared(size_t alignment,
63
                          size_t size,
64
                          __dpctl_keep const DPCTLSyclQueueRef QRef)
65
{
12✔
66
    if (!QRef) {
12✔
67
        error_handler("Input QRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
68
        return nullptr;
1✔
69
    }
1✔
70
    try {
11✔
71
        auto Q = unwrap<queue>(QRef);
11✔
72
        auto Ptr = aligned_alloc_shared(alignment, size, *Q);
11✔
73
        return wrap<void>(Ptr);
11✔
74
    } catch (std::exception const &e) {
11✔
75
        error_handler(e, __FILE__, __func__, __LINE__);
×
76
        return nullptr;
×
77
    }
×
78
}
11✔
79

80
__dpctl_give DPCTLSyclUSMRef
81
DPCTLmalloc_host(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef)
82
{
2,785✔
83
    if (!QRef) {
2,785✔
84
        error_handler("Input QRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
85
        return nullptr;
1✔
86
    }
1✔
87
    // SYCL 2020 spec: for devices without aspect::usm_host_allocations:
88
    // undefined behavior
89
    auto Q = unwrap<queue>(QRef);
2,784✔
90
    auto Ptr = malloc_host(size, *Q);
2,784✔
91
    return wrap<void>(Ptr);
2,784✔
92
}
2,785✔
93

94
__dpctl_give DPCTLSyclUSMRef
95
DPCTLaligned_alloc_host(size_t alignment,
96
                        size_t size,
97
                        __dpctl_keep const DPCTLSyclQueueRef QRef)
98
{
7✔
99
    if (!QRef) {
7✔
100
        error_handler("Input QRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
101
        return nullptr;
1✔
102
    }
1✔
103
    // SYCL 2020 spec: for devices without aspect::usm_host_allocations:
104
    // undefined behavior
105
    auto Q = unwrap<queue>(QRef);
6✔
106
    auto Ptr = aligned_alloc_host(alignment, size, *Q);
6✔
107
    return wrap<void>(Ptr);
6✔
108
}
7✔
109

110
__dpctl_give DPCTLSyclUSMRef
111
DPCTLmalloc_device(size_t size, __dpctl_keep const DPCTLSyclQueueRef QRef)
112
{
1,973✔
113
    if (!QRef) {
1,973✔
114
        error_handler("Input QRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
115
        return nullptr;
1✔
116
    }
1✔
117
    try {
1,972✔
118
        auto Q = unwrap<queue>(QRef);
1,972✔
119
        auto Ptr = malloc_device(size, *Q);
1,972✔
120
        return wrap<void>(Ptr);
1,972✔
121
    } catch (std::exception const &e) {
1,972✔
122
        error_handler(e, __FILE__, __func__, __LINE__);
×
123
        return nullptr;
×
124
    }
×
125
}
1,972✔
126

127
__dpctl_give DPCTLSyclUSMRef
128
DPCTLaligned_alloc_device(size_t alignment,
129
                          size_t size,
130
                          __dpctl_keep const DPCTLSyclQueueRef QRef)
131
{
7✔
132
    if (!QRef) {
7✔
133
        error_handler("Input QRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
134
        return nullptr;
1✔
135
    }
1✔
136
    try {
6✔
137
        auto Q = unwrap<queue>(QRef);
6✔
138
        auto Ptr = aligned_alloc_device(alignment, size, *Q);
6✔
139
        return wrap<void>(Ptr);
6✔
140
    } catch (std::exception const &e) {
6✔
141
        error_handler(e, __FILE__, __func__, __LINE__);
×
142
        return nullptr;
×
143
    }
×
144
}
6✔
145

146
void DPCTLfree_with_queue(__dpctl_take DPCTLSyclUSMRef MRef,
147
                          __dpctl_keep const DPCTLSyclQueueRef QRef)
148
{
5,605✔
149
    if (!QRef) {
5,605✔
150
        error_handler("Input QRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
151
        return;
1✔
152
    }
1✔
153
    if (!MRef) {
5,604✔
154
        error_handler("Input MRef is nullptr, nothing to free.", __FILE__,
1✔
155
                      __func__, __LINE__);
1✔
156
        return;
1✔
157
    }
1✔
158
    auto Ptr = unwrap<void>(MRef);
5,603✔
159
    auto Q = unwrap<queue>(QRef);
5,603✔
160
    free(Ptr, *Q);
5,603✔
161
}
5,603✔
162

163
void DPCTLfree_with_context(__dpctl_take DPCTLSyclUSMRef MRef,
164
                            __dpctl_keep const DPCTLSyclContextRef CRef)
165
{
2✔
166
    if (!CRef) {
2✔
167
        error_handler("Input CRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
168
        return;
1✔
169
    }
1✔
170
    if (!MRef) {
1!
171
        error_handler("Input MRef is nullptr, nothing to free.", __FILE__,
1✔
172
                      __func__, __LINE__);
1✔
173
        return;
1✔
174
    }
1✔
175
    auto Ptr = unwrap<void>(MRef);
×
176
    auto C = unwrap<context>(CRef);
×
177
    free(Ptr, *C);
×
178
}
×
179

180
DPCTLSyclUSMType
181
DPCTLUSM_GetPointerType(__dpctl_keep const DPCTLSyclUSMRef MRef,
182
                        __dpctl_keep const DPCTLSyclContextRef CRef)
183
{
12,294✔
184
    if (!CRef) {
12,294✔
185
        error_handler("Input CRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
186
        return DPCTLSyclUSMType::DPCTL_USM_UNKNOWN;
1✔
187
    }
1✔
188
    if (!MRef) {
12,293✔
189
        error_handler("Input MRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
190
        return DPCTLSyclUSMType::DPCTL_USM_UNKNOWN;
1✔
191
    }
1✔
192
    auto Ptr = unwrap<void>(MRef);
12,292✔
193
    auto C = unwrap<context>(CRef);
12,292✔
194

195
    auto kind = get_pointer_type(Ptr, *C);
12,292✔
196
    switch (kind) {
12,292✔
197
    case usm::alloc::host:
4,868✔
198
        return DPCTLSyclUSMType::DPCTL_USM_HOST;
4,868✔
199
    case usm::alloc::device:
4,474✔
200
        return DPCTLSyclUSMType::DPCTL_USM_DEVICE;
4,474✔
201
    case usm::alloc::shared:
2,950✔
202
        return DPCTLSyclUSMType::DPCTL_USM_SHARED;
2,950✔
203
    default:
×
NEW
204
        return DPCTLSyclUSMType::DPCTL_USM_UNKNOWN;
×
205
    }
12,292✔
206
}
12,292✔
207

208
DPCTLSyclDeviceRef
209
DPCTLUSM_GetPointerDevice(__dpctl_keep const DPCTLSyclUSMRef MRef,
210
                          __dpctl_keep const DPCTLSyclContextRef CRef)
211
{
483✔
212
    if (!CRef) {
483✔
213
        error_handler("Input CRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
214
        return nullptr;
1✔
215
    }
1✔
216
    if (!MRef) {
482✔
217
        error_handler("Input MRef is nullptr.", __FILE__, __func__, __LINE__);
1✔
218
        return nullptr;
1✔
219
    }
1✔
220

221
    auto Ptr = unwrap<void>(MRef);
481✔
222
    auto C = unwrap<context>(CRef);
481✔
223

224
    auto Dev = get_pointer_device(Ptr, *C);
481✔
225

226
    return wrap<device>(new device(Dev));
481✔
227
}
482✔
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