未验证 提交 083b4eb6 编写于 作者: F Feiyu Chan 提交者: GitHub

1. change the codegen code to avoid conversion from heterogeneous 'initializer...

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.
上级 aa42bc25
......@@ -62,4 +62,25 @@ void CheckTensorHasNanOrInf(
const paddle::small_vector<std::vector<paddle::experimental::Tensor>,
egr::kSlotSmallVectorSize>& tensors);
template <typename TupleT, size_t N, size_t Last>
struct NanInfChecker {
void operator()(const std::string& api_name, const TupleT& tensors) {
CheckTensorHasNanOrInf(api_name, std::get<N>(tensors));
NanInfChecker<TupleT, N + 1, Last>()(api_name, tensors);
}
};
template <typename TupleT, size_t N>
struct NanInfChecker<TupleT, N, N> {
void operator()(const std::string& api_name, const TupleT& tensors) {
CheckTensorHasNanOrInf(api_name, std::get<N>(tensors));
}
};
template <typename TupleT>
void CheckTensorHasNanOrInf(const std::string& api_name,
const TupleT& tensors) {
constexpr size_t size = std::tuple_size<TupleT>::value;
NanInfChecker<TupleT, 0, size - 1>()(api_name, tensors);
}
} // namespace egr
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册