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

IntelPython / dpctl / 12341630598

15 Dec 2024 07:24PM UTC coverage: 87.659%. First build
12341630598

Pull #1939

github

web-flow
Merge 5fbef6fb9 into ac978f10e
Pull Request #1939: Use Miniforge3 variant in test-windows step

3120 of 3640 branches covered (85.71%)

Branch coverage included in aggregate %.

11810 of 13392 relevant lines covered (88.19%)

7081.58 hits per line

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

70.63
/libsyclinterface/source/dpctl_vector_templ.cpp
1
//===-- dpctl_vector_templ.cpp - Wrapper functions for opaque vector types ===//
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 is meant to be directly included inside other source files to add
23
/// the wrapper functions for vector operations.
24
///
25
//===----------------------------------------------------------------------===//
26
#include "Support/MemOwnershipAttrs.h"
27
#include "dpctl_error_handlers.h"
28
#include "dpctl_sycl_type_casters.hpp"
29
#include "dpctl_vector_macros.h"
30
#include <type_traits>
31
#include <vector>
32

33
/*!
34
 * @brief Creates a new std::vector of the opaque SYCL pointer types.
35
 *
36
 * @return   A new dynamically allocated std::vector of opaque pointer types.
37
 */
38
__dpctl_give VECTOR(EL) FN(EL, Create)()
39
{
1✔
40
    using vecTy = std::vector<SYCLREF(EL)>;
1✔
41
    vecTy *Vec = nullptr;
1✔
42
    try {
1✔
43
        Vec = new std::vector<SYCLREF(EL)>();
1✔
44
        return ::dpctl::syclinterface::wrap<vecTy>(Vec);
1✔
45
    } catch (std::exception const &e) {
1✔
46
        delete Vec;
×
47
        error_handler(e, __FILE__, __func__, __LINE__);
×
48
        return nullptr;
×
49
    }
×
50
}
1✔
51

52
/*!
53
 * @brief Creates a new std::vector of the opaque SYCL pointer types from given
54
 * C array with deep copy.
55
 *
56
 * @return   A new dynamically allocated std::vector of opaque pointer types.
57
 */
58
__dpctl_give VECTOR(EL)
59
    FN(EL, CreateFromArray)(size_t n, __dpctl_keep SYCLREF(EL) * elems)
60
{
2✔
61
    using vecTy = std::vector<SYCLREF(EL)>;
2✔
62
    vecTy *Vec = nullptr;
2✔
63
    try {
2✔
64
        Vec = new vecTy();
2✔
65
        for (size_t i = 0; i < n; ++i) {
7!
66
            auto Ref = ::dpctl::syclinterface::unwrap<EL_SYCL_TYPE>(elems[i]);
5✔
67
            Vec->emplace_back(::dpctl::syclinterface::wrap<EL_SYCL_TYPE>(
5✔
68
                new EL_SYCL_TYPE(*Ref)));
5✔
69
        }
5✔
70
        return ::dpctl::syclinterface::wrap<vecTy>(Vec);
2✔
71
    } catch (std::exception const &e) {
2✔
72
        delete Vec;
×
73
        error_handler(e, __FILE__, __func__, __LINE__);
×
74
        return nullptr;
×
75
    }
×
76
}
2✔
77

78
/*!
79
 * @brief Frees all the elements of the passed in std::vector and then frees the
80
 * std::vector pointer.
81
 *
82
 */
83
void FN(EL, Delete)(__dpctl_take VECTOR(EL) VRef)
84
{
454✔
85
    using vecTy = std::vector<SYCLREF(EL)>;
454✔
86
    auto Vec = ::dpctl::syclinterface::unwrap<vecTy>(VRef);
454✔
87
    if (Vec) {
454!
88
        for (auto i = 0ul; i < Vec->size(); ++i) {
954✔
89
            auto D = ::dpctl::syclinterface::unwrap<EL_SYCL_TYPE>((*Vec)[i]);
500✔
90
            delete D;
500✔
91
        }
500✔
92
    }
454✔
93
    delete Vec;
454✔
94
}
454✔
95

96
/*!
97
 * @brief Frees all the elements of the vector and then calls clear().
98
 *
99
 */
100
void FN(EL, Clear)(__dpctl_keep VECTOR(EL) VRef)
101
{
7✔
102
    using vecTy = std::vector<SYCLREF(EL)>;
7✔
103
    auto Vec = ::dpctl::syclinterface::unwrap<vecTy>(VRef);
7✔
104
    if (Vec) {
7!
105
        for (auto i = 0ul; i < Vec->size(); ++i) {
9!
106
            auto D = ::dpctl::syclinterface::unwrap<EL_SYCL_TYPE>((*Vec)[i]);
2✔
107
            delete D;
2✔
108
        }
2✔
109
        Vec->clear();
7✔
110
    }
7✔
111
}
7✔
112

113
/*!
114
 * @brief Returns the number of elements in the vector.
115
 *
116
 */
117
size_t FN(EL, Size)(__dpctl_keep VECTOR(EL) VRef)
118
{
447✔
119
    using vecTy = std::vector<SYCLREF(EL)>;
447✔
120
    auto V = ::dpctl::syclinterface::unwrap<vecTy>(VRef);
447✔
121
    if (V)
447!
122
        return V->size();
447✔
123
    else
×
124
        return 0;
×
125
}
447✔
126

127
/*!
128
 * @brief Returns a copy of the opaque pointer at specified index, and throws
129
 * an out_of_range exception if the index is incorrect.
130
 *
131
 */
132
SYCLREF(EL) FN(EL, GetAt)(__dpctl_keep VECTOR(EL) VRef, size_t index)
133
{
444✔
134
    using vecTy = std::vector<SYCLREF(EL)>;
444✔
135
    auto Vec = ::dpctl::syclinterface::unwrap<vecTy>(VRef);
444✔
136
    SYCLREF(EL) copy = nullptr;
444✔
137
    if (Vec) {
444!
138
        SYCLREF(EL) ret;
444✔
139
        try {
444✔
140
            ret = Vec->at(index);
444✔
141
        } catch (std::exception const &e) {
444✔
142
            error_handler(e, __FILE__, __func__, __LINE__);
×
143
            return nullptr;
×
144
        }
×
145
        auto Ref = ::dpctl::syclinterface::unwrap<EL_SYCL_TYPE>(ret);
444✔
146
        EL_SYCL_TYPE *elPtr = nullptr;
444✔
147
        try {
444✔
148
            elPtr = new EL_SYCL_TYPE(*Ref);
444✔
149
            copy = ::dpctl::syclinterface::wrap<EL_SYCL_TYPE>(elPtr);
444✔
150
        } catch (std::exception const &e) {
444✔
151
            delete elPtr;
×
152
            error_handler(e, __FILE__, __func__, __LINE__);
×
153
            return nullptr;
×
154
        }
×
155
    }
444✔
156
    return copy;
444✔
157
}
444✔
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