forked from openvinotoolkit/openvino
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
jiwaszki
committed
Feb 16, 2024
1 parent
610dbcc
commit 47ac276
Showing
15 changed files
with
482 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/bindings/python/src/pyopenvino/core/remote_context.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "pyopenvino/core/remote_context.hpp" | ||
|
||
#include <pybind11/stl.h> | ||
|
||
#include <openvino/runtime/core.hpp> | ||
|
||
#include "common.hpp" | ||
#include "pyopenvino/utils/utils.hpp" | ||
|
||
namespace py = pybind11; | ||
|
||
void regclass_RemoteContext(py::module m) { | ||
py::class_<RemoteContextWrapper, std::shared_ptr<RemoteContextWrapper>> cls(m, "RemoteContext"); | ||
|
||
cls.def("get_device_name", [](RemoteContextWrapper& self) { | ||
return self.context.get_device_name(); | ||
}); | ||
|
||
cls.def("get_params", [](RemoteContextWrapper& self) { | ||
return self.context.get_params(); | ||
}); | ||
|
||
cls.def( | ||
"create_tensor", | ||
[](RemoteContextWrapper& self, | ||
const ov::element::Type& type, | ||
const ov::Shape& shape, | ||
const std::map<std::string, py::object>& properties) { | ||
auto _properties = Common::utils::properties_to_any_map(properties); | ||
return RemoteTensorWrapper(self.context.create_tensor(type, shape, _properties)); | ||
}, | ||
py::arg("type"), | ||
py::arg("shape"), | ||
py::arg("properties")); | ||
|
||
cls.def( | ||
"create_host_tensor", | ||
[](RemoteContextWrapper& self, const ov::element::Type& type, const ov::Shape& shape) { | ||
return self.context.create_host_tensor(type, shape); | ||
}, | ||
py::arg("type"), | ||
py::arg("shape")); | ||
} | ||
|
||
void regclass_VAContext(py::module m) { | ||
py::class_<VAContextWrapper, RemoteContextWrapper, std::shared_ptr<VAContextWrapper>> cls(m, "VAContext"); | ||
|
||
cls.def(py::init([](ov::Core& core, void* display, int target_tile_id) { | ||
ov::AnyMap context_params = { | ||
{ov::intel_gpu::context_type.name(), ov::intel_gpu::ContextType::VA_SHARED}, | ||
{ov::intel_gpu::va_device.name(), display}, | ||
{ov::intel_gpu::tile_id.name(), target_tile_id}}; | ||
auto ctx = core.create_context("GPU", context_params); | ||
return VAContextWrapper(ctx); | ||
}), | ||
py::arg("core"), | ||
py::arg("display"), | ||
py::arg("target_tile_id") = -1); | ||
|
||
cls.def( | ||
"create_tensor_nv12", | ||
[](VAContextWrapper& self, const size_t height, const size_t width, const uint32_t nv12_surface) { | ||
ov::AnyMap tensor_params = { | ||
{ov::intel_gpu::shared_mem_type.name(), ov::intel_gpu::SharedMemType::VA_SURFACE}, | ||
{ov::intel_gpu::dev_object_handle.name(), nv12_surface}, | ||
{ov::intel_gpu::va_plane.name(), uint32_t(0)}}; | ||
auto y_tensor = self.context.create_tensor(ov::element::u8, {1, height, width, 1}, tensor_params); | ||
tensor_params[ov::intel_gpu::va_plane.name()] = uint32_t(1); | ||
auto uv_tensor = self.context.create_tensor(ov::element::u8, {1, height / 2, width / 2, 2}, tensor_params); | ||
return py::make_tuple(VASurfaceTensorWrapper(y_tensor), VASurfaceTensorWrapper(uv_tensor)); | ||
}, | ||
py::arg("height"), | ||
py::arg("width"), | ||
py::arg("nv12_surface")); | ||
|
||
cls.def( | ||
"create_tensor", | ||
[](VAContextWrapper& self, | ||
const ov::element::Type& type, | ||
const ov::Shape shape, | ||
const uint32_t surface, | ||
const uint32_t plane) { | ||
ov::AnyMap params = {{ov::intel_gpu::shared_mem_type.name(), ov::intel_gpu::SharedMemType::VA_SURFACE}, | ||
{ov::intel_gpu::dev_object_handle.name(), surface}, | ||
{ov::intel_gpu::va_plane.name(), plane}}; | ||
return VASurfaceTensorWrapper(self.context.create_tensor(type, shape, params)); | ||
}, | ||
py::arg("type"), | ||
py::arg("shape"), | ||
py::arg("surface"), | ||
py::arg("plane") = 0); | ||
} |
40 changes: 40 additions & 0 deletions
40
src/bindings/python/src/pyopenvino/core/remote_context.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include <openvino/core/any.hpp> | ||
#include <openvino/core/type/element_type.hpp> | ||
#include <openvino/runtime/intel_gpu/properties.hpp> | ||
#include <openvino/runtime/intel_gpu/remote_properties.hpp> | ||
#include <openvino/runtime/remote_context.hpp> | ||
#include <openvino/runtime/tensor.hpp> | ||
|
||
#include "openvino/core/except.hpp" | ||
#include "pyopenvino/core/remote_tensor.hpp" | ||
|
||
namespace py = pybind11; | ||
|
||
class RemoteContextWrapper { | ||
public: | ||
RemoteContextWrapper() {} | ||
|
||
RemoteContextWrapper(ov::RemoteContext& _context): context{_context} {} | ||
|
||
RemoteContextWrapper(ov::RemoteContext&& _context): context{std::move(_context)} {} | ||
|
||
ov::RemoteContext context; | ||
}; | ||
|
||
void regclass_RemoteContext(py::module m); | ||
|
||
class VAContextWrapper : public RemoteContextWrapper { | ||
public: | ||
VAContextWrapper(ov::RemoteContext& _context): RemoteContextWrapper{_context} {} | ||
|
||
VAContextWrapper(ov::RemoteContext&& _context): RemoteContextWrapper{std::move(_context)} {} | ||
}; | ||
|
||
void regclass_VAContext(py::module m); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "pyopenvino/core/remote_tensor.hpp" | ||
|
||
#include <pybind11/stl.h> | ||
|
||
#include "common.hpp" | ||
#include "pyopenvino/utils/utils.hpp" | ||
|
||
namespace py = pybind11; | ||
|
||
void regclass_RemoteTensor(py::module m) { | ||
py::class_<RemoteTensorWrapper, std::shared_ptr<RemoteTensorWrapper>> cls(m, | ||
"RemoteTensor", | ||
py::base<ov::Tensor>()); | ||
|
||
cls.def("get_device_name", [](RemoteTensorWrapper& self) { | ||
return self.tensor.get_device_name(); | ||
}); | ||
|
||
cls.def("get_params", [](RemoteTensorWrapper& self) { | ||
return self.tensor.get_params(); | ||
}); | ||
|
||
cls.def("copy_to", [](RemoteTensorWrapper& self, py::object& dst) { | ||
Common::utils::raise_not_implemented(); | ||
}); | ||
|
||
cls.def_property_readonly("data", [](RemoteTensorWrapper& self) { | ||
Common::utils::raise_not_implemented(); | ||
}); | ||
|
||
cls.def_property( | ||
"bytes_data", | ||
[](RemoteTensorWrapper& self) { | ||
Common::utils::raise_not_implemented(); | ||
}, | ||
[](RemoteTensorWrapper& self, py::object& other) { | ||
Common::utils::raise_not_implemented(); | ||
}); | ||
|
||
cls.def_property( | ||
"str_data", | ||
[](RemoteTensorWrapper& self) { | ||
Common::utils::raise_not_implemented(); | ||
}, | ||
[](RemoteTensorWrapper& self, py::object& other) { | ||
Common::utils::raise_not_implemented(); | ||
}); | ||
|
||
cls.def("__repr__", [](const RemoteTensorWrapper& self) { | ||
std::stringstream ss; | ||
|
||
ss << "shape" << self.tensor.get_shape() << " type: " << self.tensor.get_element_type(); | ||
|
||
return "<" + Common::get_class_name(self) + ": " + ss.str() + ">"; | ||
}); | ||
} | ||
|
||
void regclass_VASurfaceTensor(py::module m) { | ||
py::class_<VASurfaceTensorWrapper, RemoteTensorWrapper, std::shared_ptr<VASurfaceTensorWrapper>> cls( | ||
m, | ||
"VASurfaceTensor"); | ||
|
||
cls.def_property_readonly("surface_id", [](VASurfaceTensorWrapper& self) { | ||
return self.surface_id(); | ||
}); | ||
|
||
cls.def_property_readonly("plane_id", [](VASurfaceTensorWrapper& self) { | ||
return self.plane_id(); | ||
}); | ||
|
||
cls.def_property_readonly("data", [](VASurfaceTensorWrapper& self) { | ||
Common::utils::raise_not_implemented(); | ||
}); | ||
|
||
cls.def("__repr__", [](const VASurfaceTensorWrapper& self) { | ||
std::stringstream ss; | ||
|
||
ss << "shape" << self.tensor.get_shape() << " type: " << self.tensor.get_element_type(); | ||
|
||
return "<" + Common::get_class_name(self) + ": " + ss.str() + ">"; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (C) 2018-2024 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
#pragma once | ||
|
||
#include <pybind11/pybind11.h> | ||
|
||
#include <openvino/core/any.hpp> | ||
#include <openvino/runtime/intel_gpu/properties.hpp> | ||
#include <openvino/runtime/intel_gpu/remote_properties.hpp> | ||
#include <openvino/runtime/remote_tensor.hpp> | ||
#include <openvino/runtime/tensor.hpp> | ||
#include <pyopenvino/core/tensor.hpp> | ||
|
||
namespace py = pybind11; | ||
|
||
class RemoteTensorWrapper { | ||
public: | ||
RemoteTensorWrapper() {} | ||
|
||
RemoteTensorWrapper(ov::RemoteTensor& _tensor): tensor{_tensor} {} | ||
|
||
RemoteTensorWrapper(ov::RemoteTensor&& _tensor): tensor{std::move(_tensor)} {} | ||
|
||
ov::RemoteTensor tensor; | ||
}; | ||
|
||
void regclass_RemoteTensor(py::module m); | ||
|
||
class VASurfaceTensorWrapper : public RemoteTensorWrapper { | ||
public: | ||
VASurfaceTensorWrapper(ov::RemoteTensor& _tensor): RemoteTensorWrapper{_tensor} {} | ||
|
||
VASurfaceTensorWrapper(ov::RemoteTensor&& _tensor): RemoteTensorWrapper{std::move(_tensor)} {} | ||
|
||
uint32_t surface_id() { | ||
return tensor.get_params().at(ov::intel_gpu::dev_object_handle.name()).as<uint32_t>(); | ||
} | ||
|
||
uint32_t plane_id() { | ||
return tensor.get_params().at(ov::intel_gpu::va_plane.name()).as<uint32_t>(); | ||
} | ||
}; | ||
|
||
void regclass_VASurfaceTensor(py::module m); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.