a7297870c0
* Initial commit of API server impl. * initial commit of api client * Add TVM-side glue code to use Project API * Change tvm.micro.Session to use Project API * Rework how crt_config.h is used on the host. * use template crt_config.h for host test runtime; delete src/runtime/crt/host/crt_config.h so that it doesn't diverge from the template * bring template crt_config.h inline with the one actually in use * rename to MAX_STRLEN_DLTYPE * Create a dedicated TVM-side host crt_config.h in src/runtime/micro * Modify Transport infrastructure to work with Project API * Add host microTVM API server * Zephyr implementation of microTVM API server * move all zephyr projects to apps/microtvm/zephyr/template_project * consolidate CcompilerAnnotator * Allow model library format with c backend, add test. * Update unit tests * fix incorrect doc * Delete old Zephyr build infrastructure * Delete old build abstractions * Delete old Transport implementations and simplify module * lint * ASF header * address gromero comments * final fixes? * fix is_shutdown * fix user-facing API * fix TempDirectory / operator * Update micro_tflite tutorial * lint * fix test_crt and test_link_params * undo global micro import, hopefully fix fixture * lint * fix more tests * Address tmoreau89 comments and mehrdadh comments * fix random number generator prj.conf for physical hw * uncomment proper aot option
86 lines
3.1 KiB
Python
86 lines
3.1 KiB
Python
# 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.
|
|
|
|
"""Defines functions for generating a C interface header"""
|
|
|
|
import os
|
|
|
|
from tvm.relay.backend.utils import mangle_module_name
|
|
|
|
|
|
def _emit_brief(header_file, module_name, description):
|
|
header_file.write("/*!\n")
|
|
header_file.write(f' * \\brief {description} for TVM module "{module_name}" \n')
|
|
header_file.write(" */\n")
|
|
|
|
|
|
def generate_c_interface_header(module_name, inputs, outputs, output_path):
|
|
"""Generates a C interface header for a given modules inputs and outputs
|
|
|
|
Parameters
|
|
----------
|
|
module_name : str
|
|
Name of the module to be used in defining structs and naming the header
|
|
inputs : list[str]
|
|
List of module input names to be placed in generated structs
|
|
outputs : list[str]
|
|
List of module output names to be placed in generated structs
|
|
output_path : str
|
|
Path to the output folder to generate the header into
|
|
|
|
Returns
|
|
-------
|
|
str :
|
|
Name of the generated file.
|
|
"""
|
|
mangled_name = mangle_module_name(module_name)
|
|
metadata_header = os.path.join(output_path, f"{mangled_name}.h")
|
|
with open(metadata_header, "w") as header_file:
|
|
header_file.write(
|
|
"#include <stdint.h>\n"
|
|
f"#ifndef {mangled_name.upper()}_H_\n"
|
|
f"#define {mangled_name.upper()}_H_\n"
|
|
)
|
|
|
|
_emit_brief(header_file, module_name, "Input tensor pointers")
|
|
header_file.write(f"struct {mangled_name}_inputs {{\n")
|
|
for input_name in inputs:
|
|
header_file.write(f" void* {input_name};\n")
|
|
header_file.write("};\n\n")
|
|
|
|
_emit_brief(header_file, module_name, "Output tensor pointers")
|
|
header_file.write(f"struct {mangled_name}_outputs {{\n")
|
|
for output_name in outputs:
|
|
header_file.write(f" void* {output_name};\n")
|
|
header_file.write("};\n\n")
|
|
|
|
header_file.write(
|
|
"/*!\n"
|
|
f' * \\brief entrypoint function for TVM module "{module_name}"\n'
|
|
" * \\param inputs Input tensors for the module \n"
|
|
" * \\param outputs Output tensors for the module \n"
|
|
" */\n"
|
|
f"int32_t {mangled_name}_run(\n"
|
|
f" struct {mangled_name}_inputs* inputs,\n"
|
|
f" struct {mangled_name}_outputs* outputs\n"
|
|
");\n"
|
|
)
|
|
|
|
header_file.write(f"#endif // {mangled_name.upper()}_H_\n")
|
|
|
|
return metadata_header
|