ps_gpu_wrapper_py.cc 3.9 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 41
void BindPSGPUWrapper(py::module* m) {
  py::class_<framework::PSGPUWrapper, std::shared_ptr<framework::PSGPUWrapper>>(
      *m, "PSGPU")
      .def(py::init([]() { return framework::PSGPUWrapper::GetInstance(); }))
      .def("set_slot_vector", &framework::PSGPUWrapper::SetSlotVector,
Y
yaoxuefeng 已提交
42
           py::call_guard<py::gil_scoped_release>())
F
Fan Zhang 已提交
43
#ifdef PADDLE_WITH_CUDA
Y
yaoxuefeng 已提交
44 45
      .def("set_slot_dim_vector", &framework::PSGPUWrapper::SetSlotDimVector,
           py::call_guard<py::gil_scoped_release>())
F
Fan Zhang 已提交
46
#endif
Y
yaoxuefeng 已提交
47 48 49
      .def("set_slot_offset_vector",
           &framework::PSGPUWrapper::SetSlotOffsetVector,
           py::call_guard<py::gil_scoped_release>())
50 51
      .def("set_date", &framework::PSGPUWrapper::SetDate,
           py::call_guard<py::gil_scoped_release>())
52 53 54 55
      .def("set_dataset", &framework::PSGPUWrapper::SetDataset,
           py::call_guard<py::gil_scoped_release>())
      .def("init_gpu_ps", &framework::PSGPUWrapper::InitializeGPU,
           py::call_guard<py::gil_scoped_release>())
T
Thunderbrook 已提交
56 57
      .def("end_pass", &framework::PSGPUWrapper::EndPass,
           py::call_guard<py::gil_scoped_release>())
58 59 60
      .def("begin_pass", &framework::PSGPUWrapper::BeginPass,
           py::call_guard<py::gil_scoped_release>())
      .def("load_into_memory", &framework::PSGPUWrapper::LoadIntoMemory,
61
           py::call_guard<py::gil_scoped_release>())
T
Thunderbrook 已提交
62 63 64 65
#ifdef PADDLE_WITH_PSLIB
      .def("init_afs_api", &framework::PSGPUWrapper::InitAfsApi,
           py::call_guard<py::gil_scoped_release>())
#endif
66
      .def("finalize", &framework::PSGPUWrapper::Finalize,
T
Thunderbrook 已提交
67 68
           py::call_guard<py::gil_scoped_release>());
}  // end PSGPUWrapper
T
Thunderbrook 已提交
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
#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>(); }))
      .def("init", &framework::AfsWrapper::init,
           py::call_guard<py::gil_scoped_release>())
      .def("list", &framework::AfsWrapper::list,
           py::call_guard<py::gil_scoped_release>())
      .def("mkdir", &framework::AfsWrapper::mkdir,
           py::call_guard<py::gil_scoped_release>())
      .def("exist", &framework::AfsWrapper::exist,
           py::call_guard<py::gil_scoped_release>())
      .def("download", &framework::AfsWrapper::download,
           py::call_guard<py::gil_scoped_release>())
      .def("upload", &framework::AfsWrapper::upload,
           py::call_guard<py::gil_scoped_release>())
      .def("remove", &framework::AfsWrapper::remove,
87 88 89 90 91 92
           py::call_guard<py::gil_scoped_release>())
      .def("touchz", &framework::AfsWrapper::touchz,
           py::call_guard<py::gil_scoped_release>())
      .def("cat", &framework::AfsWrapper::cat,
           py::call_guard<py::gil_scoped_release>())
      .def("mv", &framework::AfsWrapper::mv,
T
Thunderbrook 已提交
93 94 95
           py::call_guard<py::gil_scoped_release>());
}
#endif
T
Thunderbrook 已提交
96 97 98
#endif
}  // end namespace pybind
}  // end namespace paddle