File: ucl_basemat.h

package info (click to toggle)
lammps 20220106.git7586adbb6a%2Bds1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 348,064 kB
  • sloc: cpp: 831,421; python: 24,896; xml: 14,949; f90: 10,845; ansic: 7,967; sh: 4,226; perl: 4,064; fortran: 2,424; makefile: 1,501; objc: 238; lisp: 163; csh: 16; awk: 14; tcl: 6
file content (94 lines) | stat: -rw-r--r-- 3,438 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/***************************************************************************
                                 ucl_basemat.h
                             -------------------
                               W. Michael Brown

  Vector/Matrix Base Container

 __________________________________________________________________________
    This file is part of the Geryon Unified Coprocessor Library (UCL)
 __________________________________________________________________________

    begin                : Thu Jun 25 2009
    copyright            : (C) 2009 by W. Michael Brown
    email                : brownw@ornl.gov
 ***************************************************************************/

/* -----------------------------------------------------------------------
   Copyright (2009) Sandia Corporation.  Under the terms of Contract
   DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
   certain rights in this software.  This software is distributed under
   the Simplified BSD License.
   ----------------------------------------------------------------------- */

// Only allow this file to be included by CUDA and OpenCL specific headers
#ifdef _UCL_MAT_ALLOW

#include "ucl_types.h"

#define UCL_H_VecT UCL_H_Vec<numtyp>
#define UCL_H_VecD UCL_H_Vec<double>
#define UCL_H_VecS UCL_H_Vec<float>
#define UCL_H_VecI UCL_H_Vec<int>

#define UCL_D_VecT UCL_D_Vec<numtyp>
#define UCL_D_VecD UCL_D_Vec<double>
#define UCL_D_VecS UCL_D_Vec<float>
#define UCL_D_VecI UCL_D_Vec<int>
#define UCL_D_VecI2 UCL_D_Vec<int2>
#define UCL_D_VecU2 UCL_D_Vec<uint2>

#define UCL_D_MatT UCL_D_Mat<numtyp>
#define UCL_D_MatD UCL_D_Mat<double>
#define UCL_D_MatS UCL_D_Mat<float>
#define UCL_D_MatI UCL_D_Mat<int>

#define UCL_ConstMatT UCL_ConstMat<numtyp>
#define UCL_ConstMatD UCL_ConstMat<double>
#define UCL_ConstMatS UCL_ConstMat<float>
#define UCL_ConstMatI UCL_ConstMat<int>
#define UCL_ConstMatD2 UCL_ConstMat<double2>

/// Base class for vector/matrix containers
/** All containers are associated with a default command queue.
  * For CUDA, this is the default stream.
  *
  * The default queue is used for asynchonrous operations on the container
  * that do not specify a queue. For OpenCL, this queue is also used in
  * calls for reserving and copying memory **/
class UCL_BaseMat {
 public:
  UCL_BaseMat() : _cq(0), _kind(UCL_VIEW) { }
  virtual ~UCL_BaseMat() { }
  /// Return the default command queue/stream associated with this data
  inline command_queue & cq() { return _cq; }
  /// Change the default command queue associated with matrix
  inline void cq(command_queue &cq_in) { _cq=cq_in; }
  /// Block until command_queue associated with matrix is complete
  inline void sync() { ucl_sync(_cq); }
  /// Return the type/permissions of memory allocation
  /** Returns UCL_READ_WRITE, UCL_WRITE_ONLY, UCL_READ_ONLY, UCL_NOT_PINNED
    * or UCL_VIEW **/
  /// Assert that any ops in associate command queue have been issued to device
  inline void flush() { ucl_flush(_cq); }

  inline enum UCL_MEMOPT kind() const { return _kind; }

  inline bool shared_mem_device() {
    #ifdef _OCL_MAT
    cl_device_id device;
    CL_SAFE_CALL(clGetCommandQueueInfo(_cq,CL_QUEUE_DEVICE,
                                       sizeof(cl_device_id),&device,NULL));
    return _shared_mem_device(device);
    #else
    return false;
    #endif
  }

 protected:
  command_queue _cq;
  enum UCL_MEMOPT _kind;
};

#endif