imperative.cc 2.2 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* Copyright (c) 2018 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. */

#include "paddle/fluid/pybind/imperative.h"
#include "paddle/fluid/framework/block_desc.h"
#include "paddle/fluid/imperative/tracer.h"
M
minqiyang 已提交
18
#include "paddle/fluid/imperative/type_defs.h"
19 20 21 22 23

namespace paddle {
namespace pybind {

// Bind Methods
M
minqiyang 已提交
24
void BindTracer(pybind11::module* m) {
25 26
  pybind11::class_<imperative::Tracer>(*m, "Tracer", "")
      .def("__init__",
M
minqiyang 已提交
27
           [](imperative::Tracer& self, framework::BlockDesc* root_block) {
M
minqiyang 已提交
28
             new (&self) imperative::Tracer(root_block);
29
           })
M
minqiyang 已提交
30 31 32 33 34 35 36
      .def("trace",
           [](imperative::Tracer& self, imperative::OpBase* op,
              const imperative::VarBasePtrMap& inputs,
              const imperative::VarBasePtrMap& outputs,
              framework::BlockDesc* block,
              const platform::CPUPlace expected_place,
              const bool stop_gradient = false) {
M
minqiyang 已提交
37 38
             return self.Trace(op, inputs, outputs, block, expected_place,
                               stop_gradient);
M
minqiyang 已提交
39 40 41 42 43 44 45 46
           })
      .def("trace",
           [](imperative::Tracer& self, imperative::OpBase* op,
              const imperative::VarBasePtrMap& inputs,
              const imperative::VarBasePtrMap& outputs,
              framework::BlockDesc* block,
              const platform::CUDAPlace expected_place,
              const bool stop_gradient = false) {
M
minqiyang 已提交
47 48
             return self.Trace(op, inputs, outputs, block, expected_place,
                               stop_gradient);
M
minqiyang 已提交
49
           })
X
Xin Pan 已提交
50 51
      .def("py_trace", &imperative::Tracer::PyTrace,
           pybind11::return_value_policy::take_ownership);
52 53 54 55
}

}  // namespace pybind
}  // namespace paddle