diff --git a/test/cpp/phi/common/test_backend.cc b/test/cpp/phi/common/test_backend.cc index 97b5336dc17bfc..9c0b83fbc50fe2 100644 --- a/test/cpp/phi/common/test_backend.cc +++ b/test/cpp/phi/common/test_backend.cc @@ -24,29 +24,29 @@ namespace tests { TEST(Backend, OStream) { std::ostringstream oss; - oss << phi::Backend::UNDEFINED; + oss << Backend::UNDEFINED; EXPECT_EQ(oss.str(), "Undefined"); oss.str(""); - oss << phi::Backend::CPU; + oss << Backend::CPU; EXPECT_EQ(oss.str(), "CPU"); oss.str(""); - oss << phi::Backend::GPU; + oss << Backend::GPU; EXPECT_EQ(oss.str(), "GPU"); oss.str(""); - oss << phi::Backend::XPU; + oss << Backend::XPU; EXPECT_EQ(oss.str(), "XPU"); oss.str(""); - oss << phi::Backend::ONEDNN; + oss << Backend::ONEDNN; EXPECT_EQ(oss.str(), "ONEDNN"); oss.str(""); - oss << phi::Backend::GPUDNN; + oss << Backend::GPUDNN; EXPECT_EQ(oss.str(), "GPUDNN"); oss.str(""); - oss << phi::Backend::KPS; + oss << Backend::KPS; EXPECT_EQ(oss.str(), "KPS"); oss.str(""); try { - oss << phi::Backend::NUM_BACKENDS; + oss << Backend::NUM_BACKENDS; } catch (const std::exception& exception) { std::string ex_msg = exception.what(); EXPECT_TRUE(ex_msg.find("Invalid enum backend type") != std::string::npos); @@ -54,23 +54,23 @@ TEST(Backend, OStream) { } TEST(Backend, StringToBackend) { - namespace pexp = paddle::experimental; - EXPECT_EQ(phi::Backend::UNDEFINED, pexp::StringToBackend("Undefined")); - EXPECT_EQ(phi::Backend::CPU, pexp::StringToBackend("CPU")); - EXPECT_EQ(phi::Backend::GPU, pexp::StringToBackend("GPU")); - EXPECT_EQ(phi::Backend::XPU, pexp::StringToBackend("XPU")); - EXPECT_EQ(phi::Backend::ONEDNN, pexp::StringToBackend("OneDNN")); - EXPECT_EQ(phi::Backend::GPUDNN, pexp::StringToBackend("GPUDNN")); + using paddle::experimental::StringToBackend; + EXPECT_EQ(Backend::UNDEFINED, StringToBackend("Undefined")); + EXPECT_EQ(Backend::CPU, StringToBackend("CPU")); + EXPECT_EQ(Backend::GPU, StringToBackend("GPU")); + EXPECT_EQ(Backend::XPU, StringToBackend("XPU")); + EXPECT_EQ(Backend::ONEDNN, StringToBackend("OneDNN")); + EXPECT_EQ(Backend::GPUDNN, StringToBackend("GPUDNN")); #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) - EXPECT_EQ(phi::Backend::GPU, pexp::StringToBackend("KPS")); + EXPECT_EQ(Backend::GPU, StringToBackend("KPS")); #else - EXPECT_EQ(phi::Backend::KPS, pexp::StringToBackend("KPS")); + EXPECT_EQ(Backend::KPS, StringToBackend("KPS")); #endif EXPECT_EQ(static_cast( static_cast(Backend::NUM_BACKENDS) + phi::CustomRegisteredDeviceMap::Instance() .GetOrRegisterGlobalDeviceTypeId("CustomBackend")), - pexp::StringToBackend("CustomBackend")); + StringToBackend("CustomBackend")); } } // namespace tests diff --git a/test/cpp/phi/common/test_data_layout.cc b/test/cpp/phi/common/test_data_layout.cc index e267ea389f07a1..a1c7f2fbf46bd7 100644 --- a/test/cpp/phi/common/test_data_layout.cc +++ b/test/cpp/phi/common/test_data_layout.cc @@ -25,23 +25,23 @@ namespace tests { TEST(DataLayout, OStream) { std::ostringstream oss; - oss << phi::DataLayout::UNDEFINED; + oss << DataLayout::UNDEFINED; EXPECT_EQ(oss.str(), "Undefined(AnyLayout)"); oss.str(""); - oss << phi::DataLayout::ANY; + oss << DataLayout::ANY; EXPECT_EQ(oss.str(), "Undefined(AnyLayout)"); oss.str(""); - oss << phi::DataLayout::NHWC; + oss << DataLayout::NHWC; EXPECT_EQ(oss.str(), "NHWC"); oss.str(""); - oss << phi::DataLayout::NCHW; + oss << DataLayout::NCHW; EXPECT_EQ(oss.str(), "NCHW"); oss.str(""); - oss << phi::DataLayout::ONEDNN; + oss << DataLayout::ONEDNN; EXPECT_EQ(oss.str(), "ONEDNN"); oss.str(""); try { - oss << phi::DataLayout::NUM_DATA_LAYOUTS; + oss << DataLayout::NUM_DATA_LAYOUTS; } catch (const std::exception& exception) { std::string ex_msg = exception.what(); EXPECT_TRUE(ex_msg.find("Unknown Data Layout type") != std::string::npos); diff --git a/test/cpp/phi/common/test_data_type.cc b/test/cpp/phi/common/test_data_type.cc index 3bc2935b5abc82..524246f6ec2a65 100644 --- a/test/cpp/phi/common/test_data_type.cc +++ b/test/cpp/phi/common/test_data_type.cc @@ -26,50 +26,50 @@ namespace tests { TEST(DataType, OStream) { std::ostringstream oss; - oss << phi::DataType::UNDEFINED; + oss << DataType::UNDEFINED; EXPECT_EQ(oss.str(), "Undefined"); oss.str(""); - oss << phi::DataType::BOOL; + oss << DataType::BOOL; EXPECT_EQ(oss.str(), "bool"); oss.str(""); - oss << phi::DataType::INT8; + oss << DataType::INT8; EXPECT_EQ(oss.str(), "int8"); oss.str(""); - oss << phi::DataType::UINT8; + oss << DataType::UINT8; EXPECT_EQ(oss.str(), "uint8"); oss.str(""); - oss << phi::DataType::INT16; + oss << DataType::INT16; EXPECT_EQ(oss.str(), "int16"); oss.str(""); - oss << phi::DataType::INT32; + oss << DataType::INT32; EXPECT_EQ(oss.str(), "int32"); oss.str(""); - oss << phi::DataType::INT64; + oss << DataType::INT64; EXPECT_EQ(oss.str(), "int64"); oss.str(""); - oss << phi::DataType::BFLOAT16; + oss << DataType::BFLOAT16; EXPECT_EQ(oss.str(), "bfloat16"); oss.str(""); - oss << phi::DataType::FLOAT16; + oss << DataType::FLOAT16; EXPECT_EQ(oss.str(), "float16"); oss.str(""); - oss << phi::DataType::FLOAT32; + oss << DataType::FLOAT32; EXPECT_EQ(oss.str(), "float32"); oss.str(""); - oss << phi::DataType::FLOAT64; + oss << DataType::FLOAT64; EXPECT_EQ(oss.str(), "float64"); oss.str(""); - oss << phi::DataType::COMPLEX64; + oss << DataType::COMPLEX64; EXPECT_EQ(oss.str(), "complex64"); oss.str(""); - oss << phi::DataType::COMPLEX128; + oss << DataType::COMPLEX128; EXPECT_EQ(oss.str(), "complex128"); oss.str(""); - oss << phi::DataType::PSTRING; + oss << DataType::PSTRING; EXPECT_EQ(oss.str(), "pstring"); oss.str(""); try { - oss << phi::DataType::NUM_DATA_TYPES; + oss << DataType::NUM_DATA_TYPES; } catch (const std::exception& exception) { std::string ex_msg = exception.what(); EXPECT_TRUE(ex_msg.find("Invalid enum data type") != std::string::npos); @@ -77,18 +77,13 @@ TEST(DataType, OStream) { } TEST(TypeTraits, Complex) { - EXPECT_EQ(phi::dtype::ToReal(phi::DataType::COMPLEX64), - phi::DataType::FLOAT32); - EXPECT_EQ(phi::dtype::ToReal(phi::DataType::COMPLEX128), - phi::DataType::FLOAT64); - EXPECT_EQ(phi::dtype::ToReal(phi::DataType::FLOAT32), phi::DataType::FLOAT32); + EXPECT_EQ(dtype::ToReal(DataType::COMPLEX64), DataType::FLOAT32); + EXPECT_EQ(dtype::ToReal(DataType::COMPLEX128), DataType::FLOAT64); + EXPECT_EQ(dtype::ToReal(DataType::FLOAT32), DataType::FLOAT32); - EXPECT_EQ(phi::dtype::ToComplex(phi::DataType::FLOAT32), - phi::DataType::COMPLEX64); - EXPECT_EQ(phi::dtype::ToComplex(phi::DataType::FLOAT64), - phi::DataType::COMPLEX128); - EXPECT_EQ(phi::dtype::ToComplex(phi::DataType::COMPLEX64), - phi::DataType::COMPLEX64); + EXPECT_EQ(dtype::ToComplex(DataType::FLOAT32), DataType::COMPLEX64); + EXPECT_EQ(dtype::ToComplex(DataType::FLOAT64), DataType::COMPLEX128); + EXPECT_EQ(dtype::ToComplex(DataType::COMPLEX64), DataType::COMPLEX64); } } // namespace tests diff --git a/test/cpp/phi/common/test_int_array.cc b/test/cpp/phi/common/test_int_array.cc index 9c32877c9e7f52..3caf2d7123465b 100644 --- a/test/cpp/phi/common/test_int_array.cc +++ b/test/cpp/phi/common/test_int_array.cc @@ -31,10 +31,9 @@ namespace tests { TEST(IntArray, ConstructFromCPUDenseTensor) { auto& pool = paddle::experimental::DeviceContextPool::Instance(); - const auto* dev_ctx = - static_cast(pool.Get(CPUPlace())); - phi::DenseTensor shape = Full(*dev_ctx, {2}, 3); - phi::DenseTensor out = Full(*dev_ctx, shape, 1); + const auto* dev_ctx = static_cast(pool.Get(CPUPlace())); + DenseTensor shape = Full(*dev_ctx, {2}, 3); + DenseTensor out = Full(*dev_ctx, shape, 1); ASSERT_EQ(out.dims().size(), 2); ASSERT_EQ(out.dims()[0], 3); ASSERT_EQ(out.dims()[1], 3); @@ -43,12 +42,11 @@ TEST(IntArray, ConstructFromCPUDenseTensor) { TEST(IntArray, ConstructFromCPUDenseTensorVector) { auto& pool = paddle::experimental::DeviceContextPool::Instance(); - const auto* dev_ctx = - static_cast(pool.Get(CPUPlace())); - phi::DenseTensor shape0 = Full(*dev_ctx, {1}, 3); - phi::DenseTensor shape1 = Full(*dev_ctx, {1}, 3); - std::vector shape{shape0, shape1}; - phi::DenseTensor out = Full(*dev_ctx, shape, 1); + const auto* dev_ctx = static_cast(pool.Get(CPUPlace())); + DenseTensor shape0 = Full(*dev_ctx, {1}, 3); + DenseTensor shape1 = Full(*dev_ctx, {1}, 3); + std::vector shape{shape0, shape1}; + DenseTensor out = Full(*dev_ctx, shape, 1); ASSERT_EQ(out.dims().size(), 2); ASSERT_EQ(out.dims()[0], 3); ASSERT_EQ(out.dims()[1], 3); @@ -99,8 +97,8 @@ TEST(IntArray, ConstructFromGPUDenseTensor) { auto& pool = paddle::experimental::DeviceContextPool::Instance(); const auto* dev_ctx = static_cast(pool.Get(GPUPlace())); - phi::DenseTensor shape = Full(*dev_ctx, {2}, 3); - phi::DenseTensor out = Full(*dev_ctx, shape, 1); + DenseTensor shape = Full(*dev_ctx, {2}, 3); + DenseTensor out = Full(*dev_ctx, shape, 1); ASSERT_EQ(out.dims().size(), 2); ASSERT_EQ(out.dims()[0], 3); ASSERT_EQ(out.dims()[1], 3); @@ -111,10 +109,10 @@ TEST(IntArray, ConstructFromGPUDenseTensorVector) { auto& pool = paddle::experimental::DeviceContextPool::Instance(); const auto* dev_ctx = static_cast(pool.Get(GPUPlace())); - phi::DenseTensor shape0 = Full(*dev_ctx, {1}, 3); - phi::DenseTensor shape1 = Full(*dev_ctx, {1}, 3); - std::vector shape{shape0, shape1}; - phi::DenseTensor out = Full(*dev_ctx, shape, 1); + DenseTensor shape0 = Full(*dev_ctx, {1}, 3); + DenseTensor shape1 = Full(*dev_ctx, {1}, 3); + std::vector shape{shape0, shape1}; + DenseTensor out = Full(*dev_ctx, shape, 1); ASSERT_EQ(out.dims().size(), 2); ASSERT_EQ(out.dims()[0], 3); ASSERT_EQ(out.dims()[1], 3); diff --git a/test/cpp/phi/common/test_place.cc b/test/cpp/phi/common/test_place.cc index 7ca30f796a49b1..f62a2bd11ccf61 100644 --- a/test/cpp/phi/common/test_place.cc +++ b/test/cpp/phi/common/test_place.cc @@ -21,58 +21,58 @@ namespace phi { namespace tests { TEST(PhiPlace, place) { - phi::Place place; - EXPECT_EQ(place.GetType(), phi::AllocationType::UNDEFINED); + Place place; + EXPECT_EQ(place.GetType(), AllocationType::UNDEFINED); - place.Reset(phi::AllocationType::GPU, 1); - EXPECT_EQ(place.GetType(), phi::AllocationType::GPU); + place.Reset(AllocationType::GPU, 1); + EXPECT_EQ(place.GetType(), AllocationType::GPU); EXPECT_EQ(place.GetDeviceId(), 1); } TEST(Place, cpu_place) { - phi::CPUPlace place; - EXPECT_EQ(place.GetType(), phi::AllocationType::CPU); + CPUPlace place; + EXPECT_EQ(place.GetType(), AllocationType::CPU); std::cout << "cpu place repr: " << place << std::endl; } TEST(Place, gpu_place) { - phi::GPUPlace place; - EXPECT_EQ(place.GetType(), phi::AllocationType::GPU); + GPUPlace place; + EXPECT_EQ(place.GetType(), AllocationType::GPU); EXPECT_EQ(place.GetDeviceId(), 0); - phi::GPUPlace place1(2); - EXPECT_EQ(place1.GetType(), phi::AllocationType::GPU); + GPUPlace place1(2); + EXPECT_EQ(place1.GetType(), AllocationType::GPU); EXPECT_EQ(place1.GetDeviceId(), 2); std::cout << "gpu place repr: " << place1 << std::endl; - phi::GPUPinnedPlace place2; - EXPECT_EQ(place2.GetType(), phi::AllocationType::GPUPINNED); + GPUPinnedPlace place2; + EXPECT_EQ(place2.GetType(), AllocationType::GPUPINNED); std::cout << "gpu pinned place repr: " << place2 << std::endl; - EXPECT_NE(place2, phi::CPUPlace()); + EXPECT_NE(place2, CPUPlace()); } TEST(Place, convert_place) { - phi::Place base_place(phi::AllocationType::CPU); - phi::CPUPlace cpu_place = base_place; + Place base_place(AllocationType::CPU); + CPUPlace cpu_place = base_place; EXPECT_EQ(cpu_place.GetType(), base_place.GetType()); - base_place.Reset(phi::AllocationType::GPU, 2); - phi::GPUPlace gpu_place = base_place; + base_place.Reset(AllocationType::GPU, 2); + GPUPlace gpu_place = base_place; EXPECT_EQ(gpu_place.GetType(), base_place.GetType()); EXPECT_EQ(gpu_place.GetDeviceId(), base_place.GetDeviceId()); - phi::Place place = gpu_place; + Place place = gpu_place; EXPECT_EQ(gpu_place.GetType(), place.GetType()); EXPECT_EQ(gpu_place.GetDeviceId(), place.GetDeviceId()); place = cpu_place; EXPECT_EQ(cpu_place.GetType(), place.GetType()); - std::map maps; - maps[phi::CPUPlace()] = 1; - maps[phi::GPUPlace(0)] = 2; - maps[phi::GPUPlace(1)] = 3; - maps[phi::GPUPlace(2)] = 4; - maps[phi::GPUPlace(3)] = 5; - maps[phi::GPUPinnedPlace()] = 6; + std::map maps; + maps[CPUPlace()] = 1; + maps[GPUPlace(0)] = 2; + maps[GPUPlace(1)] = 3; + maps[GPUPlace(2)] = 4; + maps[GPUPlace(3)] = 5; + maps[GPUPinnedPlace()] = 6; for (auto& map_item : maps) { std::cout << map_item.first << ":" << map_item.second << std::endl; } diff --git a/test/cpp/phi/common/test_scalar.cc b/test/cpp/phi/common/test_scalar.cc index b90cd0d1b288e3..43adcaf2b43865 100644 --- a/test/cpp/phi/common/test_scalar.cc +++ b/test/cpp/phi/common/test_scalar.cc @@ -130,7 +130,7 @@ TEST(Scalar, Equality) { TEST(Scalar, WrapAsScalars) { std::vector v{1, 2, 3}; auto out = paddle::experimental::WrapAsScalars(v); - ASSERT_EQ(out[0].dtype(), phi::DataType::INT32); + ASSERT_EQ(out[0].dtype(), DataType::INT32); ASSERT_EQ(out[0].to(), 1); ASSERT_EQ(out[1].to(), 2); ASSERT_EQ(out[2].to(), 3); diff --git a/test/cpp/phi/common/test_scalar.cu b/test/cpp/phi/common/test_scalar.cu index b1748e957c565e..f3d924926690e8 100644 --- a/test/cpp/phi/common/test_scalar.cu +++ b/test/cpp/phi/common/test_scalar.cu @@ -29,11 +29,6 @@ limitations under the License. */ namespace phi { namespace tests { -using DDim = phi::DDim; -using float16 = phi::dtype::float16; -using complex64 = ::phi::dtype::complex; -using complex128 = ::phi::dtype::complex; - __global__ void FillTensor(float* data) { data[0] = 1; } TEST(Scalar, ConstructFromDenseTensor1) { diff --git a/test/cpp/phi/common/transform_test.cu b/test/cpp/phi/common/transform_test.cu index 8326160d881b61..84e65e2c94cc3b 100644 --- a/test/cpp/phi/common/transform_test.cu +++ b/test/cpp/phi/common/transform_test.cu @@ -20,6 +20,7 @@ limitations under the License. */ #include "paddle/phi/backends/context_pool.h" #include "paddle/phi/common/memory_utils.h" +namespace phi { template class Scale { public: @@ -36,13 +37,6 @@ class Multiply { HOSTDEVICE T operator()(const T& a, const T& b) const { return a * b; } }; -using phi::CPUContext; -using phi::CPUPlace; -using phi::GPUContext; -using phi::GPUPlace; - -using phi::Transform; - TEST(Transform, CPUUnary) { CPUContext ctx; float buf[4] = {0.1, 0.2, 0.3, 0.4}; @@ -55,18 +49,18 @@ TEST(Transform, CPUUnary) { TEST(Transform, GPUUnary) { GPUPlace gpu0(0); - phi::DeviceContextPool& pool = phi::DeviceContextPool::Instance(); - auto* ctx = reinterpret_cast(pool.Get(phi::GPUPlace())); + DeviceContextPool& pool = DeviceContextPool::Instance(); + auto* ctx = reinterpret_cast(pool.Get(GPUPlace())); float cpu_buf[4] = {0.1, 0.2, 0.3, 0.4}; - auto gpu_allocation = phi::memory_utils::Alloc(gpu0, sizeof(float) * 4); + auto gpu_allocation = memory_utils::Alloc(gpu0, sizeof(float) * 4); float* gpu_buf = static_cast(gpu_allocation->ptr()); - phi::memory_utils::Copy( + memory_utils::Copy( gpu0, gpu_buf, CPUPlace(), cpu_buf, sizeof(cpu_buf), ctx->stream()); - Transform trans; + Transform trans; trans(*ctx, gpu_buf, gpu_buf + 4, gpu_buf, Scale(10)); ctx->Wait(); - phi::memory_utils::Copy( + memory_utils::Copy( CPUPlace(), cpu_buf, gpu0, gpu_buf, sizeof(cpu_buf), ctx->stream()); for (int i = 0; i < 4; ++i) { ASSERT_NEAR(cpu_buf[i], static_cast(i + 1), 1e-5); @@ -75,8 +69,8 @@ TEST(Transform, GPUUnary) { TEST(Transform, CPUBinary) { int buf[4] = {1, 2, 3, 4}; - Transform trans; - phi::CPUContext ctx; + Transform trans; + CPUContext ctx; trans(ctx, buf, buf + 4, buf, buf, Multiply()); for (int i = 0; i < 4; ++i) { ASSERT_EQ((i + 1) * (i + 1), buf[i]); @@ -86,19 +80,20 @@ TEST(Transform, CPUBinary) { TEST(Transform, GPUBinary) { int buf[4] = {1, 2, 3, 4}; GPUPlace gpu0(0); - phi::DeviceContextPool& pool = phi::DeviceContextPool::Instance(); - auto* ctx = reinterpret_cast(pool.Get(phi::GPUPlace())); + DeviceContextPool& pool = DeviceContextPool::Instance(); + auto* ctx = reinterpret_cast(pool.Get(GPUPlace())); - auto gpu_allocation = phi::memory_utils::Alloc(gpu0, sizeof(buf)); + auto gpu_allocation = memory_utils::Alloc(gpu0, sizeof(buf)); int* gpu_buf = static_cast(gpu_allocation->ptr()); - phi::memory_utils::Copy( + memory_utils::Copy( gpu0, gpu_buf, CPUPlace(), buf, sizeof(buf), ctx->stream()); - Transform trans; + Transform trans; trans(*ctx, gpu_buf, gpu_buf + 4, gpu_buf, gpu_buf, Multiply()); ctx->Wait(); - phi::memory_utils::Copy( + memory_utils::Copy( CPUPlace(), buf, gpu0, gpu_buf, sizeof(buf), ctx->stream()); for (int i = 0; i < 4; ++i) { ASSERT_EQ((i + 1) * (i + 1), buf[i]); } } +} // namespace phi