| 
 | 1 | +/* Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.  | 
 | 2 | +
  | 
 | 3 | +Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 4 | +you may not use this file except in compliance with the License.  | 
 | 5 | +You may obtain a copy of the License at  | 
 | 6 | +
  | 
 | 7 | +    http://www.apache.org/licenses/LICENSE-2.0  | 
 | 8 | +
  | 
 | 9 | +Unless required by applicable law or agreed to in writing, software  | 
 | 10 | +distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 12 | +See the License for the specific language governing permissions and  | 
 | 13 | +limitations under the License. */  | 
 | 14 | + | 
 | 15 | +#pragma once  | 
 | 16 | + | 
 | 17 | +#include "paddle/phi/core/dense_tensor.h"  | 
 | 18 | +#include "paddle/phi/core/sparse_coo_tensor.h"  | 
 | 19 | +#include "paddle/phi/core/sparse_csr_tensor.h"  | 
 | 20 | + | 
 | 21 | +namespace phi {  | 
 | 22 | +namespace sparse {  | 
 | 23 | + | 
 | 24 | +// TODO(zhouwei25): implement Backward of " COO + COO @ COO -> COO"  | 
 | 25 | +template <typename T, typename Context>  | 
 | 26 | +void AddmmCooCooGradKernel(const Context& dev_ctx,  | 
 | 27 | +                           const SparseCooTensor& input,  | 
 | 28 | +                           const SparseCooTensor& x,  | 
 | 29 | +                           const SparseCooTensor& y,  | 
 | 30 | +                           const SparseCooTensor& dout,  | 
 | 31 | +                           float alpha,  | 
 | 32 | +                           float beta,  | 
 | 33 | +                           SparseCooTensor* dinput,  | 
 | 34 | +                           SparseCooTensor* dx,  | 
 | 35 | +                           SparseCooTensor* dy);  | 
 | 36 | + | 
 | 37 | +// Backward of "DENSE + COO @ DENSE -> DENSE"  | 
 | 38 | +template <typename T, typename Context>  | 
 | 39 | +void AddmmCooDenseGradKernel(const Context& dev_ctx,  | 
 | 40 | +                             const DenseTensor& input,  | 
 | 41 | +                             const SparseCooTensor& x,  | 
 | 42 | +                             const DenseTensor& y,  | 
 | 43 | +                             const DenseTensor& dout,  | 
 | 44 | +                             float alpha,  | 
 | 45 | +                             float beta,  | 
 | 46 | +                             DenseTensor* dinput,  | 
 | 47 | +                             SparseCooTensor* dx,  | 
 | 48 | +                             DenseTensor* dy);  | 
 | 49 | + | 
 | 50 | +// TODO(zhouwei25): implement Backward of " CSR + CSR @ CSR -> CSR"  | 
 | 51 | +template <typename T, typename Context>  | 
 | 52 | +void AddmmCsrCsrGradKernel(const Context& dev_ctx,  | 
 | 53 | +                           const SparseCsrTensor& input,  | 
 | 54 | +                           const SparseCsrTensor& x,  | 
 | 55 | +                           const SparseCsrTensor& y,  | 
 | 56 | +                           const SparseCsrTensor& dout,  | 
 | 57 | +                           float alpha,  | 
 | 58 | +                           float beta,  | 
 | 59 | +                           SparseCsrTensor* dinput,  | 
 | 60 | +                           SparseCsrTensor* dx,  | 
 | 61 | +                           SparseCsrTensor* dy);  | 
 | 62 | + | 
 | 63 | +/* Backward of "DENSE + CSR @ DENSE -> DENSE" */  | 
 | 64 | +template <typename T, typename Context>  | 
 | 65 | +void AddmmCsrDenseGradKernel(const Context& dev_ctx,  | 
 | 66 | +                             const DenseTensor& input,  | 
 | 67 | +                             const SparseCsrTensor& x,  | 
 | 68 | +                             const DenseTensor& y,  | 
 | 69 | +                             const DenseTensor& dout,  | 
 | 70 | +                             float alpha,  | 
 | 71 | +                             float beta,  | 
 | 72 | +                             DenseTensor* dinput,  | 
 | 73 | +                             SparseCsrTensor* dx,  | 
 | 74 | +                             DenseTensor* dy);  | 
 | 75 | + | 
 | 76 | +}  // namespace sparse  | 
 | 77 | +}  // namespace phi  | 
0 commit comments