Skip to content

Commit

Permalink
link cpp test to libpaddle.so/dll (PaddlePaddle#57789)
Browse files Browse the repository at this point in the history
* fix bug

* fix symbol redefined bug

* fix bug

* fix bug

* fix bug

* fix bug

* fix bug

* fix bug

* fix bug

* fix bug

* fix bug
  • Loading branch information
risemeup1 authored and jiahy0825 committed Oct 26, 2023
1 parent 263067b commit eea81c0
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 91 deletions.
24 changes: 24 additions & 0 deletions paddle/fluid/framework/init_default_kernel_signature_map.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */

#pragma once

#include "paddle/utils/test_macros.h"

// The implementation of InitDefaultKernelSignatureMap is in phi_utils.cc
namespace paddle {
namespace framework {
TEST_API void InitDefaultKernelSignatureMap();
} // namespace framework
} // namespace paddle
4 changes: 2 additions & 2 deletions paddle/fluid/framework/op_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ limitations under the License. */
#include "paddle/fluid/platform/enforce.h"
#include "paddle/fluid/platform/macros.h"
#include "paddle/utils/flat_hash_map.h"

#include "paddle/utils/test_macros.h"
namespace paddle {
namespace framework {

Expand Down Expand Up @@ -128,7 +128,7 @@ class OpInfo {
}
};

class OpInfoMap {
class TEST_API OpInfoMap {
public:
static OpInfoMap& Instance();

Expand Down
3 changes: 1 addition & 2 deletions paddle/fluid/framework/phi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ limitations under the License. */
#include <vector>

#include "paddle/fluid/framework/framework.pb.h"
#include "paddle/fluid/framework/init_default_kernel_signature_map.h"
#include "paddle/fluid/framework/op_kernel_type.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/tensor.h"
Expand Down Expand Up @@ -60,8 +61,6 @@ class KernelArgsNameMaker {
virtual const paddle::small_vector<const char*>& GetAttrsArgsNames() = 0;
};

TEST_API void InitDefaultKernelSignatureMap();

// TODO(Wilber): support others device context.
template <typename T>
struct ConvertToPhiContext {
Expand Down
6 changes: 3 additions & 3 deletions paddle/fluid/prim/api/manual_prim/utils/static_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ namespace paddle {
namespace prim {
using Tensor = paddle::Tensor;
template <>
Tensor empty<DescTensor>(const paddle::experimental::IntArray& shape,
phi::DataType dtype,
const paddle::Place& place) {
TEST_API Tensor empty<DescTensor>(const paddle::experimental::IntArray& shape,
phi::DataType dtype,
const paddle::Place& place) {
framework::VarDesc* new_var =
StaticCompositeContext::Instance().GetBlock()->Var(
StaticCompositeContext::Instance().GenerateUniqueName());
Expand Down
3 changes: 1 addition & 2 deletions paddle/fluid/prim/utils/static/static_global_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include "paddle/fluid/framework/op_desc.h"
#include "paddle/fluid/framework/operator.h"
#include "paddle/fluid/framework/type_defs.h"

namespace paddle {
namespace prim {

Expand Down Expand Up @@ -109,7 +108,7 @@ class StaticCompositeContext {
static thread_local bool enable_bwd_prim_;
static thread_local bool enable_fwd_prim_;
static thread_local bool enable_eager_prim_;
static StaticCompositeContext* static_composite_context_;
TEST_API static StaticCompositeContext* static_composite_context_;
DISABLE_COPY_AND_ASSIGN(StaticCompositeContext);
};

Expand Down
2 changes: 1 addition & 1 deletion paddle/phi/core/ddim.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ std::vector<T> vectorize(const DDim& ddim) {
return result;
}

int64_t product(const DDim& ddim);
TEST_API int64_t product(const DDim& ddim);

bool contain_unknown_dim(const DDim& ddim);

Expand Down
4 changes: 3 additions & 1 deletion paddle/phi/core/extended_tensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ limitations under the License. */
#include "paddle/phi/core/allocator.h"
#include "paddle/phi/core/tensor_base.h"
#include "paddle/phi/core/tensor_meta.h"
#include "paddle/utils/test_macros.h"

namespace phi {

/// \brief The ExtendedTensor is a interface for custom designed class.
/// If you want to pass some self-designed data as input/output to kernels,
/// you can inherit from this class to store your self-designed data.
class ExtendedTensor : public TensorBase {
class TEST_API ExtendedTensor : public TensorBase {
public:
ExtendedTensor() = default;
virtual ~ExtendedTensor() = default;
Expand Down
3 changes: 2 additions & 1 deletion paddle/phi/core/utils/type_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ limitations under the License. */
#pragma once

#include <string>
#include "paddle/utils/test_macros.h"

namespace phi {

Expand All @@ -40,7 +41,7 @@ class TypeInfo {
};

template <typename BaseT, typename DerivedT>
class TypeInfoTraits {
class TEST_API TypeInfoTraits {
public:
static const TypeInfo<BaseT> kType;
TypeInfoTraits();
Expand Down
2 changes: 1 addition & 1 deletion paddle/testing/paddle_gtest_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License. */

#include "gtest/gtest.h"
#include "paddle/fluid/framework/phi_utils.h"
#include "paddle/fluid/framework/init_default_kernel_signature_map.h"
#include "paddle/fluid/memory/allocation/allocator_strategy.h"
#include "paddle/fluid/platform/init.h"
#include "paddle/phi/core/flags.h"
Expand Down
22 changes: 1 addition & 21 deletions test/cpp/prim/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,7 @@ set(prim_generated_deps final_dygraph_function final_dygraph_node
if(WITH_CINN)
set(CINN_DEPS cinn_compiler)
endif()
cc_test_old(
test_comp_static
SRCS
test_static_prim.cc
DEPS
fleet_executor
static_utils
static_prim_api
generated_op
prim_utils
operator
elementwise_mul_op
elementwise_sub_op
fill_constant_op
activation_op
phi
static_global_utils
static_tensor_operants
generated_static_op
${CINN_DEPS}
python)
paddle_test(test_comp_static SRCS test_static_prim.cc)

if(NOT (NOT WITH_PYTHON AND ON_INFER))
if(WITH_CINN)
Expand Down
57 changes: 0 additions & 57 deletions test/cpp/prim/test_static_prim.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,46 +31,6 @@
PD_DECLARE_bool(prim_enabled);
PHI_DECLARE_string(tensor_operants_mode);

PD_DECLARE_KERNEL(full, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(tanh, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(tanh_grad, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(pow, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(scale, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(subtract, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(multiply, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(concat, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(less_equal, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(less_than, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(less_than_raw, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(equal, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(not_equal, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(greater_equal, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(greater_than, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(bitwise_and, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(bitwise_or, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(bitwise_xor, CPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(bitwise_not, CPU, ALL_LAYOUT);
#if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP)
PD_DECLARE_KERNEL(full, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(tanh, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(tanh_grad, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(pow, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(scale, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(subtract, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(multiply, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(concat, GPU, ALL_LAYOUT);
PD_DECLARE_KERNEL(less_equal, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(less_than, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(less_than_raw, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(equal, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(not_equal, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(greater_equal, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(greater_than, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(bitwise_and, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(bitwise_or, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(bitwise_xor, KPS, ALL_LAYOUT);
PD_DECLARE_KERNEL(bitwise_not, KPS, ALL_LAYOUT);
#endif
namespace paddle {
namespace prim {

Expand Down Expand Up @@ -569,20 +529,3 @@ TEST(StaticPrim, TestFlags) {

} // namespace prim
} // namespace paddle
USE_OP_ITSELF(fill_constant);
USE_OP_ITSELF(tanh);
USE_OP_ITSELF(tanh_grad);
USE_OP_ITSELF(elementwise_mul);
USE_OP_ITSELF(elementwise_sub);
USE_OP_ITSELF(elementwise_pow);
USE_OP_ITSELF(scale);
USE_OP_ITSELF(less_equal);
USE_OP_ITSELF(less_than);
USE_OP_ITSELF(equal);
USE_OP_ITSELF(not_equal);
USE_OP_ITSELF(greater_equal);
USE_OP_ITSELF(greater_than);
USE_OP_ITSELF(bitwise_xor);
USE_OP_ITSELF(bitwise_and);
USE_OP_ITSELF(bitwise_not);
USE_OP_ITSELF(bitwise_or);

0 comments on commit eea81c0

Please sign in to comment.