muda
device_var.h
1 #pragma once
2 #include <cuda.h>
3 #include <cuda_runtime.h>
4 #include <cuda_runtime_api.h>
5 #include <muda/buffer/var_view.h>
6 
7 namespace muda
8 {
9 template <typename T>
10 class DeviceVar
11 {
12  private:
13  friend class BufferLaunch;
14  T* m_data;
15 
16  public:
17  using value_type = T;
18 
19  DeviceVar();
20  DeviceVar(const T& value);
21 
22  DeviceVar(const DeviceVar& other);
23  DeviceVar(DeviceVar&& other) MUDA_NOEXCEPT;
24  DeviceVar& operator=(const DeviceVar<T>& other);
25  DeviceVar& operator=(DeviceVar<T>&& other);
26 
27  // device transfer
28 
29  DeviceVar& operator=(CVarView<T> other);
30  void copy_from(CVarView<T> other);
31 
32  DeviceVar& operator=(const T& val); // copy from host
33  operator T() const; // copy to host
34 
35  T* data() MUDA_NOEXCEPT { return m_data; }
36  const T* data() const MUDA_NOEXCEPT { return m_data; }
37 
38  VarView<T> view() MUDA_NOEXCEPT { return VarView<T>{m_data}; };
39  CVarView<T> view() const MUDA_NOEXCEPT { return CVarView<T>{m_data}; };
40 
41  operator VarView<T>() MUDA_NOEXCEPT { return view(); }
42  operator CVarView<T>() const MUDA_NOEXCEPT { return view(); }
43 
44  Dense<T> viewer() MUDA_NOEXCEPT;
45  CDense<T> cviewer() const MUDA_NOEXCEPT;
46 
47  ~DeviceVar();
48 };
49 } // namespace muda
50 
51 #include "details/device_var.inl"
Definition: assert.h:13