Agora
1.2.0
Agora project
|
Go to the documentation of this file.
6 #ifndef MEMORY_MANAGE_H_
7 #define MEMORY_MANAGE_H_
41 size_t alloc_size = (this->
dim1_ * this->
dim2_ *
sizeof(
T));
42 this->data_ =
static_cast<T*
>(
47 this->
Malloc(dim1, dim2, alignment);
48 std::memset(
static_cast<void*
>(this->data_), 0,
56 std::default_random_engine generator;
57 std::uniform_real_distribution<float> distribution(-1.0, 1.0);
59 assert(
sizeof(
T) >=
sizeof(
float));
60 this->
Malloc(dim1, dim2, alignment);
61 auto* base =
reinterpret_cast<float*
>(this->
data_);
62 for (
size_t i = 0;
i < (dim1 * dim2);
i++) {
63 base[
i] = distribution(generator);
71 std::default_random_engine generator;
72 std::uniform_real_distribution<float> distribution(-1.0, 1.0);
74 assert(
sizeof(
T) >=
sizeof(std::complex<float>));
75 this->
Malloc(dim1, dim2, alignment);
76 auto* base =
reinterpret_cast<std::complex<float>*
>(this->
data_);
77 for (
size_t i = 0;
i < (dim1 * dim2);
i++) {
78 base[
i] = {distribution(generator), distribution(generator)};
85 if (this->data_ !=
nullptr) {
86 std::free(this->data_);
90 this->data_ =
nullptr;
96 assert(this->
dim1_ > dim1);
97 return (this->data_ + (dim1 * this->
dim2_));
104 template <
typename T,
typename U>
107 size_t size = dim *
sizeof(
T);
111 std::memset(
static_cast<void*
>(*buffer), 0
u,
size);
115 template <
typename T>
122 template <
size_t ROWS,
size_t COLS,
class T>
129 explicit PtrGrid(
size_t num_entries) { this->
Alloc(ROWS, COLS, num_entries); }
149 const size_t alloc_sz =
n_rows *
n_cols * n_entries *
sizeof(
T);
152 std::memset(
static_cast<void*
>(this->backing_buf_), 0, alloc_sz);
157 for (
size_t j = 0; j <
n_cols; j++) {
158 mat_[
i][j] = &this->backing_buf_[offset];
167 static_assert(
sizeof(
T) == 2 *
sizeof(
float),
"T must be complex_float");
168 Alloc(ROWS, COLS, n_entries);
170 std::default_random_engine generator;
171 std::uniform_real_distribution<float> distribution(-1.0, 1.0);
174 for (
auto& entry :
row) {
175 auto* base =
reinterpret_cast<float*
>(entry);
176 for (
size_t i = 0;
i < n_entries * 2;
i++) {
177 base[
i] = distribution(generator);
184 return this->
mat_[row_idx];
192 std::array<std::array<T*, COLS>, ROWS>
mat_;
201 template <
size_t DIM1,
size_t DIM2,
size_t DIM3,
class T>
209 this->
Alloc(DIM1, DIM2, DIM3, num_entries);
216 PtrCube(
size_t dim_1,
size_t dim_2,
size_t dim_3,
size_t n_entries) {
217 assert(dim_1 <= DIM1 && dim_2 <= DIM2 && dim_3 <= DIM3);
218 this->
Alloc(dim_1, dim_2, dim_3, n_entries);
229 void Alloc(
size_t dim_1,
size_t dim_2,
size_t dim_3,
size_t n_entries) {
230 const size_t alloc_sz = dim_1 * dim_2 * dim_3 * n_entries *
sizeof(
T);
233 std::memset(
static_cast<void*
>(this->backing_buf_), 0, alloc_sz);
236 for (
auto& mat : this->
cube_) {
237 for (
auto&
row : mat) {
238 for (
auto& entry :
row) {
245 for (
size_t i = 0;
i < dim_1;
i++) {
246 for (
size_t j = 0; j < dim_2; j++) {
247 for (
size_t k = 0; k < dim_3; k++) {
248 this->cube_[
i][j][k] = &this->backing_buf_[offset];
255 std::array<std::array<T*, DIM3>, DIM2>&
operator[](
size_t row_idx) {
256 return this->
cube_[row_idx];
265 std::array<std::array<std::array<T*, DIM3>, DIM2>, DIM1>
cube_;
272 #endif // MEMORY_MANAGE_H_
void Alloc(size_t n_rows, size_t n_cols, size_t n_entries)
Allocate [n_entries] entries per pointer cell.
Definition: memory_manage.h:148
void Calloc(size_t dim1, size_t dim2, Agora_memory::Alignment_t alignment)
Definition: memory_manage.h:45
bool IsAllocated()
Definition: memory_manage.h:82
end IFFT Reshape the symbol vector into two different spatial streams size
Definition: generate_data.m:73
static void FreeBuffer1d(T **buffer)
Definition: memory_manage.h:116
const T * At(size_t dim1) const
Definition: memory_manage.h:93
void * PaddedAlignedAlloc(Alignment_t alignment, size_t size)
Definition: memory_manage.cc:15
Table()
Definition: memory_manage.h:35
PtrGrid(size_t num_entries)
Definition: memory_manage.h:129
std::array< T *, COLS > & operator[](size_t row_idx)
Definition: memory_manage.h:183
Alignment_t
Definition: memory_manage.h:18
static void AllocBuffer1d(T **buffer, U dim, Agora_memory::Alignment_t alignment, int init_zero)
Definition: memory_manage.h:105
PtrCube(size_t num_entries)
Definition: memory_manage.h:208
Definition: memory_manage.h:28
size_t dim1_
Definition: memory_manage.h:31
T * operator[](size_t dim1)
Definition: memory_manage.h:95
Definition: memory_manage.h:123
std::array< std::array< T *, DIM3 >, DIM2 > & operator[](size_t row_idx)
Definition: memory_manage.h:255
PtrGrid & operator=(PtrGrid const &)=delete
list row
Definition: plot_csv.py:11
size_t Dim1()
Definition: memory_manage.h:100
PtrGrid()
Definition: memory_manage.h:125
void Free()
Definition: memory_manage.h:84
PtrCube(size_t dim_1, size_t dim_2, size_t dim_3, size_t n_entries)
Definition: memory_manage.h:216
for i
Definition: generate_data.m:107
Plot Rx waveform for u
Definition: inspect_single_frame.m:108
n_rows
Definition: plot_csv.py:18
~PtrGrid()
Definition: memory_manage.h:140
T * backing_buf_
The pointer cells.
Definition: memory_manage.h:196
n_cols
Definition: plot_csv.py:18
std::array< std::array< T *, COLS >, ROWS > mat_
Definition: memory_manage.h:192
PtrCube & operator=(PtrCube const &)=delete
Definition: memory_manage.cc:3
PtrCube()
Definition: memory_manage.h:204
T * backing_buf_
Definition: memory_manage.h:269
~PtrCube()
Definition: memory_manage.h:221
size_t Dim2()
Definition: memory_manage.h:101
void Malloc(size_t dim1, size_t dim2, Agora_memory::Alignment_t alignment)
Definition: memory_manage.h:37
PtrGrid(size_t n_rows, size_t n_cols, size_t n_entries)
Definition: memory_manage.h:135
size_t dim2_
Definition: memory_manage.h:30
void Alloc(size_t dim_1, size_t dim_2, size_t dim_3, size_t n_entries)
Allocate [n_entries] entries per pointer cell.
Definition: memory_manage.h:229
Definition: memory_manage.h:202
size_t PaddedAllocSize(Alignment_t alignment, size_t size)
Definition: memory_manage.cc:4
T * data_
Definition: memory_manage.h:32
void RandAllocCxFloat(size_t dim1, size_t dim2, Agora_memory::Alignment_t alignment)
Definition: memory_manage.h:69
std::array< std::array< std::array< T *, DIM3 >, DIM2 >, DIM1 > cube_
The pointer cells.
Definition: memory_manage.h:265
void RandAllocFloat(size_t dim1, size_t dim2, Agora_memory::Alignment_t alignment)
Definition: memory_manage.h:54
void RandAllocCxFloat(size_t n_entries)
Definition: memory_manage.h:166