Skip to content

Commit

Permalink
【paddle_test No.16】replace parts of cc_test with paddle_test (#61672)
Browse files Browse the repository at this point in the history
* Update test_quantization_scale_pass.py

* Update test_rnn_decode_api.py

* Update test_save_inference_model.py

* Update test_seq2seq.py

* Update test_static_save_load.py

* Update CMakeLists.txt

* mv PD_DECLARE and USE_OP_ITSELF in test_mkldnn_op_inplace.cc

* Update CMakeLists.txt

* add test_API and rm USE_PASS

* add test_API

* rollback

* Update graph.h

* Apply suggestions from code review

* Update CMakeLists.txt

* delete use_it_self of conv2 in test_conv_mkldnn_nhwc.cc

* Update CMakeLists.txt

* add TEST_API and rm use_it_self

* Update CMakeLists.txt

* Update test_mkldnn_pool_adaptive_op.cc

* Update CMakeLists.txt

* add TEST_API and rm use-op-self

* Update CMakeLists.txt
  • Loading branch information
Liyulingyue authored Feb 20, 2024
1 parent 54af517 commit c94178f
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 107 deletions.
2 changes: 1 addition & 1 deletion paddle/fluid/framework/ir/graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ namespace ir {
class Graph {
public:
// Construct a main_graph with some sub_graphs
explicit Graph(const ProgramDesc &program);
TEST_API explicit Graph(const ProgramDesc &program);

// Construct a main_graph with some sub_graphs, and the 1st sub_graph is
// constructed with ops[start_op_index, end_op_index)
Expand Down
4 changes: 2 additions & 2 deletions paddle/fluid/framework/ir/pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class Pass {

std::string Type() const { return type_; }

Graph *Apply(Graph *graph) const;
TEST_API Graph *Apply(Graph *graph) const;

// Get a reference to the attributed previously set.
template <typename AttrType>
Expand Down Expand Up @@ -238,7 +238,7 @@ class Registrar {

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

bool Has(const std::string &pass_type) const {
return map_.find(pass_type) != map_.end();
Expand Down
6 changes: 3 additions & 3 deletions paddle/phi/backends/onednn/onednn_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class OneDNNContextThreadLocals {
size_t get_cur_mkldnn_session_id(void);
void set_cur_input_shape_str(std::string input_shape_str);
void set_cur_input_shape_cache_capacity(int input_shape_cache_capacity);
void set_cur_paddle_data_layout(DataLayout dl);
TEST_API void set_cur_paddle_data_layout(DataLayout dl);
DataLayout get_cur_paddle_data_layout(void);
void log_lib_version(void);
const dnnl::engine& get_engine(void) { return cur_engine; }
Expand All @@ -77,7 +77,7 @@ class OneDNNContextThreadLocals {
static constexpr size_t kMKLDNNSessionID_Default = 0;
// mkldnn session id for cache clearing mode
static constexpr size_t kMKLDNNSessionID_CacheClearing = -1;
static Body& fetch();
TEST_API static Body& fetch();
};

class OneDNNContext : public CPUContext {
Expand Down Expand Up @@ -114,7 +114,7 @@ class OneDNNContext : public CPUContext {
const dnnl::engine& GetEngine() const { return tls().get_engine(); }

// Remove all entries from the blob map
void ResetBlobMap(void* ptr);
TEST_API void ResetBlobMap(void* ptr);

// Prevent next ResetBlobMap()
void BlockNextCacheClearing();
Expand Down
76 changes: 6 additions & 70 deletions test/cpp/fluid/mkldnn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,44 +1,8 @@
get_property(paddle_lib GLOBAL PROPERTY PADDLE_LIB_NAME)
cc_test(
test_mkldnn_op_inplace
SRCS test_mkldnn_op_inplace.cc
DEPS executor
op_registry
elementwise_add_op
activation_op
phi
common
scope
device_context
enforce
generated_static_op)
cc_test(
test_mkldnn_cpu_quantize_pass
SRCS test_mkldnn_cpu_quantize_pass.cc
DEPS executor
op_registry
activation_op
conv_activation_mkldnn_fuse_pass
cpu_quantize_placement_pass
cpu_quantize_pass
phi
common
scope
device_context)
paddle_test(test_mkldnn_op_inplace SRCS test_mkldnn_op_inplace.cc)
paddle_test(test_mkldnn_cpu_quantize_pass SRCS test_mkldnn_cpu_quantize_pass.cc)

cc_test(
test_conv_mkldnn_nhwc
SRCS test_conv_mkldnn_nhwc.cc
DEPS executor
op_registry
depthwise_conv
tensor
phi
common
scope
device_context
enforce
generated_static_op)
paddle_test(test_conv_mkldnn_nhwc SRCS test_conv_mkldnn_nhwc.cc)

set(TEST_MKLDNN_CACHING_DEPS
op_registry
Expand All @@ -55,43 +19,15 @@ set(TEST_MKLDNN_CACHING_DEPS
if(WITH_GPU OR WITH_ROCM)
set(TEST_MKLDNN_CACHING_DEPS ${TEST_MKLDNN_CACHING_DEPS} depthwise_conv)
endif()
cc_test(
test_mkldnn_caching
SRCS test_mkldnn_caching.cc
DEPS ${TEST_MKLDNN_CACHING_DEPS})
paddle_test(test_mkldnn_caching SRCS test_mkldnn_caching.cc)

if(WITH_TESTING)
paddle_test(test_mkldnn_op_nhwc SRCS test_mkldnn_op_nhwc.cc)
endif()

cc_test(
test_mkldnn_pool_adaptive_op
SRCS test_mkldnn_pool_adaptive_op.cc
DEPS fleet_executor
conditional_block_op
executor
op_registry
generated_static_op
generated_op
phi
common
scope
device_context
enforce)
paddle_test(test_mkldnn_pool_adaptive_op SRCS test_mkldnn_pool_adaptive_op.cc)

cc_test(
test_mkldnn_squeeze
SRCS test_mkldnn_squeeze.cc
DEPS fleet_executor
conditional_block_op
executor
op_registry
generated_static_op
generated_op
phi
scope
device_context
enforce)
paddle_test(test_mkldnn_squeeze SRCS test_mkldnn_squeeze.cc)

if(WITH_ONNXRUNTIME AND WIN32)
# Copy onnxruntime for some c++ test in Windows, since the test will
Expand Down
3 changes: 0 additions & 3 deletions test/cpp/fluid/mkldnn/test_conv_mkldnn_nhwc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/kernel_registry.h"

USE_OP_ITSELF(conv2d);
PD_DECLARE_KERNEL(conv2d, OneDNN, ONEDNN);

template <typename DataType>
void AddVarToScope(const std::string var_name,
paddle::framework::Scope* scope,
Expand Down
11 changes: 0 additions & 11 deletions test/cpp/fluid/mkldnn/test_mkldnn_caching.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,6 @@
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/kernel_registry.h"

USE_OP_ITSELF(elementwise_add);
PD_DECLARE_KERNEL(add_raw, OneDNN, ONEDNN);
USE_OP_ITSELF(elementwise_mul);
PD_DECLARE_KERNEL(multiply_raw, OneDNN, ONEDNN);
USE_OP_ITSELF(relu);
PD_DECLARE_KERNEL(relu, OneDNN, ONEDNN);
USE_OP_ITSELF(softmax);
PD_DECLARE_KERNEL(softmax, OneDNN, ONEDNN);
USE_OP_ITSELF(conv2d);
PD_DECLARE_KERNEL(conv2d, OneDNN, ONEDNN);

namespace paddle {
namespace operators {

Expand Down
4 changes: 0 additions & 4 deletions test/cpp/fluid/mkldnn/test_mkldnn_cpu_quantize_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,3 @@ TEST(cpuQuantizePass, ConvReLU6) {

} // namespace pass
} // namespace paddle

USE_PASS(conv_activation_mkldnn_fuse_pass);
USE_PASS(cpu_quantize_placement_pass);
USE_PASS(cpu_quantize_pass);
6 changes: 0 additions & 6 deletions test/cpp/fluid/mkldnn/test_mkldnn_op_inplace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@
#include "paddle/phi/core/enforce.h"
#include "paddle/phi/core/kernel_registry.h"

USE_OP_ITSELF(elementwise_add);
PD_DECLARE_KERNEL(add_raw, OneDNN, ONEDNN);
USE_OP_ITSELF(relu);
PD_DECLARE_KERNEL(relu, OneDNN, ONEDNN);
USE_OP_ITSELF(softmax);
PD_DECLARE_KERNEL(softmax, OneDNN, ONEDNN);
PD_DECLARE_KERNEL(softmax, CPU, ALL_LAYOUT);

namespace paddle {
namespace operators {
Expand Down
4 changes: 0 additions & 4 deletions test/cpp/fluid/mkldnn/test_mkldnn_pool_adaptive_op.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,3 @@ TEST(Pool2dOpConverter, avg_ceil_test) { test_pool2d(true, true, "avg"); }
} // namespace tensorrt
} // namespace inference
} // namespace paddle

USE_OP_ITSELF(pool2d);
PD_DECLARE_KERNEL(pool2d, OneDNN, ONEDNN);
PD_DECLARE_KERNEL(pool2d, CPU, ALL_LAYOUT);
3 changes: 0 additions & 3 deletions test/cpp/fluid/mkldnn/test_mkldnn_squeeze.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,3 @@ TEST(SqueezeOpConverter_2, normal) { test_squeeze2(); }
} // namespace tensorrt
} // namespace inference
} // namespace paddle

USE_OP_ITSELF(squeeze2);
PD_DECLARE_KERNEL(squeeze_infer, OneDNN, ONEDNN);

0 comments on commit c94178f

Please sign in to comment.