DPNP C++ backend kernel library 0.18.0dev0
Data Parallel Extension for NumPy*
Loading...
Searching...
No Matches
dot.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 dot_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 dot_event;
57 try {
58 dot_event = mkl_blas::column_major::dot(exec_q,
59 n, // size of the input vectors
60 x, // Pointer to vector x.
61 incx, // Stride of vector x.
62 y, // Pointer to vector y.
63 incy, // Stride of vector y.
64 res, // Pointer to result.
65 depends);
66 } catch (oneapi::mkl::exception const &e) {
67 error_msg
68 << "Unexpected MKL exception caught during dot() call:\nreason: "
69 << e.what();
70 is_exception_caught = true;
71 } catch (sycl::exception const &e) {
72 error_msg << "Unexpected SYCL exception caught during dot() call:\n"
73 << e.what();
74 is_exception_caught = true;
75 }
76
77 if (is_exception_caught) // an unexpected error occurs
78 {
79 throw std::runtime_error(error_msg.str());
80 }
81
82 return dot_event;
83}
84
85template <typename fnT, typename varT>
87{
88 fnT get()
89 {
91 return dot_impl<varT>;
92 }
93 else {
94 return nullptr;
95 }
96 }
97};
98} // namespace dpnp::extensions::blas
A factory to define pairs of supported types for which MKL BLAS library provides support in oneapi::m...