Skip to content

Commit b48cf17

Browse files
authored
Fix cpplint errors in transform_test.cu (#9915)
* Fix cpplint errors with transformer_test.cu * Update
1 parent b668938 commit b48cf17

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

paddle/fluid/platform/transform_test.cu

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ limitations under the License. */
1818
#include "paddle/fluid/platform/hostdevice.h"
1919
#include "paddle/fluid/platform/transform.h"
2020

21+
namespace {
22+
2123
template <typename T>
2224
class Scale {
2325
public:
2426
explicit Scale(const T& scale) : scale_(scale) {}
25-
2627
HOSTDEVICE T operator()(const T& a) const { return a * scale_; }
2728

2829
private:
@@ -35,26 +36,36 @@ class Multiply {
3536
HOSTDEVICE T operator()(const T& a, const T& b) const { return a * b; }
3637
};
3738

39+
} // namespace
40+
41+
using paddle::memory::Alloc;
42+
using paddle::memory::Free;
43+
using paddle::memory::Copy;
44+
45+
using paddle::platform::CPUPlace;
46+
using paddle::platform::CUDAPlace;
47+
using paddle::platform::CPUDeviceContext;
48+
using paddle::platform::CUDADeviceContext;
49+
50+
using paddle::platform::Transform;
51+
3852
TEST(Transform, CPUUnary) {
39-
using namespace paddle::platform;
4053
CPUDeviceContext ctx;
4154
float buf[4] = {0.1, 0.2, 0.3, 0.4};
42-
Transform<paddle::platform::CPUDeviceContext> trans;
55+
Transform<CPUDeviceContext> trans;
4356
trans(ctx, buf, buf + 4, buf, Scale<float>(10));
4457
for (int i = 0; i < 4; ++i) {
4558
ASSERT_NEAR(buf[i], static_cast<float>(i + 1), 1e-5);
4659
}
4760
}
4861

4962
TEST(Transform, GPUUnary) {
50-
using namespace paddle::platform;
51-
using namespace paddle::memory;
5263
CUDAPlace gpu0(0);
5364
CUDADeviceContext ctx(gpu0);
5465
float cpu_buf[4] = {0.1, 0.2, 0.3, 0.4};
5566
float* gpu_buf = static_cast<float*>(Alloc(gpu0, sizeof(float) * 4));
5667
Copy(gpu0, gpu_buf, CPUPlace(), cpu_buf, sizeof(cpu_buf), ctx.stream());
57-
Transform<paddle::platform::CUDADeviceContext> trans;
68+
Transform<CUDADeviceContext> trans;
5869
trans(ctx, gpu_buf, gpu_buf + 4, gpu_buf, Scale<float>(10));
5970
ctx.Wait();
6071
Copy(CPUPlace(), cpu_buf, gpu0, gpu_buf, sizeof(cpu_buf), ctx.stream());
@@ -65,10 +76,8 @@ TEST(Transform, GPUUnary) {
6576
}
6677

6778
TEST(Transform, CPUBinary) {
68-
using namespace paddle::platform;
69-
using namespace paddle::memory;
7079
int buf[4] = {1, 2, 3, 4};
71-
Transform<paddle::platform::CPUDeviceContext> trans;
80+
Transform<CPUDeviceContext> trans;
7281
CPUDeviceContext ctx;
7382
trans(ctx, buf, buf + 4, buf, buf, Multiply<int>());
7483
for (int i = 0; i < 4; ++i) {
@@ -77,14 +86,12 @@ TEST(Transform, CPUBinary) {
7786
}
7887

7988
TEST(Transform, GPUBinary) {
80-
using namespace paddle::platform;
81-
using namespace paddle::memory;
8289
int buf[4] = {1, 2, 3, 4};
8390
CUDAPlace gpu0(0);
8491
CUDADeviceContext ctx(gpu0);
8592
int* gpu_buf = static_cast<int*>(Alloc(gpu0, sizeof(buf)));
8693
Copy(gpu0, gpu_buf, CPUPlace(), buf, sizeof(buf), ctx.stream());
87-
Transform<paddle::platform::CUDADeviceContext> trans;
94+
Transform<CUDADeviceContext> trans;
8895
trans(ctx, gpu_buf, gpu_buf + 4, gpu_buf, gpu_buf, Multiply<int>());
8996
ctx.Wait();
9097
Copy(CPUPlace(), buf, gpu0, gpu_buf, sizeof(buf), ctx.stream());

0 commit comments

Comments
 (0)