areusch commented on code in PR #13095: URL: https://github.com/apache/tvm/pull/13095#discussion_r997302459
########## src/relay/backend/aot/create_function_metadata.cc: ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/*! + * \file src/relay/backend/aot/create_function_metadata.cc + * \brief Create FunctionInfo metadata from a lowered TIR module. + */ +#include "./create_function_metadata.h" + +#include <tvm/ir/expr.h> +#include <tvm/ir/module.h> +#include <tvm/runtime/container/array.h> +#include <tvm/runtime/container/map.h> +#include <tvm/runtime/container/string.h> +#include <tvm/runtime/data_type.h> +#include <tvm/runtime/module.h> +#include <tvm/target/target_kind.h> +#include <tvm/tir/analysis.h> +#include <tvm/tir/function.h> +#include <tvm/tir/op.h> +#include <tvm/tir/usmp/utils.h> + +#include "../utils.h" + +namespace tvm { +namespace relay { +namespace backend { +namespace aot { + +/*! + * \brief Calculate FunctionInfo for all the PrimFuncs in a module. + */ +Map<String, backend::FunctionInfo> CalculateFunctionInfos(const IRModule& mod, + Integer workspace_byte_alignment, + Integer constant_byte_alignment) { + Map<String, backend::FunctionInfo> function_metadata; + for (const auto& kv : mod->functions) { + GlobalVar global_var = kv.first; + BaseFunc base_func = kv.second; + if (base_func->IsInstance<tir::PrimFuncNode>()) { + tir::PrimFunc pfunc = Downcast<tir::PrimFunc>(base_func); + Target tgt = pfunc->GetAttr<Target>(tvm::attr::kTarget).value(); + // Determine the size of input/output buffers + auto params = pfunc->params; + int64_t ios = 0; Review Comment: can you expand the var name? maybe `total_io_bytes` or something to map to the FunctionInfo member? ########## src/relay/backend/aot/create_function_metadata.cc: ########## @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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. + */ + +/*! + * \file src/relay/backend/aot/create_function_metadata.cc + * \brief Create FunctionInfo metadata from a lowered TIR module. + */ +#include "./create_function_metadata.h" + +#include <tvm/ir/expr.h> +#include <tvm/ir/module.h> +#include <tvm/runtime/container/array.h> +#include <tvm/runtime/container/map.h> +#include <tvm/runtime/container/string.h> +#include <tvm/runtime/data_type.h> +#include <tvm/runtime/module.h> +#include <tvm/target/target_kind.h> +#include <tvm/tir/analysis.h> +#include <tvm/tir/function.h> +#include <tvm/tir/op.h> +#include <tvm/tir/usmp/utils.h> + +#include "../utils.h" + +namespace tvm { +namespace relay { +namespace backend { +namespace aot { + +/*! + * \brief Calculate FunctionInfo for all the PrimFuncs in a module. + */ +Map<String, backend::FunctionInfo> CalculateFunctionInfos(const IRModule& mod, + Integer workspace_byte_alignment, + Integer constant_byte_alignment) { + Map<String, backend::FunctionInfo> function_metadata; + for (const auto& kv : mod->functions) { + GlobalVar global_var = kv.first; + BaseFunc base_func = kv.second; + if (base_func->IsInstance<tir::PrimFuncNode>()) { + tir::PrimFunc pfunc = Downcast<tir::PrimFunc>(base_func); + Target tgt = pfunc->GetAttr<Target>(tvm::attr::kTarget).value(); Review Comment: should we CHECK() here rather than letting `.value()` do it for us? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
