reminisce commented on a change in pull request #17530: Add deferred compute
support
URL: https://github.com/apache/incubator-mxnet/pull/17530#discussion_r378665805
##########
File path: src/imperative/imperative.cc
##########
@@ -544,4 +681,60 @@ std::vector<NDArray*> Imperative::Backward(
return {};
}
+Imperative::DCInfo::DCInfo(const std::vector<NDArray *> &inputs,
+ const std::vector<NDArray *> &outputs) {
+ this->inputs_.reserve(inputs.size());
+ this->input_handles_.reserve(inputs.size());
+ for (const NDArray *arr : inputs) {
+ CHECK(!arr->is_none());
+ this->inputs_.push_back(*arr);
+ this->input_handles_.push_back(arr);
+ }
+
+ this->outputs_.reserve(outputs.size());
+ for (const NDArray *arr : outputs) {
+ CHECK(!arr->is_none());
+ this->outputs_.push_back(*arr);
+ }
+}
+
+Imperative::DCInfo &
+Imperative::DCInfo::Create(const nnvm::ObjectPtr &node,
+ const std::vector<NDArray *> &inputs,
+ const std::vector<NDArray *> &outputs) {
+ node->info.construct<DCInfo>(inputs, outputs);
+ return Imperative::DCInfo::Get(node);
+}
+
+void Imperative::DCInfo::Compute(const NDArray &arr) {
+ if (Imperative::DCInfo::IsComputed(arr))
+ return;
+
+ DCInfo &info = Imperative::DCInfo::Get(arr.deferredcompute_entry_.node);
+ info.is_computed_ = true; // We will Invoke at the end of this function.
+
+ // Recursively compute input arrays
+ for (NDArray &input : info.inputs_) {
Review comment:
change to use `const NDArray&` ?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services