Morpheus 1.0.0
Dynamic matrix type and algorithms for sparse matrices
Loading...
Searching...
No Matches
Dia/Cuda/Morpheus_MatrixOperations_Impl.hpp
1
24#ifndef MORPHEUS_DIA_CUDA_MATRIXOPERATIONS_IMPL_HPP
25#define MORPHEUS_DIA_CUDA_MATRIXOPERATIONS_IMPL_HPP
26
27#include <Morpheus_Macros.hpp>
28#if defined(MORPHEUS_ENABLE_CUDA)
29
30#include <Morpheus_Exceptions.hpp>
31#include <Morpheus_SpaceTraits.hpp>
32#include <Morpheus_FormatTraits.hpp>
33#include <Morpheus_FormatTags.hpp>
34#include <Morpheus_Spaces.hpp>
35
36#include <impl/Morpheus_CudaUtils.hpp>
37#include <impl/Dia/Kernels/Morpheus_MatrixOperations_Impl.hpp>
38
39namespace Morpheus {
40namespace Impl {
41
42template <typename ExecSpace, typename Matrix, typename Vector>
43void update_diagonal(
44 Matrix& A, const Vector& diagonal,
45 typename std::enable_if_t<
46 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
47 Morpheus::is_dense_vector_format_container_v<Vector> &&
48 Morpheus::has_custom_backend_v<ExecSpace> &&
49 Morpheus::has_cuda_execution_space_v<ExecSpace> &&
50 Morpheus::has_access_v<ExecSpace, Matrix, Vector>>* = nullptr) {
51 using size_type = typename Matrix::size_type;
52 using index_type = typename Matrix::index_type;
53 using value_type = typename Matrix::value_type;
54
55 const size_type BLOCK_SIZE = 256;
56 const size_type MAX_BLOCKS = max_active_blocks(
57 Kernels::update_dia_diagonal_kernel<value_type, index_type, size_type>,
58 BLOCK_SIZE, 0);
59 const size_type NUM_BLOCKS =
60 std::min<size_type>(MAX_BLOCKS, DIVIDE_INTO(A.nrows(), BLOCK_SIZE));
61
62 const size_type num_diagonals = A.cvalues().ncols();
63 const size_type pitch = A.cvalues().nrows();
64
65 Kernels::update_dia_diagonal_kernel<value_type, index_type, size_type>
66 <<<NUM_BLOCKS, BLOCK_SIZE, 0>>>(A.nrows(), A.ncols(), num_diagonals,
67 pitch, A.diagonal_offsets().data(),
68 A.values().data(), diagonal.data());
69#if defined(DEBUG) || defined(MORPHEUS_DEBUG)
70 getLastCudaError("update_dia_diagonal_kernel: Kernel execution failed");
71#endif
72}
73
74template <typename ExecSpace, typename Matrix, typename Vector>
75void get_diagonal(
76 Matrix& A, const Vector& diagonal,
77 typename std::enable_if_t<
78 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
79 Morpheus::is_dense_vector_format_container_v<Vector> &&
80 Morpheus::has_custom_backend_v<ExecSpace> &&
81 Morpheus::has_cuda_execution_space_v<ExecSpace> &&
82 Morpheus::has_access_v<ExecSpace, Matrix, Vector>>* = nullptr) {
83 throw Morpheus::NotImplementedException("get_diagonal not implemented yet");
84}
85
86template <typename ExecSpace, typename Matrix, typename SizeType,
87 typename ValueType>
88void set_value(Matrix&, SizeType, SizeType, ValueType,
89 typename std::enable_if_t<
90 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
91 Morpheus::has_custom_backend_v<ExecSpace> &&
92 Morpheus::has_cuda_execution_space_v<ExecSpace> &&
93 Morpheus::has_access_v<ExecSpace, Matrix>>* = nullptr) {
94 throw Morpheus::NotImplementedException("set_value not implemented yet");
95}
96
97template <typename ExecSpace, typename Matrix, typename IndexVector,
98 typename ValueVector>
99void set_values(
100 Matrix&, typename IndexVector::value_type, const IndexVector,
101 typename IndexVector::value_type, const IndexVector, const ValueVector,
102 typename std::enable_if_t<
103 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
104 Morpheus::is_dense_vector_format_container_v<IndexVector> &&
105 Morpheus::is_dense_vector_format_container_v<ValueVector> &&
106 Morpheus::has_custom_backend_v<ExecSpace> &&
107 Morpheus::has_cuda_execution_space_v<ExecSpace> &&
108 Morpheus::has_access_v<ExecSpace, Matrix, IndexVector, ValueVector>>* =
109 nullptr) {
110 throw Morpheus::NotImplementedException("set_values not implemented yet");
111}
112
113template <typename ExecSpace, typename Matrix, typename TransposeMatrix>
114void transpose(
115 const Matrix&, TransposeMatrix&,
116 typename std::enable_if_t<
117 Morpheus::is_dia_matrix_format_container_v<Matrix> &&
118 Morpheus::is_dia_matrix_format_container_v<TransposeMatrix> &&
119 Morpheus::has_custom_backend_v<ExecSpace> &&
120 Morpheus::has_cuda_execution_space_v<ExecSpace> &&
121 Morpheus::has_access_v<ExecSpace, Matrix, TransposeMatrix>>* =
122 nullptr) {
123 throw Morpheus::NotImplementedException("transpose not implemented yet");
124}
125
126} // namespace Impl
127} // namespace Morpheus
128
129#endif // MORPHEUS_ENABLE_CUDA
130#endif // MORPHEUS_DIA_CUDA_MATRIXOPERATIONS_IMPL_HPP
Definition: Morpheus_Exceptions.hpp:43
Generic Morpheus interfaces.
Definition: dummy.cpp:24