areusch commented on a change in pull request #8072: URL: https://github.com/apache/tvm/pull/8072#discussion_r655458105
########## File path: src/printer/model_library_format_printer.cc ########## @@ -0,0 +1,75 @@ +/* + * 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. + */ + +#include <tvm/runtime/module.h> +#include <tvm/runtime/registry.h> +#include <tvm/tir/var.h> + +#include "text_printer.h" + +namespace tvm { +namespace printer { + +class ModelLibraryFormatPrinter : public ::tvm::runtime::ModuleNode { + public: + ModelLibraryFormatPrinter(bool show_meta_data, + const runtime::TypedPackedFunc<std::string(ObjectRef)>& annotate, + bool show_warning) + : text_printer_{show_meta_data, annotate, show_warning} {} + + const char* type_key() const override { return "model_library_format_printer"; } + + std::string Print(const ObjectRef& node) { + Doc doc; + doc << text_printer_.PrintFinal(node); + return doc.str(); + } + + PackedFunc GetFunction(const std::string& name, const ObjectPtr<Object>& sptr_to_self) override { + if (name == "print") { + return TypedPackedFunc<std::string(ObjectRef)>( + [sptr_to_self, this](ObjectRef node) { return Print(node); }); + } else if (name == "get_var_name") { + return PackedFunc([sptr_to_self, this](TVMArgs args, TVMRetValue* rv) { + ICHECK_EQ(args.size(), 1) << "usage: get_var_name(Var v)"; + + std::string var_name; + if (text_printer_.GetVarName(args[0], &var_name)) { + *rv = var_name; + } Review comment: i guess the thinking is that the caller can decide what to do. since the function will return None, it should be fairly straightforward. we could raise an exception. are you thinking that users may not check the return value? ########## File path: python/tvm/micro/model_library_format.py ########## @@ -203,60 +209,200 @@ def _build_function_memory_map(function_metadata): return ret -def export_model_library_format(mod: executor_factory.ExecutorFactoryModule, file_name): - """Export the build artifact in Model Library Format. +def _make_tar(source_dir, tar_file_path): + """Build a tar file from source_dir.""" + with tarfile.open(tar_file_path, "w") as tar_f: - This function creates a .tar archive containing the build artifacts in a standardized - layout. It's intended to allow downstream automation to build TVM artifacts against the C - runtime. + def reset(tarinfo): + tarinfo.uid = tarinfo.gid = 0 + tarinfo.uname = tarinfo.gname = "root" + return tarinfo + + tar_f.add(str(source_dir), arcname=".", filter=reset) + + +_GENERATED_VERSION = 2 + + +def _export_graph_model_library_format( + mod: executor_factory.GraphExecutorFactoryModule, tempdir: pathlib.Path Review comment: done -- 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. For queries about this service, please contact Infrastructure at: [email protected]
