static_backend.h 3.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
// Copyright (c) 2023 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.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#pragma once

#include <string>
#include <vector>

#include "paddle/phi/api/include/tensor.h"
21
#include "paddle/phi/common/int_array.h"
22 23 24 25 26 27

namespace paddle {
namespace primitive {
namespace backend {

using Tensor = paddle::Tensor;
28
using IntArray = paddle::experimental::IntArray;
29 30 31 32 33 34 35

template <typename T>
Tensor tanh_grad(const Tensor& out, const Tensor& grad_out);

template <typename T>
Tensor mean_grad(const Tensor& x,
                 const Tensor& out_grad,
36
                 const IntArray& axis = {},
37 38
                 bool keepdim = false,
                 bool reduce_all = false);
C
Charles-hit 已提交
39 40 41 42 43 44

template <typename T>
std::tuple<Tensor, Tensor> add_grad(const Tensor& x,
                                    const Tensor& y,
                                    const Tensor& out_grad,
                                    int axis);
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98

template <typename T>
Tensor divide(const Tensor& x, const Tensor& y);

template <typename T>
Tensor add(const Tensor& x, const Tensor& y);

template <typename T>
Tensor multiply(const Tensor& x, const Tensor& y);

template <typename T>
Tensor elementwise_pow(const Tensor& x, const Tensor& y);

template <typename T>
Tensor scale(const Tensor& x,
             const Scalar& scale = 1.0,
             float bias = 0.0,
             bool bias_after_scale = true);

template <typename T>
Tensor sum(const Tensor& x,
           const IntArray& axis = {},
           phi::DataType dtype = phi::DataType::UNDEFINED,
           bool keepdim = false);

template <typename T>
Tensor full(const IntArray& shape,
            const Scalar& value,
            phi::DataType dtype = phi::DataType::FLOAT32,
            phi::Place place = phi::CPUPlace());

template <typename T>
std::tuple<Tensor, Tensor> reshape(const Tensor& x, const IntArray& shape);

template <typename T>
Tensor expand(const Tensor& x, const IntArray& shape);

template <typename T>
Tensor tile(const Tensor& x, const IntArray& repeat_times = {});

template <typename T>
std::tuple<Tensor, Tensor> divide_grad(const Tensor& x,
                                       const Tensor& y,
                                       const Tensor& out,
                                       const Tensor& out_grad,
                                       int axis);

template <typename T>
Tensor sum_grad(const Tensor& x,
                const Tensor& out_grad,
                const IntArray& axis,
                bool keepdim,
                bool reduce_all);

99 100 101
}  // namespace backend
}  // namespace primitive
}  // namespace paddle