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
#include "paddle/fluid/framework/fleet/ps_gpu_wrapper.h"
#include "paddle/fluid/pybind/ps_gpu_wrapper_py.h"

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