eager.h 1.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* Copyright (c) 2021 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 <Python.h>

15
#include "paddle/fluid/eager/hooks.h"
W
wanghuancoder 已提交
16 17
#include "paddle/fluid/eager/pylayer/py_layer_node.h"
#include "paddle/phi/core/dense_tensor.h"
18 19
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"
W
wanghuancoder 已提交
20

21 22 23
namespace paddle {
namespace pybind {

W
wanghuancoder 已提交
24 25
typedef struct {
  PyObject_HEAD paddle::experimental::Tensor tensor;
26 27
  // Weak references
  PyObject* weakrefs;
W
wanghuancoder 已提交
28 29 30
} TensorObject;

typedef struct {
31
  PyObject_HEAD PyObject* container;
32 33
  bool container_be_packed;
  std::shared_ptr<egr::UnPackHookBase> unpack_hook;
W
wanghuancoder 已提交
34
  PyObject* non_differentiable;
35
  PyObject* not_inplace_tensors;
W
wanghuancoder 已提交
36 37 38 39 40 41
  bool materialize_grads;
  std::vector<bool> forward_input_tensor_is_duplicable;
  std::vector<bool> forward_output_tensor_is_duplicable;
  std::weak_ptr<egr::GradNodePyLayer> grad_node;
} PyLayerObject;

42
void BindEager(pybind11::module* m);
J
Jack Zhou 已提交
43
void BindEagerStringTensor(pybind11::module* module);
44
void BindFunctions(PyObject* module);
W
wanghuancoder 已提交
45
void BindEagerPyLayer(PyObject* module);
46 47
void BindEagerOpFunctions(pybind11::module* module);
void BindFinalStateEagerOpFunctions(pybind11::module* module);
48 49
}  // namespace pybind
}  // namespace paddle