24#ifndef MORPHEUS_DENSEVECTOR_HIP_DOT_IMPL_HPP
25#define MORPHEUS_DENSEVECTOR_HIP_DOT_IMPL_HPP
27#include <Morpheus_Macros.hpp>
28#if defined(MORPHEUS_ENABLE_HIP)
30#include <Morpheus_SpaceTraits.hpp>
31#include <Morpheus_FormatTraits.hpp>
32#include <Morpheus_FormatTags.hpp>
33#include <Morpheus_Spaces.hpp>
34#include <Morpheus_Reduction.hpp>
36#include <impl/DenseVector/HIP/Morpheus_Workspace.hpp>
38#ifdef MORPHEUS_ENABLE_TPL_HIPBLAS
41#include <impl/Morpheus_HIPUtils.hpp>
42#include <impl/DenseVector/Kernels/Morpheus_Dot_Impl.hpp>
48template <
typename ExecSpace,
typename Vector1,
typename Vector2>
49typename Vector2::value_type dot(
50 const typename Vector1::size_type n,
const Vector1& x,
const Vector2& y,
51 typename std::enable_if_t<
52 Morpheus::is_dense_vector_format_container_v<Vector1> &&
53 Morpheus::is_dense_vector_format_container_v<Vector2> &&
54 Morpheus::has_custom_backend_v<ExecSpace> &&
55 Morpheus::has_hip_execution_space_v<ExecSpace> &&
56 Morpheus::has_access_v<ExecSpace, Vector1, Vector2>>* =
nullptr) {
57 using size_type =
typename Vector1::size_type;
58 using value_type =
typename Vector1::non_const_value_type;
60 value_type local_result;
62#ifdef MORPHEUS_ENABLE_TPL_HIPBLAS
63 using index_type =
typename Vector1::index_type;
64 hipblasdotspace.init();
65 hipblasdotspace.allocate<value_type>(1);
66 index_type incx = 1, incy = 1;
67 hipblasDdot(hipblasdotspace.handle(), n, x.data(), incx, y.data(), incy,
68 hipblasdotspace.data<value_type>());
70 hipMemcpy(&local_result, hipblasdotspace.data<value_type>(),
71 sizeof(value_type), hipMemcpyDeviceToHost);
73 hipdotspace.allocate<value_type>(n);
75 Kernels::dot_kernel_part1<256, value_type, size_type>
76 <<<256, 256>>>(n, x.data(), y.data(), hipdotspace.data<value_type>());
77#if defined(DEBUG) || defined(MORPHEUS_DEBUG)
78 getLastHIPError(
"dot: Kernel execution failed");
81 Kernels::dot_kernel_part2<256, value_type>
82 <<<1, 256>>>(hipdotspace.data<value_type>());
83#if defined(DEBUG) || defined(MORPHEUS_DEBUG)
84 getLastHIPError(
"dot: Kernel execution failed");
87 hipMemcpy(&local_result, hipdotspace.data<value_type>(),
sizeof(value_type),
88 hipMemcpyDeviceToHost);
Generic Morpheus interfaces.
Definition: dummy.cpp:24