ps_gpu_wrapper_py.cc 4.4 KB
Newer Older
T
Thunderbrook 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/* Copyright (c) 2016 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 <fcntl.h>

#ifdef _POSIX_C_SOURCE
#undef _POSIX_C_SOURCE
#endif

#ifdef _XOPEN_SOURCE
#undef _XOPEN_SOURCE
#endif

Y
yaoxuefeng 已提交
24
#include <memory>
T
Thunderbrook 已提交
25 26 27
#include <string>
#include <vector>

F
Fan Zhang 已提交
28
#include "paddle/fluid/framework/data_set.h"
T
Thunderbrook 已提交
29 30 31 32 33 34 35
#include "paddle/fluid/framework/fleet/ps_gpu_wrapper.h"
#include "paddle/fluid/pybind/ps_gpu_wrapper_py.h"

namespace py = pybind11;

namespace paddle {
namespace pybind {
T
Thunderbrook 已提交
36
#ifdef PADDLE_WITH_HETERPS
T
Thunderbrook 已提交
37 38 39 40
void BindPSGPUWrapper(py::module* m) {
  py::class_<framework::PSGPUWrapper, std::shared_ptr<framework::PSGPUWrapper>>(
      *m, "PSGPU")
      .def(py::init([]() { return framework::PSGPUWrapper::GetInstance(); }))
41 42
      .def("set_slot_vector",
           &framework::PSGPUWrapper::SetSlotVector,
Y
yaoxuefeng 已提交
43
           py::call_guard<py::gil_scoped_release>())
F
Fan Zhang 已提交
44
#ifdef PADDLE_WITH_CUDA
45 46
      .def("set_slot_dim_vector",
           &framework::PSGPUWrapper::SetSlotDimVector,
Y
yaoxuefeng 已提交
47
           py::call_guard<py::gil_scoped_release>())
F
Fan Zhang 已提交
48
#endif
Y
yaoxuefeng 已提交
49 50 51
      .def("set_slot_offset_vector",
           &framework::PSGPUWrapper::SetSlotOffsetVector,
           py::call_guard<py::gil_scoped_release>())
52 53
      .def("set_date",
           &framework::PSGPUWrapper::SetDate,
54
           py::call_guard<py::gil_scoped_release>())
55 56
      .def("set_dataset",
           &framework::PSGPUWrapper::SetDataset,
57
           py::call_guard<py::gil_scoped_release>())
58 59
      .def("init_gpu_ps",
           &framework::PSGPUWrapper::InitializeGPU,
60
           py::call_guard<py::gil_scoped_release>())
61 62
      .def("end_pass",
           &framework::PSGPUWrapper::EndPass,
T
Thunderbrook 已提交
63
           py::call_guard<py::gil_scoped_release>())
64 65
      .def("begin_pass",
           &framework::PSGPUWrapper::BeginPass,
66
           py::call_guard<py::gil_scoped_release>())
L
lxsbupt 已提交
67 68 69
      .def("dump_to_mem",
           &framework::PSGPUWrapper::DumpToMem,
           py::call_guard<py::gil_scoped_release>())
70 71
      .def("load_into_memory",
           &framework::PSGPUWrapper::LoadIntoMemory,
72
           py::call_guard<py::gil_scoped_release>())
T
Thunderbrook 已提交
73
#ifdef PADDLE_WITH_PSLIB
74 75
      .def("init_afs_api",
           &framework::PSGPUWrapper::InitAfsApi,
T
Thunderbrook 已提交
76 77
           py::call_guard<py::gil_scoped_release>())
#endif
78 79
      .def("finalize",
           &framework::PSGPUWrapper::Finalize,
L
lxsbupt 已提交
80 81 82
           py::call_guard<py::gil_scoped_release>())
      .def("set_mode",
           &framework::PSGPUWrapper::SetMode,
T
Thunderbrook 已提交
83 84
           py::call_guard<py::gil_scoped_release>());
}  // end PSGPUWrapper
T
Thunderbrook 已提交
85 86 87 88 89
#ifdef PADDLE_WITH_PSLIB
void BindAfsWrapper(py::module* m) {
  py::class_<framework::AfsWrapper, std::shared_ptr<framework::AfsWrapper>>(
      *m, "AfsWrapper")
      .def(py::init([]() { return std::make_shared<framework::AfsWrapper>(); }))
90 91
      .def("init",
           &framework::AfsWrapper::init,
T
Thunderbrook 已提交
92
           py::call_guard<py::gil_scoped_release>())
93 94
      .def("list",
           &framework::AfsWrapper::list,
T
Thunderbrook 已提交
95
           py::call_guard<py::gil_scoped_release>())
96 97
      .def("mkdir",
           &framework::AfsWrapper::mkdir,
T
Thunderbrook 已提交
98
           py::call_guard<py::gil_scoped_release>())
99 100
      .def("exist",
           &framework::AfsWrapper::exist,
T
Thunderbrook 已提交
101
           py::call_guard<py::gil_scoped_release>())
102 103
      .def("download",
           &framework::AfsWrapper::download,
T
Thunderbrook 已提交
104
           py::call_guard<py::gil_scoped_release>())
105 106
      .def("upload",
           &framework::AfsWrapper::upload,
T
Thunderbrook 已提交
107
           py::call_guard<py::gil_scoped_release>())
108 109
      .def("remove",
           &framework::AfsWrapper::remove,
110
           py::call_guard<py::gil_scoped_release>())
111 112
      .def("touchz",
           &framework::AfsWrapper::touchz,
113
           py::call_guard<py::gil_scoped_release>())
114 115
      .def("cat",
           &framework::AfsWrapper::cat,
116
           py::call_guard<py::gil_scoped_release>())
117 118
      .def("mv",
           &framework::AfsWrapper::mv,
T
Thunderbrook 已提交
119 120 121
           py::call_guard<py::gil_scoped_release>());
}
#endif
T
Thunderbrook 已提交
122 123 124
#endif
}  // end namespace pybind
}  // end namespace paddle