|
|
|
@ -62,23 +62,31 @@ class MulGradKernel : public framework::OpKernel<T> {
|
|
|
|
|
void Compute(const framework::ExecutionContext& ctx) const override {
|
|
|
|
|
int x_num_col_dims = ctx.template Attr<int>("x_num_col_dims");
|
|
|
|
|
int y_num_col_dims = ctx.template Attr<int>("y_num_col_dims");
|
|
|
|
|
const Tensor* x = ctx.Input<Tensor>("X");
|
|
|
|
|
const Tensor* y = ctx.Input<Tensor>("Y");
|
|
|
|
|
const Tensor x_matrix = x->dims().size() > 2
|
|
|
|
|
? framework::ReshapeToMatrix(*x, x_num_col_dims)
|
|
|
|
|
: *x;
|
|
|
|
|
const Tensor y_matrix = y->dims().size() > 2
|
|
|
|
|
? framework::ReshapeToMatrix(*y, y_num_col_dims)
|
|
|
|
|
: *y;
|
|
|
|
|
const Tensor* dout = ctx.Input<Tensor>(framework::GradVarName("Out"));
|
|
|
|
|
auto* x = ctx.Input<framework::LoDTensor>("X");
|
|
|
|
|
auto* y = ctx.Input<framework::LoDTensor>("Y");
|
|
|
|
|
auto x_matrix = x->dims().size() > 2
|
|
|
|
|
? framework::ReshapeToMatrix(*x, x_num_col_dims)
|
|
|
|
|
: static_cast<const Tensor&>(*x);
|
|
|
|
|
auto y_matrix = y->dims().size() > 2
|
|
|
|
|
? framework::ReshapeToMatrix(*y, y_num_col_dims)
|
|
|
|
|
: static_cast<const Tensor&>(*y);
|
|
|
|
|
auto* dout = ctx.Input<framework::LoDTensor>(framework::GradVarName("Out"));
|
|
|
|
|
|
|
|
|
|
Tensor dout_mat;
|
|
|
|
|
dout_mat.ShareDataWith(*dout);
|
|
|
|
|
dout_mat.Resize({framework::flatten_to_2d(x->dims(), x_num_col_dims)[0],
|
|
|
|
|
framework::flatten_to_2d(y->dims(), y_num_col_dims)[1]});
|
|
|
|
|
|
|
|
|
|
Tensor* dx = ctx.Output<Tensor>(framework::GradVarName("X"));
|
|
|
|
|
Tensor* dy = ctx.Output<Tensor>(framework::GradVarName("Y"));
|
|
|
|
|
auto* dx = ctx.Output<framework::LoDTensor>(framework::GradVarName("X"));
|
|
|
|
|
auto* dy = ctx.Output<framework::LoDTensor>(framework::GradVarName("Y"));
|
|
|
|
|
|
|
|
|
|
if (dx != nullptr) {
|
|
|
|
|
dx->set_lod(x->lod());
|
|
|
|
|
}
|
|
|
|
|
if (dy != nullptr) {
|
|
|
|
|
dy->set_lod(y->lod());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto& dev_ctx = ctx.template device_context<DeviceContext>();
|
|
|
|
|
auto blas = math::GetBlas<DeviceContext, T>(dev_ctx);
|
|
|
|
|
if (dx) {
|
|
|
|
|