-
Notifications
You must be signed in to change notification settings - Fork 3.7k
[RELAY] [VIRTUALDEVICE] Change syntax for device planning and store parameter virtual devices in virtual_device_ field #10352
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
Changes from 21 commits
dc6053b
69acc6d
a92ab15
30fff16
167e4fd
e3a2ec2
a95ae9d
e62bce8
904b93a
5224b64
fd97879
3236a2d
e269437
e642a5a
6c6e5e5
a344e15
231d040
0f5e6d2
f71601d
e8e5a09
ad4c97a
78d063e
1f10769
b20dce7
8bacaba
41870f0
3d346d9
c4939e6
001a063
2075dad
9dda0c1
5bf526a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -220,9 +220,13 @@ Doc RelayTextPrinter::AllocVar(const Var& var) { | |
| } | ||
| Doc val = GetUniqueName("%" + name); | ||
| memo_[var] = val; | ||
| if (!var->virtual_device()->IsFullyUnconstrained()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any issue with this being used for both param- and let-bound vars even though we don't parse annots for let-bound vars?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess for now, let-bound variables don't have their virtual devices set so it theoretically won't be triggered.. I haven't seen any issues in CI related to this but I could split the function into two if you'd like |
||
| val << " {" << kVirtualDevice << "=" << PrintAttributeValue(var->virtual_device()) << "}"; | ||
| } | ||
| if (var->type_annotation.defined()) { | ||
| val << ": " << Print(var->type_annotation); | ||
| } | ||
|
|
||
| val << PrintOptionalInfo(var); | ||
| return val; | ||
| } | ||
|
|
@@ -329,7 +333,10 @@ Doc RelayTextPrinter::PrintExpr(const Expr& expr, bool meta, bool try_inline, bo | |
|
|
||
| // Should only be triggered when op is a free variable being visited for the | ||
| // first time. | ||
| Doc RelayTextPrinter::VisitExpr_(const VarNode* op) { return AllocVar(GetRef<Var>(op)); } | ||
| Doc RelayTextPrinter::VisitExpr_(const VarNode* op) { | ||
electriclilies marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Doc var_doc = AllocVar(GetRef<Var>(op)); | ||
| return var_doc; | ||
| } | ||
|
|
||
| /*! | ||
| * \brief special method to print out const scalar | ||
|
|
@@ -445,7 +452,7 @@ Doc RelayTextPrinter::PrintFunc(const Doc& prefix, const relay::Function& fn) { | |
| for (const Doc& d : PrintDictAttrs(fn->attrs)) { | ||
| params.push_back(d); | ||
| } | ||
| if (fn->virtual_device() != VirtualDevice::FullyUnconstrained()) { | ||
| if (!fn->virtual_device()->IsFullyUnconstrained()) { | ||
| Doc vid_doc; | ||
| vid_doc << kVirtualDevice << "=" << PrintAttributeValue(fn->virtual_device()); | ||
| params.push_back(vid_doc); | ||
|
|
@@ -454,7 +461,6 @@ Doc RelayTextPrinter::PrintFunc(const Doc& prefix, const relay::Function& fn) { | |
| if (fn->ret_type.defined()) { | ||
| doc << "-> " << Print(fn->ret_type) << " "; | ||
| } | ||
|
|
||
| doc << PrintBody(fn->body); | ||
| return doc; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -252,21 +252,16 @@ class VMFunctionCompiler : DeviceAwareExprFunctor<void(const Expr& n)> { | |
| // Do that flattening on-the-fly here. | ||
| Function inner_func = Downcast<Function>(func->body); | ||
| std::vector<Var> params; | ||
| std::vector<VirtualDevice> param_virtual_devices; | ||
| params.reserve(func->params.size() + inner_func->params.size()); | ||
| param_virtual_devices.reserve(func->params.size() + inner_func->params.size()); | ||
| param_device_indexes.reserve(func->params.size() + inner_func->params.size()); | ||
| for (size_t i = 0; i < func->params.size(); ++i) { | ||
| params.emplace_back(func->params[i]); | ||
| VirtualDevice param_virtual_device = GetFunctionParamVirtualDevice(func.get(), i); | ||
| param_virtual_devices.push_back(param_virtual_device); | ||
| param_device_indexes.push_back(GetDeviceIndex(param_virtual_device)); | ||
| param_device_indexes.push_back(GetDeviceIndex(func->params[i]->virtual_device())); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we get some payoff at last!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah!! |
||
| } | ||
| for (size_t i = 0; i < inner_func->params.size(); ++i) { | ||
| params.emplace_back(inner_func->params[i]); | ||
| VirtualDevice param_virtual_device = GetFunctionParamVirtualDevice(inner_func.get(), i); | ||
| param_virtual_devices.push_back(param_virtual_device); | ||
| param_device_indexes.push_back(GetDeviceIndex(param_virtual_device)); | ||
|
|
||
| param_device_indexes.push_back(GetDeviceIndex(inner_func->params[i]->virtual_device())); | ||
| } | ||
| std::vector<TypeVar> type_params; | ||
| type_params.reserve(func->type_params.size() + inner_func->type_params.size()); | ||
|
|
@@ -278,13 +273,12 @@ class VMFunctionCompiler : DeviceAwareExprFunctor<void(const Expr& n)> { | |
| } | ||
| Function flattened_func = Function(params, inner_func->body, inner_func->ret_type, | ||
| type_params, func->attrs, func->span); | ||
| VisitExpr(MaybeFunctionOnDevice(flattened_func, param_virtual_devices, | ||
| GetFunctionResultVirtualDevice(inner_func.get()))); | ||
| flattened_func->virtual_device_ = inner_func->virtual_device(); | ||
| VisitExpr(flattened_func); | ||
| } else { | ||
| param_device_indexes.reserve(func->params.size()); | ||
| for (size_t i = 0; i < func->params.size(); ++i) { | ||
| param_device_indexes.push_back( | ||
| GetDeviceIndex(GetFunctionParamVirtualDevice(func.get(), i))); | ||
| param_device_indexes.push_back(GetDeviceIndex(func->params[i]->virtual_device())); | ||
| } | ||
| VisitExpr(func); | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meganit: I've been using VLOG(9) for these super-duper verbose ones since I often just set TVM_LOG_DEBUG="DEFAULT=1" to get an overall debug trace that's still vaguely readable.