DPNP C++ backend kernel library 0.18.0dev0
Data Parallel Extension for NumPy*
Loading...
Searching...
No Matches
dotc.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 <stdexcept>
29
30#include "dot_common.hpp"
31
32namespace dpnp::extensions::blas
33{
34namespace mkl_blas = oneapi::mkl::blas;
35namespace type_utils = dpctl::tensor::type_utils;
36
37template <typename T>
38static sycl::event dotc_impl(sycl::queue &exec_q,
39 const std::int64_t n,
40 const char *vectorX,
41 const std::int64_t incx,
42 const char *vectorY,
43 const std::int64_t incy,
44 char *result,
45 const std::vector<sycl::event> &depends)
46{
47 type_utils::validate_type_for_device<T>(exec_q);
48
49 const T *x = reinterpret_cast<const T *>(vectorX);
50 const T *y = reinterpret_cast<const T *>(vectorY);
51 T *res = reinterpret_cast<T *>(result);
52
53 std::stringstream error_msg;
54 bool is_exception_caught = false;
55
56 sycl::event dotc_event;
57 try {
58 dotc_event =
59 mkl_blas::column_major::dotc(exec_q,
60 n, // size of the input vectors
61 x, // Pointer to vector x.
62 incx, // Stride of vector x.
63 y, // Pointer to vector y.
64 incy, // Stride of vector y.
65 res, // Pointer to result.
66 depends);
67 } catch (oneapi::mkl::exception const &e) {
68 error_msg
69 << "Unexpected MKL exception caught during dotc() call:\nreason: "
70 << e.what();
71 is_exception_caught = true;
72 } catch (sycl::exception const &e) {
73 error_msg << "Unexpected SYCL exception caught during dotc() call:\n"
74 << e.what();
75 is_exception_caught = true;
76 }
77
78 if (is_exception_caught) // an unexpected error occurs
79 {
80 throw std::runtime_error(error_msg.str());
81 }
82
83 return dotc_event;
84}
85
86template <typename fnT, typename varT>
88{
89 fnT get()
90 {
92 return dotc_impl<varT>;
93 }
94 else {
95 return nullptr;
96 }
97 }
98};
99
100} // namespace dpnp::extensions::blas
A factory to define pairs of supported types for which MKL BLAS library provides support in oneapi::m...