DPNP C++ backend kernel library 0.18.0rc1
Data Parallel Extension for NumPy*
Loading...
Searching...
No Matches
validation_utils.hpp
1//*****************************************************************************
2// Copyright (c) 2024-2025, 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#pragma once
27
28#include <string>
29#include <unordered_map>
30#include <vector>
31
32#include "dpctl4pybind11.hpp"
33
34namespace ext::validation
35{
36using array_ptr = const dpctl::tensor::usm_ndarray *;
37using array_names = std::unordered_map<array_ptr, std::string>;
38using dpctl::tensor::type_dispatch::typenum_t;
39
40std::string name_of(const array_ptr &arr, const array_names &names);
41
42void check_writable(const std::vector<array_ptr> &arrays,
43 const array_names &names);
44void check_c_contig(const std::vector<array_ptr> &arrays,
45 const array_names &names);
46void check_queue(const std::vector<array_ptr> &arrays,
47 const array_names &names,
48 const sycl::queue &exec_q);
49
50void check_no_overlap(const array_ptr &inputs,
51 const array_ptr &outputs,
52 const array_names &names);
53void check_no_overlap(const std::vector<array_ptr> &inputs,
54 const std::vector<array_ptr> &outputs,
55 const array_names &names);
56
57void check_num_dims(const array_ptr &arr,
58 const size_t ndim,
59 const array_names &names);
60void check_num_dims(const std::vector<array_ptr> &arrays,
61 const size_t ndim,
62 const array_names &names);
63void check_max_dims(const array_ptr &arr,
64 const size_t max_ndim,
65 const array_names &names);
66
67void check_size_at_least(const array_ptr &arr,
68 const size_t size,
69 const array_names &names);
70
71void check_has_dtype(const array_ptr &arr,
72 const typenum_t dtype,
73 const array_names &names);
74
75void check_same_dtype(const array_ptr &arr1,
76 const array_ptr &arr2,
77 const array_names &names);
78
79void check_same_size(const array_ptr &arr1,
80 const array_ptr &arr2,
81 const array_names &names);
82void check_same_size(const std::vector<array_ptr> &arrays,
83 const array_names &names);
84
85void common_checks(const std::vector<array_ptr> &inputs,
86 const std::vector<array_ptr> &outputs,
87 const array_names &names);
88} // namespace ext::validation
89
90#include "ext/details/validation_utils_internal.hpp"