Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Rocblas.h
Go to the documentation of this file.
1 /* *******************************************************************
2  * Rocstar Simulation Suite *
3  * Copyright@2015, Illinois Rocstar LLC. All rights reserved. *
4  * *
5  * Illinois Rocstar LLC *
6  * Champaign, IL *
7  * www.illinoisrocstar.com *
8  * sales@illinoisrocstar.com *
9  * *
10  * License: See LICENSE file in top level of distribution package or *
11  * http://opensource.org/licenses/NCSA *
12  *********************************************************************/
13 /* *******************************************************************
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
16  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND *
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR *
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
20  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
21  * USE OR OTHER DEALINGS WITH THE SOFTWARE. *
22  *********************************************************************/
23 // $Id: Rocblas.h,v 1.14 2009/08/07 23:24:11 gzagaris Exp $
24 
28 /* Author: Greg Mackey and Xiangmin Jiao
29  * Creation date: 3/3/2002
30  */
31 #include <cstdio>
32 #include "roccom.h"
33 #include "roccom_devel.h"
34 
35 USE_COM_NAME_SPACE
36 
37 class Rocblas {
38  typedef unsigned int Size;
39 public:
41  static
42  void init(const std::string &name);
43 
45  static
46  void finalize(const std::string &name);
47 
49  static
50  void add(const Attribute *x, const Attribute *y, Attribute *z);
51 
53  static
54  void sub(const Attribute *x, const Attribute *y, Attribute *z);
55 
57  static
58  void mul(const Attribute *x, const Attribute *y, Attribute *z);
59 
61  static
62  void limit1(const Attribute *x, const Attribute *y, Attribute *z);
63 
65  static
66  void div(const Attribute *x, const Attribute *y, Attribute *z);
67 
69  static
70  void add_scalar(const Attribute *x, const void *y, Attribute *z, int swap = 0);
71 
73  static
74  void sub_scalar(const Attribute *x, const void *y, Attribute *z, int swap = 0);
75 
77  static
78  void mul_scalar(const Attribute *x, const void *y, Attribute *z, int swap = 0);
79 
81  static
82  void div_scalar(const Attribute *x, const void *y, Attribute *z, int swap = 0);
83 
85  static
86  void maxof_scalar(const Attribute *x, const void *y, Attribute *z, int swap = 0);
87 
89  static
90  void dot(const Attribute *x, const Attribute *y, Attribute *z,
91  const Attribute *mults=NULL);
92 
94  static
95  void dot_scalar(const Attribute *x, const Attribute *y, void *z,
96  const Attribute *mults=NULL);
97 
99  static
100  void dot_MPI(const Attribute *x, const Attribute *y, Attribute *z,
101  const MPI_Comm *comm=NULL, const Attribute *mults=NULL);
102 
104  static
105  void dot_scalar_MPI(const Attribute *x, const Attribute *y, void *z,
106  const MPI_Comm *comm=NULL, const Attribute *mults=NULL);
107 
109  static
110  void nrm2(const Attribute *x, Attribute *y, const Attribute*mults=NULL);
111 
113  static
114  void nrm2_scalar(const Attribute *x, void *y, const Attribute*mults=NULL);
115 
117  static
118  void nrm2_MPI(const Attribute *x, Attribute *y,
119  const MPI_Comm *comm=NULL, const Attribute*mults=NULL);
120 
122  static
123  void nrm2_scalar_MPI(const Attribute *x, void *y,
124  const MPI_Comm *comm, const Attribute *mults=NULL);
125 
127  static
128  void swap(Attribute *x, Attribute *y);
129 
131  static
132  void copy(const Attribute *x, Attribute *y);
133 
135  static
136  void rand(const Attribute *a, Attribute *z);
137 
139  static
140  void copy_scalar(const void *x, Attribute *y);
141 
143  static
144  void rand_scalar(const void *a, Attribute *z);
145 
147  static
148  void neg(const Attribute *x, Attribute *y);
149 
151  static
152  void sqrt(const Attribute *x, Attribute *y);
153 
155  static
156  void acos(const Attribute *x, Attribute *y);
157 
159  static
160  void max_MPI(const Attribute *x, Attribute *y, const MPI_Comm *comm=NULL);
161 
163  static
164  void max_scalar_MPI(const Attribute *x, void *y, const MPI_Comm *comm=NULL);
165 
167  static
168  void min_MPI(const Attribute *x, Attribute *y, const MPI_Comm *comm=NULL);
169 
171  static
172  void min_scalar_MPI(const Attribute *x, void *y, const MPI_Comm *comm=NULL);
173 
175  static
176  void sum_MPI(const Attribute *x, Attribute *y, const MPI_Comm *comm=NULL);
177 
179  static
180  void sum_scalar_MPI(const Attribute *x, void *y, const MPI_Comm *comm=NULL);
181 
183  static
184  void axpy(const Attribute *a, const Attribute *x, const Attribute *y,
185  Attribute *z);
186 
188  static
189  void axpy_scalar(const void *a, const Attribute *x, const Attribute *y,
190  Attribute *z);
191 
192 protected:
194  template <class FuncType, int ytype>
195  static
196  void calc(Attribute *z, const Attribute *x, const void *yin,
197  FuncType opp, bool swap=false);
198 
200  template <class data_type, int ztype>
201  static
202  void calcDot( void *zout, const Attribute *x, const Attribute *y,
203  const MPI_Comm *comm=NULL, const Attribute *mults=NULL);
204 
206  template <class FuncType, int ytype>
207  static
208  void gen2arg( Attribute *z, void *yin, FuncType opp);
209 
211  template <class data_type, int atype>
212  static
213  void axpy_gen( const void *a, const Attribute *x, const Attribute *y,
214  Attribute *z);
215 
217  template <class FuncType>
218  static
219  void calcChoose(const Attribute *x, const Attribute *y, Attribute *z,
220  FuncType opp);
221 
222 
223  template < class Op> static
224  void copy_helper( const Attribute *x, Attribute *z);
225 
226  //Function object that implements an assignment.
227  template <class T_src, class T_trg> struct assn;
228 
229  //Function object that implements a random number generator.
230  template <class T> struct random;
231 
232  //Function object that implements a swap.
233  template <class T> struct swapp;
234 
235  //Function object that implements a max operation.
236  template <class T> struct maxv;
237 
238  //Function object that implements a min operation.
239  template <class T> struct minv;
240 
241  //Function object that implements a sum operation.
242  template <class T> struct sumv;
243 
244  //Function object that implements a negation.
245  template <class T> struct nega;
246 
247  //Function object that implements sqrt.
248  template <class T> struct sqrta;
249 
250  //Function object that implements acos.
251  template <class T> struct acosa;
252 
253  //Function object that implements a limit1.
254  template <class T> struct limit1v;
255 
256  //Function object that implements a maxof.
257  template <class T> struct maxof;
258 
260 
261  template <int attr_type>
262  inline static int
263  get_stride( const Attribute *attr);
264 
265  template <class data_type, int attr_type, bool is_staggered>
266  inline static data_type &
267  getref( data_type *base, const int r, const int c, const int nc);
268 
269  template <class data_type, int attr_type, bool is_staggered>
270  inline static const data_type &
271  getref( const data_type *base, const int r, const int c, const int nc);
272 
273  template <class OPint, class OPdbl, int OPMPI>
274  inline static
275  void reduce_MPI(const Attribute *x, Attribute *z,
276  const MPI_Comm *comm, int, double);
277 
278  template <class OPint, class OPdbl, int OPMPI>
279  inline static
280  void reduce_scalar_MPI(const Attribute *x, void *y,
281  const MPI_Comm* comm, int, double);
282 
283  static std::string to_str(int i) {
284  char buf[10];
285  std::sprintf( buf, "%d", i);
286  return buf;
287  }
288 };
289 
290 template <int attr_type>
291 inline int Rocblas::get_stride( const Attribute *attr) {
292  if ( attr_type == BLAS_SCNE || attr_type == BLAS_VEC2D) {
293  if ( attr->size_of_items()>1)
294  return attr->stride();
295  else
296  return 0;
297  }
298  else if ( attr_type == BLAS_VEC)
299  return 0;
300  else
301  return 1;
302 }
303 
304 template <class data_type, int attr_type, bool is_staggered>
305 inline data_type &
306 Rocblas::getref( data_type *base, const int r, const int c, const int nc) {
307  if ( attr_type == BLAS_SCNE || attr_type == BLAS_VEC2D && is_staggered)
308  return base[r*nc];
309  else if ( attr_type == BLAS_VEC2D)
310  return base[r*nc+c];
311  else if ( attr_type == BLAS_VEC)
312  return base[c];
313  else
314  return *base;
315 }
316 
317 template <class data_type, int attr_type, bool is_staggered>
318 inline const data_type &
319 Rocblas::getref( const data_type *base, const int r,
320  const int c, const int nc) {
321  if ( attr_type == BLAS_SCNE || attr_type == BLAS_VEC2D && is_staggered)
322  return base[r*nc];
323  else if ( attr_type == BLAS_VEC2D)
324  return base[r*nc+c];
325  else if ( attr_type == BLAS_VEC)
326  return base[c];
327  else
328  return *base;
329 }
330 
331 
333 extern "C" void Rocblas_load_module(const char *name);
334 extern "C" void Rocblas_unload_module(const char *name);
335 
336 
static void div_scalar(const Attribute *x, const void *y, Attribute *z, int swap=0)
Operation wrapper for division with y as a scalar pointer.
Definition: op3args.C:363
static void reduce_MPI(const Attribute *x, Attribute *z, const MPI_Comm *comm, int, double)
Definition: op2args.C:630
static void sub(const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for subtraction.
Definition: op3args.C:237
static void calcDot(void *zout, const Attribute *x, const Attribute *y, const MPI_Comm *comm=NULL, const Attribute *mults=NULL)
Performs the operation: z = &lt;x, y&gt;
Definition: dots.C:27
static void nrm2_scalar(const Attribute *x, void *y, const Attribute *mults=NULL)
Wrapper for 2-norm with y as a scalar pointer.
Definition: dots.C:293
static void calc(Attribute *z, const Attribute *x, const void *yin, FuncType opp, bool swap=false)
Performs the operation: z = x op y.
Definition: op3args.C:49
An Attribute object is a data member of a window.
Definition: Attribute.h:51
void int int REAL REAL * y
Definition: read.cpp:74
static void nrm2_MPI(const Attribute *x, Attribute *y, const MPI_Comm *comm=NULL, const Attribute *mults=NULL)
Wrapper for 2-norm with MPI.
Definition: dots.C:298
static void rand(const Attribute *a, Attribute *z)
Generate a random number between 0 and $a$ for each entry in z.
Definition: op2args.C:388
This file contains the prototypes for Roccom API.
static void max_scalar_MPI(const Attribute *x, void *y, const MPI_Comm *comm=NULL)
Operation wrapper for max (y is a scalar pointer).
Definition: op2args.C:763
static void init(const std::string &name)
Creates window for Rocblas and registers functions.
Definition: Rocblas.C:37
static void limit1(const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for limit1.
Definition: op3args.C:284
static void dot_scalar_MPI(const Attribute *x, const Attribute *y, void *z, const MPI_Comm *comm=NULL, const Attribute *mults=NULL)
Wrapper for 2-norm with z as a scalar pointer.
Definition: dots.C:264
static void axpy(const Attribute *a, const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for z = a * x + y.
Definition: axpy.C:170
static void min_MPI(const Attribute *x, Attribute *y, const MPI_Comm *comm=NULL)
Wrapper for min.
Definition: op2args.C:714
static void max_MPI(const Attribute *x, Attribute *y, const MPI_Comm *comm=NULL)
Wrapper for max.
Definition: op2args.C:708
static void acos(const Attribute *x, Attribute *y)
Wrapper for acos (y=acos(x)).
Definition: op2args.C:545
static void add(const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for addition.
Definition: op3args.C:221
static void mul_scalar(const Attribute *x, const void *y, Attribute *z, int swap=0)
Operation wrapper for multiplication with y as a scalar pointer.
Definition: op3args.C:347
static void finalize(const std::string &name)
Delete window for Rocblas.
Definition: Rocblas.C:112
static void dot_scalar(const Attribute *x, const Attribute *y, void *z, const Attribute *mults=NULL)
Wrapper for 2-norm with z as a scalar pointer.
Definition: dots.C:283
void int int int REAL REAL REAL * z
Definition: write.cpp:76
static void axpy_scalar(const void *a, const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for z = a * x + y (a is a scalar pointer).
Definition: axpy.C:210
void Rocblas_unload_module(const char *name)
Definition: Rocblas.C:121
static void min_scalar_MPI(const Attribute *x, void *y, const MPI_Comm *comm=NULL)
Operation wrapper for min (y is a scalar pointer).
Definition: op2args.C:771
blockLoc i
Definition: read.cpp:79
void int int REAL * x
Definition: read.cpp:74
static void sum_scalar_MPI(const Attribute *x, void *y, const MPI_Comm *comm=NULL)
Operation wrapper for sum (y is a scalar pointer).
Definition: op2args.C:778
static void div(const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for division.
Definition: op3args.C:269
static void sum_MPI(const Attribute *x, Attribute *y, const MPI_Comm *comm=NULL)
Wrapper for sum.
Definition: op2args.C:720
static void calcChoose(const Attribute *x, const Attribute *y, Attribute *z, FuncType opp)
Chooses which calc function to call based on type of y.
Definition: op3args.C:192
static void reduce_scalar_MPI(const Attribute *x, void *y, const MPI_Comm *comm, int, double)
Definition: op2args.C:726
int stride() const
Obtain the stride of the attribute in base datatype.
Definition: Attribute.h:233
static void neg(const Attribute *x, Attribute *y)
Wrapper for neg (y=-x).
Definition: op2args.C:455
static std::string to_str(int i)
Definition: Rocblas.h:283
static void copy_helper(const Attribute *x, Attribute *z)
Definition: op2args.C:315
static void nrm2_scalar_MPI(const Attribute *x, void *y, const MPI_Comm *comm, const Attribute *mults=NULL)
Wrapper for 2-norm with y as a scalar pointer with MPI.
Definition: dots.C:303
static void gen2arg(Attribute *z, void *yin, FuncType opp)
Performs the operation opp(x, y)
Definition: op2args.C:114
static void copy_scalar(const void *x, Attribute *y)
Operation wrapper for copy (x is a scalar pointer).
Definition: op2args.C:583
unsigned int Size
Definition: Rocblas.h:38
static int get_stride(const Attribute *attr)
Definition: Rocblas.h:291
static void rand_scalar(const void *a, Attribute *z)
Generate a random number between 0 and $a$ for each entry in z.
Definition: op2args.C:604
static void swap(Attribute *x, Attribute *y)
Wrapper for swap.
Definition: op2args.C:271
static void copy(const Attribute *x, Attribute *y)
Wrapper for copy.
Definition: op2args.C:333
static void axpy_gen(const void *a, const Attribute *x, const Attribute *y, Attribute *z)
Performs the operation: z = a*x + y.
Definition: axpy.C:27
static void nrm2(const Attribute *x, Attribute *y, const Attribute *mults=NULL)
Wrapper for 2-norm.
Definition: dots.C:288
static void sqrt(const Attribute *x, Attribute *y)
Wrapper for sqrt (y=sqrt(x)).
Definition: op2args.C:507
static void dot(const Attribute *x, const Attribute *y, Attribute *z, const Attribute *mults=NULL)
Wrapper for dot product.
Definition: dots.C:279
static void maxof_scalar(const Attribute *x, const void *y, Attribute *z, int swap=0)
Operation wrapper for addition with y as a scalar pointer.
Definition: op3args.C:315
static void dot_MPI(const Attribute *x, const Attribute *y, Attribute *z, const MPI_Comm *comm=NULL, const Attribute *mults=NULL)
Wrapper for dot product.
Definition: dots.C:226
void Rocblas_load_module(const char *name)
Calls Rocblas initialization function.
Definition: Rocblas.C:118
static data_type & getref(data_type *base, const int r, const int c, const int nc)
Definition: Rocblas.h:306
static void add_scalar(const Attribute *x, const void *y, Attribute *z, int swap=0)
Operation wrapper for addition with y as a scalar pointer.
Definition: op3args.C:299
int size_of_items() const
Obtain the number of items in the attribute.
Definition: Attribute.C:111
static void mul(const Attribute *x, const Attribute *y, Attribute *z)
Operation wrapper for multiplication.
Definition: op3args.C:253
static void sub_scalar(const Attribute *x, const void *y, Attribute *z, int swap=0)
Operation wrapper for subtraction with y as a scalar pointer.
Definition: op3args.C:331