ThunderSVM
ThunderSVM: An Open-Source SVM Library on GPUs and CPUs
syncarray.h
1 //
2 // Created by jiashuai on 17-9-17.
3 //
4 
5 #ifndef THUNDERSVM_SYNCDATA_H
6 #define THUNDERSVM_SYNCDATA_H
7 
8 #include "thundersvm.h"
9 #include "syncmem.h"
10 
15 template<typename T>
16 class SyncArray : public el::Loggable {
17 public:
22  explicit SyncArray(size_t count);
23 
24  SyncArray() : mem(nullptr), size_(0) {};
25 
26  ~SyncArray();
27 
28  const T *host_data() const;
29 
30  const T *device_data() const;
31 
32  T *host_data();
33 
34  T *device_data();
35 
36  void set_host_data(T *host_ptr){
37  mem->set_host_data(host_ptr);
38  }
39 
40  void set_device_data(T *device_ptr){
41  mem->set_device_data(device_ptr);
42  }
43 
44  void to_host() const{
45  mem->to_host();
46  }
47 
48  void to_device() const{
49  mem->to_device();
50  }
51 
52  //deprecated because of performance issue
53 // /**
54 // * random access operator
55 // * @param index the index of the elements
56 // * @return **host** element at the index
57 // */
58 // const T &operator[](int index) const{
59 // return host_data()[index];
60 // }
61 //
62 // T &operator[](int index){
63 // return host_data()[index];
64 // }
65 
71  void copy_from(const T *source, size_t count);
72 
73  void copy_from(const SyncArray<T> &source);
74 
79  void mem_set(const T &value);
80 
85  void resize(size_t count);
86 
87  size_t mem_size() const {//number of bytes
88  return mem->size();
89  }
90 
91  size_t size() const {//number of values
92  return size_;
93  }
94 
95  SyncMem::HEAD head() const{
96  return mem->head();
97  }
98 
99  void log(el::base::type::ostream_t &ostream) const override;
100 
101 private:
102  SyncArray<T> &operator=(const SyncArray<T> &);
103 
104  SyncArray(const SyncArray<T> &);
105 
106  SyncMem *mem;
107  size_t size_;
108 };
109 
110 #endif //THUNDERSVM_SYNCDATA_H
void set_device_data(void *data)
Definition: syncmem.cpp:114
void resize(size_t count)
Definition: syncarray.cpp:42
size_t size() const
return the size of memory
Definition: syncmem.cpp:46
void to_device()
transfer data to device
Definition: syncmem.cpp:79
void set_host_data(void *data)
Definition: syncmem.cpp:104
void to_host()
transfer data to host
Definition: syncmem.cpp:54
void copy_from(const T *source, size_t count)
Definition: syncarray.cpp:49
Wrapper of SyncMem with a type.
Definition: syncarray.h:16
void mem_set(const T &value)
Definition: syncarray.cpp:80
Auto-synced memory for CPU and GPU.
Definition: syncmem.h:38