diff --git a/paddle/fluid/eager/api/generated/eager_generated/backwards/scale_node.h b/paddle/fluid/eager/api/generated/eager_generated/backwards/scale_node.h index 68bb2089b19a3..e2036bc8363d8 100644 --- a/paddle/fluid/eager/api/generated/eager_generated/backwards/scale_node.h +++ b/paddle/fluid/eager/api/generated/eager_generated/backwards/scale_node.h @@ -43,16 +43,17 @@ class GradNodeScale : public GradNodeBase { // Functor: perform backward computations virtual paddle::small_vector, kSlotSmallVectorSize> - operator()(paddle::small_vector, - kSlotSmallVectorSize>& grads, // NOLINT - bool create_graph = false, - bool is_new_grad = false) override; + TEST_API + operator()(paddle::small_vector, + kSlotSmallVectorSize>& grads, // NOLINT + bool create_graph = false, + bool is_new_grad = false) override; void ClearTensorWrappers() override { VLOG(6) << "Do nothing here now"; } void SetTensorWrappers_X(const std::vector& tensors); - void SetAttributes_scale(float scale); + TEST_API void SetAttributes_scale(float scale); std::string name() override { return "scale node"; } // Members: define fwd input tensors // For Scale there is no fwd input tensor needed diff --git a/paddle/fluid/eager/api/utils/hook_utils.h b/paddle/fluid/eager/api/utils/hook_utils.h index 4c2523619d452..bbfd2aac80768 100644 --- a/paddle/fluid/eager/api/utils/hook_utils.h +++ b/paddle/fluid/eager/api/utils/hook_utils.h @@ -22,15 +22,15 @@ namespace egr { namespace egr_utils_api { -int64_t RegisterGradientHookForTensor( +TEST_API int64_t RegisterGradientHookForTensor( const paddle::Tensor& tensor, const std::function& hook); -void RegisterReduceHookForTensor(const paddle::Tensor& tensor, - const std::function& hook); +TEST_API void RegisterReduceHookForTensor(const paddle::Tensor& tensor, + const std::function& hook); TEST_API void RetainGradForTensor(const paddle::Tensor& tensor); -void RegisterBackwardFinalHook(const std::function& hook); +TEST_API void RegisterBackwardFinalHook(const std::function& hook); } // namespace egr_utils_api } // namespace egr diff --git a/paddle/fluid/eager/backward.h b/paddle/fluid/eager/backward.h index 098ef93b09457..81e338f21b83e 100644 --- a/paddle/fluid/eager/backward.h +++ b/paddle/fluid/eager/backward.h @@ -27,7 +27,7 @@ TEST_API void Backward(const std::vector& tensors, const std::vector& grad_tensors, bool retain_graph = false); -std::vector Grad( +TEST_API std::vector Grad( const std::vector& tensors, const std::vector& inputs, const std::vector& grad_tensors = {}, diff --git a/paddle/fluid/eager/grad_node_info.h b/paddle/fluid/eager/grad_node_info.h index 3b6405285eea3..248b4b88af4c0 100644 --- a/paddle/fluid/eager/grad_node_info.h +++ b/paddle/fluid/eager/grad_node_info.h @@ -255,7 +255,7 @@ class GradNodeBase { size_t slot_rank); void SetGradOutMeta(const std::vector& fwd_in, size_t slot_rank); - void SetGradOutMeta(const paddle::Tensor& fwd_in, size_t slot_rank); + TEST_API void SetGradOutMeta(const paddle::Tensor& fwd_in, size_t slot_rank); void SetGradOutMeta(const paddle::Tensor& fwd_in, const AutogradMeta* fwd_in_other, size_t slot_rank); diff --git a/paddle/fluid/eager/nan_inf_utils.h b/paddle/fluid/eager/nan_inf_utils.h index 4f412cf6db88d..c66fb7a4c70ea 100644 --- a/paddle/fluid/eager/nan_inf_utils.h +++ b/paddle/fluid/eager/nan_inf_utils.h @@ -35,41 +35,42 @@ using TupleOfSixTensors = using TupleOfTensorAndVector = std::tuple, std::vector>; -void CheckTensorHasNanOrInf(const std::string& api_name, const Tensor& tensor); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const Tensor& tensor); -void CheckTensorHasNanOrInf(const std::string& api_name, - const paddle::optional& tensor); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const paddle::optional& tensor); -void CheckTensorHasNanOrInf(const std::string& api_name, - const TupleOfTwoTensors& tensors); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const TupleOfTwoTensors& tensors); -void CheckTensorHasNanOrInf(const std::string& api_name, - const TupleOfThreeTensors& tensors); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const TupleOfThreeTensors& tensors); -void CheckTensorHasNanOrInf(const std::string& api_name, - const TupleOfFourTensors& tensors); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const TupleOfFourTensors& tensors); -void CheckTensorHasNanOrInf(const std::string& api_name, - const TupleOfFiveTensors& tensors); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const TupleOfFiveTensors& tensors); -void CheckTensorHasNanOrInf(const std::string& api_name, - const TupleOfSixTensors& tensors); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const TupleOfSixTensors& tensors); -void CheckTensorHasNanOrInf(const std::string& api_name, - const std::vector& tensors); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const std::vector& tensors); -void CheckTensorHasNanOrInf( +TEST_API void CheckTensorHasNanOrInf( const std::string& api_name, const paddle::optional>& tensors); -void CheckTensorHasNanOrInf(const std::string& api_name, - const TupleOfTensorAndVector& tensors); +TEST_API void CheckTensorHasNanOrInf(const std::string& api_name, + const TupleOfTensorAndVector& tensors); void SetCheckOpList(const std::string& check_op_list); void SetSkipOpList(const std::string& skip_op_list); -void CheckTensorHasNanOrInf( +TEST_API void CheckTensorHasNanOrInf( const std::string& api_name, const paddle::small_vector, egr::kSlotSmallVectorSize>& tensors); diff --git a/paddle/phi/common/memory_utils.h b/paddle/phi/common/memory_utils.h index 9e4e573277549..288ffe175809b 100644 --- a/paddle/phi/common/memory_utils.h +++ b/paddle/phi/common/memory_utils.h @@ -390,11 +390,11 @@ class MemoryUtils { namespace memory_utils { -Allocator::AllocationPtr Alloc(const phi::GPUPlace& place, - size_t size, - const phi::Stream& stream); +TEST_API Allocator::AllocationPtr Alloc(const phi::GPUPlace& place, + size_t size, + const phi::Stream& stream); -Allocator::AllocationPtr Alloc(const phi::Place& place, size_t size); +TEST_API Allocator::AllocationPtr Alloc(const phi::Place& place, size_t size); std::shared_ptr AllocShared(const phi::Place& place, size_t size, diff --git a/test/cpp/eager/task_tests/CMakeLists.txt b/test/cpp/eager/task_tests/CMakeLists.txt index 9bcd4b19f856a..39a11d9582ae3 100755 --- a/test/cpp/eager/task_tests/CMakeLists.txt +++ b/test/cpp/eager/task_tests/CMakeLists.txt @@ -1,47 +1,20 @@ -cc_test( - test_egr_task_nan_inf_utils - SRCS nan_inf_utils_test.cc - DEPS eager_nan_inf_utils phi common) +paddle_test(test_egr_task_nan_inf_utils SRCS nan_inf_utils_test.cc DEPS common) if(NOT ((NOT WITH_PYTHON) AND ON_INFER)) - cc_test( - test_egr_task_hook - SRCS hook_test.cc - DEPS ${eager_deps} ${fluid_deps} ${generated_deps} eager_scale scale_node) - cc_test( - test_egr_task_backward - SRCS backward_test.cc - DEPS ${eager_deps} ${fluid_deps} ${generated_deps} eager_scale scale_node) - cc_test( - test_egr_task_grad - SRCS grad_test.cc - DEPS ${eager_deps} ${fluid_deps} ${generated_deps} eager_scale scale_node) - cc_test( - test_egr_task_fwd_bwd_joint - SRCS fwd_bwd_joint_test.cc - DEPS ${eager_deps} ${fluid_deps} ${generated_deps} eager_scale scale_node) - cc_test( - test_egr_task_cross_batch - SRCS cross_batch_accumulation_test.cc - DEPS ${eager_deps} ${fluid_deps} ${generated_deps} eager_scale scale_node) - cc_test( - test_egr_task_hook_intermidiate - SRCS hook_test_intermidiate.cc - DEPS ${eager_deps} ${fluid_deps} ${generated_deps} dygraph_node) - cc_test( - test_egr_task_autocodegen - SRCS generated_test.cc - DEPS ${eager_deps} ${fluid_deps} ${generated_deps}) - cc_test( - test_egr_task_tensor_utils - SRCS tensor_utils_test.cc - DEPS ${eager_deps} ${generated_deps}) - cc_test( - test_egr_task_eager_utils - SRCS eager_utils_test.cc - DEPS ${eager_deps} ${generated_deps}) - cc_test( - test_egr_task_forward_autograd - SRCS forward_autograd_test.cc - DEPS ${eager_deps} ${fluid_deps} ${generated_deps} eager_scale scale_node) + paddle_test(test_egr_task_hook SRCS hook_test.cc) + paddle_test(test_egr_task_backward SRCS backward_test.cc) + paddle_test(test_egr_task_grad SRCS grad_test.cc) + paddle_test(test_egr_task_fwd_bwd_joint SRCS fwd_bwd_joint_test.cc) + paddle_test(test_egr_task_cross_batch SRCS cross_batch_accumulation_test.cc) + paddle_test(test_egr_task_hook_intermidiate SRCS hook_test_intermidiate.cc) + paddle_test(test_egr_task_autocodegen SRCS generated_test.cc) + paddle_test(test_egr_task_tensor_utils SRCS tensor_utils_test.cc) + paddle_test(test_egr_task_eager_utils SRCS eager_utils_test.cc) + paddle_test(test_egr_task_forward_autograd SRCS forward_autograd_test.cc) +endif() + +if(WITH_ONNXRUNTIME AND WIN32) + # Copy onnxruntime for some c++ test in Windows, since the test will + # be build only in CI, so suppose the generator in Windows is Ninja. + copy_onnx(test_egr_task_nan_inf_utils) endif() diff --git a/test/cpp/eager/task_tests/generated_test.cc b/test/cpp/eager/task_tests/generated_test.cc index 3c1753a3dd526..747d89e930e47 100644 --- a/test/cpp/eager/task_tests/generated_test.cc +++ b/test/cpp/eager/task_tests/generated_test.cc @@ -31,8 +31,6 @@ PD_DECLARE_KERNEL(matmul, CPU, ALL_LAYOUT); PD_DECLARE_KERNEL(matmul_grad, CPU, ALL_LAYOUT); PD_DECLARE_KERNEL(add, CPU, ALL_LAYOUT); PD_DECLARE_KERNEL(add_grad, CPU, ALL_LAYOUT); -PD_DECLARE_KERNEL(sigmoid, CPU, ALL_LAYOUT); -PD_DECLARE_KERNEL(sigmoid_grad, CPU, ALL_LAYOUT); namespace egr { @@ -145,7 +143,3 @@ TEST(Generated, ElementwiseAdd) { } } // namespace egr - -USE_OP_ITSELF(sigmoid); -USE_OP_ITSELF(elementwise_add); -USE_OP_ITSELF(matmul_v2); diff --git a/test/cpp/eager/task_tests/hook_test_intermidiate.cc b/test/cpp/eager/task_tests/hook_test_intermidiate.cc index 050672e2f07c5..9eda6dd63abb6 100644 --- a/test/cpp/eager/task_tests/hook_test_intermidiate.cc +++ b/test/cpp/eager/task_tests/hook_test_intermidiate.cc @@ -324,7 +324,3 @@ TEST(Hook_intermidiate, Matmul_v2) { TEST(Hook_intermidiate, BackwardFinal) { test_backward_final_hooks(); } } // namespace egr - -USE_OP_ITSELF(sigmoid); -USE_OP_ITSELF(elementwise_add); -USE_OP_ITSELF(matmul_v2);