1 /***************************************************************************
2                                  ucl_basemat.h
3                              -------------------
4                                W. Michael Brown
5 
6   Vector/Matrix Base Container
7 
8  __________________________________________________________________________
9     This file is part of the Geryon Unified Coprocessor Library (UCL)
10  __________________________________________________________________________
11 
12     begin                : Thu Jun 25 2009
13     copyright            : (C) 2009 by W. Michael Brown
14     email                : brownw@ornl.gov
15  ***************************************************************************/
16 
17 /* -----------------------------------------------------------------------
18    Copyright (2009) Sandia Corporation.  Under the terms of Contract
19    DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
20    certain rights in this software.  This software is distributed under
21    the Simplified BSD License.
22    ----------------------------------------------------------------------- */
23 
24 // Only allow this file to be included by CUDA and OpenCL specific headers
25 #ifdef _UCL_MAT_ALLOW
26 
27 #include "ucl_types.h"
28 
29 #define UCL_H_VecT UCL_H_Vec<numtyp>
30 #define UCL_H_VecD UCL_H_Vec<double>
31 #define UCL_H_VecS UCL_H_Vec<float>
32 #define UCL_H_VecI UCL_H_Vec<int>
33 
34 #define UCL_D_VecT UCL_D_Vec<numtyp>
35 #define UCL_D_VecD UCL_D_Vec<double>
36 #define UCL_D_VecS UCL_D_Vec<float>
37 #define UCL_D_VecI UCL_D_Vec<int>
38 #define UCL_D_VecI2 UCL_D_Vec<int2>
39 #define UCL_D_VecU2 UCL_D_Vec<uint2>
40 
41 #define UCL_D_MatT UCL_D_Mat<numtyp>
42 #define UCL_D_MatD UCL_D_Mat<double>
43 #define UCL_D_MatS UCL_D_Mat<float>
44 #define UCL_D_MatI UCL_D_Mat<int>
45 
46 #define UCL_ConstMatT UCL_ConstMat<numtyp>
47 #define UCL_ConstMatD UCL_ConstMat<double>
48 #define UCL_ConstMatS UCL_ConstMat<float>
49 #define UCL_ConstMatI UCL_ConstMat<int>
50 #define UCL_ConstMatD2 UCL_ConstMat<double2>
51 
52 /// Base class for vector/matrix containers
53 /** All containers are associated with a default command queue.
54   * For CUDA, this is the default stream.
55   *
56   * The default queue is used for asynchonrous operations on the container
57   * that do not specify a queue. For OpenCL, this queue is also used in
58   * calls for reserving and copying memory **/
59 class UCL_BaseMat {
60  public:
UCL_BaseMat()61   UCL_BaseMat() : _cq(0), _kind(UCL_VIEW) { }
~UCL_BaseMat()62   virtual ~UCL_BaseMat() { }
63   /// Return the default command queue/stream associated with this data
cq()64   inline command_queue & cq() { return _cq; }
65   /// Change the default command queue associated with matrix
cq(command_queue & cq_in)66   inline void cq(command_queue &cq_in) { _cq=cq_in; }
67   /// Block until command_queue associated with matrix is complete
sync()68   inline void sync() { ucl_sync(_cq); }
69   /// Return the type/permissions of memory allocation
70   /** Returns UCL_READ_WRITE, UCL_WRITE_ONLY, UCL_READ_ONLY, UCL_NOT_PINNED
71     * or UCL_VIEW **/
kind()72   inline enum UCL_MEMOPT kind() const { return _kind; }
73 
shared_mem_device()74   inline bool shared_mem_device() {
75     #ifdef _OCL_MAT
76     cl_device_id device;
77     CL_SAFE_CALL(clGetCommandQueueInfo(_cq,CL_QUEUE_DEVICE,
78                                        sizeof(cl_device_id),&device,NULL));
79     cl_device_type device_type;
80     CL_SAFE_CALL(clGetDeviceInfo(device,CL_DEVICE_TYPE,
81                                  sizeof(device_type),&device_type,NULL));
82     return _shared_mem_device(device_type);
83     #else
84     return false;
85     #endif
86   }
87 
88  protected:
89   command_queue _cq;
90   enum UCL_MEMOPT _kind;
91 };
92 
93 #endif
94 
95