未验证 提交 3e9ffaef 编写于 作者: H HongyuJia 提交者: GitHub

[Error Msg] Polish error message when GPU kernel not found (#50880)

* [Error Msg] Polish error message when GPU kernel not found

* Only test in GPU environment
上级 f3aec871
...@@ -155,8 +155,11 @@ phi::KernelKey FallBackToCpu(const phi::KernelKey& kernel_key, ...@@ -155,8 +155,11 @@ phi::KernelKey FallBackToCpu(const phi::KernelKey& kernel_key,
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
if (kernel_key.backend() == phi::Backend::GPU || if (kernel_key.backend() == phi::Backend::GPU ||
kernel_key.backend() == phi::Backend::GPUDNN) { kernel_key.backend() == phi::Backend::GPUDNN) {
PADDLE_THROW(platform::errors::Unavailable( PADDLE_THROW(
"For GPU kernel, they must not fallback into CPU kernel.")); phi::errors::NotFound("The kernel (%s) with key %s is not found and "
"GPU kernel cannot fallback to CPU one.",
op.Type(),
kernel_key));
} }
#endif #endif
......
...@@ -247,6 +247,18 @@ class TestMaxOp(OpTest): ...@@ -247,6 +247,18 @@ class TestMaxOp(OpTest):
def test_check_output(self): def test_check_output(self):
self.check_output(check_eager=True) self.check_output(check_eager=True)
def test_raise_error(self):
if core.is_compiled_with_cuda():
self.inputs = {'X': np.random.random((5, 6, 10)).astype("float16")}
place = core.CUDAPlace(0)
with self.assertRaises(RuntimeError) as cm:
self.check_output_with_place(place, check_eager=True)
error_msg = str(cm.exception).split("\n")[-2].strip().split(".")[0]
self.assertEqual(
error_msg,
"NotFoundError: The kernel (reduce_max) with key (GPU, Undefined(AnyLayout), float16) is not found and GPU kernel cannot fallback to CPU one",
)
class TestMaxOp_ZeroDim(OpTest): class TestMaxOp_ZeroDim(OpTest):
"""Remove Max with subgradient from gradient check to confirm the success of CI.""" """Remove Max with subgradient from gradient check to confirm the success of CI."""
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册