27#ifndef BACKEND_UTILS_H
28#define BACKEND_UTILS_H
37#include <sycl/sycl.hpp>
39#include <dpnp_iface_fptr.hpp>
45#ifndef __SYCL_COMPILER_VECTOR_ABS_CHANGED
46#define __SYCL_COMPILER_VECTOR_ABS_CHANGED 20230503L
52#ifndef __INTEL_MKL_2023_0_0_VERSION_REQUIRED
53#define __INTEL_MKL_2023_0_0_VERSION_REQUIRED 20230000
62#ifndef __INTEL_MKL_2023_2_0_VERSION_REQUIRED
63#define __INTEL_MKL_2023_2_0_VERSION_REQUIRED 20230002L
86template <
typename _DataType>
91 size_t dim_prod_input = 1;
92 for (
size_t i = 0; i < shape_size; ++i) {
93 long i_reverse = shape_size - 1 - i;
94 offsets[i_reverse] = dim_prod_input;
95 dim_prod_input *= shape[i_reverse];
117template <
typename _DataType>
119 const _DataType *offsets,
126 assert(axis < offsets_size);
128 _DataType xyz_id = 0;
129 long reminder = global_id;
130 for (
size_t i = 0; i < axis + 1; ++i) {
131 const _DataType axis_val = offsets[i];
132 xyz_id = reminder / axis_val;
133 reminder = reminder % axis_val;
150template <
typename _DataType>
151static inline bool array_equal(
const _DataType *input1,
152 const size_t input1_size,
153 const _DataType *input2,
154 const size_t input2_size)
156 if (input1_size != input2_size)
159 const std::vector<_DataType> input1_vec(input1, input1 + input1_size);
160 const std::vector<_DataType> input2_vec(input2, input2 + input2_size);
162 return std::equal(std::begin(input1_vec), std::end(input1_vec),
163 std::begin(input2_vec));
177static inline void validate_type_for_device(
const sycl::device &d)
179 if constexpr (std::is_same_v<T, double>) {
180 if (!d.has(sycl::aspect::fp64)) {
181 throw std::runtime_error(
"Device " +
182 d.get_info<sycl::info::device::name>() +
183 " does not support type 'double'");
186 else if constexpr (std::is_same_v<T, std::complex<double>>) {
187 if (!d.has(sycl::aspect::fp64)) {
188 throw std::runtime_error(
189 "Device " + d.get_info<sycl::info::device::name>() +
190 " does not support type 'complex<double>'");
193 else if constexpr (std::is_same_v<T, sycl::half>) {
194 if (!d.has(sycl::aspect::fp16)) {
195 throw std::runtime_error(
"Device " +
196 d.get_info<sycl::info::device::name>() +
197 " does not support type 'half'");
213static inline void validate_type_for_device(
const sycl::queue &q)
215 validate_type_for_device<T>(q.get_device());
227std::ostream &
operator<<(std::ostream &out,
const std::vector<T> &vec)
229 std::string delimiter;
234 for (
auto &elem : vec) {
235 out << delimiter << elem;
236 if (delimiter.empty()) {
237 delimiter.assign(
", ");
257 out << static_cast<size_t>(elem);
DPNPFuncType
Template types which are used in this interface.
std::ostream & operator<<(std::ostream &out, const std::vector< T > &vec)
print std::vector to std::ostream.
void get_shape_offsets_inkernel(const _DataType *shape, size_t shape_size, _DataType *offsets)
Shape offset calculation used in kernels.
_DataType get_xyz_id_by_id_inkernel(size_t global_id, const _DataType *offsets, size_t offsets_size, size_t axis)
Calculate xyz id for given axis from linear index.