mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-21 05:34:18 +08:00
Summary: pretty simple. if planner exists, which implies that planning is enabled, create a manager for each frame. the associated serial executor will use the withMemoryPlannner fn to ensure the deallocation is done after execution completes. Test Plan: CI Differential Revision: D73635809 Pull Request resolved: https://github.com/pytorch/pytorch/pull/157053 Approved by: https://github.com/henryoier, https://github.com/georgiaphillips
35 lines
1.2 KiB
C++
35 lines
1.2 KiB
C++
#include <torch/nativert/executor/ExecutionPlanner.h>
|
|
#include <torch/nativert/executor/ExecutorConfig.h>
|
|
#include <torch/nativert/executor/SerialGraphExecutor.h>
|
|
|
|
namespace torch::nativert {
|
|
|
|
std::vector<c10::IValue> SerialGraphExecutor::execute(
|
|
ExecutionFrame& executionFrame,
|
|
std::vector<c10::IValue> inputs) {
|
|
fillUserInputs(executionFrame, std::move(inputs));
|
|
|
|
return executeWithPrefilledFrame(executionFrame);
|
|
}
|
|
|
|
std::vector<c10::IValue> SerialGraphExecutor::executeWithPrefilledFrame(
|
|
ExecutionFrame& executionFrame) {
|
|
executionFrame.withMemoryPlanner([&]() {
|
|
// Execute kernels for all nodes except prim.Input and prim.Output
|
|
for (NodeIndex nodeIdx = 1; nodeIdx < nodeKernels_.size() - 1; ++nodeIdx) {
|
|
nodeKernels_[nodeIdx]->compute(executionFrame);
|
|
|
|
// don't free intermediate values when static memory planning is enabled
|
|
if (executorConfig_.tryFreeUnmanagedValuesAfterUse) {
|
|
// Free the intermediate values that are no used anymore
|
|
for (const auto& valueKey : execPlan_->valuesToFree[nodeIdx]) {
|
|
executionFrame.releaseValueIfNeeded(valueKey);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
return executionFrame.tryMoveUserOutputs();
|
|
}
|
|
|
|
} // namespace torch::nativert
|