|
|
|
@ -26,12 +26,7 @@ limitations under the License. */
|
|
|
|
|
#include "paddle/string/to_string.h"
|
|
|
|
|
|
|
|
|
|
namespace paddle {
|
|
|
|
|
namespace framework {
|
|
|
|
|
|
|
|
|
|
using Tensor = framework::Tensor;
|
|
|
|
|
using LoDTensor = framework::LoDTensor;
|
|
|
|
|
using LoD = framework::LoD;
|
|
|
|
|
|
|
|
|
|
namespace pybind {
|
|
|
|
|
static size_t UniqueIntegerGenerator() {
|
|
|
|
|
static std::atomic<size_t> generator;
|
|
|
|
|
return generator.fetch_add(1);
|
|
|
|
@ -48,6 +43,10 @@ bool IsCompileGPU() {
|
|
|
|
|
PYBIND11_PLUGIN(core) {
|
|
|
|
|
py::module m("core", "C++ core of PaddlePaddle");
|
|
|
|
|
|
|
|
|
|
// using framework in this function. Since it is inside a function, it will
|
|
|
|
|
// not cause namespace pollution.
|
|
|
|
|
using namespace paddle::framework; // NOLINT
|
|
|
|
|
|
|
|
|
|
py::class_<Tensor>(m, "Tensor", py::buffer_protocol())
|
|
|
|
|
.def_buffer(
|
|
|
|
|
[](Tensor &self) -> py::buffer_info { return CastToPyBuffer(self); })
|
|
|
|
@ -99,7 +98,7 @@ PYBIND11_PLUGIN(core) {
|
|
|
|
|
#ifdef PADDLE_ONLY_CPU
|
|
|
|
|
new (&instance) LoDTensor(lod);
|
|
|
|
|
#else
|
|
|
|
|
paddle::framework::LoD new_lod;
|
|
|
|
|
LoD new_lod;
|
|
|
|
|
new_lod.reserve(lod.size());
|
|
|
|
|
std::copy(lod.begin(), lod.end(), std::back_inserter(new_lod));
|
|
|
|
|
new (&instance) LoDTensor(new_lod);
|
|
|
|
@ -110,7 +109,7 @@ PYBIND11_PLUGIN(core) {
|
|
|
|
|
#ifdef PADDLE_ONLY_CPU
|
|
|
|
|
self.set_lod(lod);
|
|
|
|
|
#else
|
|
|
|
|
paddle::framework::LoD new_lod;
|
|
|
|
|
LoD new_lod;
|
|
|
|
|
new_lod.reserve(lod.size());
|
|
|
|
|
std::copy(lod.begin(), lod.end(), std::back_inserter(new_lod));
|
|
|
|
|
self.set_lod(new_lod);
|
|
|
|
@ -124,7 +123,7 @@ PYBIND11_PLUGIN(core) {
|
|
|
|
|
std::vector<std::vector<size_t>> new_lod;
|
|
|
|
|
new_lod.reserve(lod.size());
|
|
|
|
|
std::transform(lod.begin(), lod.end(), std::back_inserter(new_lod),
|
|
|
|
|
[](paddle::framework::Vector<size_t> item) ->
|
|
|
|
|
[](Vector<size_t> item) ->
|
|
|
|
|
std::vector<size_t> {
|
|
|
|
|
std::vector<size_t> v;
|
|
|
|
|
v.reserve(item.size());
|
|
|
|
@ -314,5 +313,5 @@ All parameter, weight, gradient are variables in Paddle.
|
|
|
|
|
|
|
|
|
|
return m.ptr();
|
|
|
|
|
}
|
|
|
|
|
} // namespace framework
|
|
|
|
|
} // namespace pybind
|
|
|
|
|
} // namespace paddle
|
|
|
|
|