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

Function AddRewritesForShape

tensorflow/compiler/aot/codegen.cc:127–150  ·  view source on GitHub ↗

Add (from,to) rewrite pairs based on the given shape. These rewrite pairs are used to generate methods for args and results.

Source from the content-addressed store, hash-verified

125// Add (from,to) rewrite pairs based on the given shape. These rewrite pairs
126// are used to generate methods for args and results.
127Status AddRewritesForShape(int i, const xla::Shape& shape,
128 std::vector<std::pair<string, string>>* rewrites) {
129 string type;
130 TF_RETURN_IF_ERROR(XLATypeToCpp(shape.element_type(), &type));
131 std::vector<string> dim_vars;
132 string dim_sizes, indices;
133 if (shape.rank() == 0 ||
134 (shape.dimensions_size() == 1 && shape.dimensions(0) == 1)) {
135 dim_sizes = "[1]";
136 indices = "[0]";
137 } else {
138 for (int dim = 0; dim < shape.dimensions_size(); ++dim) {
139 dim_vars.push_back(absl::StrCat("size_t dim", dim));
140 dim_sizes += absl::StrCat("[", shape.dimensions(dim), "]");
141 indices += absl::StrCat("[dim", dim, "]");
142 }
143 }
144 rewrites->push_back({"{{I}}", absl::StrCat(i)});
145 rewrites->push_back({"{{TYPE}}", type});
146 rewrites->push_back({"{{DIM_VARS}}", absl::StrJoin(dim_vars, ", ")});
147 rewrites->push_back({"{{DIM_SIZES}}", dim_sizes});
148 rewrites->push_back({"{{INDICES}}", indices});
149 return Status::OK();
150}
151
152// Returns code rewritten by replacing all rewrite pairs, with an extra rewrite
153// for the name. Note that the rewriting strategy is roughly O(N*M), where N is

Callers 3

GenArgMethodsFunction · 0.85
GenResultMethodsFunction · 0.85
GenVariableMethodsFunction · 0.85

Calls 7

XLATypeToCppFunction · 0.85
dimensions_sizeMethod · 0.80
StrCatFunction · 0.50
element_typeMethod · 0.45
rankMethod · 0.45
dimensionsMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected