41 #ifndef INCLUDE_UTILS_BLOB_
42 #define INCLUDE_UTILS_BLOB_
45 #include <glog/logging.h>
46 #include "proto/model.pb.h"
47 using std::shared_ptr;
50 #define NOT_IMPLEMENTED LOG(FATAL) << "Not implemented function"
51 inline void MallocHost(
void** ptr,
size_t size) {
55 inline void FreeHost(
void* ptr) {
68 : cpu_ptr_(NULL), gpu_ptr_(NULL), size_(0), head_(UNINITIALIZED),
69 own_cpu_data_(
false) {}
71 : cpu_ptr_(NULL), gpu_ptr_(NULL), size_(size), head_(UNINITIALIZED),
72 own_cpu_data_(
false) {}
74 const void* cpu_data();
75 void set_cpu_data(
void* data);
76 const void* gpu_data();
77 void* mutable_cpu_data();
78 void* mutable_gpu_data();
79 enum SyncedHead { UNINITIALIZED, HEAD_AT_CPU, HEAD_AT_GPU, SYNCED };
80 SyncedHead head() {
return head_; }
81 size_t size() {
return size_; }
95 template <
typename Dtype>
98 Blob(): count_(0), capacity_(0) , version_(-1){}
99 Blob(
const vector<int>&shape);
114 void Reshape(
const vector<int>& shape);
115 void ReshapeLike(
const Blob& other);
116 const vector<int>& shape()
const{
119 inline int count()
const {
return count_; }
120 void set_version(
int v){
123 const int version()
const {
136 inline const shared_ptr<SyncedMemory>& data()
const {
141 const Dtype* cpu_data()
const;
142 void set_cpu_data(Dtype* data);
143 const Dtype* gpu_data()
const;
144 Dtype* mutable_cpu_data();
145 Dtype* mutable_gpu_data();
153 Dtype sum_data()
const;
164 void Swap(
Blob& other);
165 shared_ptr<SyncedMemory> data_;
173 #endif // INCLUDE_UTILS_BLOB_
Manages memory allocation and synchronization between the host (CPU) and device (GPU).
Definition: blob.h:65
Definition: model.pb.h:3695
void ShareData(const Blob &other)
Set the data_ shared_ptr to point to the SyncedMemory holding the data_ of Blob other – useful in Lay...
Dtype asum_data() const
Compute the sum of absolute values (L1 norm) of the data.
void Reshape(const vector< int > &shape)
Change the dimensions of the blob, allocating new memory if necessary.
void CopyFrom(const Blob< Dtype > &source, bool reshape=false)
Copy from a source Blob.
ReshapeExp< SrcExp, dimdst, ExpInfo< SrcExp >::kDim > reshape(const Exp< SrcExp, etype > &src, Shape< dimdst > oshape)
a expression that reshapes a tensor to another shape
Definition: tensor_expr_ext.h:406