71template <
typename Dtype>
74 std::vector<int> shape(4);
82template <
typename Dtype>
86 shape_.resize(shape.size());
87 if (!shape_data_ || shape_data_->size() < shape.size() *
sizeof(
int)) {
89 new SyncedMemory(shape.size() *
sizeof(
int), use_cuda_host_malloc_));
91 int* shape_data =
static_cast<int*
>(shape_data_->mutable_cpu_data());
92 for (
size_t i = 0; i < shape.size(); ++i) {
93 CHECK_GE(shape[i], 0);
95 CHECK_LE(shape[i], std::numeric_limits<int>::max() / count_)
96 <<
"blob size exceeds std::numeric_limits<int>::max()";
100 shape_data[i] = shape[i];
102 if (count_ > capacity_) {
105 new SyncedMemory(capacity_ *
sizeof(Dtype), use_cuda_host_malloc_));
109template <
typename Dtype>
111 Reshape(other.
shape());
114template <
typename Dtype>
116 const int width,
const bool use_cuda_host_malloc)
118 : capacity_(0), use_cuda_host_malloc_(use_cuda_host_malloc) {
122template <
typename Dtype>
124 const bool use_cuda_host_malloc)
126 : capacity_(0), use_cuda_host_malloc_(use_cuda_host_malloc) {
130template <
typename Dtype>
133 return (
const int*)shape_data_->gpu_data();
136template <
typename Dtype>
139 return (
const Dtype*)data_->cpu_data();
142template <
typename Dtype>
146 size_t size = count_ *
sizeof(Dtype);
147 if (data_->size() != size) {
148 data_.reset(
new SyncedMemory(size, use_cuda_host_malloc_));
150 data_->set_cpu_data(data);
153template <
typename Dtype>
156 return (
const Dtype*)data_->gpu_data();
159template <
typename Dtype>
163 size_t size = count_ *
sizeof(Dtype);
164 if (data_->size() != size) {
165 data_.reset(
new SyncedMemory(size, use_cuda_host_malloc_));
167 data_->set_gpu_data(data);
170template <
typename Dtype>
173 return static_cast<Dtype*
>(data_->mutable_cpu_data());
176template <
typename Dtype>
179 return static_cast<Dtype*
>(data_->mutable_gpu_data());
182template <
typename Dtype>
184 CHECK_EQ(count_, other.
count());
185 data_ = other.
data();
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
const std::vector< int > & shape() const
void ReshapeLike(const Blob &other)
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
int height() const
Deprecated legacy shape accessor height: use shape(2) instead.
int channels() const
Deprecated legacy shape accessor channels: use shape(1) instead.
int num() const
Deprecated legacy shape accessor num: use shape(0) instead.
const std::shared_ptr< SyncedMemory > & data() const
int width() const
Deprecated legacy shape accessor width: use shape(3) instead.
Manages memory allocation and synchronization between the host (CPU) and device (GPU).
constexpr size_t kMaxBlobAxes