Skip to content

Commit

Permalink
fix NPUDeviceContext in all c++ unittest (PaddlePaddle#32198)
Browse files Browse the repository at this point in the history
* fix NPUDeviceContext in all c++ unittest

* refine log

Co-authored-by: pangyoki <pangyoki@126.com>
  • Loading branch information
zhiqiu and pangyoki committed Apr 15, 2021
1 parent 62d42f0 commit b046809
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ void Compare(f::Scope *scope, const p::DeviceContext &ctx) {

TEST(check_finite_and_unscale, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx);
auto *ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx);
}

TEST(check_finite_and_unscale, NPU_fp16) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<p::float16>(&scope, ctx);
auto *ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<p::float16>(&scope, *ctx);
}
4 changes: 2 additions & 2 deletions paddle/fluid/operators/assign_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,6 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx,

TEST(assign, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx, "assign");
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx, "assign");
}
24 changes: 12 additions & 12 deletions paddle/fluid/operators/elementwise/elementwise_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ USE_OP(elementwise_sub);
USE_OP_DEVICE_KERNEL(elementwise_sub, NPU);

template <typename T>
void Compare(f::Scope* scope, const p::DeviceContext& ctx,
void Compare(f::Scope *scope, const p::DeviceContext &ctx,
std::string op_type) {
// init
auto x = scope->Var("X");
Expand Down Expand Up @@ -90,7 +90,7 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx,
}

template <typename T>
void CompareGrad(f::Scope* scope, const p::DeviceContext& ctx,
void CompareGrad(f::Scope *scope, const p::DeviceContext &ctx,
std::string op_type) {
// init
auto dout = scope->Var("DOut");
Expand Down Expand Up @@ -154,30 +154,30 @@ void CompareGrad(f::Scope* scope, const p::DeviceContext& ctx,

TEST(elementwise_add, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx, "elementwise_add");
auto *ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx, "elementwise_add");
}

TEST(elementwise_sub, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx, "elementwise_sub");
auto *ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx, "elementwise_sub");
}

TEST(elementwise_sub, NPU_fp16) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<p::float16>(&scope, ctx, "elementwise_sub");
auto *ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<p::float16>(&scope, *ctx, "elementwise_sub");
}

TEST(elementwise_sub_grad, NPU) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
CompareGrad<float>(&scope, ctx, "elementwise_sub_grad");
auto *ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
CompareGrad<float>(&scope, *ctx, "elementwise_sub_grad");
}

TEST(elementwise_add_grad, NPU) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
CompareGrad<float>(&scope, ctx, "elementwise_add_grad");
auto *ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
CompareGrad<float>(&scope, *ctx, "elementwise_add_grad");
}
4 changes: 2 additions & 2 deletions paddle/fluid/operators/expand_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx) {

TEST(expand, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx);
}
12 changes: 6 additions & 6 deletions paddle/fluid/operators/gather_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,18 @@ void CompareGrad(f::Scope* scope, const p::DeviceContext& ctx,

TEST(gather, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx, "gather");
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx, "gather");
}

TEST(gather, NPU_fp16) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<p::float16>(&scope, ctx, "gather");
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<p::float16>(&scope, *ctx, "gather");
}

TEST(gather_grad, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
CompareGrad<float>(&scope, ctx, "gather_grad");
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
CompareGrad<float>(&scope, *ctx, "gather_grad");
}
8 changes: 4 additions & 4 deletions paddle/fluid/operators/gelu_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ void CompareGrad(f::Scope* scope, const p::DeviceContext& ctx) {

TEST(gelu, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx);
}

TEST(gelu_grad, NPU) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
CompareGrad<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
CompareGrad<float>(&scope, *ctx);
}
8 changes: 4 additions & 4 deletions paddle/fluid/operators/increment_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx,

TEST(increment, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx, "increment");
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx, "increment");
}

TEST(increment, NPU_fp64) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx, "increment");
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<double>(&scope, *ctx, "increment");
}
4 changes: 2 additions & 2 deletions paddle/fluid/operators/range_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx,

TEST(range, NPU) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<int>(&scope, ctx, "range");
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<int>(&scope, *ctx, "range");
}
4 changes: 2 additions & 2 deletions paddle/fluid/operators/reduce_ops/reduce_any_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,6 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx) {

TEST(reduce_any, NPU) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<bool>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<bool>(&scope, *ctx);
}
8 changes: 4 additions & 4 deletions paddle/fluid/operators/softmax_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ void CompareGrad(f::Scope* scope, const p::DeviceContext& ctx) {

TEST(softmax, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx);
}

TEST(softmax_grad, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
CompareGrad<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
CompareGrad<float>(&scope, *ctx);
}
4 changes: 2 additions & 2 deletions paddle/fluid/operators/squeeze_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx) {

TEST(squeeze, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx);
}
8 changes: 4 additions & 4 deletions paddle/fluid/operators/transpose_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,12 @@ void CompareGrad(f::Scope* scope, const p::DeviceContext& ctx) {

TEST(transpose2, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx);
}

TEST(transpose2_grad, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
CompareGrad<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
CompareGrad<float>(&scope, *ctx);
}
4 changes: 2 additions & 2 deletions paddle/fluid/operators/unsqueeze_op_npu_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ void Compare(f::Scope* scope, const p::DeviceContext& ctx) {

TEST(unsqueeze, NPU_fp32) {
f::Scope scope;
p::NPUDeviceContext ctx(p::NPUPlace(0));
Compare<float>(&scope, ctx);
auto* ctx = p::DeviceContextPool::Instance().Get(p::NPUPlace(0));
Compare<float>(&scope, *ctx);
}
2 changes: 1 addition & 1 deletion paddle/fluid/platform/device_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ NPUDeviceContext::~NPUDeviceContext() {

void NPUDeviceContext::Wait() const {
platform::RecordEvent record_event("NPUDeviceContext/wait");
VLOG(4) << "NPU context Wait";
VLOG(4) << "NPU context(" << this << ") Wait";
stream_->Wait();
}

Expand Down

0 comments on commit b046809

Please sign in to comment.