Skip to content

Conversation

@grant-arm
Copy link
Contributor

@grant-arm grant-arm commented Apr 11, 2022

Currently there is no way to pass an output module name to tvmc on the command line when compiling a model.
This means that (for the use cases we are interested in) generated C code is always placed in files named default_lib*.c and that functions are named tvmgen_default*().
If we want to compile multiple models for use with a single application, the C source file names and function names are not unique, resulting in failure when building the generated C code.

This PR allows module-name to be passed to tvmc on the command line, for example:

tvmc compile --target=cmsis-nn,c \
    --target-cmsis-nn-mcpu=cortex-m55 \
    --runtime=crt \
    --executor=aot \
    --executor-aot-interface-api=c \
    --executor-aot-unpacked-api=1 \
    --pass-config tir.usmp.enable=1 \
    --pass-config tir.usmp.algorithm=hill_climb \
    --pass-config tir.disable_storage_rewrite=1 \
    --pass-config tir.disable_vectorize=1 ./mobilenet_v2_1.0_224_INT8.tflite \
    --output-format=mlf \
    --module-name=classify

In this case, the generated C code is placed in files named classify_lib*.c and functions are named tvmgen_classify*().

Additionally, this PR updates the microNPU and CMSIS-NN graph partitioners to pass the module name to PartitionGraph().
This is necessary to ensure that the C code function names generated for microNPU and CMSIS-NN include the module name and not default.

@leandron @Mousius @manupa-arm @areusch

cc @gromero

Copy link
Contributor

@areusch areusch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grant-arm thanks for this PR, looks great! a few minor comments, could be swayed either way on them (don't take my review as blocking)

pass_context_configs: Optional[List[str]] = None,
additional_target_options: Optional[Dict[str, Dict[str, Any]]] = None,
use_vm: bool = False,
mod_name: Optional[str] = "default",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps "default" should be a constant somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @areusch , I agree it would be good to have "default" as a constant.
It feels like this should be a separate PR though.

Copy link
Contributor

@gromero gromero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grant-arm LGTM! Thanks for cc:ing me, I just learned about the different ACCEL_TYPES :)

Copy link
Contributor

@NicolaLancellotti NicolaLancellotti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@grant-arm grant-arm force-pushed the tvmc_module_name_arg branch from 681770c to b6435f1 Compare April 12, 2022 13:47
Copy link
Contributor

@ekalda ekalda left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! :) Got a question about a test...

 * Allows module-name as a command line argument to tvmc
 * Updates microNPU graph partitioner to pass module name to PartitionGraph()
 * Updates CMSIS-NN graph partitioner to pass module name to PartitionGraph()

Change-Id: I12a4a2eef2ddc7e3c4a6c0dd8fdcab009c975bac
@grant-arm grant-arm force-pushed the tvmc_module_name_arg branch from b6435f1 to 061f1ea Compare April 12, 2022 15:53
@masahi masahi merged commit 5cfb4bc into apache:main Apr 13, 2022
AndrewZhaoLuo added a commit to AndrewZhaoLuo/tvm that referenced this pull request Apr 15, 2022
* main: (527 commits)
  [hexagon] 'add_hvx' test to explore HVX usage. (apache#10604)
  [COMMUNITY] @yzh119 -> Reviewer (apache#10993)
  [Metaschedule] Make custom schedule_rule registration optional (apache#10975)
  [ONNX] Add imports for BERT contrib operators (apache#10949)
  sort axes (apache#10985)
  [Hexagon] Remove HexagonBuffer external constructor and support (apache#10978)
  [CI] Update GPU image (apache#10992)
  [Runtime][Vulkan] Add RGP support to TVM for vulkan device (apache#10953)
  [FIX] resolve int64/32 for AttrStmtNode (apache#10983)
  [TVMC] Allow output module name to be passed as a command line argument (apache#10962)
  [ONNX] Add MatMulInteger importer (apache#10450)
  [COMMUNITY] @guberti -> Reviewer (apache#10976)
  Support `qnn.conv2d` in FoldExplicitPading (apache#10982)
  change Hexagon docker version (apache#10981)
  remove exception handling of autotvm xgboost extract functions (apache#10948)
  [CUDNN] Add partitioning support for conv2d and log_softmax (apache#10961)
  [Hexagon][LLVM] Enable/test tensorized Hexagon DMA on 2d transformed layout (apache#10905)
  [Hexagon] Move aot/graph_executor interactions into launcher (apache#10907)
  [HEXAGON] Split huge 1D DMA Transfers into smaller transfers with legal sizes. (apache#10971)
  [CI][DOCKER] Add pytest-lazy-fixture to images (apache#10970)
  ...
Lucien0 pushed a commit to Lucien0/tvm that referenced this pull request Apr 19, 2022
…nt (apache#10962)

* Allows module-name as a command line argument to tvmc
 * Updates microNPU graph partitioner to pass module name to PartitionGraph()
 * Updates CMSIS-NN graph partitioner to pass module name to PartitionGraph()

Change-Id: I12a4a2eef2ddc7e3c4a6c0dd8fdcab009c975bac
altanh pushed a commit to altanh/tvm that referenced this pull request Apr 28, 2022
…nt (apache#10962)

* Allows module-name as a command line argument to tvmc
 * Updates microNPU graph partitioner to pass module name to PartitionGraph()
 * Updates CMSIS-NN graph partitioner to pass module name to PartitionGraph()

Change-Id: I12a4a2eef2ddc7e3c4a6c0dd8fdcab009c975bac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants