From 083b4eb6238aa1eeb638a7d6e67295264d5f84bb Mon Sep 17 00:00:00 2001 From: Feiyu Chan Date: Wed, 10 Aug 2022 17:02:59 +0800 Subject: [PATCH] 1. change the codegen code to avoid conversion from heterogeneous 'initializer list' to tuple, which fails on gcc 5.4; (#45036) 2. add a template CheckTensorHasNanOrInf to handle arbitary tuple of supported types. --- paddle/fluid/eager/nan_inf_utils.h | 21 +++++++++++++++++++++ paddle/phi/api/yaml/generator/api_gen.py | 2 +- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/eager/nan_inf_utils.h b/paddle/fluid/eager/nan_inf_utils.h index 815e3bd6cd1..9abc1ca02f1 100644 --- a/paddle/fluid/eager/nan_inf_utils.h +++ b/paddle/fluid/eager/nan_inf_utils.h @@ -62,4 +62,25 @@ void CheckTensorHasNanOrInf( const paddle::small_vector, egr::kSlotSmallVectorSize>& tensors); +template +struct NanInfChecker { + void operator()(const std::string& api_name, const TupleT& tensors) { + CheckTensorHasNanOrInf(api_name, std::get(tensors)); + NanInfChecker()(api_name, tensors); + } +}; + +template +struct NanInfChecker { + void operator()(const std::string& api_name, const TupleT& tensors) { + CheckTensorHasNanOrInf(api_name, std::get(tensors)); + } +}; + +template +void CheckTensorHasNanOrInf(const std::string& api_name, + const TupleT& tensors) { + constexpr size_t size = std::tuple_size::value; + NanInfChecker()(api_name, tensors); +} } // namespace egr diff --git a/paddle/phi/api/yaml/generator/api_gen.py b/paddle/phi/api/yaml/generator/api_gen.py index 64c2fac85cd..dc4581472f8 100644 --- a/paddle/phi/api/yaml/generator/api_gen.py +++ b/paddle/phi/api/yaml/generator/api_gen.py @@ -130,7 +130,7 @@ class ForwardAPI(BaseAPI): selected_code = [ f"std::get<{i}>(api_output)" for i in return_out_list ] - return 'return {' + ", ".join(selected_code) + '};' + return 'return std::make_tuple(' + ", ".join(selected_code) + ');' def gene_output(self, out_dtype_list, -- GitLab