STORMM Source Documentation
Loading...
Searching...
No Matches
matrix.h
1// -*-c++-*-
2#ifndef STORMM_MATRIX_H
3#define STORMM_MATRIX_H
4
5#include "copyright.h"
6#include "Accelerator/hybrid.h"
7#include "Random/random.h"
8
9namespace stormm {
10namespace stmath {
11
12using card::default_hpc_format;
13using card::Hybrid;
14using card::HybridFormat;
15using card::HybridKind;
16using card::HybridLabel;
17using card::HybridTargetLevel;
18using random::Ran2Generator;
19
20enum class MatrixFillMode {
21 ZEROS,
22 ONES,
23 EYE,
24 RANDU,
25 RANDN,
26 VALUE,
27};
28
30template <typename T> class HpcMatrix {
31public:
32
33 // Public-facing, read-only forms of the private variables (allows syntactically simpler access
34 // than getter functions)
35 const size_t& n_rows;
36 const size_t& n_cols;
37 const size_t& n_elem;
38
53 HpcMatrix(const char* tag_in = nullptr, HybridFormat format_in = default_hpc_format);
54 HpcMatrix(size_t rows_in, size_t cols_in, const char* tag_in = nullptr,
55 HybridFormat format_in = default_hpc_format,
56 MatrixFillMode fill_method = MatrixFillMode::VALUE, T fill_value = static_cast<T>(0));
57 HpcMatrix(size_t rows_in, size_t cols_in, MatrixFillMode fill_method,
58 T fill_value = static_cast<T>(0), const char* tag_in = nullptr,
59 HybridFormat format_in = default_hpc_format);
60 HpcMatrix(size_t rows_in, size_t cols_in, MatrixFillMode fill_method,
61 Ran2Generator *matrng, const char* tag_in = nullptr,
62 HybridFormat format_in = default_hpc_format);
64
67
74 void resize(size_t new_rows, size_t new_cols);
75
77 void reset();
78
88 const T* memptr(HybridTargetLevel tier = HybridTargetLevel::HOST) const;
89 T* memptr(HybridTargetLevel tier = HybridTargetLevel::HOST);
91
98 T operator()(size_t row_idx, size_t col_idx, HybridTargetLevel tier = HybridTargetLevel::HOST);
99
105 T atHost(size_t row_idx, size_t col_idx);
106
112 T atDevice(size_t row_idx, size_t col_idx);
113
118 Hybrid<T> colptr(size_t col_idx, const char* tag_in = nullptr);
119
120#ifdef STORMM_USE_HPC
122 void upload();
123
125 void download();
126#endif
127
128private:
129 size_t n_rows_pr;
130 size_t n_cols_pr;
131 size_t n_elem_pr;
132 Hybrid<T> contents;
133#ifdef STORMM_USE_HPC
134 Hybrid<T> transfer_buffer;
137 T* devc_data;
139#endif
140 T* host_data;
142};
143
144} // namespace stmath
145} // namespace stormm
146
147#include "matrix.tpp"
148
149#endif
An evolution of GpuBuffer in pmemd.cuda, the Composite array has elements that are accessible from ei...
Definition hybrid.h:202
Stores the state of a Ran2 pseudo-random number generator. Member functions produce random numbers al...
Definition random.h:81
const T * memptr(HybridTargetLevel tier=HybridTargetLevel::HOST) const
Pointer to the memory itself, on the host or the device. This takes its name from the Armadillo vec,...
T atDevice(size_t row_idx, size_t col_idx)
Element-wise access to data on the GPU without bounds checks, following on the Armadillo naming conve...
T operator()(size_t row_idx, size_t col_idx, HybridTargetLevel tier=HybridTargetLevel::HOST)
Element-wise access via the function call () operator. This entails two bounds checks.
HpcMatrix(const char *tag_in=nullptr, HybridFormat format_in=default_hpc_format)
Constructors must set public-facing reference variables in addition to private member variables.
T atHost(size_t row_idx, size_t col_idx)
Element-wise access to host data without bounds checks, following on the Armadillo naming conventions...
void resize(size_t new_rows, size_t new_cols)
Change the number of rows and columns. Elements outside the bounds of the new matrix will be discarde...
Hybrid< T > colptr(size_t col_idx, const char *tag_in=nullptr)
Get a Hybrid POINTER-kind object that is set directly to the column of interest.
void reset()
Empty the matrix and set its size to 0 by 0.
HybridLabel getLabel() const
Produce the label for this matrix (obtained from the label of its primary contents)
A Hybrid object's immutable identifying information, stored as a const member variable within the Hyb...
Definition hybrid.h:65