69 #include "absl/strings/str_cat.h" 70 #include "absl/strings/str_join.h" 76 namespace perception {
87 template <
typename Dtype>
91 explicit Blob(
bool use_cuda_host_malloc)
99 const bool use_cuda_host_malloc =
false);
100 explicit Blob(
const std::vector<int>&
shape,
101 const bool use_cuda_host_malloc =
false);
107 void Reshape(
const int num,
const int channels,
const int height,
123 void Reshape(
const std::vector<int>& shape);
127 ? absl::StrCat(
"(",
count_,
")")
128 : absl::StrCat(absl::StrJoin(
shape_,
" "),
" (",
count_,
")");
153 inline int count(
int start_axis,
int end_axis)
const {
154 CHECK_LE(start_axis, end_axis);
155 CHECK_GE(start_axis, 0);
156 CHECK_GE(end_axis, 0);
160 for (
int i = start_axis; i < end_axis; ++i) {
171 inline int count(
int start_axis)
const {
198 <<
"axis " << axis_index <<
" out of range for " <<
num_axes()
201 <<
"axis " << axis_index <<
" out of range for " <<
num_axes()
203 if (axis_index < 0) {
219 <<
"Cannot use legacy accessors on Blobs with > 4 axes.";
231 inline int offset(
const int n,
const int c = 0,
const int h = 0,
232 const int w = 0)
const {
239 CHECK_GE(
width(), 0);
240 CHECK_LE(w,
width());
244 inline int offset(
const std::vector<int>& indices)
const {
245 CHECK_LE(indices.size(),
static_cast<size_t>(
num_axes()));
247 for (
int i = 0; i <
num_axes(); ++i) {
249 if (static_cast<int>(indices.size()) > i) {
250 CHECK_GE(indices[i], 0);
251 CHECK_LT(indices[i],
shape(i));
252 offset += indices[i];
267 inline Dtype
data_at(
const int n,
const int c,
const int h,
272 inline Dtype
data_at(
const std::vector<int>& index)
const {
276 inline const std::shared_ptr<SyncedMemory>&
data()
const {
304 std::shared_ptr<SyncedMemory>
data_;
312 template <
typename Dtype>
314 template <
typename Dtype>
Dtype * mutable_cpu_data()
Dtype data_at(const std::vector< int > &index) const
Definition: blob.h:272
int channels() const
Deprecated legacy shape accessor channels: use shape(1) instead.
Definition: blob.h:212
int shape(int index) const
Returns the dimension of the index-th axis (or the negative index-th axis from the end...
Definition: blob.h:139
Dtype data_at(const int n, const int c, const int h, const int w) const
Definition: blob.h:267
#define ACHECK(cond)
Definition: log.h:80
void set_head_gpu()
Definition: blob.h:288
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
int offset(const int n, const int c=0, const int h=0, const int w=0) const
Definition: blob.h:231
SyncedHead
Definition: syncedmem.h:101
void ReshapeLike(const Blob &other)
int count() const
Definition: blob.h:143
int num() const
Deprecated legacy shape accessor num: use shape(0) instead.
Definition: blob.h:210
int height() const
Deprecated legacy shape accessor height: use shape(2) instead.
Definition: blob.h:214
void set_cpu_data(Dtype *data)
int CanonicalAxisIndex(int axis_index) const
create RoI Blob.
Definition: blob.h:196
std::string shape_string() const
Definition: blob.h:125
A wrapper around SyncedMemory holders serving as the basic computational unit for images...
Definition: blob.h:88
void Reshape(const int num, const int channels, const int height, const int width)
Deprecated; use Reshape(const std::vector<int>& shape).
Blob(bool use_cuda_host_malloc)
Definition: blob.h:91
std::vector< int > shape_
Definition: blob.h:306
void set_gpu_data(Dtype *data)
int count(int start_axis, int end_axis) const
Compute the volume of a slice; i.e., the product of dimensions among a range of axes.
Definition: blob.h:153
const Dtype * gpu_data() const
std::shared_ptr< const Blob< Dtype > > BlobConstPtr
Definition: blob.h:315
int count_
Definition: blob.h:307
Dtype * mutable_gpu_data()
int count(int start_axis) const
Compute the volume of a slice spanning from a particular first axis to the final axis.
Definition: blob.h:171
int LegacyShape(int index) const
Definition: blob.h:217
const Dtype * cpu_data() const
void CopyFrom(const Blob< Dtype > &source, bool reshape=false)
Copy from a source Blob.
std::shared_ptr< SyncedMemory > shape_data_
Definition: blob.h:305
std::shared_ptr< SyncedMemory > data_
Definition: blob.h:304
std::shared_ptr< Blob< Dtype > > BlobPtr
Definition: blob.h:313
constexpr size_t kMaxBlobAxes
Definition: blob.h:79
int offset(const std::vector< int > &indices) const
Definition: blob.h:244
const std::shared_ptr< SyncedMemory > & data() const
Definition: blob.h:276
void operator=(const Blob &)=delete
int width() const
Deprecated legacy shape accessor width: use shape(3) instead.
Definition: blob.h:216
void ShareData(const Blob &other)
Set the data_ std::shared_ptr to point to the SyncedMemory holding the data_ of Blob other – useful ...
void set_head_cpu()
Definition: blob.h:289
const int * gpu_shape() const
SyncedMemory::SyncedHead head() const
Definition: blob.h:290
const std::vector< int > & shape() const
Definition: blob.h:130
int num_axes() const
Definition: blob.h:142
int capacity_
Definition: blob.h:308
Blob()
Definition: blob.h:90
bool use_cuda_host_malloc_
Definition: blob.h:309