Image Utilities (IU)
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Friends Groups Pages
volume_allocator_gpu.h
1 #pragma once
2 
3 #include <assert.h>
4 #include <cuda_runtime.h>
5 #include "coredefs.h"
6 #include "../iucutil.h"
7 
8 namespace iuprivate {
9 
10 //--------------------------------------------------------------------------
11 template <typename PixelType>
13 {
14 public:
15  static PixelType* alloc(iu::Size<3> size, size_t *pitch)
16  {
17  if ((size.width==0) || (size.height==0) || (size.depth==0))
18  throw IuException("width, height or depth is 0", __FILE__,__FUNCTION__, __LINE__);
19  PixelType* buffer = 0;
20  cudaError_t status = cudaMallocPitch((void **)&buffer, pitch, size.width * sizeof(PixelType), size.height*size.depth);
21  if (buffer == 0) throw std::bad_alloc();
22  if (status != cudaSuccess)
23  throw IuException("cudaMallocPitch returned error code", __FILE__, __FUNCTION__, __LINE__);
24 
25  return buffer;
26  }
27 
28  static void free(PixelType *buffer)
29  {
30  IU_CUDA_SAFE_CALL(cudaFree((void *)buffer));
31  }
32 
33  static void copy(const PixelType *src, size_t src_pitch, PixelType *dst, size_t dst_pitch, iu::Size<3> size)
34  {
35  IU_CUDA_SAFE_CALL(cudaMemcpy2D(dst, dst_pitch, src, src_pitch,
36  size.width * sizeof(PixelType), size.height*size.depth,
37  cudaMemcpyDeviceToDevice));
38  }
39 };
40 
41 } // namespace iuprivate
42 
43 
unsigned int & depth
Definition: vector.h:613
unsigned int & height
Definition: vector.h:611
Exceptions with additional error information.
Definition: coredefs.h:32
Template specialization for 3-d unsigned int vectors (size vectors).
Definition: vector.h:605
unsigned int & width
Definition: vector.h:609
Definition: volume_allocator_gpu.h:12