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

[RUNTIME] Initial implementation of Hexagon runtime support #5252

Merged
merged 12 commits into from
Apr 10, 2020
Merged

[RUNTIME] Initial implementation of Hexagon runtime support #5252

merged 12 commits into from
Apr 10, 2020

Conversation

kparzysz-quic
Copy link
Contributor

This is only the TVM runtime. The FastRPC libraries, simulator driver, etc. will be provided in subsequent commits.

@tqchen
Copy link
Member

tqchen commented Apr 6, 2020

cc @kazum @tmoreau89 @kazum

Copy link
Contributor

@tmoreau89 tmoreau89 left a comment

Choose a reason for hiding this comment

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

Great work, awesome to see a major new runtime being added to TVM. I left a couple comments.


The TVM runtime that contains Hexagon runtime is the one executing on host. In either case, there will need to be a separate TVM runtime (i.e. the `libtvm_runtime.so` library) compiled for execution on Hexagon.

The prerequisite is to have Hexagon SDK installed, preferably version 3.5.0.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a link to installing the Hexagon SDK?

Copy link
Contributor

Choose a reason for hiding this comment

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

In addition, is there a way to install it "automatically" to this back-end can be tested in the CI?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll add the link. I'm not sure about automatic install, because there is a license that needs to be accepted during installation.

Copy link
Member

Choose a reason for hiding this comment

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

While it might be hard to create an automatic installed version, we can look into at least do the compilation tests, to make sure that the runtime compiles

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The SDK link is https://developer.qualcomm.com/software/hexagon-dsp-sdk. I'll update the PR once the build completes (I want to see if it passes)...

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

include/tvm/runtime/device_api.h Show resolved Hide resolved
Copy link
Contributor

@tmoreau89 tmoreau89 left a comment

Choose a reason for hiding this comment

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

Thanks for the PR, and addressing the comments, the changes LGTM.

TVM_LOGD_HT("Done VTCM free from HexagonTarget::FreeVtcm");
}

void HexagonTarget::CopyDeviceToDevice(void* dst, const void* src,
Copy link
Member

Choose a reason for hiding this comment

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

As comment said: #3163 (comment) We should implement it. I tested on real device and find it is one must for device.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

const DspRpcAPI* dsp_api = DspRpcAPI::Global();
const StubAPI* stub_api = StubAPI::Global();

stub_api->rpcmem_init_ptr()();
Copy link
Member

Choose a reason for hiding this comment

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

I maybe forget a little bit, because I do it last year. However, I remember rpcmem_init_ptr will have problem when we set use_unsigned_pd be false. In your code logic of this pr, you will always set use_unsigned_pd be true. Could you double check it? I set it be false, because I find when we set it be true, we can not do parallel on DSP. But I don't have device now and can not verify it sadly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can set it to false, would you prefer that? I don't think there is a way to make it a parameter that the user can provide at run time.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. I prefer setting it to be false.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@FrozenGene
Copy link
Member

Could you provide the .idl file too? Because you have provided tvm_hexagon_remote.h, if we don't have .idl we can not generate .cc / .h for hexagon. I think it is core part of Hexagon runtime support too.

@kparzysz-quic
Copy link
Contributor Author

The IDL file and the implementation of the Hexagon-side target code will be upstreamed in an upcoming PR.

Copy link
Contributor

@tmoreau89 tmoreau89 left a comment

Choose a reason for hiding this comment

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

Thanks @kparzysz-quic , the changes LGTM

USE_HEXAGON_SDK=/path/to/sdk
```

Set the C/C++ compiler to `clang`, and pass `-DCMAKE_CXX_FLAGS='-stdlib=libc++'` to the cmake command.
Copy link
Member

Choose a reason for hiding this comment

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

Does it a must? I use g++ and libstdc++ ever and no problem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we started, I was seeing some problems with libstdc++, but I don't remember what they were anymore. Since it worked for you, I removed this line.

CHECKED_CALL(ConfigureAppCommandLine, sim_dev_args_.size(), sim_dev_args_);

LOG(INFO) << "HexagonSimulator: ConfigureHVXLength: 128";
CHECKED_CALL(ConfigureHVXLength, 128);
Copy link
Member

Choose a reason for hiding this comment

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

I am concerning here. When we create Hexagon target and use HVX 64, but we write hard code of 128 here. We can not find the problem easily. I didn't think of good solution before too. If we don't have a better way, could we add comment in def hexagon(cpu_ver='v66', sim_args=None, hvx=128): to prompt users if you change the hvx length, we should change the simulator here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually only setting the default HVX length. If --hvx_length was specified in sim_args, it would be processed in Configure` below, resetting the HVX length to the new value.

I changed the processing of sim_args to always add --hvx_length that matches hvx (it already printed a warning if both were given and didn't match). Now, configuring the default HVX length here is not needed, so I removed it.


std::shared_ptr<Device> Device::Global() {
// Declare device constructors.
#ifdef __ANDROID__
Copy link
Member

@FrozenGene FrozenGene Apr 8, 2020

Choose a reason for hiding this comment

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

If we want to support more Hexagon target in the future, we maybe have problem. For example, hexagon could run embed system of Ubuntu, which is official support of Hexagon SDK too. Then we can not use __ANDROID__ to distinguish target or simulator. One proposal is in our Hexagon.cmake, when we build for simulator, we define one macro like -D__HEXAGON_SIM__=1 to indicate we are running on simulator or like -D__HEXAGON_DEVICE__=1 to indicate we are running on real devices. This is one nit-pick comment, however, I wish we could consider it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can probably do that, but I'd prefer to do it in another commit.


When configuring TVM (cmake), set the following variables:
```
USE_LLVM=llvm-config
Copy link
Member

Choose a reason for hiding this comment

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

Need us to add one line of LLVM version requirement? If I remember correctly, older LLVM version (like 6.0 or before) has many bugs on Hexagon DSP.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I'm not aware of any specific issues with older LLVMs for Hexagon, so I didn't know which version is the minimum. I used 7.0.0 as the minimum, based on your comment, but recommended using as recent version as possible.

@FrozenGene
Copy link
Member

LGTM except one last comment. @kparzysz-quic Could you fix the CI?

@kparzysz-quic
Copy link
Contributor Author

I don't think that the CI failure has anything to do with this PR, there are other PRs that failed in the same way. I rebased it op top of the current master, maybe that will help...

@kparzysz-quic
Copy link
Contributor Author

@kparzysz-quic
Copy link
Contributor Author

@FrozenGene If you're happy with the code, could you approve? Your review is still showing as "requested changes".

@FrozenGene FrozenGene merged commit 02d3a59 into apache:master Apr 10, 2020
@FrozenGene
Copy link
Member

@kparzysz-quic Thanks for the great work. Looking forward other parts of Hexagon like IDL / codegen part and so on. Thanks @tmoreau89 for the code review!

@kparzysz-quic kparzysz-quic deleted the hexagon.rt branch April 10, 2020 14:52
trevor-m pushed a commit to trevor-m/tvm that referenced this pull request Apr 16, 2020
)

* [RUNTIME] Initial implementation of Hexagon runtime support

This is only the TVM runtime. The FastRPC libraries, simulator driver,
etc. will be provided in subsequent commits.

* Fix pylint complaints

* Fix some more pylint complaints

* Add link to the Hexagon SDK website

* Extract VTCM marker into a common variable

* Implement device->device memory copy

* Disable unsigned PDs by default

* Ensure that --hvx_length is present in sim_args if HVX is enabled

* Remove the line about clang from README.md

Apparently things work with libstdc++.

* Mention to set USE_RPC=OFF when building libtvm_runtime.so for Hexagon

* Remember to use codegen_hvx in validate_hvx_length

* Add a line about minimum version of LLVM
zhiics pushed a commit to neo-ai/tvm that referenced this pull request Apr 17, 2020
)

* [RUNTIME] Initial implementation of Hexagon runtime support

This is only the TVM runtime. The FastRPC libraries, simulator driver,
etc. will be provided in subsequent commits.

* Fix pylint complaints

* Fix some more pylint complaints

* Add link to the Hexagon SDK website

* Extract VTCM marker into a common variable

* Implement device->device memory copy

* Disable unsigned PDs by default

* Ensure that --hvx_length is present in sim_args if HVX is enabled

* Remove the line about clang from README.md

Apparently things work with libstdc++.

* Mention to set USE_RPC=OFF when building libtvm_runtime.so for Hexagon

* Remember to use codegen_hvx in validate_hvx_length

* Add a line about minimum version of LLVM
dpankratz pushed a commit to dpankratz/incubator-tvm that referenced this pull request Apr 24, 2020
)

* [RUNTIME] Initial implementation of Hexagon runtime support

This is only the TVM runtime. The FastRPC libraries, simulator driver,
etc. will be provided in subsequent commits.

* Fix pylint complaints

* Fix some more pylint complaints

* Add link to the Hexagon SDK website

* Extract VTCM marker into a common variable

* Implement device->device memory copy

* Disable unsigned PDs by default

* Ensure that --hvx_length is present in sim_args if HVX is enabled

* Remove the line about clang from README.md

Apparently things work with libstdc++.

* Mention to set USE_RPC=OFF when building libtvm_runtime.so for Hexagon

* Remember to use codegen_hvx in validate_hvx_length

* Add a line about minimum version of LLVM
monklof pushed a commit to monklof/incubator-tvm that referenced this pull request Jan 22, 2021
…m_data:master to master

* commit 'cd0d52daa6942bdafa9363ff6cfa3d25fcd5b8d6': (824 commits)
  [Intrinsic] Add log1p, ldexp, atan2, hypot, nextafter, copysign (apache#5312)
  [Rust][CI] Restore Rust CI (apache#5137)
  Remove PrimExpr from String (apache#5311)
  [Requantize] Cleanup and Optimize Lowering (apache#5286)
  [IR][TRANSFORM] Enable CopyOnWrite for passes. (apache#5309)
  [PYTORCH]Abs, Arange, Softplus ops (apache#5295)
  [LLVM] Fix generation of LLVM intrinsics (apache#5282)
  [BYOC] Add example of Composite + Annotate for DNNL fused op (apache#5272)
  [Frontend][TensorFlow]Improve TensorFlow Static Shape Tensor Array (apache#5243)
  [RUNTIME] Introduce RValue reference(move) support to TypedPackedFunc (apache#5271)
  [RELAY][FRONTEND][CAFFE2] add Mul and ConvTranspose operator (apache#5302)
  [BYOC] Refine AnnotateTarget and MergeCompilerRegion Passes (apache#5277)
  [CI] Fix the hexagon string (apache#5304)
  [Arith] linear system and equation solver (apache#5171)
  [PYTORCH]Repeat, Reciprocal & Reshape Op support (apache#5280)
  [FRONTEND][TENSORFLOW] Fix gather_nd indices (apache#5279)
  Update device_annotation.cc (apache#5291)
  [REFACTOR][IR] Move to runtime::String (apache#5276)
  [NDArray] Set shape_ in NDArray::FromDLPack (apache#5301)
  [RUNTIME] Initial implementation of Hexagon runtime support (apache#5252)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants