ps_gpu_wrapper_py.cc 4.5 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>())
44 45 46
      .def("set_slot_num_for_pull_feature",
           &framework::PSGPUWrapper::SetPullFeatureSlotNum,
           py::call_guard<py::gil_scoped_release>())
F
Fan Zhang 已提交
47
#ifdef PADDLE_WITH_CUDA
48 49
      .def("set_slot_dim_vector",
           &framework::PSGPUWrapper::SetSlotDimVector,
Y
yaoxuefeng 已提交
50
           py::call_guard<py::gil_scoped_release>())
F
Fan Zhang 已提交
51
#endif
Y
yaoxuefeng 已提交
52 53 54
      .def("set_slot_offset_vector",
           &framework::PSGPUWrapper::SetSlotOffsetVector,
           py::call_guard<py::gil_scoped_release>())
55 56
      .def("set_date",
           &framework::PSGPUWrapper::SetDate,
57
           py::call_guard<py::gil_scoped_release>())
58 59
      .def("set_dataset",
           &framework::PSGPUWrapper::SetDataset,
60
           py::call_guard<py::gil_scoped_release>())
61 62
      .def("init_gpu_ps",
           &framework::PSGPUWrapper::InitializeGPU,
63
           py::call_guard<py::gil_scoped_release>())
64 65
      .def("end_pass",
           &framework::PSGPUWrapper::EndPass,
T
Thunderbrook 已提交
66
           py::call_guard<py::gil_scoped_release>())
67 68
      .def("begin_pass",
           &framework::PSGPUWrapper::BeginPass,
69
           py::call_guard<py::gil_scoped_release>())
L
lxsbupt 已提交
70 71 72
      .def("dump_to_mem",
           &framework::PSGPUWrapper::DumpToMem,
           py::call_guard<py::gil_scoped_release>())
73 74
      .def("load_into_memory",
           &framework::PSGPUWrapper::LoadIntoMemory,
75
           py::call_guard<py::gil_scoped_release>())
T
Thunderbrook 已提交
76
#ifdef PADDLE_WITH_PSLIB
77 78
      .def("init_afs_api",
           &framework::PSGPUWrapper::InitAfsApi,
T
Thunderbrook 已提交
79 80
           py::call_guard<py::gil_scoped_release>())
#endif
81 82
      .def("finalize",
           &framework::PSGPUWrapper::Finalize,
L
lxsbupt 已提交
83 84 85
           py::call_guard<py::gil_scoped_release>())
      .def("set_mode",
           &framework::PSGPUWrapper::SetMode,
T
Thunderbrook 已提交
86 87
           py::call_guard<py::gil_scoped_release>());
}  // end PSGPUWrapper
T
Thunderbrook 已提交
88 89 90 91 92
#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>(); }))
93 94
      .def("init",
           &framework::AfsWrapper::init,
T
Thunderbrook 已提交
95
           py::call_guard<py::gil_scoped_release>())
96 97
      .def("list",
           &framework::AfsWrapper::list,
T
Thunderbrook 已提交
98
           py::call_guard<py::gil_scoped_release>())
99 100
      .def("mkdir",
           &framework::AfsWrapper::mkdir,
T
Thunderbrook 已提交
101
           py::call_guard<py::gil_scoped_release>())
102 103
      .def("exist",
           &framework::AfsWrapper::exist,
T
Thunderbrook 已提交
104
           py::call_guard<py::gil_scoped_release>())
105 106
      .def("download",
           &framework::AfsWrapper::download,
T
Thunderbrook 已提交
107
           py::call_guard<py::gil_scoped_release>())
108 109
      .def("upload",
           &framework::AfsWrapper::upload,
T
Thunderbrook 已提交
110
           py::call_guard<py::gil_scoped_release>())
111 112
      .def("remove",
           &framework::AfsWrapper::remove,
113
           py::call_guard<py::gil_scoped_release>())
114 115
      .def("touchz",
           &framework::AfsWrapper::touchz,
116
           py::call_guard<py::gil_scoped_release>())
117 118
      .def("cat",
           &framework::AfsWrapper::cat,
119
           py::call_guard<py::gil_scoped_release>())
120 121
      .def("mv",
           &framework::AfsWrapper::mv,
T
Thunderbrook 已提交
122 123 124
           py::call_guard<py::gil_scoped_release>());
}
#endif
T
Thunderbrook 已提交
125 126 127
#endif
}  // end namespace pybind
}  // end namespace paddle