Skip to content
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

Fix -mfloat-abi=soft compilation for ARM with OpenCL target #6150

Merged
merged 1 commit into from
Aug 5, 2020

Conversation

trevor-m
Copy link
Contributor

@trevor-m trevor-m commented Jul 27, 2020

Currently, any extra attributes of the llvm target are not being passed through to LLVMModule during ModulePackImportsToLLVM. This will cause compilation to fail with error: /tmp/tmpctakbpk1/devc.o uses VFP register arguments, output does not when the target is opencl and the target_host requires -mfloat-abi=soft. This regression was introduced by #4657.

There are two reasons why:

  1. python/tvm/runtime/module.py uses "_get_target_triple" to get the target triple to use for ModulePackImportsToLLVM. However, the implementation of that function returns tm_->getTargetTriple().str() which will only have the standard <arch><sub>-<vendor>-<sys>-<abi> and is missing any extra flags or attributes such as -mfloat-abi=soft.
  2. Since the module was created by CodegenBlob, it doesn't store anything in the "tvm_target" module metadata and therefore module_->getTargetTriple() is called which again doesn't have the extra flags and attributes: https://github.com/apache/incubator-tvm/blob/master/src/target/llvm/llvm_module.cc#L254

This PR fixes those problems by:

  1. Adding important attributes back into _get_target_triple (only mfloat-abi for now). This part doesn't seem ideal to me. Any thoughts on how to improve? Can we store the user's full target string earlier on?
  2. Saving full target triple string in "tvm_target" module metadata flag during CodeGenBlob so that LLVMModuleNode::Init(std::unique_ptr<llvm::Module> module, std::shared_ptr<llvm::LLVMContext> ctx) can retrieve it: https://github.com/apache/incubator-tvm/blob/master/src/target/llvm/llvm_module.cc#L247 This matches what LLVMModuleNode::Init(const IRModule& mod, std::string target) already does.

Discuss post: https://discuss.tvm.ai/t/opencl-target-for-32-bit-arm-linux-android-broken-after-pr-4657/7252
Fixes #6019

Copy link
Member

@junrushao junrushao left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks Trevor!

Copy link
Contributor

@kevinthesun kevinthesun left a comment

Choose a reason for hiding this comment

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

LGTM

@trevor-m trevor-m force-pushed the trevmorr-fix-opencl-mfloat-abi branch from cf1db08 to 19a7795 Compare July 28, 2020 16:49
@trevor-m
Copy link
Contributor Author

Looks like some unrelated failures in ci? tests/python/frontend/tensorflow/test_forward.py::test_forward_nms FAILED [ 50%]

E     let %x7: Tensor[(5), int32] = vm.reshape_tensor(%x5, meta[relay.Constant][6], meta[relay.attrs.ReshapeTensorAttrs][0]) an internal invariant was violated while typechecking your program [00:42:28] /workspace/src/relay/op/vm/vm.cc:195: Check failed: tt: input must be tensor type

@junrushao
Copy link
Member

Yes, looks like the CI failure is not related

@trevor-m trevor-m force-pushed the trevmorr-fix-opencl-mfloat-abi branch from 19a7795 to 01d6a32 Compare July 29, 2020 21:06
@trevor-m trevor-m force-pushed the trevmorr-fix-opencl-mfloat-abi branch from 01d6a32 to 647b7b9 Compare August 4, 2020 18:55
@trevor-m
Copy link
Contributor Author

trevor-m commented Aug 5, 2020

@kevinthesun CI is passing now

@tqchen tqchen merged commit 9a362be into apache:master Aug 5, 2020
wjliu1998 pushed a commit to wjliu1998/incubator-tvm that referenced this pull request Aug 13, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Aug 26, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Aug 26, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Aug 26, 2020
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Sep 2, 2020
trevor-m pushed a commit to neo-ai/tvm that referenced this pull request Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants