Cyclops Tensor Framework
parallel arithmetic on multidimensional arrays
sum_tsr.h
Go to the documentation of this file.
1 /*Copyright (c) 2011, Edgar Solomonik, all rights reserved.*/
2 
3 #ifndef __SUM_TSR_H__
4 #define __SUM_TSR_H__
5 
6 #include "../tensor/algstrct.h"
7 #include "../interface/fun_term.h"
8 
9 namespace CTF_int {
10  class summation;
15  public:
16  void (*f)(char const *, char *);
17 
18  bool is_distributive = false;
19 
25  virtual void apply_f(char const * a, char * b)const { f(a,b); }
26 
33  virtual void acc_f(char const * a, char * b, CTF_int::algstrct const * sr_B) const {
34 
35  char tb[sr_B->el_size];
36  f(a,tb);
37  sr_B->add(b, tb, b);
38  }
39 
40  virtual bool is_transform() const { return false; };
41 
42  univar_function(void (*f_)(char const *, char *)) { f=f_; }
43  univar_function(void (*f_)(char const *, char *), bool is_dist) { f=f_; is_distributive=is_dist; }
45  univar_function(univar_function const & other) { f = other.f; is_distributive=other.is_distributive; }
46 
52  Unifun_Term operator()(Term const & A) const;
53 
59  void operator()(Term const & A, Term const & B) const;
60 
61  virtual ~univar_function(){}
62 
63  virtual bool is_accumulator() const { return false; }
64  };
65 
66 
67  class tsum {
68  public:
69  char * A;
70  algstrct const * sr_A;
71  char const * alpha;
72  char * B;
73  algstrct const * sr_B;
74  char const * beta;
75  void * buffer;
76 
77  virtual void run() {};
78  virtual void print() {};
79 // virtual int64_t calc_new_nnz_B() { return nnz_B; } //if sparse
84  virtual int64_t mem_fp() { return 0; };
85  virtual tsum * clone() { return NULL; };
86  virtual ~tsum();
87  tsum(tsum * other);
88  tsum(summation const * s);
89  };
90 
91  class tsum_virt : public tsum {
92  public:
93  /* Class to be called on sub-blocks */
95 
96  int num_dim;
97  int * virt_dim;
98  int order_A;
99  int64_t blk_sz_A; //if dense
100  int const * idx_map_A;
101  int order_B;
102  int64_t blk_sz_B; //if dense
103  int const * idx_map_B;
104 
105  void run();
106  void print();
107  int64_t mem_fp();
108  tsum * clone();
109 
113  tsum_virt(tsum * other);
114  ~tsum_virt();
115  tsum_virt(summation const * s);
116  };
117 
118 
122  class tsum_replicate : public tsum {
123  public:
124  int64_t size_A; /* size of A blocks */
125  int64_t size_B; /* size of B blocks */
126  int ncdt_A; /* number of processor dimensions to replicate A along */
127  int ncdt_B; /* number of processor dimensions to replicate B along */
128 
131  /* Class to be called on sub-blocks */
133 
134  void run();
135  void print();
136  int64_t mem_fp();
137  tsum * clone();
138 
139  tsum_replicate(tsum * other);
140  ~tsum_replicate();
141  tsum_replicate(summation const * s,
142  int const * phys_mapped,
143  int64_t blk_sz_A,
144  int64_t blk_sz_B);
145  };
146 
147  class seq_tsr_sum : public tsum {
148  public:
149  int order_A;
150  int * edge_len_A;
151  int const * idx_map_A;
152  int * sym_A;
153  int order_B;
154  int * edge_len_B;
155  int const * idx_map_B;
156  int * sym_B;
157  //fseq_tsr_sum func_ptr;
158 
159  int is_inner;
161 
162  int64_t map_pfx;
163 
165  univar_function const * func; //fseq_elm_sum custom_params;
166 
170  void run();
171  void print();
172  int64_t mem_fp();
173  tsum * clone();
174 
179  seq_tsr_sum(tsum * other);
180  ~seq_tsr_sum(){ CTF_int::cdealloc(edge_len_A), CTF_int::cdealloc(edge_len_B),
181  CTF_int::cdealloc(sym_A), CTF_int::cdealloc(sym_B); };
182  seq_tsr_sum(summation const * s);
183 
184  };
185 
195  void inv_idx(int order_A,
196  int const * idx_A,
197  int order_B,
198  int const * idx_B,
199  int * order_tot,
200  int ** idx_arr);
201 
202 }
203 
204 #endif // __SUM_TSR_H__
a term is an abstract object representing some expression of tensors
Definition: term.h:33
CommData ** cdt_A
Definition: sum_tsr.h:129
algstrct const * sr_A
Definition: sum_tsr.h:70
void * buffer
Definition: sum_tsr.h:75
virtual bool is_transform() const
Definition: sum_tsr.h:40
Unifun_Term operator()(Term const &A) const
evaluate B=f(A)
Definition: sum_tsr.cxx:10
void inv_idx(int order_A, int const *idx_A, int order_B, int const *idx_B, int order_C, int const *idx_C, int *order_tot, int **idx_arr)
invert index map
Definition: ctr_tsr.cxx:592
int const * idx_map_B
Definition: sum_tsr.h:155
int const * idx_map_A
Definition: sum_tsr.h:151
univar_function(univar_function const &other)
Definition: sum_tsr.h:45
tsum * rec_tsum
Definition: sum_tsr.h:94
untyped internal class for doubly-typed univariate function
Definition: sum_tsr.h:14
int64_t blk_sz_B
Definition: sum_tsr.h:102
univar_function(void(*f_)(char const *, char *), bool is_dist)
Definition: sum_tsr.h:43
int const * idx_map_A
Definition: sum_tsr.h:100
virtual int64_t mem_fp()
returns the number of bytes of buffer space needed
Definition: sum_tsr.h:84
performs replication along a dimension, generates 2.5D algs
Definition: sum_tsr.h:122
virtual void acc_f(char const *a, char *b, CTF_int::algstrct const *sr_B) const
compute b = b+f(a)
Definition: sum_tsr.h:33
virtual bool is_accumulator() const
Definition: sum_tsr.h:63
virtual void run()
Definition: sum_tsr.h:77
univar_function const * func
Definition: sum_tsr.h:165
univar_function(void(*f_)(char const *, char *))
Definition: sum_tsr.h:42
char const * alpha
Definition: sum_tsr.h:71
char * B
Definition: sum_tsr.h:72
CommData ** cdt_B
Definition: sum_tsr.h:130
void(* f)(char const *, char *)
Definition: sum_tsr.h:16
virtual void add(char const *a, char const *b, char *c) const
c = a+b
Definition: algstrct.cxx:109
int el_size
size of each element of algstrct in bytes
Definition: algstrct.h:16
int cdealloc(void *ptr)
free abstraction
Definition: memcontrol.cxx:480
algstrct (algebraic structure) defines the elementwise operations computed in each tensor contraction...
Definition: algstrct.h:34
algstrct const * sr_B
Definition: sum_tsr.h:73
virtual tsum * clone()
Definition: sum_tsr.h:85
virtual ~univar_function()
Definition: sum_tsr.h:61
class for execution distributed summation of tensors
Definition: summation.h:15
int64_t blk_sz_A
Definition: sum_tsr.h:99
int const * idx_map_B
Definition: sum_tsr.h:103
char * A
Definition: sum_tsr.h:69
virtual void print()
Definition: sum_tsr.h:78
char const * beta
Definition: sum_tsr.h:74
virtual void apply_f(char const *a, char *b) const
apply function f to value stored at a
Definition: sum_tsr.h:25