cheshirekow  v0.1.0
wrap.hpp
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  */
26 #ifndef MPBLOCKS_CUDA_WRAP_HPP_
27 #define MPBLOCKS_CUDA_WRAP_HPP_
28 
29 
30 namespace mpblocks {
31 namespace cuda {
32 
33 
34 template <typename T>
35 void FuncAttributes::getFrom( T* entry )
36 {
37  cudaError_t result = cudaFuncGetAttributes( this, (void*)entry );
38  cudaEx(result) << "In cudaFuncGetAttributes";
39 }
40 
41 template <typename T>
42 T* mallocT( size_t nObjs )
43 {
44  T* devPtr = (T*)cuda::malloc(nObjs*sizeof(T) );
45  return devPtr;
46 }
47 
48 template <typename T>
49 T* mallocPitchT( size_t& pitch, size_t obsPerRow, size_t cols )
50 {
51  T* devPtr = (T*)cuda::mallocPitch(pitch, obsPerRow*sizeof(T), cols );
52  return devPtr;
53 }
54 
55 template <typename T>
56 void memcpyT( T* dst, const T* src, size_t nObjs, MemcpyKind kind )
57 {
58  cuda::memcpy( dst, src, nObjs*sizeof(T), kind );
59 }
60 
61 template <typename T>
62 void memcpy2DT(
63  T* dst,
64  size_t dpitchBytes,
65  const T* src,
66  size_t spitchBytes,
67  size_t widthObjs,
68  size_t height,
69  MemcpyKind kind )
70 {
71  cuda::memcpy2D( (void*)dst, dpitchBytes,
72  (const void*)src, spitchBytes,
73  widthObjs*sizeof(T), height,
74  kind );
75 
76 }
77 
78 
80 template <typename T>
81 void memset( T* devPtr, int value, size_t nObs )
82 {
83  cuda::memset( (void*)devPtr, value, nObs*sizeof(T) );
84 }
85 
87 template <typename T>
88 void memset2DT(
89  T* devPtr,
90  size_t pitchBytes,
91  int value,
92  size_t widthObjs,
93  size_t height )
94 {
95  cuda::memset2D( (void*)devPtr, pitchBytes, value,
96  widthObjs*sizeof(T), height );
97 
98 }
99 
100 
101 
102 } // namespace cuda
103 } // namespace mpblocks
104 
105 
106 
107 
108 
109 
110 
111 
112 #endif /* UTILS_H_ */
void * malloc(size_t size)
wraps cudaMalloc
cudaMemcpyKind MemcpyKind
Definition: wrap.h:36
CudaExceptionStream cudaEx
T * mallocPitchT(size_t &pitch, size_t obsPerRow, size_t cols)
allocates nObjs objects of type T
Definition: wrap.hpp:49
T * mallocT(size_t nObjs)
allocates nObjs objects of type T
Definition: wrap.hpp:42
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 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 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 memcpy(void *dst, const void *src, size_t count, MemcpyKind kind)
wraps cudaMemcpy
void memset2D(void *devPtr, size_t pitch, int value, size_t width, size_t height)
wraps cudaMemset2D
void * mallocPitch(size_t &pitch, size_t cols, size_t rows)
wraps cudaMallocPitch