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

Fix an issue that CUDA EP fallback too much nodes to CPU for some case #1727

Merged
merged 1 commit into from
Aug 29, 2019
Merged
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
10 changes: 8 additions & 2 deletions onnxruntime/core/providers/cuda/cuda_execution_provider.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1018,19 +1018,25 @@ CUDAExecutionProvider::GetCapability(const onnxruntime::GraphViewer& graph,
// Note that nodes with only inputs from initializer would not be place on CUDA
// Ideally, those nodes should be eliminated in constant folding
bool should_force_outside = true;
bool all_input_are_initializer = true;
node.ForEachWithIndex(
node.InputDefs(),
[&](const NodeArg& def, size_t index) {
const ONNX_NAMESPACE::TensorProto* initializer = nullptr;
// The input is not a initializer and the input is from CPU
// or the input declared as CPU memory and is from CPU
// in that case we should still keep the node on CUDA
if ((!graph.GetInitializedTensor(def.Name(), initializer) && !defs_outside_cuda.count(&def)) ||
bool initializer_input = graph.GetInitializedTensor(def.Name(), initializer);
if ((!initializer_input && !defs_outside_cuda.count(&def)) ||
(defs_outside_cuda.count(&def) && cuda_kernel_def->kernel_def->IsInputOnCpu(index)))
should_force_outside = false;
if (!initializer_input) {
all_input_are_initializer = false;
}
return Status::OK();
});
if (should_force_outside) {
// If all the inputs are initialier, we shouldn't force it to CPU
if (should_force_outside && !all_input_are_initializer) {
force_outside = true;
}
}
Expand Down