Commit Graph

97 Commits

Author SHA1 Message Date
Mark Shields d1467777c6 Finish support for list-of-targets (#11382)
* Finish support for list-of-targets

This finishes the work started in https://github.com/apache/tvm/pull/11173 to support
'external codegen' targets in the N build-like API surfaces.

 - It turns out it's ok if a build is given only a single 'external codegen' target, so remove that check
   in CompilationConfig::Init. When Collage builds a 'candidate partition' it does so for a single target.
   As far as Collage is concerned it does not care whether the target is regular (eg Target("cuda")), or
   for a specific external codegen (eg Target("cutlass")), it just passes the target into the build.

 - Add CompilationConfig::FindPrimitiveTargetForKind which I'll later need to retrieve
   the external codegen Target instance corresponding to a "Compiler" attribute value.

 - Target.update_target_host_consist was supporting three API styles:
    - single target
    - map from device type to target
    - map from target to IRModule (for the ir_to_runtime API)
   I replaced all those calls with a more specialized 'canonicalize' call:
    - Target.canonicalize_target_and_host
    - Target.canonicalize_multi_targets_and_host
    - Target.canonicalize_target_map_and_host
   In particular, all the tuning interfaces (task extraction, tuning, tuning records) all explicitly
   *do not* support multiple targets since the underlying code just doesn't support that.

* - Lints
- Revert unintended changes

* - more lints

* - Fix model_library_format handling of target.
- Improve comments in compilation_config.h

* - Lints
- Update target/target_host params documentation

* - Fix micro library format tests
- Rev micro library format from 5 to 6
- Use Target.current() in a few places

* - eta contract comprehension

* - Woops, one more device: target map left
- Handle host already being in Target

* - lint

* - lint

* - Bug with append
- Take device type from target

* - Fix hexagon
2022-05-23 09:14:28 -07:00
Andrew Reusch 07d91fa041 Fix function number datatype from char to uint16_t (#11365)
* Fix function number datatype from char to uint16_t

rewrite the modified part to pass lint check

Use 2 bytes for func num in fun_registry

Fix errors in linter

Add the declaration of the helper functions

set 2 bytes for func num in func_registry test units

pass num_func by value

This commit change the datatype of the number of the function from 1 Byte to 2 Bytes.
Besides, I use some helper functions to access the number of function and the first function name.

* Fix aot_executor_module to unbreak CI.

* Fix GraphExecutorModule.

* Remove graph_json_to_c_func_registry.

 * No longer needed and not called anywhere.
 * Superseded by emitting the FuncRegistry directly in codegen.

Co-authored-by: 嚴中璟 <a1245967@gmail.com>
2022-05-20 18:12:55 +09:00
Mehrdad Hessar 5e29dddd02 [microTVM][ARM] Add Relay tests for conv2d registered schedules (#11250)
* Added conv2d relay test for each schedule
* Enable relay tests in qemu
* split aot test utils
2022-05-19 16:09:51 -07:00
Mohamad Katanbaf 53fe596682 [rpc] Implemented rpc logging (#11232)
* Implemented rpc logging

* fixing windows build issue

* trigger

Co-authored-by: Mohamad <mkatanbaf@users.noreply.github.com>
2022-05-12 11:48:30 -07:00
Leandro Nunes ff7efe767a Revert "Implemented rpc logging (#10967)" (#11227)
This reverts commit aa3bcd9d33, because it
fails on Windows CI as reported in issue #11220. PR #11223 tries to address
it but is is failing in the regular CI with testing issue on Hexagon.
2022-05-06 12:14:20 +01:00
Mohamad Katanbaf aa3bcd9d33 Implemented rpc logging (#10967)
Co-authored-by: Mohamad <mkatanbaf@users.noreply.github.com>
2022-05-04 17:10:18 -07:00
Manupa Karunaratne ce29f02f4c [USMP] Adding support for U4 usecase (#10785)
* [USMP] Adding support for U4 usecase

This commit adds support for placing I/O
tensors within the workspace buffer.

This is enabled using PassConfig option
tir.usmp.use_workspace_io. Once it is enabled,
it will remove the I/O tensors from the TIR
main PrimFunc and replace them with Allocate
nodes that is annotated to contain Input and
Output tensors.

The USMP will plan memory for them accordingly.
(i.e. it will re-use space used by them for
intermediaries depending on the liveness).

This will only be supported with C Interface API.
Thus, this commit produces two functions to the
metadata sources to obtain input and output structs
that points to location inside the workspace struct.

Change-Id: I4c7e750ead9a880ba900602c17f53a125f97dbf9

* fixup! [USMP] Adding support for U4 usecase

Change-Id: I78f03d36b12b4a5e8eae8d11701f51019489defc

* fixup! [USMP] Adding support for U4 usecase

Change-Id: I857f3d0ba7bc192d56d750c44b232998b2876e7a
2022-04-25 17:37:59 -07:00
driazati 96f701fd66 [ci] Don't diff Python files when checking formatting (#10895) 2022-04-06 09:25:22 +01:00
Andrew Reusch d721d320bd [runtime] AOTExecutor implementation and c target code-generator (#10283)
* Add memory pools to Metadata classes.

* Move ShapeToJSON to utils.

* Track returned TensorType from AOTExecutorCodegen.

* Support calling Relay functions with Tuple.

* Expand supported TIR calling conventions to work with C++ runtime.

* Rename MetadataModule to ConstLoaderModule.

* Add runtime AOT executor module.

* Add AOT code-generation.

* Add a runtime Module to mux between .text Metadata and live Metadata.

* Move launch_param to namespace

* Add test of c++ AOT.

* Fix incongruity between kTvmRuntimeCrt constant

* Expand ExecutorCodegenMetadata to include AOT runtime metadata.

* commit cpp test

* Make Metadata compile under C.

* Ignore ephemeral metadata_module export_model_library_format.

 * This module does not need to be exported, since it is merely a C++
   wrapper around get_c_metadata, and get_metadata is not used in C.

* address manupa, kparszsyc, masahi comments.

* further address comments

* clang and python format

* Fix broken test

* Address lingering comments from masahi, kparszyzc
2022-03-03 09:50:55 -08:00
Manupa Karunaratne 2f937801de [microNPU] enable USMP (#10022)
This commit enables USMP in the microNPU codegen
and tests. The microNPU codegen is modified to
support Let nodes that are produced as from USMP.
2022-02-21 11:02:12 +00:00
Grant Watson 81df151935 Generate correct output tensor names in C Interface API (#10191) 2022-02-21 10:25:55 +00:00
Manupa Karunaratne 55849e651e [USMP] adding support for U2 and U3 usecases (#10193)
This commit adds a MemoryPools argument for
the compilation flow according to RFC0029.

Moreover, it is used to provide support for
external pools from the application layer
that could be pinned for different memories
and/or be reused between multiple inferences
of a model.
2022-02-14 09:54:06 +00:00
Grant Watson 3b20c21f9e [microTVM] Include standalone_crt dependencies in MLF (#10095)
* Adds runtime to AOTExecutorFactoryModule
 * Standalone CRT files are added to MLF tarball if runtime is crt
 * external_dependencies info added to metadata.json for crt runtime
 * microNPU demo Makefile references standalone crt files from MLF tarball
2022-01-31 10:50:29 +00:00
Philipp van Kempen cc5382ed41 Add runtime.ModuleGetFormat method enabling export of BYOC generated sources which require a .cpp/.cc file extension (#9243)
* Allow export of C++ kernels using correct file extension

* [WIP] Set module_key=c for CSourceCrtMetadataModuleNode to temporarily fix failing tests

I realized that the module format `cc` is currently already used by the `CSourceCrtMetadataModuleNode` declared in `src/target/source/source_module.cc`.
This needs to be discussed first to decide if either the module_key should be changed or the test cases expecting the systemlib kernel (e.g. `default_lib0.c`) to have a `.c` extension.

* Update Makefiles used by tests/python/relay/aot/ to support C++ file extensions

AOT: Add c++ support to aot_test.mk
AOT: Add c++ support to corstone300.mk

* Add missing definition of GetFormat to cmsisnn and ethosn codegens (WIP)

* Resolve PR comments

* lint python/tvm/runtime/module.py

* fix EthosUModuleNode for CI

* Fix: detect empty module.format

* Add error message to assertion

* Lint python/tvm/runtime/module.py
2022-01-20 06:48:07 +09:00
Gustavo Romero a03a85b832 [microTVM] Remove prepare_options() (#9644)
This commit removes prepare_options() helper function because it's now
superfluous since the default values for the project options are now set
correctly at the server side, hence there is no need to force settting
them at the client side.

Also prepare_options() can incorrectly set the default value of Zephyr's
'west_cmd' option when that option is not passed by the user. Hence by
removing that function this issue is resolved too.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
2021-12-06 11:57:24 +00:00
Mehrdad Hessar 32e80128d1 [microTVM][TVMC] Add TVMC test for Arduino and Zephyr (#9584)
* Add TVMC test for Arduino and Zephyr

* Address @gromero comments

* address comments
2021-11-30 18:52:08 -08:00
Grant Watson 8e1425d4d0 Expose workspace size in tvmgen_default.h (#9510)
This PR exposes the workspace size as a macro 
TVMGEN_DEFAULT_WORKSPACE_SIZE in tvmgen_default.h 
(or TVMGEN_<MODEL_NAME>_WORKSPACE_SIZE in 
tvmgen_<model_name>.h in the case that the model name is not default).

This functionality is useful for microTVM/AOT use cases 
where it's useful to know the workspace size at compile time.
2021-11-22 14:35:18 +00:00
Christopher Sidebottom 0cb633777a [TVMC][Relay] Introduce executor and runtime parameters (#9352)
* [TVMC][Relay] Introduce executor and runtime parameters

This introduces `executor` and `runtime` into the various entrypoints but also into `tvmc` as `--executor` and `--runtime`. This touchs a lot of files and I've tried to update anywhere as necessary.

Notable, executor code generators now accept the initial `IRModule` rather than creating
it themselves so it can be annotated once.

Validated the demo application continues to classify the tabby cat with
new CLI options.

* Correct Graph Executor Python API
2021-11-19 17:11:40 -08:00
Gustavo Romero 53cb5eadfb [TVMC][microTVM] Add new micro context (#9229)
* [microTVM] zephyr: Make platform options comply with RFC-0020

Make Zephyr platform options comply with RFC-0020 specification.

Project options now need to specify the required metadata for every
option, i.e. 'required', 'optional', and 'type'.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* [microTVM] arduino: Make platform options comply with RFC-0020

Make Arduino platform options comply with RFC-0020 specification.

Project options now need to specify the required metadata for every
option, i.e. 'required', 'optional', and 'type'.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* [microTVM] crt: Make crt options comply with RFC-0020

Make crt project options comply with RFC-0020 specification.

Project options now need to specify the required metadata for every
option, i.e. 'required', 'optional', and 'type'.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* [microTVM][Unittest] Adapt test to RFC-0020

Adapt test to new metadata fields accordingly to RFC-0020 specification.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* [microTVM] Add info() method to GeneratedProject class

Add info() method to GeneratedProject class so one can use the Project
API to query options for project dirs instead of only for template
projects.

This commit also adds for the sake of convenience a setter and a getter
for 'options' in case it's necessary to set or get 'options' after a
GeneratedProject class is instantiated without initializing 'options'.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* [microTVM] Fix typo in python/tvm/micro/session.py

Fix typo in comment.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* Allow multiple runs on micro targets

Currently there is a limitation on microTVM / TVM which doesn't allow
running a model multiple times in sequence without previously flashing
the model to the device.

Root cause is that RPCModuleNode class destructor is called once a run
finishes. The destructor sends a RPCCode::kFreeHandle packet with
type_code = kTVMModuleHandle to the device which wipes entries in
crt/src/runtime/crt/common/crt_runtime_api.c:147:static const TVMModule*
registered_modules[TVM_CRT_MAX_REGISTERED_MODULES] when TVMFreeMod() is
called when the target receives a kFreeHandle packet.

Hence when one tries to re-run a model registered_modules[0] == NULL
causes a backtrace on the host side. Probably never before a model on
microTVM was run without being flashed just before the run, so tvmc run
implementation for micro targets exposed the issue.

This commit fixes it by not calling TVMFreeMod() for system_lib_handle
on the target side when a session terminates so the pointer to the
system_lib_handle is not flushed from 'registered_modules', allowing
multiple runs on micro targets.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* [TVMC] Pass main parser when calling add_*_parser functions

Currently when a add_*_parser functions are called in main.py to build
and add the various subparsers to the main parser only a subparser is
passed to the functions. However if one of these functions need to build
a dynamic parser it needs also to call the main parser at least once to
parse once the command line and get the arguments necessary to finally
build the complete parser.

This commit fixes that limitation by passing also the main parser when
calling the subparser builders so it can be used to build the dynamic
subparses.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* [TVMC] micro: Add new micro context

This commit introduces support for micro targets (targets supported by
microTVM). It creates a new micro context under the new TVMC command
'tvmc micro'. Moreover, three new subcommands are made available in the
new context under 'tvmc micro': 'create-project', 'build', and 'flash'.

The new support relies on the Project API to query all the options
available for a selected platform (like Zephyr and Arduino) and also
from any adhoc platform template directory which provides a custom
Project API server.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* [TVMC] run: Add support for micro devices

Add support for micro devices using the Project API to query all options
available for a given platform and open a session with an specified
micro device. Use of 'tvmc run' with micro device is enabled via the
'--device micro' option in addition to the project directory.

Once the project directory is specified 'tvmc run' will make all options
specific to the platform found in the project dir available as options
in 'tvmc run'. They can be listed by '--list-options' and passed via
'--options'.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
2021-11-19 10:14:04 -08:00
Ashutosh Parkhi ee230138cb [4/10] Code generation for Conv2D via CMSIS-NN (#9331)
This PR is for support of Conv2D via CMSIS-NN.
2021-11-17 09:51:24 +00:00
Christopher Sidebottom 67714c64f2 [1/3][AOT][DeviceAPI] Connecting devices structure to relevant operators (#9395)
* [AOT][DeviceAPI] Connecting devices structure to relevant operators

This patch adds support for passing the device context via the unpacked API in AOT, generating an additional struct if necessary:

```c
/*!
 * \brief Device context pointers for TVM module "default"
 */
struct tvmgen_default_devices {
  void* npu;
};
```

Which is then added as an argument to the entry function:
```c
/*!
 * \brief entrypoint function for TVM module "default"
 * \param inputs Input tensors for the module
 * \param outputs Output tensors for the module
 * \param devices Device context pointers for the module
 */
int32_t tvmgen_default_run(
  struct tvmgen_default_inputs* inputs,
  struct tvmgen_default_outputs* outputs,
  struct tvmgen_default_devices* devices
);
```

I've temporarily added the collection of external code generators to the TE compiler pending proper annotation of the eventual functions.

Co-authored-by: Grant Watson <grant.watson@arm.com>

* Correct "use_device_api" attribute name on Target

Co-authored-by: Grant Watson <grant.watson@arm.com>
2021-11-12 12:16:11 -08:00
Matthew Brookhart dc56eea906 [Support] Add libinfo into the runtime build (#9310)
* Move libinfo into the runtime build

* put libinfo back into libtvm

* limit microtvm imports when we only have the runtime lib

* fix lint

* try conditional for micro import
2021-11-10 16:46:42 -07:00
Mehrdad Hessar 54019b9436 [microTVM] Add microTVM Template Projects to tlcpack pip Package (#9309)
* zephyr lib fixed

* restructure

* readme

* add arduino

* add project template to setup.py

* fix lint

* fix tutorial

* address comments from PR9274
2021-11-01 17:16:23 +00:00
Mehrdad Hessar dae71db771 [microTVM] Fix AOT/ARMv7m tests on physical devices. (#9364)
* init

* test on hardware

* moved to testing.py

* add option to set workspace size

* changed model

* fix memory issue

* fix tests

* conv2d test

* fix simd test

* format

* fix exception

* refactor workspace helper function

* address comments

* revert to fix the bug

* address comment
2021-10-28 17:02:21 -07:00
Christopher Sidebottom b53472c7b6 Migrate C Interface API Generation to C++ (#9106)
Using the new name transformations added in #9088, the C interface API is now generated in C++ rather than in Python. This is intended to be a no-op for the actual users of this change and thus I've undone some of my overzealous sanitizing to match that expectation.

Follow up PRs will clean up any remaining name transformation inconsistencies.

Fixes #8792
2021-10-08 07:40:07 +01:00
stoa b48c9efc32 Contributing the STM32 port (#7742)
* Contribute apps/stm32 application.

* Removed a useless file.

* STM32: Use Model Library Format in demo. Added test.

* STM32: Added quantized mnist test.

* STM32: Fixed apps/stm32/Makefile.

* STM32: Added quantized models test.

* STM32: Added tests to tests/scripts/task_python_microtvm.sh

* STM32: Listed specific files with lint.

* STM32: removed external copyright notices.

* STM32: Added missing ASF copyright notice.

* STM32: style fixes.

* STM32: more style fixes.

* STM32: fixed liny for C files.

* STM32: Does extern C help with cpplint.

* STM32: Fixed wrong LINT_C_FILE spelling.

* STM32: Still some lint fixes.

* STM32: more style.

* STM32: More fixes lint+formatting.

* STM32: cleanup.

* STM32: style cleanup.

* STM32: Moved ai_runner to the apps/stm32.

* Alignment with PR 7742

* lint cleanup.

* STM32: Use crt_backend_api.c with standalone build.

* STM32: Fixed the CI test.

* STM32: style fixes.

* STM32: Removed unused files.

* STM32: Moved to crt_backend_api

* STM32: style fix.

* STM32: style fix.

* Revert "STM32: Removed unused files."

This reverts commit d72f8e5be3bae3c36da1758b6e61cd39ef7036c7.

Undo changes to c_backend_api/c_runtime_api.

* Revert "STM32: Moved to crt_backend_api"

This reverts commit 6c0e66672cb636d47244e99e8efd893004acc382.

Undo changes to the c_backend-api/c_runtime_api.

* stm32: aligned to micro TVM structure.

* stm32: improved the python style.

* stm32: cpplint fixes.

* stm32: Fixed the test

* stm32: style fixes.

* stm32: style fixes.

* stm32: style fixes.

* stm32: style fixes.
2021-10-06 10:50:37 -07:00
Gustavo Romero 3d647837dc [microTVM] Add wrapper for creating project using a MLF (#9090)
Currently there is already a wrapper function for creating a new project
directory based on an ExportableModule, but there isn't one for creating
a new project directory based on an existing MLF archive, which is also
handy. Hence that commit adds a new wrapper for creating a project using
an existing model compiled and kept in a MLF archive.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
Reviewed-by: Christopher Sidebottom <chris.sidebottom@arm.com>
Reviewed-by: Andrew Reusch <areusch@octoml.ai>
2021-09-30 13:03:21 +01:00
Christopher Sidebottom 83ba991286 Add extern "C" to C Interface API header (#9094)
This is to provide the hint to C++ compilers that these functions are C linkage.

New header looks similar to:

```c++

extern "C" {

/*!
 * \brief Input tensor pointers for TVM module "default"
 */
struct tvmgen_default_inputs {
  void* y;
};

/*!
 * \brief Output tensor pointers for TVM module "default"
 */
struct tvmgen_default_outputs {
  void* output;
};

/*!
 * \brief entrypoint function for TVM module "default"
 * \param inputs Input tensors for the module
 * \param outputs Output tensors for the module
 */
int32_t tvmgen_default_run(
  struct tvmgen_default_inputs* inputs,
  struct tvmgen_default_outputs* outputs
);

}

```
2021-09-24 09:52:15 +01:00
Mehrdad Hessar 73c28455d3 [microTVM][Zephyr] Add 'config_main_stack_size' option to API server (#9026) 2021-09-23 08:54:38 -07:00
Mehrdad Hessar 9100a3c975 [microTVM][autoTVM] Follow up fixes to #9003 (#9018)
* fix test and cleanup

* fix tutorial doc

* fix verbose for tutorial

* fix tune check

* address comments

* address comments
2021-09-17 08:57:17 -07:00
Mehrdad Hessar dc2f70e3c8 [microTVM][AutoTVM] Fix autotvm bug and tests (#9003)
* debuggging

* cleanup and fix tutorial, zephyr and crt test

* fix crt test

* address comments
2021-09-14 15:41:01 -07:00
Mehrdad Hessar aa2b37d35b [microTVM] Add support for AutoTVM (#8715)
* 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

* Add session_constructor_args to tracker request() function.

 * Allows tracker clients to open non-traditional RPC sessions

* Generate entry_func symbol in C host codegen.

 * Needed for AutoTVM.

* print MeasureErrorNo enum value in MeasureResult repr

* Add microTVM session constructor.

 * This constructor is to be called from the RPC driver to flash and
   connect to the RPC server on the microcontroller.

* add build_kwargs as a Builder constructor arg.

 * build_kwargs is derived from pre-configured args, the runner, and
   now from the script.
 * user-supplied build kwargs override the other two, and a warning is
   printed if any key is overridden.

* Add do_fork option to Builder, to support stateful builders

 * When AutoTVM builder forks, any global state modified by the
   build_func is lost between builds

* Checkin module_loader used to build and flash microTVM for autotuning.

* Import micro into top-level when enabled.

 * AutoTVM RPC server needs to load the micro session constructor.

* Add tvm.contrib.random.random_fill to microTVM.

 * Allows autotuning with random data.

* Move compilation to runner :O

* Add a tutorial for AutoTVM with microcontrollers.

* Fix si_prefix in autotuner callback

* black format and git-clang-format

* Switch tutorial back to qemu version

* improve error reporting so CI will show test error

* black format

* autotvm is working

* fix tutorial

* fix dependencies

* fix auto tune issue

* lint

* address comments

* fix lint

* test crt and zephyr added

* fix func registery size

* moved autotune test and fixed

* fix crt test

* address comments

* change relay text

* change relay in text_zephyr

* class added

* changed relay module in tutorial and cleanup

* address comments

* address TK comments

* change fork

* final comments

* retrigger due to flahy test

* fix tutorial

* retrigger

* fix changes due to merge

Co-authored-by: Andrew Reusch <areusch@octoml.ai>
2021-09-09 18:51:44 +09:00
Leandro Nunes 2e0a71184a Set tvm.micro.project_api as a Python Module (#8963)
* Add missing tvm.micro.project_api module file. The missing
  __init__.py makes it impossible to import this module with
  `import tvm.micro.project_api`.

* This uncover 30-ish linting errors, which are also fixed here.
2021-09-09 06:32:26 +01:00
Gustavo Romero af9d100361 [microTVM] Add method to query template info without creating a project (#8950)
Add info() method to TemplateProject class so it's possible to query all
available options for a given template project without creating a new
one. This is necessary because TVMC will query the available options for
a given template project to show them to the user so the user can use
them to finally create a new project dir.

That is also useful in general to query the available options for any
project type. For example, one can query all boards available on the
Zephyr platform with:

import tvm.micro.project as project_api

template = project_api.TemplateProject.from_directory(ZEPHYR_TEMPLATE_DIR)
boards = template.info()["project_options"][8]["choices"]

where 8 element refers to the "zephyr_board" option.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
2021-09-08 09:50:32 +09:00
Grant Watson 06a0d63c43 Sanitize names of input tensors in interface header (#8720)
* Sanitize names of input tensors in interface header

Change-Id: I7f02a993887bf84316262cd2586a734a9079c338

* Update tensor name sanitizer tests to parameterize them.

Change-Id: I157d8d8d607de2904285e403893f146e97b510d5

* Only test unpacked, C interface API, AOT case

Change-Id: I9082ae32079a1a3924c06c7f26c757aafa46dec2
2021-09-03 17:18:10 +01:00
Andrew Reusch a7297870c0 [microTVM] Project API infrastructure (#8380)
* 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
2021-08-07 11:51:32 -07:00
Christopher Sidebottom 49d5879e1b Introduce --interface-api={c,packed} parameter (#8280)
* Introduce --interface-api={c,packed} parameter

This introduces structures generated to provide a documented and stable user
friendly interface to a TVM generated model, as can be seen in the AOT
demo application:
```
struct tvmgen_default_inputs inputs = {
  .input_1 = input_data,
};
struct tvmgen_default_outputs outputs = {
  .output = output_data,
};
int ret_val = tvmgen_default_run(&inputs, &outputs, NULL, NULL);
```

To facilitate this, some other changes are included:
* Removed dependency on `aot_executor.{c,h}` in tests, pending the
discussion in the interface RFC as to whether we keep them.
* Moved creation of test DLTensor's into the AOT test utils, in future this
can be replaced by loading via the Python API or otherwise
* Introduce `parametrize_aot_options` which can be used to test
permutations of AOT which work together - for now this filters C
interface and packed operators
* Updated demo application to generate the header for demonstration
purposes, we should consider porting the demo application to Model
Library Format and using the toolchain in the Zephyr App via CMake
instead?

This patch builds upon the improvements @giuseros made to AOT testing
and name mangling from #8014

* Tweak metadata variable description and MLF target loop

* Remove direct usage of `relay::Var` in meta_data.h

This looks like the only place that could be causing the Windows CI failures, so trying removing the additional header in meta_data.h

* Linting fix

* Post-rebase files fixing

These tests were somehow transmuted in transit, I've updated them to the
most recent variant of the test helpers.

* Strip back interface API to just inputs and outputs

This removes any speculative structures from the generated code and cleans up some of the documentation.

* Add header guards and tweak documentation
2021-08-02 16:04:55 -07:00
Andrew Reusch ca28dfff35 Rename runtime-config to executor-config and add documentation for Model Library Format (#8270)
* Rename runtime-config to executor-config.

* Add documentation.

* address comments, make tests pass

* fix unit test

* fix sphinx doc errors

* address manupa comments
2021-07-20 20:14:09 +01:00
Mehrdad Hessar 7e3f068373 [microTVM] Add Nucleo stm32l4r5zi board to zephyr (#8386)
* add stm32l4r5zi_nucleo

* add parameter for test qemu

* file type check

* fix test

* change order

* revert
2021-07-03 11:48:06 +01:00
Andrew Reusch 970aefffe9 Add "operator" style to Model Library Format (#8072)
* rename _update_target and document its function

* make tvm.build return OperatorModule to return multiple outputs

* allow retrieving the var names used in TIR repr

* add Operator Model Library Format and test

* Add pathlib convenience functions to utils.TempDirectory.

* fix tests

* black format

* git-clang-format

* pylint fixes

* add asf header

* change memory map to make more sense, fix tests

* address giuseros comments

* align GetVarName with future TypedPackedFunc

* fix test

* clang-format

* rev model library format to v4 (bad merge)
2021-07-02 23:10:55 +01:00
Giuseppe Rossini 36fc525620 [AOT] Name mangling in AOT (#8014)
* [AOT] Name mangling in AOT

Mini-RFC is here: https://discuss.tvm.apache.org/t/mini-rfc-name-mangling-in-aot

With this change we'll mangle the name of global symbols so that we can bundle
together multiple models in the same application.

The relay.build interface has been left unchanged, which means I am
resuing mod_name as a prefix for all functions. If mod_name is None then
a "_tvm" prefix is used.

I had to add two different compilation functions:
- _CompileEngineLowerWithModuleName to mangle all the operators with the mod_name
- PartitionGraphWithModName to mangle all the operators produced by BYOC

I could have changed signature of both, but that would have meant a very
invasive refactoring.

I refactored the aot test utils and added some tests for multiple
models.

Change-Id: I30e93fa075f660054577ea36cf9268ec0c6eebcb

* retrigger CI

Change-Id: I4f11da7fce1327ad89bb25f25209b57077b2c6a3
2021-06-28 08:34:49 -07:00
Lunderberg d9fe67259e [Docs] Prevented docs/1 file from being generated. (#8029)
* [Docs] Prevented docs/1 file from being generated.

Typo in tests/scripts/task_sphinx_precheck.sh caused $TVM_HOME/docs/1
file to be created with stderr output, rather than merged stderr and
stdout.

* [Docs] Corrected sphinx build warnings

- Previously, several warnings were generated by sphinx, but were
  unintentionally suppressed.  This PR resolves the sphinx warnings.

* [Docs] Corrected additional sphinx build warnings.

- Rebased on main and corrected warnings, now up to date as of commit
  53e4c603.

* [Docs] Corrected additional sphinx build warnings

- Rebased on main and corrected warnings, now up to date as of commit
  1f2ca068c.

* [Docs] Corrected additional sphinx build warnings

- Rebased on main and corrected warnings, now up to date as of commit
  d0791d3db.

* [Docs] Ignore sphinx warnings from missing "git describe" and sckit-learn versions.

Co-authored-by: Eric Lunderberg <elunderberg@octoml.ai>
2021-06-24 10:27:29 -04:00
Mehrdad Hessar 3cb838de43 [microTVM] Refactor uTVM to microTVM (#8283)
* refactor

* rename utvm_rpc_server.h

* rename file

* rename

* rename file

* rename

* variables

* directories

* format

* trigger

* more refactor

* one more

* format
2021-06-21 17:09:00 -07:00
Mehrdad Hessar 5df25cf8db [microTVM] Add wait to QEMU Setup (#8236)
* add wait

* address comments

* address comments

* test added

* add suggestions

* fadd message assert for test
2021-06-15 08:46:56 -07:00
Gustavo Romero c29301ea65 [µTVM] Zephyr: Fix missing board-specific config file in build dir (#8230)
Currently board-specific config files (boards/*.conf) are not
copied from Zephyr project dir to the destination build dir, so
as a consequence the per board configs are not used when building
the runtime libraries, like libcommon. Hence, for instance, it's
currently not possible to set CONFIG_FPU per board since it only
takes effect when it's set in the generic 'prj.con' config file.

This commit fixes it by copying to the build dir (to each lib
dir) the proper .conf for the selected target board. For example,
if target 'qemu_x86' is selected 'qemu_x86.conf' is copied to
the boards/ dir inside the lib dirs, so Zephyr build system can
find it and combine it with configs found in the generic 'prj.conf'.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>
2021-06-11 15:06:47 +09:00
Mehrdad Hessar dad59be176 [microTVM] AOT Demo (#8075)
* initial

* remove compare

* temp fix

* debugging

* hack

* hack for testing

* both test pass

* cleanup

* fix tests and tutorials

* restructure

* cleanup

* cleanup

* fix check files

* fixed for physical devices

* address comments

* reduce nrf stack size

* update sample url

* format
2021-05-28 10:13:17 -07:00
Gustavo Romero 7da97b9c91 [TVMC] Add support for the MLF to 'compile' command (#8086)
* [TVMC] Add support for the MLF to 'compile' command

Add support for the Model Library Format (MLF) to 'tvmc' so users can
output compilation artifacts to a MLF archive passing the new flag
'--output-format mlf'. For instance:

$ python3 -m tvm.driver.tvmc compile ./sine_model.tflite --target="c" --output sine.tar --output-format mlf

will generate a sine.tar archive that is serialized accordingly to the
MLF.

Since the MLF is currently meant to be used only on micro targets, an
error is generated if one tries to run a MLF outside a micro context.

The micro context does not exist yet but will be later introduced as
part of the [RFC] "TVMC: Add support for µTVM".

That commit also adds 3 pytest tests to test tvmc + MLF.

Finally, it also fixes some missing periods in the 'compile' command
help sections and renames export_format to output_format so there is
no confusion with flag '--dump-code', which contains "formats to export"
in its help section.

Signed-off-by: Gustavo Romero <gustavo.romero@linaro.org>

* Fix missing importorskip in the import_package test

Fix missing importorskip() in the import_package test allowing the
test in question to be skipped when 'tflite' is not installed in the
test environment, otherwise the test will fail with:

[...]
>       archive_path = exported_tvmc_package.package_path
E       AttributeError: 'str' object has no attribute 'package_path'
2021-05-25 14:13:38 +01:00
Manupa Karunaratne c0690496af Improved MLF to contain workspace info (#7938)
* Improved MLF to contain workspace info

Added functionality to calculate workspace, io and constant
memory required by each primfunc and main function. Moreover,
the workspace information required by each primfunc and main
is reported in metadata.json in the Model Library Format(MLF).
- added functionality to record tir and relay primfuncs
- added tests for model_library_format changes

Change-Id: Ib4a8b787345aa35f8a1645e8a648fad84de37bce

* Improved MLF to contain workspace info

* disable AoT for now
* addressing comments

Change-Id: I5f041ec461b02dac6ea9c96ea50eb400d55eef53

* Improved MLF to contain workspace info

* addressed comments
* added aot executor support

Change-Id: I9b54a7939d8ccb3c6ce0454f0fe62866ac66eb5c

* Improved MLF to contain workspace info

* removed redundant utils.py

Change-Id: I256dd88fab31a595bf9509bd1c4ab59b0c145b1e

* Improved MLF to contain workspace info

* removed redundant ffi api

Change-Id: I9ad6795aa839edfdfd05b902d4531fb0a20e894d
2021-05-07 14:54:40 -07:00
Giuseppe Rossini f85cab2052 [AOT] Introducing AOT in TVM (#7785)
* [AOT] Introducing AOT in TVM

This change adds the code generation and minimal runtime API to use the
Ahead Of Time (AOT) compilation flow. The main logic is contained in:

- src/relay/backend/aot_codegen.cc

Which produces a TIR PrimFunc traversing the Relay graph

The runtime interface (authored by @mousius) leaves a gap for future
iterations using platform-specific features from RTOS.

Currently AOT runs successfully on x86 in a host OS, running these
tests on micro is coming soon.

This PR is based on the RFC described here: https://discuss.tvm.apache.org/t/implementing-aot-in-tvm/9206

Co-authored-by: Christopher Sidebottom <Christopher.Sidebottom@arm.com>
Change-Id: I9f731c953231f129e1472298915dddc01788efd7

* Rebasing 2

Change-Id: Ia0a533a49960f1cb4bf3c3833511e539cf7c459f

* Applying comments/refactoring

Change-Id: Iea1832355f8b1d4c921d02c6b4ceec7db3a681c1

* Fixing comments + refactoring - 2

Change-Id: I7200cc17b297e42bf67dcdef6f643e86991ca0a8

* fix linting

Change-Id: Iba6544ac7101595696b352b8702345cf916625f6

* fix linting - 2

Change-Id: I7f80d16005f2c621d37a9aae2cbbd61df0277cbe

* fix linting - 3

Change-Id: I7a1ba40afeea46d5f122563a20cd4b2f08751a1e

* fix tests

Change-Id: I1297ccc54dd6d93647f421e0beb226f410bf73f5

* Addressing comments - 3

Change-Id: Id25d1382c30d6d0a0013b5e8986fb8cd886666dc

* Addressing comments - 4

Change-Id: Ibe29676abe3b75161b5a0903e007118a8318d862

* fix tests - 2

Change-Id: I2117f9d4392bfd87102ecbef0993c8b320f479a0

* fix tests - 3

Change-Id: Ic0373543b0f9a54dbd4dc32d428272f7293200ba

* fix tests - 4

Change-Id: I8a6f229c9a3a9e169779c8d49cbfa3f473348b1f

* Addressing comments - 5

Change-Id: Ib9ccd07c87392034a21b2eb70955d0b091b780f1

* fix tests - 5

Change-Id: I4b13c3b548ced414991e83072e9e6fc99b64f939

* fix tests - 6

Change-Id: Id5af1f778ae25bc60849cc054a605181c1b7a765

* addressing comments - 6

Change-Id: Id94a2bbcaae891f9498d41be538f13a952f55b81

* fix linting - 4

Change-Id: I371a0aa5b81824b5a3a1278fac22ace57832027a

* add missing file

Change-Id: If359bef96dd0773ead4f75f0d9f5234276347e2d

* fix build

Change-Id: I73fc1feb6f7b5d454a528e3289228484dc2b07d5

* addressing comments - 7

Change-Id: I7f908f3908ffc77e408391f62edcc06f2600c6c2

* addressing comments - 8

Change-Id: I90bced4e18259a6d42e6a406d93958e204f3859e

* rebasing

Change-Id: Id28751b069bd046f00faee301b2b446b2ea4fab8

* Addressing comments - 9

Change-Id: I06c9f280de0a9bf0ca5545bbbbfcc70cb66831b3

* fix tests - 7

Change-Id: I739f29779862f05def36e5f3e0722019596d17f8

* Addressing comments - 9

Change-Id: Ie736f40a5225f4e56e79006753d7732127da5408

* Applying comments + fixing tests

Change-Id: I83e16068b93aaccc7a86b79d42f13328bc76b53d

* Applying comments - 10

Change-Id: I443d72f53913849f3c28fd6e416162d1ca99e647

* Addressing comments - 11

Change-Id: I7fefbd0076949b9c38d0abbf2759ebf1502de330

* Addressing comments - 11

Change-Id: Iad028144d7b394b2dd2fce41a35ca689d1680200

* fix tests - 7

Change-Id: I14286e665dcdba1e9bc10bb5a27dd6ced50372b0

* fixing tests -8

Change-Id: I7b4c966da9680870ceda1704c749ee3bdc751926

* fixing tests - 9

Change-Id: Icf62128a604998ed1b7d5af4cbeadf7d39196d0b

Co-authored-by: Christopher Sidebottom <Christopher.Sidebottom@arm.com>
2021-05-05 11:21:22 -07:00
Andrew Reusch 1ebfafd1c5 Fix Zephyr flashing on physical hardware, busted in #7813 (#7853) 2021-04-15 09:58:32 -04:00