MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / TensorSizeHistogram

Class TensorSizeHistogram

tensorflow/core/grappler/costs/utils.h:77–111  ·  view source on GitHub ↗

Simple histogram for profiling Tensor size; histogram uses logarithmic buckets.

Source from the content-addressed store, hash-verified

75// Simple histogram for profiling Tensor size; histogram uses logarithmic
76// buckets.
77class TensorSizeHistogram {
78 public:
79 TensorSizeHistogram() : buckets_(kMaxBuckets, 0) {}
80
81 void Add(const uint64 value);
82 void Merge(const TensorSizeHistogram& src);
83 double Average() const {
84 if (num_elem_ > 0) {
85 return static_cast<double>(sum_elem_) / num_elem_;
86 } else {
87 return 0.0;
88 }
89 }
90 uint64 Min() const { return min_; }
91 uint64 Max() const { return max_; }
92 uint64 NumElem() const { return num_elem_; }
93 uint64 SumElem() const { return sum_elem_; }
94 string ToString() const;
95
96 protected:
97 const int Index(const uint64 value) const;
98 const std::vector<uint64>& GetBuckets() const { return buckets_; }
99
100 private:
101 const int kMaxBuckets = 64;
102 uint64 num_elem_ = 0;
103 uint64 sum_elem_ = 0;
104 // min_ and max_ are initialized to a very large value and zero, respectively,
105 // so that any value added can replace the initial min_ and max_.
106 uint64 min_ = kuint64max;
107 uint64 max_ = 0;
108 // Buckets are logarithmic:
109 // 0B, 1B, 2-3B, 4-7B, 8-15B, ..., 2^N - 2^(N+1)-1B, ...
110 std::vector<uint64> buckets_;
111};
112
113// Helper functions for aggregating per-device stats into per-device-class
114// stats.

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected