Skip to content

Commit

Permalink
add several base unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
chenwhql committed Oct 22, 2021
1 parent 7b7e988 commit 52fead0
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 40 deletions.
2 changes: 2 additions & 0 deletions paddle/pten/hapi/include/math.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ limitations under the License. */
namespace paddle {
namespace experimental {

// TODO(chenweihang): add scale API
// TODO(chenweihang): move mean API into stat.h/cc
Tensor mean(const Tensor& x);

} // namespace experimental
Expand Down
3 changes: 3 additions & 0 deletions paddle/pten/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
cc_test(pten_backend_test SRCS backend_test.cc DEPS gtest)
cc_test(pten_data_layout_test SRCS data_layout_test.cc DEPS gtest)
cc_test(pten_data_type_test SRCS data_type_test.cc DEPS gtest)
cc_test(dense_tensor_test SRCS dense_tensor_test.cc DEPS dense_tensor)
cc_test(kernel_factory_test SRCS kernel_factory_test.cc DEPS kernel_factory)
cc_test(test_mean_api SRCS test_mean_api.cc DEPS math_api)
Expand Down
32 changes: 32 additions & 0 deletions paddle/pten/tests/backend_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,35 @@ limitations under the License. */
#include "paddle/pten/common/backend.h"

#include <gtest/gtest.h>
#include <iostream>

TEST(Backend, OStream) {
std::ostringstream oss;
oss << pten::Backend::UNDEFINED;
EXPECT_EQ(oss.str(), "Undefined");
oss.str("");
oss << pten::Backend::CPU;
EXPECT_EQ(oss.str(), "CPU");
oss.str("");
oss << pten::Backend::CUDA;
EXPECT_EQ(oss.str(), "CUDA");
oss.str("");
oss << pten::Backend::XPU;
EXPECT_EQ(oss.str(), "XPU");
oss.str("");
oss << pten::Backend::NPU;
EXPECT_EQ(oss.str(), "NPU");
oss.str("");
oss << pten::Backend::MKLDNN;
EXPECT_EQ(oss.str(), "MKLDNN");
oss.str("");
oss << pten::Backend::CUDNN;
EXPECT_EQ(oss.str(), "CUDNN");
oss.str("");
try {
oss << pten::Backend::NUM_BACKENDS;
} catch (paddle::platform::EnforceNotMet &exception) {
std::string ex_msg = exception.what();
EXPECT_TRUE(ex_msg.find("Invalid enum backend type") != std::string::npos);
}
}
44 changes: 44 additions & 0 deletions paddle/pten/tests/data_layout_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/* Copyright (c) 2021 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. */

#include <gtest/gtest.h>
#include <iostream>
#include <sstream>
#include "paddle/pten/common/layout.h"

TEST(DataLayout, OStream) {
std::ostringstream oss;
oss << pten::DataLayout::UNDEFINED;
EXPECT_EQ(oss.str(), "Undefined");
oss.str("");
oss << pten::DataLayout::ANY;
EXPECT_EQ(oss.str(), "Any");
oss.str("");
oss << pten::DataLayout::NHWC;
EXPECT_EQ(oss.str(), "NHWC");
oss.str("");
oss << pten::DataLayout::NCHW;
EXPECT_EQ(oss.str(), "NCHW");
oss.str("");
oss << pten::DataLayout::MKLDNN;
EXPECT_EQ(oss.str(), "MKLDNN");
oss.str("");
try {
oss << pten::DataLayout::NUM_DATA_LAYOUTS;
} catch (paddle::platform::EnforceNotMet &exception) {
std::string ex_msg = exception.what();
EXPECT_TRUE(ex_msg.find("Invalid enum data layout type") !=
std::string::npos);
}
}
68 changes: 68 additions & 0 deletions paddle/pten/tests/data_type_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* Copyright (c) 2021 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. */

#include "paddle/pten/common/data_type.h"

#include <gtest/gtest.h>
#include <iostream>
#include <sstream>

TEST(DataType, OStream) {
std::ostringstream oss;
oss << pten::DataType::UNDEFINED;
EXPECT_EQ(oss.str(), "Undefined");
oss.str("");
oss << pten::DataType::BOOL;
EXPECT_EQ(oss.str(), "bool");
oss.str("");
oss << pten::DataType::INT8;
EXPECT_EQ(oss.str(), "int8");
oss.str("");
oss << pten::DataType::UINT8;
EXPECT_EQ(oss.str(), "uint8");
oss.str("");
oss << pten::DataType::INT16;
EXPECT_EQ(oss.str(), "int16");
oss.str("");
oss << pten::DataType::INT32;
EXPECT_EQ(oss.str(), "int32");
oss.str("");
oss << pten::DataType::INT64;
EXPECT_EQ(oss.str(), "int64");
oss.str("");
oss << pten::DataType::BFLOAT16;
EXPECT_EQ(oss.str(), "bfloat16");
oss.str("");
oss << pten::DataType::FLOAT16;
EXPECT_EQ(oss.str(), "float16");
oss.str("");
oss << pten::DataType::FLOAT32;
EXPECT_EQ(oss.str(), "float32");
oss.str("");
oss << pten::DataType::FLOAT64;
EXPECT_EQ(oss.str(), "float64");
oss.str("");
oss << pten::DataType::COMPLEX64;
EXPECT_EQ(oss.str(), "complex64");
oss.str("");
oss << pten::DataType::COMPLEX128;
EXPECT_EQ(oss.str(), "complex128");
oss.str("");
try {
oss << pten::DataType::NUM_DATA_TYPES;
} catch (paddle::platform::EnforceNotMet &exception) {
std::string ex_msg = exception.what();
EXPECT_TRUE(ex_msg.find("Invalid enum data type") != std::string::npos);
}
}
12 changes: 0 additions & 12 deletions paddle/pten/tests/dense_tensor_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,3 @@ TEST(DenseTensor, Constructor) {
ASSERT_EQ(tensor.data_type(), pten::DataType::FLOAT32);
ASSERT_EQ(tensor.layout(), pten::DataLayout::NCHW);
}

TEST(DenseTensor, Dims) {
// impl later
}

TEST(DenseTensor, Place) {
// impl later
}

TEST(DenseTensor, Data) {
// impl later
}
13 changes: 0 additions & 13 deletions paddle/pten/tests/dtype_test.cc

This file was deleted.

28 changes: 26 additions & 2 deletions paddle/pten/tests/kernel_factory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,36 @@ 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. */

#include <iostream>
#include <sstream>

#include "paddle/pten/core/kernel_factory.h"

#include "gtest/gtest.h"

TEST(KernelFactory, KernelKey) {
// TODO(chenweihang): add more unittests later

TEST(KernelName, ConstructAndOStream) {
std::ostringstream oss;
oss << pten::KernelName("scale", "host");
EXPECT_EQ(oss.str(), "scale.host");
pten::KernelName kernel_name1("scale.host");
EXPECT_EQ(kernel_name1.name(), "scale");
EXPECT_EQ(kernel_name1.overload_name(), "host");
pten::KernelName kernel_name2("scale.host");
EXPECT_EQ(kernel_name2.name(), "scale");
EXPECT_EQ(kernel_name2.overload_name(), "host");
}

TEST(KernelKey, ConstructAndOStream) {
pten::KernelKey key(
pten::Backend::CPU, pten::DataLayout::NCHW, pten::DataType::FLOAT32);
std::cout << key;
EXPECT_EQ(key.backend(), pten::Backend::CPU);
EXPECT_EQ(key.layout(), pten::DataLayout::NCHW);
EXPECT_EQ(key.dtype(), pten::DataType::FLOAT32);
std::ostringstream oss;
oss << key;
std::cout << oss.str();
// EXPECT_EQ(oss.str(), "scale.host");
oss.flush();
}
13 changes: 0 additions & 13 deletions paddle/pten/tests/layout_test.cc

This file was deleted.

1 change: 1 addition & 0 deletions paddle/pten/tests/test_dot_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PT_DECLARE_MODULE(LinalgCUDA);
namespace framework = paddle::framework;
using DDim = paddle::framework::DDim;

// TODO(chenweihang): Remove this test after the API is used in the dygraph
TEST(API, dot) {
// 1. create tensor
auto dense_x = std::make_shared<pten::DenseTensor>(
Expand Down
1 change: 1 addition & 0 deletions paddle/pten/tests/test_fill_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PT_DECLARE_MODULE(CreationCUDA);
namespace framework = paddle::framework;
using DDim = paddle::framework::DDim;

// TODO(chenweihang): Remove this test after the API is used in the dygraph
TEST(API, full_like) {
// 1. create tensor
auto dense_x = std::make_shared<pten::DenseTensor>(
Expand Down
1 change: 1 addition & 0 deletions paddle/pten/tests/test_flatten_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PT_DECLARE_MODULE(ManipulationCUDA);
namespace framework = paddle::framework;
using DDim = paddle::framework::DDim;

// TODO(chenweihang): Remove this test after the API is used in the dygraph
TEST(API, flatten) {
// 1. create tensor
auto dense_x = std::make_shared<pten::DenseTensor>(
Expand Down
1 change: 1 addition & 0 deletions paddle/pten/tests/test_mean_api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ PT_DECLARE_MODULE(MathCUDA);
namespace framework = paddle::framework;
using DDim = paddle::framework::DDim;

// TODO(chenweihang): Remove this test after the API is used in the dygraph
TEST(API, mean) {
// 1. create tensor
auto dense_x = std::make_shared<pten::DenseTensor>(
Expand Down

1 comment on commit 52fead0

@paddle-bot-old
Copy link

@paddle-bot-old paddle-bot-old bot commented on 52fead0 Oct 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕵️ CI failures summary

🔍 PR: #34425 Commit ID: 52fead0 contains failed CI.

🔹 Failed: PR-CI-APPROVAL

approve_failed
2021-10-22 22:26:37 正在保存至: “bk.txt”
2021-10-22 22:26:37 0K 100% 2.76M=0s
2021-10-22 22:26:37 2021-10-22 22:26:37 (2.76 MB/s) - 已保存 “bk.txt” [5/5])
2021-10-22 22:26:44 ****************
2021-10-22 22:26:44 0. You must have one RD (lanxianghit (Recommend), phlrain or luotao1) approval for changing the FLAGS, which manages the environment variables.
2021-10-22 22:26:44 1. You must have Dianhai approval for change 20+ files or add than 1000+ lines of content.
2021-10-22 22:26:44 2. You must have one RD (XiaoguangHu01,chenwhql,zhiqiu,Xreki,luotao1) approval for paddle/fluid/framework/operator.h, which manages the underlying code for fluid.
2021-10-22 22:26:44 3. You must have one RD (zhiqiu (Recommend) , phlrain) approval for the changes of paddle/fluid/pybind/op_function_generator.cc, which manages the logic of automatic generating op functions for dygraph.
2021-10-22 22:26:44 4. You must have one RD (XiaoguangHu01,chenwhql,zhiqiu,Xreki,luotao1) approval for the usage of const_cast.
2021-10-22 22:26:44 5. You must have one RD (Avin0323(Recommend) or zhouwei25 or wanghuancoder or luotao1) approval for modifying unity_build_rule.cmake which the rules of Unity Build.
2021-10-22 22:26:44 There are 6 approved errors.
2021-10-22 22:26:44 ****************
2021-10-22 22:26:44 + EXCODE=6
2021-10-22 22:26:44 + echo 'EXCODE: 6'
2021-10-22 22:26:44 EXCODE: 6
2021-10-22 22:26:44 + echo 'ipipe_log_param_EXCODE: 6'
2021-10-22 22:26:44 ipipe_log_param_EXCODE: 6
2021-10-22 22:26:44 + exit 6

🔹 Failed: PR-CI-Windows

test_failed
2021-10-22 23:13:35 The following tests FAILED:
2021-10-22 23:13:35 372 - test_complex_simplenet (Timeout)
2021-10-22 23:13:35 633 - test_imperative_layers (Timeout)
2021-10-22 23:13:35 654 - test_imperative_using_non_zero_gpu (Timeout)
2021-10-22 23:13:35 1095 - test_assert (Timeout)
2021-10-22 23:13:37 Errors while running CTest
2021-10-22 23:13:37 ************************************************************************
2021-10-22 23:13:37 These unittests run 2 job each time with 1 GPU**
2021-10-22 23:13:37 ************************************************************************
2021-10-22 23:13:37 Test project C:/Users/Administrator/Downloads/workspace/1eaa9986-e475-493c-9991-d45142316e93/Paddle/build
2021-10-22 23:13:37 Start 179: im2col_test
2021-10-22 23:13:47 Start 180: vol2col_test
2021-10-22 23:13:57 1/290 Test #179: im2col_test ................................. Passed 19.73 sec
2021-10-22 23:13:57 Start 181: sequence_padding_test
2021-10-22 23:14:06 2/290 Test #180: vol2col_test ................................ Passed 19.02 sec
2021-10-22 23:14:06 Start 182: sequence_pooling_test
2021-10-22 23:14:16 3/290 Test #181: sequence_padding_test ....................... Passed 19.01 sec
2021-10-22 23:14:16 Start 211: test_analysis_predictor
2021-10-22 23:14:23 4/290 Test #182: sequence_pooling_test ....................... Passed 17.01 sec
2021-10-22 23:14:23 Start 213: zero_copy_tensor_test
2021-10-22 23:14:36 5/290 Test #213: zero_copy_tensor_test ....................... Passed 13.19 sec

🔹 Failed: PR-CI-OP-benchmark

Unknown Failed
2021-10-23 02:11:59 + echo '[tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "mean"(paddle/fluid/operators/mean_op.cu) in benchmark.'
2021-10-23 02:11:59 [tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "mean"(paddle/fluid/operators/mean_op.cu) in benchmark.
2021-10-23 02:11:59 + for op_name in '${!CHANGE_OP_MAP[@]}'
2021-10-23 02:11:59 + '[' -z '' ']'
2021-10-23 02:11:59 + exit_code=8
2021-10-23 02:11:59 + LOG '[ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.'
2021-10-23 02:11:59 + echo '[tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.'
2021-10-23 02:11:59 [tools/test_ci_op_benchmark.sh:271] [ERROR] Missing test script of "fill_any_like"(paddle/fluid/operators/fill_any_like_op.cu) in benchmark.
2021-10-23 02:11:59 + for op_name in '${!CHANGE_OP_MAP[@]}'
2021-10-23 02:11:59 + '[' -z matmul,matmul,matmul.json,True ']'
2021-10-23 02:11:59 + '[' 8 -ne 0 ']'
2021-10-23 02:11:59 + LOG '[INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.'
2021-10-23 02:11:59 + echo '[tools/test_ci_op_benchmark.sh:275] [INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.'
2021-10-23 02:11:59 [tools/test_ci_op_benchmark.sh:275] [INFO] See https://github.com/PaddlePaddle/Paddle/wiki/PR-CI-OP-benchmark-Manual for details.
2021-10-23 02:11:59 + LOG '[INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.'
2021-10-23 02:11:59 + echo '[tools/test_ci_op_benchmark.sh:276] [INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.'
2021-10-23 02:11:59 [tools/test_ci_op_benchmark.sh:276] [INFO] Or you can apply for one RD (Avin0323(Recommend), Xreki, luotao1) approval to pass this PR.
2021-10-23 02:11:59 + exit 8
2021-10-23 02:11:59 {build code state=8}

🔹 Failed: PR-CI-Coverage

coverage_failed
2021-10-23 04:07:08 + CURL_OPTS='-s --connect-timeout 600 --retry 10 --retry-delay 10'
2021-10-23 04:07:08 ++ uuid
2021-10-23 04:07:08 ++ curl -s --connect-timeout 600 --retry 10 --retry-delay 10 -u paddle:915eedab953b6f51151f50eb https://xly.bce.baidu.com/ipipe/ipipe-report/uuid
2021-10-23 04:07:08 + UPLOAD_FILE=/tmp/upload-333544f7-da42-46b8-bd61-da4bbdfed28b.tar.gz
2021-10-23 04:07:08 + echo Archiving
2021-10-23 04:07:08 Archiving
2021-10-23 04:07:08 + tar -czvf /tmp/upload-333544f7-da42-46b8-bd61-da4bbdfed28b.tar.gz .
2021-10-23 04:07:08 ./
2021-10-23 04:07:08 + du -hs /tmp/upload-333544f7-da42-46b8-bd61-da4bbdfed28b.tar.gz
2021-10-23 04:07:08 4.0K /tmp/upload-333544f7-da42-46b8-bd61-da4bbdfed28b.tar.gz
2021-10-23 04:07:08 + curl -s --connect-timeout 600 --retry 10 --retry-delay 10 -u paddle:915eedab953b6f51151f50eb -F buildId=8558874 -F path=python-coverage -F file=@/tmp/upload-333544f7-da42-46b8-bd61-da4bbdfed28b.tar.gz https://xly.bce.baidu.com/ipipe/ipipe-report/upload
2021-10-23 04:07:08 + rm -f /tmp/upload-333544f7-da42-46b8-bd61-da4bbdfed28b.tar.gz
2021-10-23 04:07:08 report uploaded
2021-10-23 04:07:08 9
2021-10-23 04:07:08 ipipe_log_param_EXCODE: 9
2021-10-23 04:07:08 Sorry, coverage check failed.
2021-10-23 04:07:08 + exit 9
2021-10-23 04:07:08 {build code state=9}
2021-10-23 04:07:18 kill agent BUILD_CODE_FAIL

Please sign in to comment.