aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/java/src/gen/cc/op_specs.h
blob: 3b53c730df23c6f81f968f09b9d145a8efa1030a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/* Copyright 2018 The TensorFlow Authors. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef TENSORFLOW_JAVA_SRC_GEN_CC_OP_SPECS_H_
#define TENSORFLOW_JAVA_SRC_GEN_CC_OP_SPECS_H_

#include <string>
#include <vector>

#include "tensorflow/core/framework/op_def.pb.h"
#include "tensorflow/core/framework/api_def.pb.h"
#include "tensorflow/core/framework/attr_value.pb.h"
#include "tensorflow/java/src/gen/cc/java_defs.h"

namespace tensorflow {
namespace java {

constexpr const char kDefaultEndpointPackage[] = "core";

class EndpointSpec {
 public:
  // A specification for an operation endpoint
  //
  // package: package of this endpoint (from which also derives its package)
  // name: name of this endpoint class
  // javadoc: the endpoint class documentation
  // TODO(annarev): hardcode depcreated to false until deprecated is possible
  EndpointSpec(const string& package, const string& name,
      const Javadoc& javadoc)
    : package_(package), name_(name), javadoc_(javadoc),
      deprecated_(false) {}

  const string& package() const { return package_; }
  const string& name() const { return name_; }
  const Javadoc& javadoc() const { return javadoc_; }
  bool deprecated() const { return deprecated_; }

 private:
  const string package_;
  const string name_;
  const Javadoc javadoc_;
  const bool deprecated_;
};

class ArgumentSpec {
 public:
  // A specification for an operation argument
  //
  // op_def_name: argument name, as known by TensorFlow core
  // var: a variable to represent this argument in Java
  // type: the tensor type of this argument
  // description: a description of this argument, in javadoc
  // iterable: true if this argument is a list
  ArgumentSpec(const string& op_def_name, const Variable& var,
      const Type& type, const string& description, bool iterable)
    : op_def_name_(op_def_name), var_(var), type_(type),
      description_(description), iterable_(iterable) {}

  const string& op_def_name() const { return op_def_name_; }
  const Variable& var() const { return var_; }
  const Type& type() const { return type_; }
  const string& description() const { return description_; }
  bool iterable() const { return iterable_; }

 private:
  const string op_def_name_;
  const Variable var_;
  const Type type_;
  const string description_;
  const bool iterable_;
};

class AttributeSpec {
 public:
  // A specification for an operation attribute
  //
  // op_def_name: attribute name, as known by TensorFlow core
  // var: a variable to represent this attribute in Java
  // type: the type of this attribute
  // jni_type: the type of this attribute in JNI layer (see OperationBuilder)
  // description: a description of this attribute, in javadoc
  // iterable: true if this attribute is a list
  // has_default_value: true if this attribute has a default value if not set
  AttributeSpec(const string& op_def_name, const Variable& var,
      const Type& type, const Type& jni_type, const string& description,
      bool iterable, bool has_default_value)
    : op_def_name_(op_def_name), var_(var), type_(type),
      description_(description), iterable_(iterable),
      jni_type_(jni_type), has_default_value_(has_default_value) {}

  const string& op_def_name() const { return op_def_name_; }
  const Variable& var() const { return var_; }
  const Type& type() const { return type_; }
  const string& description() const { return description_; }
  bool iterable() const { return iterable_; }
  const Type& jni_type() const { return jni_type_; }
  bool has_default_value() const { return has_default_value_; }

 private:
  const string op_def_name_;
  const Variable var_;
  const Type type_;
  const string description_;
  const bool iterable_;
  const Type jni_type_;
  const bool has_default_value_;
};

class OpSpec {
 public:
  // Parses an op definition and its API to produce a specification used for
  // rendering its Java wrapper
  //
  // op_def: Op definition
  // api_def: Op API definition
  static OpSpec Create(const OpDef& op_def, const ApiDef& api_def);

  const string& graph_op_name() const { return graph_op_name_; }
  bool hidden() const { return hidden_; }
  const string& deprecation_explanation() const {
    return deprecation_explanation_;
  }
  const std::vector<EndpointSpec> endpoints() const { return endpoints_; }
  const std::vector<ArgumentSpec>& inputs() const { return inputs_; }
  const std::vector<ArgumentSpec>& outputs() const { return outputs_; }
  const std::vector<AttributeSpec>& attributes() const { return attributes_; }
  const std::vector<AttributeSpec>& optional_attributes() const {
    return optional_attributes_;
  }

 private:
  // A specification for an operation
  //
  // graph_op_name: name of this op, as known by TensorFlow core engine
  // hidden: true if this op should not be visible through the Graph Ops API
  // deprecation_explanation: message to show if all endpoints are deprecated
  explicit OpSpec(const string& graph_op_name, bool hidden,
      const string& deprecation_explanation)
    : graph_op_name_(graph_op_name), hidden_(hidden),
      deprecation_explanation_(deprecation_explanation) {}

  const string graph_op_name_;
  const bool hidden_;
  const string deprecation_explanation_;
  std::vector<EndpointSpec> endpoints_;
  std::vector<ArgumentSpec> inputs_;
  std::vector<ArgumentSpec> outputs_;
  std::vector<AttributeSpec> attributes_;
  std::vector<AttributeSpec> optional_attributes_;
};

}  // namespace java
}  // namespace tensorflow

#endif  // TENSORFLOW_JAVA_SRC_GEN_CC_OP_SPECS_H_