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

IntelPython / dpnp / 18462105984

13 Oct 2025 10:00AM UTC coverage: 72.021% (+0.006%) from 72.015%
18462105984

Pull #2616

github

web-flow
Merge 88f29534e into 71e7d82fc
Pull Request #2616: Add `dpnp.exceptions` submodule to aggregate generic exceptions

5067 of 10224 branches covered (49.56%)

Branch coverage included in aggregate %.

8 of 8 new or added lines in 2 files covered. (100.0%)

2041 existing lines in 130 files now uncovered.

18659 of 22719 relevant lines covered (82.13%)

18875.14 hits per line

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

59.32
/dpnp/backend/src/memory_sycl.cpp
1
//*****************************************************************************
2
// Copyright (c) 2016, 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
// - Neither the name of the copyright holder nor the names of its contributors
13
//   may be used to endorse or promote products derived from this software
14
//   without specific prior written permission.
15
//
16
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26
// THE POSSIBILITY OF SUCH DAMAGE.
27
//*****************************************************************************
28

29
#include <cstring>
30
#include <iostream>
31
#include <stdexcept>
32

33
#include "dpnp_iface.hpp"
34
#include "queue_sycl.hpp"
35

36
static bool use_sycl_device_memory()
37
{
298✔
38
    // TODO need to move all getenv() into common dpnpc place
39
    char *dpnpc_memtype_device = nullptr;
298✔
40

41
#ifdef _WIN32
42
    size_t dpnpc_memtype_device_size = 0;
43
    _dupenv_s(&dpnpc_memtype_device, &dpnpc_memtype_device_size,
44
              "DPNPC_OUTPUT_DPARRAY_USE_MEMORY_DEVICE");
45
#else
46
    dpnpc_memtype_device =
298✔
47
        std::getenv("DPNPC_OUTPUT_DPARRAY_USE_MEMORY_DEVICE");
298✔
48
#endif
298✔
49

50
    if (dpnpc_memtype_device != nullptr) {
298!
51
#ifdef _WIN32
52
        free(dpnpc_memtype_device);
53
#endif
UNCOV
54
        return true;
×
UNCOV
55
    }
×
56

57
    return false;
298✔
58
}
298✔
59

60
// This variable is needed for the NumPy corner case
61
// if we have zero memory array (ex. shape=(0,10)) we must keep the pointer to
62
// somewhere memory of this variable must not be used
63
const char *numpy_stub = "...the NumPy Stub...";
64

65
char *dpnp_memory_alloc_c(DPCTLSyclQueueRef q_ref, size_t size_in_bytes)
66
{
298✔
67
    char *array = const_cast<char *>(numpy_stub);
298✔
68

69
    // std::cout << "dpnp_memory_alloc_c(size=" << size_in_bytes << std::flush;
70
    if (size_in_bytes > 0) {
298!
71
        sycl::queue q = *(reinterpret_cast<sycl::queue *>(q_ref));
298✔
72
        sycl::usm::alloc memory_type = sycl::usm::alloc::shared;
298✔
73
        if (use_sycl_device_memory()) {
298!
UNCOV
74
            memory_type = sycl::usm::alloc::device;
×
UNCOV
75
        }
×
76
        array = reinterpret_cast<char *>(
298✔
77
            sycl::malloc(size_in_bytes, q, memory_type));
298✔
78
        if (array == nullptr) {
298!
79
            // TODO add information about number of allocated bytes
UNCOV
80
            throw std::runtime_error(
×
UNCOV
81
                "DPNP Error: dpnp_memory_alloc_c() out of memory.");
×
UNCOV
82
        }
×
83

84
#if not defined(NDEBUG)
85
        if (memory_type != sycl::usm::alloc::device) {
86
            for (size_t i = 0; i < size_in_bytes / sizeof(char); ++i) {
87
                array[i] = 0; // type dependent is better. set double(42.42)
88
                              // instead zero
89
            }
90
        }
91
        // std::cout << ") -> ptr=" << (void*)array << std::endl;
92
#endif
93
    }
298✔
94

95
    return array;
298✔
96
}
298✔
97

98
char *dpnp_memory_alloc_c(size_t size_in_bytes)
99
{
×
UNCOV
100
    DPCTLSyclQueueRef q_ref = reinterpret_cast<DPCTLSyclQueueRef>(&DPNP_QUEUE);
×
UNCOV
101
    return dpnp_memory_alloc_c(q_ref, size_in_bytes);
×
UNCOV
102
}
×
103

104
void dpnp_memory_free_c(DPCTLSyclQueueRef q_ref, void *ptr)
105
{
302✔
106
    // std::cout << "dpnp_memory_free_c(ptr=" << (void*)ptr << ")" << std::endl;
107
    sycl::queue q = *(reinterpret_cast<sycl::queue *>(q_ref));
302✔
108
    if (ptr != numpy_stub) {
302!
109
        sycl::free(ptr, q);
302✔
110
    }
302✔
111
}
302✔
112

113
void dpnp_memory_free_c(void *ptr)
114
{
×
UNCOV
115
    DPCTLSyclQueueRef q_ref = reinterpret_cast<DPCTLSyclQueueRef>(&DPNP_QUEUE);
×
UNCOV
116
    dpnp_memory_free_c(q_ref, ptr);
×
UNCOV
117
}
×
118

119
void dpnp_memory_memcpy_c(DPCTLSyclQueueRef q_ref,
120
                          void *dst,
121
                          const void *src,
122
                          size_t size_in_bytes)
123
{
442✔
124
    // std::cout << "dpnp_memory_memcpy_c(dst=" << dst << ", src=" << src << ")"
125
    // << std::endl;
126
    sycl::queue q = *(reinterpret_cast<sycl::queue *>(q_ref));
442✔
127
    q.memcpy(dst, src, size_in_bytes).wait();
442✔
128
}
442✔
129

130
void dpnp_memory_memcpy_c(void *dst, const void *src, size_t size_in_bytes)
131
{
×
UNCOV
132
    DPCTLSyclQueueRef q_ref = reinterpret_cast<DPCTLSyclQueueRef>(&DPNP_QUEUE);
×
UNCOV
133
    dpnp_memory_memcpy_c(q_ref, dst, src, size_in_bytes);
×
UNCOV
134
}
×
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