Skip to content

Commit 50ac67f

Browse files
authored
Bugfix/check if kernel for type exist (#7657)
* check if kernel if found for kernel type * do kernel check before data transform
1 parent 55ec0e2 commit 50ac67f

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

paddle/framework/operator.cc

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,15 @@ void OperatorWithKernel::Run(const Scope& scope,
485485
// }
486486

487487
auto expected_kernel_key = this->GetExpectedKernelType(ctx);
488-
489488
VLOG(3) << "expected_kernel_key:" << expected_kernel_key;
490489

490+
auto kernel_iter = kernels.find(expected_kernel_key);
491+
if (kernel_iter == kernels.end()) {
492+
PADDLE_THROW("op %s does not have kernel for %s", type_,
493+
KernelTypeToString(expected_kernel_key));
494+
}
495+
496+
// do data transform
491497
Scope& new_scope = scope.NewScope();
492498

493499
for (auto& var_name_item : this->Inputs()) {
@@ -520,8 +526,6 @@ void OperatorWithKernel::Run(const Scope& scope,
520526
}
521527
}
522528

523-
auto kernel_iter = kernels.find(expected_kernel_key);
524-
525529
auto* new_dev_ctx = pool.Get(expected_kernel_key.place_);
526530
kernel_iter->second->Compute(
527531
ExecutionContext(*this, new_scope, *new_dev_ctx));

0 commit comments

Comments
 (0)