• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2021 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #ifndef TENSORFLOW_CORE_FRAMEWORK_RESOURCE_BASE_H_
17 #define TENSORFLOW_CORE_FRAMEWORK_RESOURCE_BASE_H_
18 
19 #include "tensorflow/core/lib/core/refcount.h"
20 #include "tensorflow/core/lib/core/status.h"
21 #include "tensorflow/core/platform/errors.h"
22 
23 namespace tensorflow {
24 
25 // Forward declaration to avoid introducing a dependency on headers in
26 // "tensorflow/core/graph/...".
27 class GraphDefBuilder;
28 class Node;
29 
30 // This is the base class of all resource classes. Each resource must be
31 // represented as a sub-class of ResourceBase (which is reference counted) to be
32 // able to work with resource facilities such ResourceHandle and ResourceMgr.
33 class ResourceBase : public core::WeakRefCounted {
34  public:
35   // Returns a debug string for *this.
36   virtual std::string DebugString() const = 0;
37 
38   // Returns memory used by this resource.
MemoryUsed()39   virtual int64_t MemoryUsed() const { return 0; }
40 
41   // Writes a representation of this resource into `builder`, so that executing
42   // `*out` will recreate this resource.
AsGraphDef(GraphDefBuilder * builder,Node ** out)43   virtual Status AsGraphDef(GraphDefBuilder* builder, Node** out) const {
44     return errors::Unimplemented("AsGraphDef not implemented for resource ",
45                                  DebugString());
46   }
47 };
48 }  //  end namespace tensorflow
49 
50 #endif  // TENSORFLOW_CORE_FRAMEWORK_RESOURCE_BASE_H_
51