-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Introduce --interface-api={c,packed} parameter #8280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7348419
a019367
babb2e2
f8e6e43
c699703
4f5fa2a
1481471
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ | |
|
|
||
| #include "input_data.h" | ||
| #include "output_data.h" | ||
| #include "tvmgen_default.h" | ||
| #include "zephyr_uart.h" | ||
|
|
||
| #ifdef CONFIG_ARCH_POSIX | ||
|
|
@@ -194,18 +195,18 @@ void main(void) { | |
| } | ||
| TVMLogf("Zephyr AOT Runtime\n"); | ||
|
|
||
| void* inputs[1] = { | ||
| input_data, | ||
| struct tvmgen_default_inputs inputs = { | ||
| .input_1 = input_data, | ||
| }; | ||
| void* outputs[1] = { | ||
| output_data, | ||
| struct tvmgen_default_outputs outputs = { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TvmGenDefaultOutputs |
||
| .output = output_data, | ||
| }; | ||
|
|
||
| StackMemoryManager_Init(&app_workspace, g_aot_memory, WORKSPACE_SIZE); | ||
|
|
||
| double elapsed_time = 0; | ||
| TVMPlatformTimerStart(); | ||
| int ret_val = tvm_runtime_run(&tvmgen_default_network, inputs, outputs); | ||
| int ret_val = tvmgen_default_run(&inputs, &outputs); | ||
| TVMPlatformTimerStop(&elapsed_time); | ||
|
|
||
| if (ret_val != 0) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # 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 | ||
| """ | ||
|
|
||
| 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") | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you add struct-level \brief documentation here?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've added an example of the emitted header to the PR, the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since memory and devices was removed, i think what you have is fine now. it's pretty hard to confuse "inputs" and "outputs," since they are core concepts of the model (perhaps parameters may be confusing--are they inputs?). when we add "memory" and "devices," i'd like us to be explicit about which memory is intended to be there, where the user might expect to configure this in TVM, and which memory is not going to be there. likewise with devices--what should be expected, where should it get configured, and what should a user fill in here? but ok to merge now. |
||
| 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") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TvmGenDefaultInputs