Skip to content

Conversation

@Lunderberg
Copy link
Contributor

Prior to this commit, any caller that uses a different Target than its callee is lowered to a device-kernel launch. However, if the caller and callee are on the same device, despite using a different target (e.g. Target("llvm") and Target("c") both use kDLCPU), then the kernel launch is unnecessary.

This commit updates LowerDeviceKernelLaunch to produce a kernel launch only when the callee is on another device, and to produce T.call_extern for callees on the same device.

@tvm-bot
Copy link
Collaborator

tvm-bot commented May 30, 2023

Thanks for contributing to TVM! Please refer to the contributing guidelines https://tvm.apache.org/docs/contribute/ for useful information and tips. Please request code reviews from Reviewers by @-ing them in a comment.

Generated by tvm-bot

@Lunderberg
Copy link
Contributor Author

Lunderberg commented May 30, 2023

This is a subset of functionality from #14862, split out into an independent PR for ease of testing and review. was previously a subset of functionality from #14862, but after splitting out, wasn't required for the functionality in that PR.

Copy link
Member

@masahi masahi left a comment

Choose a reason for hiding this comment

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

Makes sense to me.

Optional<Target> current_target_;
std::unordered_map<const GlobalVarNode*, KernelInfo> device_info_map_;
std::unordered_set<const GlobalVarNode*> device_kernel_launch_;
std::unordered_set<const GlobalVarNode*> extern_method_call_;
Copy link
Member

Choose a reason for hiding this comment

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

method -> func? Since we don't use that term.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, and renamed extern_method_call_ to extern_function_call_.

Prior to this commit, any caller that uses a different `Target` than
its callee is lowered to a device-kernel launch.  However, if the
caller and callee are on the same device, despite using a different
target (e.g. `Target("llvm")` and `Target("c")` both use `kDLCPU`),
then the kernel launch is unnecessary.

This commit updates `LowerDeviceKernelLaunch` to produce a kernel
launch only when the callee is on another device, and to produce
`T.call_extern` for callees on the same device.
@Lunderberg Lunderberg force-pushed the callee_on_same_device_different_codegen branch from 0f74875 to 922df81 Compare June 3, 2023 19:41
@Lunderberg
Copy link
Contributor Author

Similar to #14951, rebased this PR on top of main, now that #14982 has landed.

@masahi masahi merged commit 9877db5 into apache:main Jun 4, 2023
@Lunderberg Lunderberg deleted the callee_on_same_device_different_codegen branch June 4, 2023 13:32
junrushao pushed a commit to junrushao/tvm that referenced this pull request Jun 22, 2023
* [TIR] Handle callees on same target, different codegen

Prior to this commit, any caller that uses a different `Target` than
its callee is lowered to a device-kernel launch.  However, if the
caller and callee are on the same device, despite using a different
target (e.g. `Target("llvm")` and `Target("c")` both use `kDLCPU`),
then the kernel launch is unnecessary.

This commit updates `LowerDeviceKernelLaunch` to produce a kernel
launch only when the callee is on another device, and to produce
`T.call_extern` for callees on the same device.

* Rename "extern_method_call_" to "extern_function_call_"
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.

3 participants