Make DebugString() in ResourceBase constant

PiperOrigin-RevId: 228300469
This commit is contained in:
Gaurav Jain 2019-01-08 02:23:41 -08:00 committed by TensorFlower Gardener
parent 84cf1da2b9
commit f09a6224ba
52 changed files with 77 additions and 69 deletions

View File

@ -62,7 +62,7 @@ XlaCompilationCache::~XlaCompilationCache() {
// about?
}
string XlaCompilationCache::DebugString() {
string XlaCompilationCache::DebugString() const {
return "XLA JIT compilation cache";
}

View File

@ -88,7 +88,7 @@ class XlaCompilationCache : public ResourceBase {
xla::LocalClient* client() const { return client_; }
const DeviceType& device_type() const { return device_type_; }
string DebugString() override;
string DebugString() const override;
// Describes the types, shapes and any compile-time constant arguments
// to a kernel. Key that uniquely identifies a compilation output.

View File

@ -82,7 +82,7 @@ namespace {
// compiled kernels.
class DummyResourceForTest : public ResourceBase {
public:
string DebugString() override { return "dummy"; }
string DebugString() const override { return "dummy"; }
void Increment() { ++value_; }
int Get() { return value_; }

View File

@ -61,7 +61,7 @@ void XlaContext::set_args(std::vector<XlaExpression> args) {
XlaContext::XlaContext(XlaCompiler* compiler, xla::XlaBuilder* builder)
: compiler_(compiler), builder_(builder) {}
string XlaContext::DebugString() { return "XLA JIT context"; }
string XlaContext::DebugString() const { return "XLA JIT context"; }
void XlaContext::SetRetval(int index, const XlaExpression& expression) {
if (retvals_.size() <= index) {

View File

@ -47,7 +47,7 @@ class XlaContext : public ResourceBase {
XlaContext(XlaCompiler* compiler, xla::XlaBuilder* builder);
// Virtual method defined by ResourceBase.
string DebugString() override;
string DebugString() const override;
XlaCompiler* compiler() const { return compiler_; }

View File

@ -273,6 +273,8 @@ Status XRTCompilationCache::Lookup(
return Status::OK();
}
string XRTCompilationCache::DebugString() { return "XRTCompilationCache"; }
string XRTCompilationCache::DebugString() const {
return "XRTCompilationCache";
}
} // namespace tensorflow

View File

@ -118,7 +118,7 @@ class XRTCompilationCache : public ResourceBase {
// EntryRef holding the program is returned in entry.
Status Lookup(int64 uid, std::unique_ptr<XRTCompilationCacheEntryRef>* entry);
string DebugString() override;
string DebugString() const override;
private:
// An entry in the compilation cache. The entry is deleted once it has been

View File

@ -172,7 +172,7 @@ class XRTTupleAllocation : public ResourceBase {
// ownership of the device memory is transferred to the result.
xla::ShapeTree<xla::MaybeOwningDeviceMemory> ToDeviceMemoryTree(bool release);
string DebugString() override { return "XLA allocation handle"; }
string DebugString() const override { return "XLA allocation handle"; }
private:
// Creates a new handle with (tuple) shape.

View File

@ -42,7 +42,7 @@ class BigtableClientResource : public ResourceBase {
return client_;
}
string DebugString() override {
string DebugString() const override {
return strings::StrCat("BigtableClientResource(project_id: ", project_id_,
", instance_id: ", instance_id_, ")");
}
@ -67,7 +67,7 @@ class BigtableTableResource : public ResourceBase {
::google::cloud::bigtable::noex::Table& table() { return table_; }
string DebugString() override {
string DebugString() const override {
return strings::StrCat(
"BigtableTableResource(client: ", client_->DebugString(),
", table: ", table_name_, ")");

View File

@ -96,7 +96,7 @@ class StatsAccumulatorResource : public boosted_trees::StampedResource {
TensorShapeUtils::IsScalar(hessian_shape));
}
string DebugString() override {
string DebugString() const override {
return strings::StrCat("StatsAccumulatorResource[size=", values_.size(),
"]");
}

View File

@ -34,7 +34,7 @@ class DecisionTreeEnsembleResource : public StampedResource {
protobuf::Arena::CreateMessage<
boosted_trees::trees::DecisionTreeEnsembleConfig>(&arena_)) {}
string DebugString() override {
string DebugString() const override {
return strings::StrCat("GTFlowDecisionTreeEnsemble[size=",
decision_tree_ensemble_->trees_size(), "]");
}

View File

@ -43,7 +43,7 @@ class QuantileStreamResource : public StampedResource {
set_stamp(stamp_token);
}
string DebugString() override { return "QuantileStreamResource"; }
string DebugString() const override { return "QuantileStreamResource"; }
tensorflow::mutex* mutex() { return &mu_; }

View File

@ -32,7 +32,7 @@ class DecisionTreeResource : public ResourceBase {
// Constructor.
explicit DecisionTreeResource(const TensorForestParams& params);
string DebugString() override {
string DebugString() const override {
return strings::StrCat("DecisionTree[size=",
decision_tree_->decision_tree().nodes_size(), "]");
}

View File

@ -40,7 +40,7 @@ class FertileStatsResource : public ResourceBase {
model_op_ = LeafModelOperatorFactory::CreateLeafModelOperator(params_);
}
string DebugString() override { return "FertileStats"; }
string DebugString() const override { return "FertileStats"; }
void ExtractFromProto(const FertileStats& stats);

View File

@ -48,7 +48,7 @@ class TRTCalibrationResource : public tensorflow::ResourceBase {
allocator_.reset();
}
string DebugString() override {
string DebugString() const override {
std::stringstream oss;
using std::dec;
using std::endl;

View File

@ -131,7 +131,7 @@ class LookupInterface : public ResourceBase {
// - the default_value tensor shape matches the table's value shape.
Status CheckFindArguments(const Tensor& keys, const Tensor& default_value);
string DebugString() override {
string DebugString() const override {
return strings::StrCat("A lookup table of size: ", size());
}

View File

@ -85,11 +85,11 @@ class QueueInterface : public ResourceBase {
virtual Status MatchesNodeDef(const NodeDef& node_def) = 0;
// Returns the number of elements in the queue.
virtual int32 size() = 0;
virtual int32 size() const = 0;
virtual const DataTypeVector& component_dtypes() const = 0;
string DebugString() override {
string DebugString() const override {
return strings::StrCat("A Queue of size: ", size());
}

View File

@ -76,7 +76,7 @@ class ReaderInterface : public ResourceBase {
// Note: Must Reset on error.
virtual Status RestoreState(const string& state) = 0;
string DebugString() override { return "a reader"; }
string DebugString() const override { return "a reader"; }
protected:
virtual ~ReaderInterface() {}

View File

@ -77,7 +77,7 @@ namespace tensorflow {
class ResourceBase : public core::RefCounted {
public:
// Returns a debug string for *this.
virtual string DebugString() = 0;
virtual string DebugString() const = 0;
// Returns memory used by this resource.
virtual int64 MemoryUsed() const { return 0; }

View File

@ -32,7 +32,7 @@ class Resource : public ResourceBase {
explicit Resource(const string& label) : label_(label) {}
~Resource() override {}
string DebugString() override { return strings::StrCat("R/", label_); }
string DebugString() const override { return strings::StrCat("R/", label_); }
private:
string label_;
@ -43,7 +43,7 @@ class Other : public ResourceBase {
explicit Other(const string& label) : label_(label) {}
~Other() override {}
string DebugString() override { return strings::StrCat("O/", label_); }
string DebugString() const override { return strings::StrCat("O/", label_); }
private:
string label_;
@ -245,7 +245,7 @@ class StubDevice : public DeviceBase {
// Empty stub resource for testing resource handles.
class StubResource : public ResourceBase {
public:
string DebugString() override { return ""; }
string DebugString() const override { return ""; }
int value_{0};
};
@ -305,7 +305,7 @@ TEST(ResourceHandleTest, DifferentDevice) {
// Other stub resource to test type-checking of resource handles.
class OtherStubResource : public ResourceBase {
public:
string DebugString() override { return ""; }
string DebugString() const override { return ""; }
};
TEST(ResourceHandleTest, DifferentType) {

View File

@ -46,7 +46,7 @@ class StubDevice : public DeviceBase {
// Stub resource for testing resource op kernel.
class StubResource : public ResourceBase {
public:
string DebugString() override { return ""; }
string DebugString() const override { return ""; }
int code;
};

View File

@ -67,7 +67,7 @@ class Var : public ResourceBase {
mutex* mu() { return &mu_; }
Tensor* tensor() { return &tensor_; }
string DebugString() override {
string DebugString() const override {
return strings::StrCat(DataTypeString(tensor_.dtype()), "/",
tensor_.shape().DebugString());
}

View File

@ -83,7 +83,7 @@ class StatsAggregatorResource : public ResourceBase {
return stats_aggregator_;
}
string DebugString() { return "StatsAggregatorResource"; }
string DebugString() const override { return "StatsAggregatorResource"; }
private:
const std::shared_ptr<StatsAggregator> stats_aggregator_;

View File

@ -300,7 +300,7 @@ class Barrier : public ResourceBase {
ready_queue_->Unref();
}
string DebugString() override { return "A barrier"; }
string DebugString() const override { return "A barrier"; }
protected:
template <typename T>

View File

@ -233,7 +233,7 @@ class BatchResource : public ResourceBase {
return Status::OK();
}
string DebugString() final { return "BatchResource"; }
string DebugString() const final { return "BatchResource"; }
// Ingests data from one invocation of the batch op. The data is enqueued to
// be combined with others into a batch, asynchronously.
@ -878,7 +878,7 @@ class UnbatchResource : public ResourceBase {
timeout_enforcer_ = nullptr;
}
string DebugString() final { return "UnbatchResource"; }
string DebugString() const final { return "UnbatchResource"; }
Status Compute(OpKernelContext* context, AsyncOpKernel::DoneCallback done) {
const Tensor& data_t = context->input(0);
@ -1094,7 +1094,7 @@ class UnbatchGradResource : public ResourceBase {
public:
UnbatchGradResource() {}
string DebugString() final { return "UnbatchGradResource"; }
string DebugString() const final { return "UnbatchGradResource"; }
// Flushes the information for one batch, given its context and done
// callback. Clears all information about it from the available_tensors_.

View File

@ -37,15 +37,15 @@ class BoostedTreesQuantileStreamResource : public ResourceBase {
epsilon_(epsilon),
num_streams_(num_streams),
max_elements_(max_elements) {
streams_.reserve(num_streams_);
boundaries_.reserve(num_streams_);
for (int64 idx = 0; idx < num_streams; ++idx) {
streams_.push_back(QuantileStream(epsilon, max_elements));
boundaries_.push_back(std::vector<float>());
}
}
streams_.reserve(num_streams_);
boundaries_.reserve(num_streams_);
for (int64 idx = 0; idx < num_streams; ++idx) {
streams_.push_back(QuantileStream(epsilon, max_elements));
boundaries_.push_back(std::vector<float>());
}
}
string DebugString() override { return "QuantileStreamResource"; }
string DebugString() const override { return "QuantileStreamResource"; }
tensorflow::mutex* mutex() { return &mu_; }

View File

@ -31,7 +31,7 @@ BoostedTreesEnsembleResource::BoostedTreesEnsembleResource()
protobuf::Arena::CreateMessage<boosted_trees::TreeEnsemble>(
&arena_)) {}
string BoostedTreesEnsembleResource::DebugString() {
string BoostedTreesEnsembleResource::DebugString() const {
return strings::StrCat("TreeEnsemble[size=", tree_ensemble_->trees_size(),
"]");
}

View File

@ -48,7 +48,7 @@ class BoostedTreesEnsembleResource : public StampedResource {
public:
BoostedTreesEnsembleResource();
string DebugString() override;
string DebugString() const override;
bool InitFromSerialized(const string& serialized, const int64 stamp_token);

View File

@ -68,7 +68,7 @@ class ConditionalAccumulatorBase : public ResourceBase {
const DataType& dtype() const { return dtype_; }
string DebugString() override { return "A conditional accumulator"; }
string DebugString() const override { return "A conditional accumulator"; }
// SetGlobalStep is a modifier method for current_global_step.
// It returns an InvalidArgument error if the new_global_step is less than

View File

@ -63,7 +63,7 @@ struct Im2ColBufferResource : public ResourceBase {
// the buffer memory held by this resource.
mutex mu;
T* data;
string DebugString() { return "Im2ColBufferResource"; }
string DebugString() const { return "Im2ColBufferResource"; }
};
// Convolution parameters specified by Op attributes.

View File

@ -614,7 +614,9 @@ class CacheDatasetOp : public UnaryDatasetOpKernel {
public:
MemoryCache() = default;
string DebugString() override { return "CacheDataset::MemoryCache"; }
string DebugString() const override {
return "CacheDataset::MemoryCache";
}
// Marks the cache as completed.
void Complete() {

View File

@ -106,7 +106,7 @@ class MaterializedDatasetResource : public ResourceBase {
const std::vector<PartialTensorShape>& output_shapes)
: output_dtypes_(output_dtypes), output_shapes_(output_shapes) {}
string DebugString() override {
string DebugString() const override {
return "Materialized IndexedDataset resource";
}

View File

@ -51,7 +51,7 @@ class ThreadPoolResource : public ResourceBase {
int32 NumThreads() { return thread_pool_.NumThreads(); }
string DebugString() override { return "ThreadPoolResource"; }
string DebugString() const override { return "ThreadPoolResource"; }
private:
thread::ThreadPool thread_pool_;

View File

@ -231,7 +231,7 @@ class IteratorResource : public ResourceBase {
return Status::OK();
}
string DebugString() override { return "Iterator resource"; }
string DebugString() const override { return "Iterator resource"; }
const DataTypeVector& output_dtypes() const { return output_dtypes_; }

View File

@ -59,7 +59,7 @@ class MultiDeviceIterator : public ResourceBase {
DCHECK(lib_ != nullptr);
}
string DebugString() override {
string DebugString() const override {
return strings::StrCat("MultiDeviceIterator for ", devices_.size(),
" devices");
}

View File

@ -412,7 +412,7 @@ class ShuffleDatasetOp : public ShuffleDatasetOpBase {
parent_generator_(seed, seed2),
generator_(&parent_generator_) {}
string DebugString() override {
string DebugString() const override {
return "ReshufflingDataset::RandomSeedGenerator";
}

View File

@ -49,7 +49,7 @@ class FIFOQueue : public TypedQueue<std::deque<PersistentTensor> > {
CallbackWithTuple callback) override;
Status MatchesNodeDef(const NodeDef& node_def) override;
int32 size() override {
int32 size() const override {
mutex_lock lock(mu_);
return queues_[0].size();
}

View File

@ -480,7 +480,7 @@ class StagingMap : public ResourceBase {
return map_.size();
}
string DebugString() override { return "StagingMap"; }
string DebugString() const override { return "StagingMap"; }
};
template <bool Ordered>

View File

@ -54,7 +54,7 @@ class Scratch : public ResourceBase {
uint8_t* buffer() { return scratch_32_aligned_; }
string DebugString() { return "MetaGemmScratchResource"; }
string DebugString() const override { return "MetaGemmScratchResource"; }
private:
std::unique_ptr<uint8_t> scratch_;

View File

@ -45,7 +45,9 @@ class Mutex : public ResourceBase {
VLOG(2) << "Creating mutex with name " << name << ": " << this;
}
string DebugString() override { return strings::StrCat("Mutex ", name_); }
string DebugString() const override {
return strings::StrCat("Mutex ", name_);
}
class LockReleaser {
public:

View File

@ -68,7 +68,7 @@ class PriorityQueue
Status MatchesPriorityNodeDefTypes(const NodeDef& node_def) const;
Status MatchesPriorityNodeDefShapes(const NodeDef& node_def) const;
int32 size() override {
int32 size() const override {
mutex_lock lock(mu_);
return queues_[0].size();
}

View File

@ -59,7 +59,7 @@ class RandomShuffleQueue : public TypedQueue<std::vector<PersistentTensor> > {
CallbackWithTuple callback) override;
Status MatchesNodeDef(const NodeDef& node_def) override;
int32 size() override {
int32 size() const override {
mutex_lock lock(mu_);
return queues_[0].size();
}

View File

@ -43,7 +43,7 @@ class SparseTensorsMap : public ResourceBase {
public:
explicit SparseTensorsMap(const string& name) : name_(name), counter_(0) {}
string DebugString() override { return "A SparseTensorsMap"; }
string DebugString() const override { return "A SparseTensorsMap"; }
typedef struct {
PersistentTensor indices;

View File

@ -96,7 +96,7 @@ class Stack : public ResourceBase {
DataType ElemType() { return elem_type_; }
string DebugString() override {
string DebugString() const override {
mutex_lock l(mu_);
return strings::StrCat("Stack[", stack_name_, "]");
}

View File

@ -132,7 +132,7 @@ class Buffer : public ResourceBase {
notify_inserters_if_bounded(&lock);
}
string DebugString() override {
string DebugString() const override {
std::unique_lock<std::mutex> lock(mu_);
return strings::StrCat("Staging size: ", buf_.size());
}
@ -170,7 +170,7 @@ class Buffer : public ResourceBase {
std::size_t capacity_;
std::size_t memory_limit_;
std::size_t current_bytes_;
std::mutex mu_;
mutable std::mutex mu_;
std::condition_variable non_empty_cond_var_;
std::condition_variable full_cond_var_;
std::deque<Tuple> buf_;

View File

@ -124,7 +124,9 @@ TF_CALL_REAL_NUMBER_TYPES(REGISTER)
struct HistogramResource : public ResourceBase {
histogram::ThreadSafeHistogram histogram;
string DebugString() override { return "A histogram summary. Stats ..."; }
string DebugString() const override {
return "A histogram summary. Stats ...";
}
};
class SummaryMergeOp : public OpKernel {

View File

@ -261,7 +261,7 @@ class TensorArray : public ResourceBase {
return Status::OK();
}
string DebugString() override {
string DebugString() const override {
mutex_lock l(mu_);
CHECK(!closed_);
return strings::StrCat("TensorArray[", tensors_.size(), "]");
@ -376,7 +376,7 @@ class TensorArray : public ResourceBase {
const DataType dtype_;
Tensor handle_;
mutex mu_;
mutable mutex mu_;
// Marks that the tensor_array_ has been cleared.
bool closed_ GUARDED_BY(mu_);

View File

@ -34,7 +34,7 @@ class TensorForestTreeResource : public ResourceBase {
public:
TensorForestTreeResource();
string DebugString() override {
string DebugString() const override {
return strings::StrCat("TensorForestTree[size=", get_size(), "]");
}

View File

@ -35,7 +35,7 @@ class LegacyVar : public ResourceBase {
mutex* mu() { return &mu_; }
Tensor* tensor() { return &tensor_; }
string DebugString() override {
string DebugString() const override {
return strings::StrCat(DataTypeString(tensor_.dtype()), "/",
tensor_.shape().DebugString());
}
@ -116,7 +116,7 @@ class TemporaryVariableOp : public OpKernel {
mutex mu;
Tensor val;
string name;
string DebugString() override { return name; }
string DebugString() const override { return name; }
~TmpVar() override { VLOG(3) << "TmpVar " << name << " deleted"; }
};

View File

@ -972,7 +972,7 @@ class SummaryDbWriter : public SummaryWriterInterface {
return MigrateEvent(std::move(e));
}
string DebugString() override { return "SummaryDbWriter"; }
string DebugString() const override { return "SummaryDbWriter"; }
private:
Status Write(int64 step, const Tensor& t, const string& tag,

View File

@ -148,7 +148,7 @@ class SummaryFileWriter : public SummaryWriterInterface {
return Status::OK();
}
string DebugString() override { return "SummaryFileWriter"; }
string DebugString() const override { return "SummaryFileWriter"; }
private:
double GetWallTime() {

View File

@ -157,7 +157,7 @@ REGISTER_KERNEL_BUILDER(Name("Old").Device(DEVICE_CPU), OldOp);
// Stubbed-out resource to test resource handle ops.
class StubResource : public ResourceBase {
public:
string DebugString() override { return ""; }
string DebugString() const override { return ""; }
};
REGISTER_RESOURCE_HANDLE_KERNEL(StubResource);