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

[Relay] Add LowerTEPass into vm lowering proecss #9134

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/relay/backend/te_compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,17 @@ Target GetTargetFromInteger(DLDeviceType dev_type, tec::TargetMap targets) {
}
}

TargetMap GetTecTargetMapFromTargetMap(Map<tvm::Integer, tvm::Target> targets) {
tec::TargetMap targets_;
for (const auto& it : targets) {
auto dev_type = it.first.as<tir::IntImmNode>();
ICHECK(dev_type);
targets_[static_cast<DLDeviceType>(dev_type->value)] = it.second;
}

return targets_;
}

Pass LowerTensorExpr(TargetMap targets, DeviceMap device_context_map, const String& module_name,
TECompiler compiler, std::function<void(Function)> process_fn) {
runtime::TypedPackedFunc<Function(Function, IRModule, PassContext)> pass_func =
Expand Down
10 changes: 9 additions & 1 deletion src/relay/backend/te_compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,14 @@ void UpdateFunctionMetadata(Function relay_func,
*/
Target GetTargetFromInteger(DLDeviceType dev_type, TargetMap targets);

/*!
* \brief Obtain the TargetMap from the Map<tvm::Integer, tvm::Target>.
*
* \param targets
* \return TargetMap
*/
TargetMap GetTecTargetMapFromTargetMap(Map<tvm::Integer, tvm::Target> targets);

/*!
* \brief Update the "main" control function's metadata
*
Expand Down Expand Up @@ -196,7 +204,7 @@ IRModule LowerTE(
* \param module_name The name of this module
* \param process_fn Callback allowing one-level up code generators to process
* each function that we lower
* \returns The pass which lowers primative functions to TIR
* \returns The pass which lowers primitive functions to TIR
*/
transform::Pass LowerTEPass(TargetMap targets, DeviceMap device_context_map,
const String& module_name, std::function<void(Function)> process_fn);
Expand Down
9 changes: 8 additions & 1 deletion src/relay/backend/vm/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -921,7 +921,6 @@ void VMCompiler::Lower(IRModule mod, const TargetsMap& targets, const tvm::Targe
context_.module = OptimizeModule(mod, targets_, target_host_);

// Populate the global map.
//
// This maps global variables to a global index
// in the VMFunction table.
PopulateGlobalMap();
Expand Down Expand Up @@ -1083,13 +1082,21 @@ IRModule VMCompiler::OptimizeModule(IRModule mod, const TargetsMap& targets_arg,
pass_seqs.push_back(transform::InferType());
pass_seqs.push_back(transform::LabelOps());

tec::TargetMap targets_;
tec::DeviceMap device_map;

targets_ = GetTecTargetMapFromTargetMap(targets);

pass_seqs.push_back(tec::LowerTEPass(targets_, device_map, "vm_mod", [this](Function func) {}));
Copy link
Contributor

Choose a reason for hiding this comment

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

For others: This PR also needs to remove the direct calls to the TECompiler Lower and LowerShapeFunc which are a bit fiddly to change over. I believe Michalis is working on that.


transform::Sequential seq(pass_seqs);
tvm::With<relay::transform::PassContext> ctx(pass_ctx);
if (targets.size() == 1) {
const auto& it = targets.begin();
With<Target> tctx((*it).second);
return seq(mod);
}

return seq(mod);
}

Expand Down