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

Function GenArgMethods

tensorflow/compiler/aot/codegen.cc:168–206  ·  view source on GitHub ↗

Generate methods for args (inputs).

Source from the content-addressed store, hash-verified

166
167// Generate methods for args (inputs).
168Status GenArgMethods(const tf2xla::Config& config,
169 const xla::ProgramShapeProto& ps,
170 const CompileResult& compile_result, string* methods) {
171 size_t num_args = ps.parameters_size();
172 if (config.feed_size() + config.variable_size() != num_args) {
173 return errors::InvalidArgument(
174 "mismatch between feed_size(", config.feed_size(), ")+variable_size(",
175 config.variable_size(), ") and num_args(", num_args, ")");
176 }
177 for (int i = 0; i < config.feed_size(); ++i) {
178 std::vector<std::pair<string, string>> rewrites;
179 TF_RETURN_IF_ERROR(
180 AddRewritesForShape(i, xla::Shape(ps.parameters(i)), &rewrites));
181 const string code = R"(
182 void set_arg{{NAME}}_data(const void* data) {
183 set_arg_data({{I}}, data);
184 }
185 {{TYPE}}* arg{{NAME}}_data() {
186 return static_cast<{{TYPE}}*>(arg_data({{I}}));
187 }
188 {{TYPE}}& arg{{NAME}}({{DIM_VARS}}) {
189 return (*static_cast<{{TYPE}}(*){{DIM_SIZES}}>(
190 arg_data({{I}}))){{INDICES}};
191 }
192 const {{TYPE}}* arg{{NAME}}_data() const {
193 return static_cast<const {{TYPE}}*>(arg_data({{I}}));
194 }
195 const {{TYPE}}& arg{{NAME}}({{DIM_VARS}}) const {
196 return (*static_cast<const {{TYPE}}(*){{DIM_SIZES}}>(
197 arg_data({{I}}))){{INDICES}};
198 }
199)";
200 *methods += RewriteWithName(absl::StrCat(i), code, rewrites);
201 if (!config.feed(i).name().empty()) {
202 *methods += RewriteWithName("_" + config.feed(i).name(), code, rewrites);
203 }
204 }
205 return Status::OK();
206}
207
208// Generate methods for results (outputs).
209Status GenResultMethods(const tf2xla::Config& config,

Callers 1

GenerateHeaderFunction · 0.85

Calls 10

InvalidArgumentFunction · 0.85
AddRewritesForShapeFunction · 0.85
RewriteWithNameFunction · 0.85
parameters_sizeMethod · 0.80
nameMethod · 0.65
ShapeClass · 0.50
StrCatFunction · 0.50
parametersMethod · 0.45
emptyMethod · 0.45
feedMethod · 0.45

Tested by

no test coverage detected