From 6402b59a7c3944ac56154e1b5540709c5ecb19a1 Mon Sep 17 00:00:00 2001 From: Abhinav Arora Date: Fri, 20 Apr 2018 18:37:27 -0700 Subject: [PATCH] Fix CPPLint issues in some tests in fluid/framework (#10068) * Fix CPPLint in data_device_transform_test * Fix compilation error * Fix compilation error * Fix CPPLint errors in data_layout_transform_test * Fix CPPLint errors in data_type_transform_test * Fix CPPLint errors in data_type_transform_test.cu * Fix compilation error * Fix CPPLint issues in threadpool_test * Fix CPPLInt issues in op_registry_test * Fix CPPLint issues in operator_test * Fix compilation error * test --- .../framework/data_device_transform_test.cu | 19 +- .../framework/data_layout_transform_test.cc | 41 ++-- .../framework/data_type_transform_test.cc | 126 ++++++----- .../framework/data_type_transform_test.cu | 199 +++++++++++------- paddle/fluid/framework/op_registry_test.cc | 5 +- paddle/fluid/framework/operator_test.cc | 16 +- paddle/fluid/framework/threadpool_test.cc | 8 +- 7 files changed, 240 insertions(+), 174 deletions(-) diff --git a/paddle/fluid/framework/data_device_transform_test.cu b/paddle/fluid/framework/data_device_transform_test.cu index a66525303da..df4caa45eba 100644 --- a/paddle/fluid/framework/data_device_transform_test.cu +++ b/paddle/fluid/framework/data_device_transform_test.cu @@ -103,9 +103,7 @@ static void BuildVar(const std::string& param_name, } TEST(Operator, CPUtoGPU) { - using namespace paddle::framework; - using namespace paddle::platform; - InitDevices(true); + paddle::framework::InitDevices(true); paddle::framework::Scope scope; paddle::platform::CPUPlace cpu_place; @@ -118,8 +116,9 @@ TEST(Operator, CPUtoGPU) { auto cpu_op = paddle::framework::OpRegistry::CreateOp(cpu_op_desc); // prepare input - auto* in_t = scope.Var("IN1")->GetMutable(); - auto* src_ptr = in_t->mutable_data({2, 3}, CPUPlace()); + auto* in_t = scope.Var("IN1")->GetMutable(); + auto* src_ptr = + in_t->mutable_data({2, 3}, paddle::platform::CPUPlace()); for (int i = 0; i < 2 * 3; ++i) { src_ptr[i] = static_cast(i); } @@ -128,7 +127,7 @@ TEST(Operator, CPUtoGPU) { auto* output = scope.Var("OUT1"); cpu_op->Run(scope, cpu_place); - auto* output_ptr = output->Get().data(); + auto* output_ptr = output->Get().data(); for (int i = 0; i < 2 * 3; ++i) { ASSERT_EQ(output_ptr[i], static_cast(i) * 2); } @@ -153,12 +152,14 @@ TEST(Operator, CPUtoGPU) { VLOG(3) << "after gpu_op run"; // auto* output2_ptr = output2->Get().data(); - DeviceContextPool& pool = DeviceContextPool::Instance(); + paddle::platform::DeviceContextPool& pool = + paddle::platform::DeviceContextPool::Instance(); auto dev_ctx = pool.Get(cuda_place); paddle::framework::Tensor output_tensor; - TensorCopy(output2->Get(), paddle::platform::CPUPlace(), *dev_ctx, - &output_tensor); + paddle::framework::TensorCopy(output2->Get(), + paddle::platform::CPUPlace(), *dev_ctx, + &output_tensor); dev_ctx->Wait(); float* output2_ptr = output_tensor.data(); diff --git a/paddle/fluid/framework/data_layout_transform_test.cc b/paddle/fluid/framework/data_layout_transform_test.cc index dd17cac0e10..a0d08826b85 100644 --- a/paddle/fluid/framework/data_layout_transform_test.cc +++ b/paddle/fluid/framework/data_layout_transform_test.cc @@ -18,27 +18,28 @@ #include "paddle/fluid/platform/device_context.h" TEST(DataTransform, DataLayoutFunction) { - using namespace paddle::framework; - using namespace paddle::platform; - - auto place = CPUPlace(); - Tensor in = Tensor(); - Tensor out = Tensor(); - in.mutable_data(make_ddim({2, 3, 1, 2}), place); - in.set_layout(DataLayout::kNHWC); - - auto kernel_nhwc = OpKernelType(proto::VarType::FP32, place, - DataLayout::kNHWC, LibraryType::kPlain); - auto kernel_ncwh = OpKernelType(proto::VarType::FP32, place, - DataLayout::kNCHW, LibraryType::kPlain); - - TransDataLayout(kernel_nhwc, kernel_ncwh, in, &out); - - EXPECT_TRUE(out.layout() == DataLayout::kNCHW); - EXPECT_TRUE(out.dims() == make_ddim({2, 2, 3, 1})); + auto place = paddle::platform::CPUPlace(); + paddle::framework::Tensor in = paddle::framework::Tensor(); + paddle::framework::Tensor out = paddle::framework::Tensor(); + in.mutable_data(paddle::framework::make_ddim({2, 3, 1, 2}), place); + in.set_layout(paddle::framework::DataLayout::kNHWC); + + auto kernel_nhwc = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::FP32, place, + paddle::framework::DataLayout::kNHWC, + paddle::framework::LibraryType::kPlain); + auto kernel_ncwh = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::FP32, place, + paddle::framework::DataLayout::kNCHW, + paddle::framework::LibraryType::kPlain); + + paddle::framework::TransDataLayout(kernel_nhwc, kernel_ncwh, in, &out); + + EXPECT_TRUE(out.layout() == paddle::framework::DataLayout::kNCHW); + EXPECT_TRUE(out.dims() == paddle::framework::make_ddim({2, 2, 3, 1})); TransDataLayout(kernel_ncwh, kernel_nhwc, in, &out); - EXPECT_TRUE(in.layout() == DataLayout::kNHWC); - EXPECT_TRUE(in.dims() == make_ddim({2, 3, 1, 2})); + EXPECT_TRUE(in.layout() == paddle::framework::DataLayout::kNHWC); + EXPECT_TRUE(in.dims() == paddle::framework::make_ddim({2, 3, 1, 2})); } diff --git a/paddle/fluid/framework/data_type_transform_test.cc b/paddle/fluid/framework/data_type_transform_test.cc index 6b9a8f5e28b..bbebea9f13f 100644 --- a/paddle/fluid/framework/data_type_transform_test.cc +++ b/paddle/fluid/framework/data_type_transform_test.cc @@ -17,43 +17,58 @@ limitations under the License. */ #include "gtest/gtest.h" TEST(DataTypeTransform, CPUTransform) { - using namespace paddle::framework; - using namespace paddle::platform; - - auto place = CPUPlace(); - - auto kernel_fp16 = OpKernelType(proto::VarType::FP16, place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_fp32 = OpKernelType(proto::VarType::FP32, place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_fp64 = OpKernelType(proto::VarType::FP64, place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_int32 = OpKernelType(proto::VarType::INT32, place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_int64 = OpKernelType(proto::VarType::INT64, place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_bool = OpKernelType(proto::VarType::BOOL, place, - DataLayout::kAnyLayout, LibraryType::kPlain); + auto place = paddle::platform::CPUPlace(); + + auto kernel_fp16 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::FP16, place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_fp32 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::FP32, place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_fp64 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::FP64, place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_int32 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::INT32, place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_int64 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::INT64, place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_bool = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::BOOL, place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); // data type transform from float32 { - Tensor in; - Tensor out; + paddle::framework::Tensor in; + paddle::framework::Tensor out; - float* ptr = in.mutable_data(make_ddim({2, 3}), place); + float* ptr = + in.mutable_data(paddle::framework::make_ddim({2, 3}), place); int data_number = 2 * 3; for (int i = 0; i < data_number; ++i) { ptr[i] = i / 3; } - TransDataType(kernel_fp32, kernel_fp64, in, &out); + paddle::framework::TransDataType(kernel_fp32, kernel_fp64, in, &out); double* out_data_double = out.data(); for (int i = 0; i < data_number; ++i) { EXPECT_EQ(out_data_double[i], static_cast(i / 3)); } - TransDataType(kernel_fp32, kernel_int32, in, &out); + paddle::framework::TransDataType(kernel_fp32, kernel_int32, in, &out); int* out_data_int = out.data(); for (int i = 0; i < data_number; ++i) { EXPECT_EQ(out_data_int[i], static_cast(i / 3)); @@ -62,10 +77,11 @@ TEST(DataTypeTransform, CPUTransform) { // data type transform from/to float16 { - Tensor in; - Tensor out; + paddle::framework::Tensor in; + paddle::framework::Tensor out; - float16* ptr = in.mutable_data(make_ddim({2, 3}), place); + paddle::platform::float16* ptr = in.mutable_data( + paddle::framework::make_ddim({2, 3}), place); int data_number = 2 * 3; for (int i = 0; i < data_number; ++i) { @@ -73,94 +89,104 @@ TEST(DataTypeTransform, CPUTransform) { } // transform from float16 to other data types - TransDataType(kernel_fp16, kernel_fp32, in, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_fp32, in, &out); float* out_data_float = out.data(); for (int i = 0; i < data_number; ++i) { EXPECT_EQ(out_data_float[i], static_cast(ptr[i])); } - TransDataType(kernel_fp16, kernel_fp64, in, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_fp64, in, &out); double* out_data_double = out.data(); for (int i = 0; i < data_number; ++i) { EXPECT_EQ(out_data_double[i], static_cast(ptr[i])); } - TransDataType(kernel_fp16, kernel_int32, in, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_int32, in, &out); int* out_data_int = out.data(); for (int i = 0; i < data_number; ++i) { EXPECT_EQ(out_data_int[i], static_cast(ptr[i])); } - TransDataType(kernel_fp16, kernel_int64, in, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_int64, in, &out); int64_t* out_data_int64 = out.data(); for (int i = 0; i < data_number; ++i) { EXPECT_EQ(out_data_int64[i], static_cast(ptr[i])); } - TransDataType(kernel_fp16, kernel_bool, in, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_bool, in, &out); bool* out_data_bool = out.data(); for (int i = 0; i < data_number; ++i) { EXPECT_EQ(out_data_bool[i], static_cast(ptr[i])); } // transform float to float16 - float* in_data_float = in.mutable_data(make_ddim({2, 3}), place); + float* in_data_float = + in.mutable_data(paddle::framework::make_ddim({2, 3}), place); for (int i = 0; i < data_number; ++i) { in_data_float[i] = i; } - TransDataType(kernel_fp32, kernel_fp16, in, &out); - ptr = out.data(); + paddle::framework::TransDataType(kernel_fp32, kernel_fp16, in, &out); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_float[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_float[i]).x); } // transform double to float16 - double* in_data_double = in.mutable_data(make_ddim({2, 3}), place); + double* in_data_double = + in.mutable_data(paddle::framework::make_ddim({2, 3}), place); for (int i = 0; i < data_number; ++i) { in_data_double[i] = i; } - TransDataType(kernel_fp64, kernel_fp16, in, &out); - ptr = out.data(); + paddle::framework::TransDataType(kernel_fp64, kernel_fp16, in, &out); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_double[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_double[i]).x); } // transform int to float16 - int* in_data_int = in.mutable_data(make_ddim({2, 3}), place); + int* in_data_int = + in.mutable_data(paddle::framework::make_ddim({2, 3}), place); for (int i = 0; i < data_number; ++i) { in_data_int[i] = i; } - TransDataType(kernel_int32, kernel_fp16, in, &out); - ptr = out.data(); + paddle::framework::TransDataType(kernel_int32, kernel_fp16, in, &out); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_int[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_int[i]).x); } // transform int64 to float16 - int64_t* in_data_int64 = in.mutable_data(make_ddim({2, 3}), place); + int64_t* in_data_int64 = + in.mutable_data(paddle::framework::make_ddim({2, 3}), place); for (int i = 0; i < data_number; ++i) { in_data_int64[i] = i; } - TransDataType(kernel_int64, kernel_fp16, in, &out); - ptr = out.data(); + paddle::framework::TransDataType(kernel_int64, kernel_fp16, in, &out); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_int64[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_int64[i]).x); } // transform bool to float16 - bool* in_data_bool = in.mutable_data(make_ddim({2, 3}), place); + bool* in_data_bool = + in.mutable_data(paddle::framework::make_ddim({2, 3}), place); for (int i = 0; i < data_number; ++i) { in_data_bool[i] = i; } - TransDataType(kernel_bool, kernel_fp16, in, &out); - ptr = out.data(); + paddle::framework::TransDataType(kernel_bool, kernel_fp16, in, &out); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_bool[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_bool[i]).x); } } } diff --git a/paddle/fluid/framework/data_type_transform_test.cu b/paddle/fluid/framework/data_type_transform_test.cu index de389ddabcb..0874509a879 100644 --- a/paddle/fluid/framework/data_type_transform_test.cu +++ b/paddle/fluid/framework/data_type_transform_test.cu @@ -18,42 +18,58 @@ limitations under the License. */ #include "gtest/gtest.h" TEST(DataTypeTransform, GPUTransform) { - using namespace paddle::framework; - using namespace paddle::platform; - - auto cpu_place = CPUPlace(); - auto gpu_place = CUDAPlace(0); - CUDADeviceContext context(gpu_place); - - auto kernel_fp16 = OpKernelType(proto::VarType::FP16, gpu_place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_fp32 = OpKernelType(proto::VarType::FP32, gpu_place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_fp64 = OpKernelType(proto::VarType::FP64, gpu_place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_int32 = OpKernelType(proto::VarType::INT32, gpu_place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_int64 = OpKernelType(proto::VarType::INT64, gpu_place, - DataLayout::kAnyLayout, LibraryType::kPlain); - auto kernel_bool = OpKernelType(proto::VarType::BOOL, gpu_place, - DataLayout::kAnyLayout, LibraryType::kPlain); + auto cpu_place = paddle::platform::CPUPlace(); + auto gpu_place = paddle::platform::CUDAPlace(0); + paddle::platform::CUDADeviceContext context(gpu_place); + + auto kernel_fp16 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::FP16, gpu_place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_fp32 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::FP32, gpu_place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_fp64 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::FP64, gpu_place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_int32 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::INT32, gpu_place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_int64 = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::INT64, gpu_place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); + + auto kernel_bool = paddle::framework::OpKernelType( + paddle::framework::proto::VarType::BOOL, gpu_place, + paddle::framework::DataLayout::kAnyLayout, + paddle::framework::LibraryType::kPlain); // data type transform from float32 { - Tensor in; - Tensor in_gpu; - Tensor out_gpu; - Tensor out; + paddle::framework::Tensor in; + paddle::framework::Tensor in_gpu; + paddle::framework::Tensor out_gpu; + paddle::framework::Tensor out; - float* in_ptr = in.mutable_data(make_ddim({2, 3}), cpu_place); + float* in_ptr = + in.mutable_data(paddle::framework::make_ddim({2, 3}), cpu_place); float arr[6] = {0, 1, 2, 3, 4, 5}; int data_number = sizeof(arr) / sizeof(arr[0]); memcpy(in_ptr, arr, sizeof(arr)); - TensorCopy(in, gpu_place, context, &in_gpu); + paddle::framework::TensorCopy(in, gpu_place, context, &in_gpu); context.Wait(); - TransDataType(kernel_fp32, kernel_fp64, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp32, kernel_fp64, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); double* out_data_double = out.data(); @@ -61,8 +77,9 @@ TEST(DataTypeTransform, GPUTransform) { EXPECT_EQ(out_data_double[i], static_cast(arr[i])); } - TransDataType(kernel_fp32, kernel_int32, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp32, kernel_int32, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); int* out_data_int = out.data(); @@ -73,22 +90,27 @@ TEST(DataTypeTransform, GPUTransform) { // data type transform from/to float16 { - Tensor in; - Tensor in_gpu; - Tensor out_gpu; - Tensor out; - - float16* ptr = in.mutable_data(make_ddim({2, 3}), cpu_place); - float16 arr[6] = {float16(0), float16(1), float16(2), - float16(3), float16(4), float16(5)}; + paddle::framework::Tensor in; + paddle::framework::Tensor in_gpu; + paddle::framework::Tensor out_gpu; + paddle::framework::Tensor out; + + paddle::platform::float16* ptr = in.mutable_data( + paddle::framework::make_ddim({2, 3}), cpu_place); + paddle::platform::float16 arr[6] = { + paddle::platform::float16(0), paddle::platform::float16(1), + paddle::platform::float16(2), paddle::platform::float16(3), + paddle::platform::float16(4), paddle::platform::float16(5)}; + int data_number = sizeof(arr) / sizeof(arr[0]); memcpy(ptr, arr, sizeof(arr)); - TensorCopy(in, gpu_place, context, &in_gpu); + paddle::framework::TensorCopy(in, gpu_place, context, &in_gpu); context.Wait(); // transform from float16 to other data types - TransDataType(kernel_fp16, kernel_fp32, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_fp32, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); float* out_data_float = out.data(); @@ -96,8 +118,9 @@ TEST(DataTypeTransform, GPUTransform) { EXPECT_EQ(out_data_float[i], static_cast(ptr[i])); } - TransDataType(kernel_fp16, kernel_fp64, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_fp64, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); double* out_data_double = out.data(); @@ -105,8 +128,9 @@ TEST(DataTypeTransform, GPUTransform) { EXPECT_EQ(out_data_double[i], static_cast(ptr[i])); } - TransDataType(kernel_fp16, kernel_int32, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_int32, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); int* out_data_int = out.data(); @@ -114,8 +138,9 @@ TEST(DataTypeTransform, GPUTransform) { EXPECT_EQ(out_data_int[i], static_cast(ptr[i])); } - TransDataType(kernel_fp16, kernel_int64, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_int64, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); int64_t* out_data_int64 = out.data(); @@ -123,8 +148,9 @@ TEST(DataTypeTransform, GPUTransform) { EXPECT_EQ(out_data_int64[i], static_cast(ptr[i])); } - TransDataType(kernel_fp16, kernel_bool, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp16, kernel_bool, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); bool* out_data_bool = out.data(); @@ -133,90 +159,103 @@ TEST(DataTypeTransform, GPUTransform) { } // transform float to float16 - float* in_data_float = in.mutable_data(make_ddim({2, 3}), cpu_place); + float* in_data_float = + in.mutable_data(paddle::framework::make_ddim({2, 3}), cpu_place); for (int i = 0; i < data_number; ++i) { in_data_float[i] = i; } - TensorCopy(in, gpu_place, context, &in_gpu); + paddle::framework::TensorCopy(in, gpu_place, context, &in_gpu); context.Wait(); - TransDataType(kernel_fp32, kernel_fp16, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp32, kernel_fp16, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); - ptr = out.data(); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_float[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_float[i]).x); } // transform double to float16 - double* in_data_double = - in.mutable_data(make_ddim({2, 3}), cpu_place); + double* in_data_double = in.mutable_data( + paddle::framework::make_ddim({2, 3}), cpu_place); for (int i = 0; i < data_number; ++i) { in_data_double[i] = i; } - TensorCopy(in, gpu_place, context, &in_gpu); + paddle::framework::TensorCopy(in, gpu_place, context, &in_gpu); context.Wait(); - TransDataType(kernel_fp64, kernel_fp16, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_fp64, kernel_fp16, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); - ptr = out.data(); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_double[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_double[i]).x); } // transform int to float16 - int* in_data_int = in.mutable_data(make_ddim({2, 3}), cpu_place); + int* in_data_int = + in.mutable_data(paddle::framework::make_ddim({2, 3}), cpu_place); for (int i = 0; i < data_number; ++i) { in_data_int[i] = i; } - TensorCopy(in, gpu_place, context, &in_gpu); + paddle::framework::TensorCopy(in, gpu_place, context, &in_gpu); context.Wait(); - TransDataType(kernel_int32, kernel_fp16, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_int32, kernel_fp16, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); - ptr = out.data(); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_int[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_int[i]).x); } // transform int64 to float16 - int64_t* in_data_int64 = - in.mutable_data(make_ddim({2, 3}), cpu_place); + int64_t* in_data_int64 = in.mutable_data( + paddle::framework::make_ddim({2, 3}), cpu_place); for (int i = 0; i < data_number; ++i) { in_data_int64[i] = i; } - TensorCopy(in, gpu_place, context, &in_gpu); + paddle::framework::TensorCopy(in, gpu_place, context, &in_gpu); context.Wait(); - TransDataType(kernel_int64, kernel_fp16, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_int64, kernel_fp16, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); - ptr = out.data(); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_int64[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_int64[i]).x); } // transform bool to float16 - bool* in_data_bool = in.mutable_data(make_ddim({2, 3}), cpu_place); + bool* in_data_bool = + in.mutable_data(paddle::framework::make_ddim({2, 3}), cpu_place); for (int i = 0; i < data_number; ++i) { in_data_bool[i] = i; } - TensorCopy(in, gpu_place, context, &in_gpu); + paddle::framework::TensorCopy(in, gpu_place, context, &in_gpu); context.Wait(); - TransDataType(kernel_bool, kernel_fp16, in_gpu, &out_gpu); - TensorCopy(out_gpu, cpu_place, context, &out); + paddle::framework::TransDataType(kernel_bool, kernel_fp16, in_gpu, + &out_gpu); + paddle::framework::TensorCopy(out_gpu, cpu_place, context, &out); context.Wait(); - ptr = out.data(); + ptr = out.data(); for (int i = 0; i < data_number; ++i) { - EXPECT_EQ(ptr[i].x, static_cast(in_data_bool[i]).x); + EXPECT_EQ(ptr[i].x, + static_cast(in_data_bool[i]).x); } } } diff --git a/paddle/fluid/framework/op_registry_test.cc b/paddle/fluid/framework/op_registry_test.cc index 0d791c85835..6dc4cf261ba 100644 --- a/paddle/fluid/framework/op_registry_test.cc +++ b/paddle/fluid/framework/op_registry_test.cc @@ -202,8 +202,9 @@ class CosineOpComplete : public paddle::framework::CosineOp { }; TEST(OperatorRegistrar, Test) { - using namespace paddle::framework; - OperatorRegistrar reg("cos"); + paddle::framework::OperatorRegistrar< + CosineOpComplete, paddle::framework::CosineOpProtoAndCheckerMaker> + reg("cos"); } namespace paddle { diff --git a/paddle/fluid/framework/operator_test.cc b/paddle/fluid/framework/operator_test.cc index 25f622b7252..1bf8c81469b 100644 --- a/paddle/fluid/framework/operator_test.cc +++ b/paddle/fluid/framework/operator_test.cc @@ -226,10 +226,8 @@ REGISTER_OP_CPU_KERNEL(op_multi_inputs_with_kernel, // test with multi inputs TEST(OpKernel, multi_inputs) { - using namespace paddle::framework; - paddle::framework::InitDevices(true); - proto::OpDesc op_desc; + paddle::framework::proto::OpDesc op_desc; op_desc.set_type("op_multi_inputs_with_kernel"); BuildVar("xs", {"x0", "x1", "x2"}, op_desc.add_inputs()); @@ -243,12 +241,12 @@ TEST(OpKernel, multi_inputs) { paddle::platform::CPUPlace cpu_place; paddle::framework::Scope scope; - scope.Var("x0")->GetMutable(); - scope.Var("x1")->GetMutable(); - scope.Var("x2")->GetMutable(); - scope.Var("k0")->GetMutable(); - scope.Var("y0")->GetMutable(); - scope.Var("y1")->GetMutable(); + scope.Var("x0")->GetMutable(); + scope.Var("x1")->GetMutable(); + scope.Var("x2")->GetMutable(); + scope.Var("k0")->GetMutable(); + scope.Var("y0")->GetMutable(); + scope.Var("y1")->GetMutable(); auto op = paddle::framework::OpRegistry::CreateOp(op_desc); op->Run(scope, cpu_place); diff --git a/paddle/fluid/framework/threadpool_test.cc b/paddle/fluid/framework/threadpool_test.cc index 4da83d630a5..27a4ffd4fcb 100644 --- a/paddle/fluid/framework/threadpool_test.cc +++ b/paddle/fluid/framework/threadpool_test.cc @@ -15,14 +15,14 @@ limitations under the License. */ #include #include -#include "threadpool.h" +#include "paddle/fluid/framework/threadpool.h" namespace framework = paddle::framework; -void do_sum(framework::ThreadPool* pool, std::atomic& sum, int cnt) { +void do_sum(framework::ThreadPool* pool, std::atomic* sum, int cnt) { std::vector> fs; for (int i = 0; i < cnt; ++i) { - fs.push_back(framework::Async([&sum]() { sum.fetch_add(1); })); + fs.push_back(framework::Async([sum]() { sum->fetch_add(1); })); } } @@ -46,7 +46,7 @@ TEST(ThreadPool, ConcurrentRun) { int n = 50; // sum = (n * (n + 1)) / 2 for (int i = 1; i <= n; ++i) { - std::thread t(do_sum, pool, std::ref(sum), i); + std::thread t(do_sum, pool, &sum, i); threads.push_back(std::move(t)); } for (auto& t : threads) { -- GitLab