Home | History | Annotate | Download | only in compat
      1 /* Copyright 2015 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_OPS_COMPAT_OP_COMPATIBILITY_LIB_H_
     17 #define TENSORFLOW_CORE_OPS_COMPAT_OP_COMPATIBILITY_LIB_H_
     18 
     19 #include <set>
     20 
     21 #include "tensorflow/core/framework/op_def.pb.h"
     22 #include "tensorflow/core/platform/env.h"
     23 #include "tensorflow/core/platform/types.h"
     24 
     25 namespace tensorflow {
     26 
     27 class OpCompatibilityLib {
     28  public:
     29   // `ops_prefix` is a filename prefix indicating where to find the
     30   //   ops files.
     31   // `history_version` is used to construct the ops history file name.
     32   // `*stable_ops` has an optional list of ops that we care about.
     33   //   If stable_ops == nullptr, we use all registered ops.
     34   //   Otherwise ValidateCompatible() ignores ops not in *stable_ops
     35   //   and require all ops in *stable_ops to exist.
     36   OpCompatibilityLib(const string& ops_prefix, const string& history_version,
     37                      const std::set<string>* stable_ops);
     38 
     39   // Name of the file that contains the checked-in versions of *all*
     40   // ops, with docs.
     41   const string& ops_file() const { return ops_file_; }
     42 
     43   // Name of the file that contains all versions of *stable* ops,
     44   // without docs.  Op history is in (alphabetical, oldest-first)
     45   // order.
     46   const string& op_history_file() const { return op_history_file_; }
     47 
     48   // Should match the contents of ops_file().  Run before calling
     49   // ValidateCompatible().
     50   string OpsString() const { return op_list_.DebugString(); }
     51 
     52   // Returns the number of ops in OpsString(), includes all ops, not
     53   // just stable ops.
     54   int num_all_ops() const { return op_list_.op_size(); }
     55 
     56   // Make sure the current version of the *stable* ops are compatible
     57   // with the historical versions, and if out_op_history != nullptr,
     58   // generate a new history adding all changed ops.  Sets
     59   // *changed_ops/*added_ops to the number of changed/added ops
     60   // (ignoring doc changes).
     61   Status ValidateCompatible(Env* env, int* changed_ops, int* added_ops,
     62                             OpList* out_op_history);
     63 
     64  private:
     65   const string ops_file_;
     66   const string op_history_file_;
     67   const std::set<string>* stable_ops_;
     68   OpList op_list_;
     69 };
     70 
     71 }  // namespace tensorflow
     72 
     73 #endif  // TENSORFLOW_CORE_OPS_COMPAT_OP_COMPATIBILITY_LIB_H_
     74