cheshirekow  v0.1.0
wrap.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_CUDA_WRAP_H_
28 #define MPBLOCKS_CUDA_WRAP_H_
29 
30 #include <map>
31 
32 namespace mpblocks {
33 namespace cuda {
34 
35 
36 typedef cudaMemcpyKind MemcpyKind;
37 
39  public cudaFuncAttributes
40 {
42 
43  template <typename T>
44  void getFrom( T* entry );
45 };
46 
47 
48 struct DeviceProp:
49  public cudaDeviceProp
50 {
51  DeviceProp();
52  DeviceProp(int device);
53 
54  void getFrom( int device );
55 };
56 
57 
59 void checkResult( cudaError_t result, const std::string& where);
60 
62 void* malloc(size_t size);
63 
65 void* mallocPitch( size_t& pitch, size_t cols, size_t rows );
66 
68 template <typename T>
69 T* mallocT( size_t nObjs );
70 
73 template <typename T>
74 T* mallocPitchT( size_t& pitch, size_t obsPerRow, size_t cols );
75 
77 void free(void* devPtr);
78 
80 void memcpy( void *dst, const void *src, size_t count, MemcpyKind kind);
81 
83 void memcpy2D(
84  void* dst,
85  size_t dpitch,
86  const void* src,
87  size_t spitch,
88  size_t width,
89  size_t height,
90  MemcpyKind kind );
91 
93 template <typename T>
94 void memcpy2DT(
95  T* dst,
96  size_t dpitchBytes,
97  const T* src,
98  size_t spitchBytes,
99  size_t widthObs,
100  size_t height,
101  MemcpyKind kind );
102 
104 template <typename T>
105 void memcpyT( T* dst, const T* src, size_t nObjs, MemcpyKind kind );
106 
108 void memset( void* devPtr, int value, size_t count );
109 
111 template <typename T>
112 void memset( T* devPtr, int value, size_t nObs );
113 
115 void memset2D(
116  void* devPtr,
117  size_t pitch,
118  int value,
119  size_t width,
120  size_t height );
121 
123 template <typename T>
124 void memset2DT(
125  T* devPtr,
126  size_t pitchBytes,
127  int value,
128  size_t widthObjs,
129  size_t height );
130 
132 int getDeviceCount();
133 
136 
138 int getDevice();
139 
141 void setDevice(int dev);
142 
144 void deviceSynchronize();
145 
147 void checkLastError(const std::string& msg="checkLastError");
148 
150 template <class oiter>
151 void getDeviceList( oiter& out )
152 {
153  int nDevices = getDeviceCount();
154  for(int dev=0; dev < nDevices; dev++)
155  {
156  DeviceProp prop = getDeviceProperties(dev);
157  *(out++) = prop.name;
158  }
159 }
160 
162 void printDeviceReport( std::ostream& out, int dev );
163 void printDeviceReport( std::ostream& out );
164 
166 typedef std::map<std::string,FuncAttributes> fattrMap_t;
167 void printKernelReport( std::ostream& out, const fattrMap_t& attr );
168 
169 
170 } // namespace cuda
171 } // namespace mpblocks
172 
173 
174 
175 #endif /* UTILS_H_ */
void printKernelReport(std::ostream &out, const fattrMap_t &attr)
void * malloc(size_t size)
wraps cudaMalloc
cudaMemcpyKind MemcpyKind
Definition: wrap.h:36
void getFrom(int device)
void deviceSynchronize()
blocks the host thread until kernels are done executing
T * mallocPitchT(size_t &pitch, size_t obsPerRow, size_t cols)
allocates nObjs objects of type T
Definition: wrap.hpp:49
void free(void *devPtr)
wraps cudaFree
T * mallocT(size_t nObjs)
allocates nObjs objects of type T
Definition: wrap.hpp:42
void checkResult(cudaError_t result, const std::string &where)
throws an exception if result is not success
void checkLastError(const std::string &msg="checkLastError")
wraps getLastError
void memcpy2DT(T *dst, size_t dpitchBytes, const T *src, size_t spitchBytes, size_t widthObs, size_t height, MemcpyKind kind)
wraps cudaMemcpy2D
Definition: wrap.hpp:62
void getDeviceList(oiter &out)
build a list of device names
Definition: wrap.h:151
int getDeviceCount()
wraps cudaGetDeviceCount
void memcpy2D(void *dst, size_t dpitch, const void *src, size_t spitch, size_t width, size_t height, MemcpyKind kind)
wraps cudaMemcpy2D
void memcpyT(T *dst, const T *src, size_t nObjs, MemcpyKind kind)
allocates nObjs objects of type T
Definition: wrap.hpp:56
void getFrom(T *entry)
Definition: wrap.hpp:35
void printDeviceReport(std::ostream &out, int dev)
print a formatted report about the specified device
void memset(void *devPtr, int value, size_t count)
wraps cudaMemset
void memset2DT(T *devPtr, size_t pitchBytes, int value, size_t widthObjs, size_t height)
wraps cudaMemset2D
Definition: wrap.hpp:88
void setDevice(int dev)
wraps cudaSetDevice
DeviceProp getDeviceProperties(int dev)
wraps cudaGetDeviceProperties
void memcpy(void *dst, const void *src, size_t count, MemcpyKind kind)
wraps cudaMemcpy
std::map< std::string, FuncAttributes > fattrMap_t
print a formatted report about the specified kernels
Definition: wrap.h:166
void memset2D(void *devPtr, size_t pitch, int value, size_t width, size_t height)
wraps cudaMemset2D
int getDevice()
wraps cudaGetDevice
void * mallocPitch(size_t &pitch, size_t cols, size_t rows)
wraps cudaMallocPitch