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

Function GenVariableMethods

tensorflow/compiler/aot/codegen.cc:256–288  ·  view source on GitHub ↗

Generate methods for variables.

Source from the content-addressed store, hash-verified

254
255// Generate methods for variables.
256Status GenVariableMethods(const tf2xla::Config& config,
257 const xla::ProgramShapeProto& ps, string* methods) {
258 size_t num_args = ps.parameters_size();
259 for (int i = config.feed_size(); i < num_args; ++i) {
260 std::vector<std::pair<string, string>> rewrites;
261 TF_RETURN_IF_ERROR(
262 AddRewritesForShape(i, xla::Shape(ps.parameters(i)), &rewrites));
263 const string code = R"(
264 void set_var_{{NAME}}_data({{MAYBE_CONST}}{{TYPE}}* data) {
265 set_arg_data({{I}}, data);
266 }
267 {{MAYBE_CONST}}{{TYPE}}* var_{{NAME}}_data() {
268 return static_cast<{{MAYBE_CONST}}{{TYPE}}*>(arg_data({{I}}));
269 }
270 {{MAYBE_CONST}}{{TYPE}}& var_{{NAME}}({{DIM_VARS}}) {
271 return (*static_cast<{{MAYBE_CONST}}{{TYPE}}(*){{DIM_SIZES}}>(
272 arg_data({{I}}))){{INDICES}};
273 }
274 const {{TYPE}}* var_{{NAME}}_data() const {
275 return static_cast<const {{TYPE}}*>(arg_data({{I}}));
276 }
277 const {{TYPE}}& var_{{NAME}}({{DIM_VARS}}) const {
278 return (*static_cast<const {{TYPE}}(*){{DIM_SIZES}}>(
279 arg_data({{I}}))){{INDICES}};
280 }
281)";
282 const tf2xla::Variable& var = config.variable(i - config.feed_size());
283 rewrites.emplace_back("{{MAYBE_CONST}}", var.readonly() ? "const " : "");
284 *methods += RewriteWithName(
285 var.name().empty() ? var.node_name() : var.name(), code, rewrites);
286 }
287 return Status::OK();
288}
289
290// Generates code implementing {Arg,Result}Names(), where T is one of
291// tf2xla::{Feed,Fetch}. Each feed or fetch name results in a C-style string

Callers 1

GenerateHeaderFunction · 0.85

Calls 9

AddRewritesForShapeFunction · 0.85
RewriteWithNameFunction · 0.85
parameters_sizeMethod · 0.80
nameMethod · 0.65
ShapeClass · 0.50
parametersMethod · 0.45
emplace_backMethod · 0.45
emptyMethod · 0.45
node_nameMethod · 0.45

Tested by

no test coverage detected