/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.4.1/hipcub/include/hipcub/backend/cub/device/device_spmv.hpp Source File

/home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.4.1/hipcub/include/hipcub/backend/cub/device/device_spmv.hpp Source File#

hipCUB: /home/docs/checkouts/readthedocs.org/user_builds/advanced-micro-devices-hipcub/checkouts/docs-5.4.1/hipcub/include/hipcub/backend/cub/device/device_spmv.hpp Source File
device_spmv.hpp
1 /******************************************************************************
2  * Copyright (c) 2010-2011, Duane Merrill. All rights reserved.
3  * Copyright (c) 2011-2018, NVIDIA CORPORATION. All rights reserved.
4  * Modifications Copyright (c) 2017-2020, Advanced Micro Devices, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the NVIDIA CORPORATION nor the
14  * names of its contributors may be used to endorse or promote products
15  * derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20  * DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE FOR ANY
21  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  ******************************************************************************/
29 
30 #ifndef HIPCUB_CUB_DEVICE_DEVICE_SPMV_HPP_
31 #define HIPCUB_CUB_DEVICE_DEVICE_SPMV_HPP_
32 
33 #include "../../../config.hpp"
34 
35 #include <cub/device/device_spmv.cuh>
36 #include <cub/iterator/tex_ref_input_iterator.cuh>
37 
38 BEGIN_HIPCUB_NAMESPACE
39 
41 {
42 
43 public:
44 
45 template <
46  typename ValueT,
47  typename OffsetT>
48 struct SpmvParams
49 {
50  ValueT* d_values;
51  OffsetT* d_row_end_offsets;
52  OffsetT* d_column_indices;
53  ValueT* d_vector_x;
54  ValueT* d_vector_y;
55  int num_rows;
56  int num_cols;
58  ValueT alpha;
59  ValueT beta;
60 
61  ::cub::TexRefInputIterator<ValueT, 66778899, OffsetT> t_vector_x;
62 };
63 
64 template <typename ValueT>
65  HIPCUB_RUNTIME_FUNCTION
66  static hipError_t CsrMV(
67  void* d_temp_storage,
68  size_t& temp_storage_bytes,
69  ValueT* d_values,
70  int* d_row_offsets,
71  int* d_column_indices,
72  ValueT* d_vector_x,
73  ValueT* d_vector_y,
74  int num_rows,
75  int num_cols,
76  int num_nonzeros,
77  hipStream_t stream = 0,
78  bool debug_synchronous = false)
79  {
80  ::cub::SpmvParams<ValueT, int> spmv_params;
81  spmv_params.d_values = d_values;
82  spmv_params.d_row_end_offsets = d_row_offsets + 1;
83  spmv_params.d_column_indices = d_column_indices;
84  spmv_params.d_vector_x = d_vector_x;
85  spmv_params.d_vector_y = d_vector_y;
86  spmv_params.num_rows = num_rows;
87  spmv_params.num_cols = num_cols;
88  spmv_params.num_nonzeros = num_nonzeros;
89  spmv_params.alpha = 1.0;
90  spmv_params.beta = 0.0;
91 
92  return static_cast<hipError_t>(::cub::DispatchSpmv<ValueT, int>::Dispatch(
93  d_temp_storage,
94  temp_storage_bytes,
95  spmv_params,
96  stream,
97  debug_synchronous));
98  }
99 };
100 
101 END_HIPCUB_NAMESPACE
102 
103 #endif // HIPCUB_CUB_DEVICE_DEVICE_SELECT_HPP_
Definition: device_spmv.hpp:41
static __host__ hipError_t CsrMV(void *d_temp_storage, size_t &temp_storage_bytes, ValueT *d_values, int *d_row_offsets, int *d_column_indices, ValueT *d_vector_x, ValueT *d_vector_y, int num_rows, int num_cols, int num_nonzeros, hipStream_t stream=0, bool debug_synchronous=false)
Definition: device_spmv.hpp:66
< Signed integer type for sequence offsets
Definition: device_spmv.hpp:49
int num_cols
Number of columns of matrix A.
Definition: device_spmv.hpp:56
OffsetT * d_row_end_offsets
Pointer to the array of m offsets demarcating the end of every row in d_column_indices and d_values.
Definition: device_spmv.hpp:51
ValueT * d_values
Pointer to the array of num_nonzeros values of the corresponding nonzero elements of matrix A.
Definition: device_spmv.hpp:50
ValueT * d_vector_y
Pointer to the array of num_rows values corresponding to the dense output vector y
Definition: device_spmv.hpp:54
int num_nonzeros
Number of nonzero elements of matrix A.
Definition: device_spmv.hpp:57
ValueT * d_vector_x
Pointer to the array of num_cols values corresponding to the dense input vector x
Definition: device_spmv.hpp:53
int num_rows
Number of rows of matrix A.
Definition: device_spmv.hpp:55
ValueT alpha
Alpha multiplicand.
Definition: device_spmv.hpp:58
OffsetT * d_column_indices
Pointer to the array of num_nonzeros column-indices of the corresponding nonzero elements of matrix A...
Definition: device_spmv.hpp:52
ValueT beta
Beta addend-multiplicand.
Definition: device_spmv.hpp:59