Skip to content

Commit

Permalink
fix the ut,test=develop, test=kunlun
Browse files Browse the repository at this point in the history
  • Loading branch information
ForFishes committed Oct 12, 2020
1 parent 5acf466 commit 09e965f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions paddle/fluid/operators/gather_op_xpu.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved.
/* Copyright (c) 2020 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.
Expand Down Expand Up @@ -87,13 +87,21 @@ class GatherGradOpXPUKernel : public framework::OpKernel<T> {
auto *index = ctx.Input<Tensor>("Index");
auto *dx = ctx.Output<Tensor>(framework::GradVarName("X"));
auto *dout = ctx.Input<Tensor>(framework::GradVarName("Out"));
auto &dev_ctx = ctx.template device_context<platform::XPUDeviceContext>();

if (ctx.HasInput("Axis")) {
PADDLE_THROW(platform::errors::InvalidArgument(
"Now, it doesn't support XPU with Axis."));
}

dx->mutable_data<T>(ctx.GetPlace());
const int zero = 0;
int r_dx = xpu::memset(dev_ctx.x_context(), dx->data<T>(), zero,
dx->numel() * sizeof(T));
PADDLE_ENFORCE_EQ(
r_dx, xpu::Error_t::SUCCESS,
platform::errors::External("XPU kernel error! error code=%d", r_dx));

if (dout->numel() == 0) {
return;
}
Expand Down Expand Up @@ -127,7 +135,6 @@ class GatherGradOpXPUKernel : public framework::OpKernel<T> {
int index_size = index_dims[0];
int slice_size = dout->numel() / dout->dims()[0];

auto &dev_ctx = ctx.template device_context<platform::XPUDeviceContext>();
int r = xpu::scatter<T>(dev_ctx.x_context(), dout->data<T>(),
index->data<int>(), index_size, slice_size,
dx->data<T>(), overwrite);
Expand Down

1 comment on commit 09e965f

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

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

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.