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

IntelPython / dpnp / 5134050444

pending completion
5134050444

Pull #1388

github

web-flow
Merge ce3f60310 into 340ec405e
Pull Request #1388: Add type dispatching to pybind11 extension of dpnp.linalg.eigh()

7401 of 26555 branches covered (27.87%)

Branch coverage included in aggregate %.

11535 of 17686 relevant lines covered (65.22%)

39511.07 hits per line

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

32.61
/dpnp/backend/src/queue_sycl.cpp
1
//*****************************************************************************
2
// Copyright (c) 2016-2023, Intel Corporation
3
// All rights reserved.
4
//
5
// Redistribution and use in source and binary forms, with or without
6
// modification, are permitted provided that the following conditions are met:
7
// - Redistributions of source code must retain the above copyright notice,
8
//   this list of conditions and the following disclaimer.
9
// - Redistributions in binary form must reproduce the above copyright notice,
10
//   this list of conditions and the following disclaimer in the documentation
11
//   and/or other materials provided with the distribution.
12
//
13
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
14
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
17
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
// THE POSSIBILITY OF SUCH DAMAGE.
24
//*****************************************************************************
25

26
#include <chrono>
27
#include <exception>
28
#include <iostream>
29

30
#include <dpnp_iface.hpp>
31
#include "queue_sycl.hpp"
32
#include "dpnp_utils.hpp"
33

34
#if defined(DPNP_LOCAL_QUEUE)
35
sycl::queue* backend_sycl::queue = nullptr;
36
#endif
37
mkl_rng::mt19937* backend_sycl::rng_engine = nullptr;
38

39
static void dpnpc_show_mathlib_version()
40
{
×
41
#if 1
×
42
    const int len = 256;
×
43
    std::string mathlib_version_str(len, 0x0);
×
44

45
    char* buf = const_cast<char*>(mathlib_version_str.c_str()); // TODO avoid write into the container
×
46

47
    mkl_get_version_string(buf, len);
×
48

49
    std::cout << "Math backend version: " << mathlib_version_str << std::endl;
×
50
#else
51
    // Failed to load library under Python environment die to unresolved symbol
52
    MKLVersion version;
53

54
    mkl_get_version(&version);
55

56
    std::cout << "Math backend version: " << version.MajorVersion << "." << version.UpdateVersion << "."
57
              << version.MinorVersion << std::endl;
58
#endif
59
}
×
60

61
#if (not defined(NDEBUG)) && defined(DPNP_LOCAL_QUEUE)
62
static void show_available_sycl_devices()
63
{
64
    const std::vector<sycl::device> devices = sycl::device::get_devices();
65

66
    std::cout << "Available SYCL devices:" << std::endl;
67
    for (std::vector<sycl::device>::const_iterator it = devices.cbegin(); it != devices.cend(); ++it)
68
    {
69
        std::cout
70
            // not yet implemented error << " " << it->has(sycl::aspect::usm_shared_allocations)  << " "
71
            << " - id=" << it->get_info<sycl::info::device::vendor_id>()
72
            << ", type=" << static_cast<pi_uint64>(it->get_info<sycl::info::device::device_type>())
73
            << ", gws=" << it->get_info<sycl::info::device::max_work_group_size>()
74
            << ", cu=" << it->get_info<sycl::info::device::max_compute_units>()
75
            << ", name=" << it->get_info<sycl::info::device::name>() << std::endl;
76
    }
77
}
78
#endif
79

80
#if defined(DPNP_LOCAL_QUEUE)
81
static sycl::device get_default_sycl_device()
82
{
83
    int dpnpc_queue_gpu = 0;
84
    sycl::device dev = sycl::device(sycl::cpu_selector());
85

86
    const char* dpnpc_queue_gpu_var = getenv("DPNPC_QUEUE_GPU");
87
    if (dpnpc_queue_gpu_var != NULL)
88
    {
89
        dpnpc_queue_gpu = atoi(dpnpc_queue_gpu_var);
90
    }
91

92
    if (dpnpc_queue_gpu)
93
    {
94
        dev = sycl::device(sycl::gpu_selector());
95
    }
96

97
    return dev;
98
}
99
#endif
100

101
#if defined(DPNPC_TOUCH_KERNEL_TO_LINK)
102
/**
103
 * Function push the SYCL kernels to be linked (final stage of the compilation) for the current queue
104
 *
105
 * TODO it is not the best idea to just a call some kernel. Needs better solution.
106
 */
107
static long dpnp_kernels_link()
108
{
109
    /* must use memory pre-allocated at the current queue */
110
    long* value_ptr = reinterpret_cast<long*>(dpnp_memory_alloc_c(1 * sizeof(long)));
111
    long* result_ptr = reinterpret_cast<long*>(dpnp_memory_alloc_c(1 * sizeof(long)));
112
    long result = 1;
113

114
    *value_ptr = 2;
115

116
    dpnp_square_c<long>(value_ptr, result_ptr, 1);
117

118
    result = *result_ptr;
119

120
    dpnp_memory_free_c(result_ptr);
121
    dpnp_memory_free_c(value_ptr);
122

123
    return result;
124
}
125
#endif
126

127
#if defined(DPNP_LOCAL_QUEUE)
128
// Catch asynchronous exceptions
129
static void exception_handler(sycl::exception_list exceptions)
130
{
131
    for (std::exception_ptr const& e : exceptions)
132
    {
133
        try
134
        {
135
            std::rethrow_exception(e);
136
        }
137
        catch (sycl::exception const& e)
138
        {
139
            std::cout << "DPNP. Caught asynchronous SYCL exception:\n" << e.what() << std::endl;
140
        }
141
    }
142
};
143
#endif
144

145
void backend_sycl::backend_sycl_queue_init(QueueOptions selector)
146
{
×
147
#if defined(DPNP_LOCAL_QUEUE)
148
    std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
149

150
    if (queue)
151
    {
152
        backend_sycl::destroy();
153
    }
154

155
    sycl::device dev;
156

157
#if not defined(NDEBUG)
158
    show_available_sycl_devices();
159
#endif
160

161
    if (QueueOptions::CPU_SELECTOR == selector)
162
    {
163
        dev = sycl::device(sycl::cpu_selector());
164
    }
165
    else if (QueueOptions::GPU_SELECTOR == selector)
166
    {
167
        dev = sycl::device(sycl::gpu_selector());
168
    }
169
    else
170
    {
171
        dev = get_default_sycl_device();
172
    }
173

174
    if (is_verbose_mode())
175
    {
176
        sycl::property_list properties{sycl::property::queue::enable_profiling()};
177
        queue = new sycl::queue(dev, exception_handler, properties);
178
    }
179
    else
180
    {
181
        queue = new sycl::queue(dev, exception_handler);
182
    }
183

184
    std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
185
    std::chrono::duration<double> time_queue_init = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - t1);
186
#else
187
    (void)selector;
×
188
#endif
×
189

190
    std::chrono::high_resolution_clock::time_point t3 = std::chrono::high_resolution_clock::now();
×
191
#if defined(DPNPC_TOUCH_KERNEL_TO_LINK)
192
    // Remove pre-link kernel library at startup time
193
    dpnp_kernels_link();
194
#endif
195
    std::chrono::high_resolution_clock::time_point t4 = std::chrono::high_resolution_clock::now();
×
196
    std::chrono::duration<double> time_kernels_link =
×
197
        std::chrono::duration_cast<std::chrono::duration<double>>(t4 - t3);
×
198

199
    std::cout << "Running on: " << DPNP_QUEUE.get_device().get_info<sycl::info::device::name>() << "\n";
×
200
#if defined(DPNP_LOCAL_QUEUE)
201
    std::cout << "queue initialization time: " << time_queue_init.count() << " (sec.)\n";
202
#else
203
    std::cout << "DPCtrl SYCL queue used\n";
×
204
#endif
×
205
    std::cout << "SYCL kernels link time: " << time_kernels_link.count() << " (sec.)\n";
×
206
    dpnpc_show_mathlib_version();
×
207

208
    std::cout << std::endl;
×
209
}
×
210

211
bool backend_sycl::backend_sycl_is_cpu()
212
{
1✔
213
    sycl::queue& qptr = get_queue();
1✔
214

215
    if (qptr.get_device().is_cpu()) {
1!
216
        return true;
1✔
217
    }
1✔
218

219
    return false;
×
220
}
1✔
221

222
void backend_sycl::backend_sycl_rng_engine_init(size_t seed)
223
{
1✔
224
    if (rng_engine)
1!
225
    {
×
226
        backend_sycl::destroy_rng_engine();
×
227
    }
×
228
    rng_engine = new mkl_rng::mt19937(DPNP_QUEUE, seed);
1✔
229
}
1✔
230

231
void dpnp_queue_initialize_c(QueueOptions selector)
232
{
×
233
    backend_sycl::backend_sycl_queue_init(selector);
×
234
}
×
235

236
size_t dpnp_queue_is_cpu_c()
237
{
1✔
238
    return backend_sycl::backend_sycl_is_cpu();
1✔
239
}
1✔
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