MemoryCUDA.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2009 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 #ifndef __dsp_MemoryCUDA_h_
10 #define __dsp_MemoryCUDA_h_
11 
12 #include "dsp/MemoryHost.h"
13 
14 #include <cuda_runtime.h>
15 
16 namespace CUDA
17 {
19  class PinnedMemory : public dsp::MemoryHost
20  {
21  public:
22  void* do_allocate (size_t nbytes) override;
23  void do_free (void*) override;
24  };
25 
27  class DeviceMemory : public dsp::Memory
28  {
29  public:
30 
31  DeviceMemory (cudaStream_t _stream = 0, int _device = 0);
32 
33  void* do_allocate (size_t nbytes);
34  void do_free (void*);
35  void do_copy (void* to, const void* from, size_t bytes);
36  void do_zero (void*, size_t);
37  bool on_host () const { return false; }
38 
39  void set_stream (cudaStream_t _stream) { stream = _stream; }
40  cudaStream_t get_stream () { return stream; }
41  cudaStream_t get_stream () const { return stream; }
42 
43  int get_device () { return device; };
44  int get_device () const { return device; };
45 
46 
47  protected:
48  cudaStream_t stream;
49  int device;
50  };
51 
52  class SharedPinnedMemory : public dsp::Memory
53  {
54  public:
55  void * do_allocate (size_t nbytes);
56  void do_free (void*);
57  };
58 
59 }
60 
61 #endif
Manages CUDA device memory allocation and destruction.
Definition: MemoryCUDA.h:32
Manages memory allocation and destruction on the host machine.
Definition: MemoryHost.h:22
Pure virtual base class of objects that manage memory allocation and destruction.
Definition: Memory.h:23

Generated using doxygen 1.8.17