1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
|
/*! \file */
/* ************************************************************************
* Copyright (C) 2020-2022 Advanced Micro Devices, Inc. All rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* ************************************************************************ */
#pragma once
#ifndef ROCSPARSE_MATRIX_FACTORY_HPP
#define ROCSPARSE_MATRIX_FACTORY_HPP
#include "rocsparse_import.hpp"
#include "rocsparse_matrix_utils.hpp"
std::string rocsparse_exepath();
#include "rocsparse_matrix_factory_file.hpp"
#include "rocsparse_matrix_factory_laplace2d.hpp"
#include "rocsparse_matrix_factory_laplace3d.hpp"
#include "rocsparse_matrix_factory_pentadiagonal.hpp"
#include "rocsparse_matrix_factory_random.hpp"
#include "rocsparse_matrix_factory_tridiagonal.hpp"
#include "rocsparse_matrix_factory_zero.hpp"
template <typename T, typename I = rocsparse_int, typename J = rocsparse_int>
struct rocsparse_matrix_factory : public rocsparse_matrix_factory_base<T, I, J>
{
public:
const Arguments& m_arg;
private:
rocsparse_matrix_factory_base<T, I, J>* m_instance;
public:
~rocsparse_matrix_factory();
rocsparse_matrix_factory(const Arguments& arg,
rocsparse_matrix_init matrix,
bool to_int = false,
bool full_rank = false,
bool noseed = false);
rocsparse_matrix_factory(const rocsparse_matrix_factory& that) = delete;
rocsparse_matrix_factory& operator=(const rocsparse_matrix_factory& that) = delete;
explicit rocsparse_matrix_factory(const Arguments& arg,
bool to_int = false,
bool full_rank = false,
bool noseed = false);
virtual void init_csr(std::vector<I>& csr_row_ptr,
std::vector<J>& csr_col_ind,
std::vector<T>& csr_val,
J& m,
J& n,
I& nnz,
rocsparse_index_base base,
rocsparse_matrix_type matrix_type,
rocsparse_fill_mode uplo,
rocsparse_storage_mode storage)
{
return this->m_instance->init_csr(
csr_row_ptr, csr_col_ind, csr_val, m, n, nnz, base, matrix_type, uplo, storage);
}
virtual void init_gebsr(std::vector<I>& bsr_row_ptr,
std::vector<J>& bsr_col_ind,
std::vector<T>& bsr_val,
rocsparse_direction dirb,
J& mb,
J& nb,
I& nnzb,
J& row_block_dim,
J& col_block_dim,
rocsparse_index_base base,
rocsparse_matrix_type matrix_type,
rocsparse_fill_mode uplo,
rocsparse_storage_mode storage)
{
return this->m_instance->init_gebsr(bsr_row_ptr,
bsr_col_ind,
bsr_val,
dirb,
mb,
nb,
nnzb,
row_block_dim,
col_block_dim,
base,
matrix_type,
uplo,
storage);
}
virtual void init_coo(std::vector<I>& coo_row_ind,
std::vector<I>& coo_col_ind,
std::vector<T>& coo_val,
I& m,
I& n,
I& nnz,
rocsparse_index_base base,
rocsparse_matrix_type matrix_type,
rocsparse_fill_mode uplo,
rocsparse_storage_mode storage)
{
return this->m_instance->init_coo(
coo_row_ind, coo_col_ind, coo_val, m, n, nnz, base, matrix_type, uplo, storage);
}
//
// COO
//
void init_coo(std::vector<I>& coo_row_ind,
std::vector<I>& coo_col_ind,
std::vector<T>& coo_val,
I& m,
I& n,
I& nnz,
rocsparse_index_base base);
void init_coo(host_coo_matrix<T, I>& that);
void init_coo(host_coo_matrix<T, I>& that, I& m, I& n);
void init_coo(host_coo_matrix<T, I>& that, I& m, I& n, rocsparse_index_base base);
//
// CSR
//
void init_csr(std::vector<I>& csr_row_ptr,
std::vector<J>& csr_col_ind,
std::vector<T>& csr_val,
J& m,
J& n,
I& nnz,
rocsparse_index_base base);
void init_csr(host_csr_matrix<T, I, J>& that);
void init_csr(host_csr_matrix<T, I, J>& that, J& m, J& n);
void init_csr(host_csr_matrix<T, I, J>& that, J& m, J& n, rocsparse_index_base base);
//
// CSC
//
void init_csc(std::vector<I>& csc_col_ptr,
std::vector<J>& csc_row_ind,
std::vector<T>& csc_val,
J& m,
J& n,
I& nnz,
rocsparse_index_base base);
void init_csc(host_csc_matrix<T, I, J>& that, J& m, J& n, rocsparse_index_base base);
//
// GEBSR
//
void init_gebsr(std::vector<I>& bsr_row_ptr,
std::vector<J>& bsr_col_ind,
std::vector<T>& bsr_val,
rocsparse_direction dirb,
J& mb,
J& nb,
I& nnzb,
J& row_block_dim,
J& col_block_dim,
rocsparse_index_base base);
void init_gebsr(host_gebsr_matrix<T, I, J>& that);
void init_gebsr(host_gebsr_matrix<T, I, J>& that,
J& mb,
J& nb,
J& row_block_dim,
J& col_block_dim,
rocsparse_index_base base_);
void init_gebsr(host_gebsr_matrix<T, I, J>& that,
rocsparse_direction block_dir_,
J& mb_,
J& nb_,
I& nnzb_,
J& row_block_dim_,
J& col_block_dim_,
rocsparse_index_base base_);
void init_gebsr_spezial(host_gebsr_matrix<T, I, J>& that, J& mb, J& nb);
void init_gebsc(std::vector<I>& bsc_col_ptr,
std::vector<J>& bsc_row_ind,
std::vector<T>& bsc_val,
rocsparse_direction dirb,
J& Mb,
J& Nb,
I& nnzb,
J& row_block_dim,
J& col_block_dim,
rocsparse_index_base base);
//
// BSR
//
void init_bsr(std::vector<I>& bsr_row_ptr,
std::vector<J>& bsr_col_ind,
std::vector<T>& bsr_val,
rocsparse_direction dirb,
J& mb,
J& nb,
I& nnzb,
J& block_dim,
rocsparse_index_base base);
void init_bsr(host_gebsr_matrix<T, I, J>& that_, J& mb_, J& nb_, rocsparse_index_base base_);
void init_bsr(host_gebsr_matrix<T, I, J>& that,
device_gebsr_matrix<T, I, J>& that_on_device,
J& mb_,
J& nb_,
rocsparse_index_base base_);
//
// COO AOS
//
void init_coo_aos(host_coo_aos_matrix<T, I>& that, I& m, I& n, rocsparse_index_base base);
//
// ELL
//
void init_ell(host_ell_matrix<T, I>& that, I& m, I& n, rocsparse_index_base base);
//
// HYBRID
//
void init_hyb(
rocsparse_hyb_mat hyb, I& m, I& n, I& nnz, rocsparse_index_base base, bool& conform);
};
//
// Transform a csr matrix in a general bsr matrix.
// It fills the values such as the conversion to the csr matrix
// will give to 1,2,3,4,5,6,7,8,9, etc...
//
template <typename T>
inline void rocsparse_init_gebsr_matrix_from_csr(rocsparse_matrix_factory<T>& matrix_factory,
std::vector<rocsparse_int>& bsr_row_ptr,
std::vector<rocsparse_int>& bsr_col_ind,
std::vector<T>& bsr_val,
rocsparse_direction direction,
rocsparse_int& mb,
rocsparse_int& nb,
rocsparse_int row_block_dim,
rocsparse_int col_block_dim,
rocsparse_int& nnzb,
rocsparse_index_base bsr_base)
{
// Uncompressed CSR matrix on host
std::vector<T> hcsr_val_A;
// Generate uncompressed CSR matrix on host (or read from file)
matrix_factory.init_csr(bsr_row_ptr, bsr_col_ind, hcsr_val_A, mb, nb, nnzb, bsr_base);
bsr_val.resize(row_block_dim * col_block_dim * nnzb);
rocsparse_int idx = 0;
switch(direction)
{
case rocsparse_direction_column:
{
for(rocsparse_int i = 0; i < mb; ++i)
{
for(rocsparse_int r = 0; r < row_block_dim; ++r)
{
for(rocsparse_int k = bsr_row_ptr[i] - bsr_base; k < bsr_row_ptr[i + 1] - bsr_base;
++k)
{
for(rocsparse_int c = 0; c < col_block_dim; ++c)
{
bsr_val[k * row_block_dim * col_block_dim + c * row_block_dim + r]
= static_cast<T>(++idx);
}
}
}
}
break;
}
case rocsparse_direction_row:
{
for(rocsparse_int i = 0; i < mb; ++i)
{
for(rocsparse_int r = 0; r < row_block_dim; ++r)
{
for(rocsparse_int k = bsr_row_ptr[i] - bsr_base; k < bsr_row_ptr[i + 1] - bsr_base;
++k)
{
for(rocsparse_int c = 0; c < col_block_dim; ++c)
{
bsr_val[k * row_block_dim * col_block_dim + r * col_block_dim + c]
= static_cast<T>(++idx);
}
}
}
}
break;
}
}
}
#endif // ROCSPARSE_MATRIX_FACTORY_HPP
|