8 #ifndef GRID_DGEMM_TENSOR_LOCAL_H
9 #define GRID_DGEMM_TENSOR_LOCAL_H
46 const int *
const sizes) {
51 for (
int d = 0;
d < dim;
d++)
52 a->size[
d] = sizes[
d];
56 a->ld_ = sizes[
a->dim_ - 1];
59 a->offsets[0] =
a->ld_ *
a->size[1] *
a->size[2];
60 a->offsets[1] =
a->ld_ *
a->size[2];
61 a->offsets[2] =
a->ld_;
65 a->offsets[0] =
a->ld_ *
a->size[1];
66 a->offsets[1] =
a->ld_;
69 a->offsets[0] =
a->ld_;
75 a->alloc_size_ =
a->offsets[0] *
a->size[0];
85 int size_[2] = {n1, n2};
95 int size_[3] = {n1, n2, n3};
105 int size_[4] = {n1, n2, n3, n4};
118 a->data = (
double *)malloc(
sizeof(
double) *
a->alloc_size_);
121 a->old_alloc_size_ =
a->alloc_size_;
136 return a->alloc_size_;
142 a->data = (
double *)data;
164 a->offsets[0] =
a->ld_ *
a->size[1] *
a->size[2] *
a->size[3];
165 a->offsets[1] =
a->ld_ *
a->size[1] *
a->size[2];
166 a->offsets[2] =
a->ld_ *
a->size[2];
167 a->offsets[3] =
a->ld_;
171 a->offsets[0] =
a->ld_ *
a->size[1] *
a->size[2];
172 a->offsets[1] =
a->ld_ *
a->size[2];
173 a->offsets[2] =
a->ld_;
177 a->offsets[0] =
a->ld_ *
a->size[1];
178 a->offsets[1] =
a->ld_;
181 a->offsets[0] =
a->ld_;
190 return (n1 * n2 * n3);
194 const int n3,
const int n4) {
195 return (n1 * n2 * n3 * n4);
199 const int *
const full_size) {
200 switch (
grid->dim_) {
202 grid->full_size[0] = full_size[0];
205 grid->full_size[1] = full_size[0];
206 grid->full_size[0] = full_size[1];
209 grid->full_size[0] = full_size[2];
210 grid->full_size[1] = full_size[1];
211 grid->full_size[2] = full_size[0];
214 for (
int d = 0;
d <
grid->dim_;
d++)
215 grid->full_size[
d] = full_size[
grid->dim_ -
d - 1];
221 const int *
const shift_local,
222 const int *
const border_width,
223 const int border_mask) {
224 for (
int d = 0;
d <
grid->dim_;
d++) {
225 grid->lower_corner[
d] = shift_local[
grid->dim_ -
d - 1];
226 grid->window_shift[
d] = 0;
229 grid->window_size[
d]--;
234 if (border_mask & (1 << 0))
235 grid->window_shift[2] += border_width[0];
236 if (border_mask & (1 << 1))
237 grid->window_size[2] -= border_width[0];
238 if (border_mask & (1 << 2))
239 grid->window_shift[1] += border_width[1];
240 if (border_mask & (1 << 3))
241 grid->window_size[1] -= border_width[1];
242 if (border_mask & (1 << 4))
243 grid->window_shift[0] += border_width[2];
244 if (border_mask & (1 << 5))
245 grid->window_size[0] -= border_width[2];
252 #define idx5(a, i, j, k, l, m) \
253 a.data[(i)*a.offsets[0] + (j)*a.offsets[1] + (k)*a.offsets[2] + (l)*a.ld_ + m]
254 #define idx4(a, i, j, k, l) \
255 a.data[(i)*a.offsets[0] + (j)*a.offsets[1] + (k)*a.ld_ + (l)]
256 #define idx3(a, i, j, k) a.data[(i)*a.offsets[0] + (j)*a.ld_ + (k)]
257 #define idx2(a, i, j) a.data[(i)*a.ld_ + (j)]
static void const int const int const int const int const int const double const int const int const int int GRID_CONST_WHEN_COLLOCATE double GRID_CONST_WHEN_INTEGRATE double * grid
static int tensor_get_leading_dimension(struct tensor_ *a)
static void setup_grid_window(tensor *const grid, const int *const shift_local, const int *const border_width, const int border_mask)
static size_t compute_memory_space_tensor_4(const int n1, const int n2, const int n3, const int n4)
static void initialize_tensor_4(struct tensor_ *a, int n1, int n2, int n3, int n4)
static void recompute_tensor_offsets(struct tensor_ *a)
static size_t compute_memory_space_tensor_3(const int n1, const int n2, const int n3)
static void setup_global_grid_size(tensor *const grid, const int *const full_size)
static void destroy_tensor(tensor *a)
static void initialize_tensor_3(struct tensor_ *a, int n1, int n2, int n3)
void tensor_copy(tensor *const b, const tensor *const a)
static void initialize_tensor_2(struct tensor_ *a, int n1, int n2)
static void tensor_assign_memory(struct tensor_ *a, void *data)
static tensor * create_tensor(const int dim, const int *sizes)
size_t realloc_tensor(tensor *t)
static void tensor_set_leading_dimension(struct tensor_ *a, const int ld)
static void initialize_tensor(struct tensor_ *a, const int dim, const int *const sizes)
void alloc_tensor(tensor *t)
static size_t tensor_return_memory_size(const struct tensor_ *const a)