eager.h 1.8 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13
/* 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>
14 15 16 17
// Avoid a problem with copysign defined in pyconfig.h on Windows.
#ifdef copysign
#undef copysign
#endif
18

19
#include "paddle/fluid/eager/hooks.h"
W
wanghuancoder 已提交
20 21
#include "paddle/fluid/eager/pylayer/py_layer_node.h"
#include "paddle/phi/core/dense_tensor.h"
22 23
#include "pybind11/pybind11.h"
#include "pybind11/stl.h"
W
wanghuancoder 已提交
24

25 26 27
namespace paddle {
namespace pybind {

W
wanghuancoder 已提交
28 29
typedef struct {
  PyObject_HEAD paddle::experimental::Tensor tensor;
30 31
  // Weak references
  PyObject* weakrefs;
W
wanghuancoder 已提交
32 33 34
} TensorObject;

typedef struct {
35
  PyObject_HEAD PyObject* container;
36 37
  bool container_be_packed;
  std::shared_ptr<egr::UnPackHookBase> unpack_hook;
W
wanghuancoder 已提交
38
  PyObject* non_differentiable;
39
  PyObject* not_inplace_tensors;
W
wanghuancoder 已提交
40 41 42 43 44 45
  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;

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