Skip to content

Commit

Permalink
Merge branch 'master' into warnings_v3
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-cv authored Mar 15, 2023
2 parents b648e5e + 8189d18 commit 9a1a427
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 18 deletions.
8 changes: 7 additions & 1 deletion docs/openvino_sphinx_theme/openvino_sphinx_theme/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from bs4 import BeautifulSoup
from sphinx.util import logging
from pydata_sphinx_theme import index_toctree
from .directives.code import DoxygenSnippet
from .directives.code import DoxygenSnippet, Scrollbox, Nodescrollbox, visit_scrollbox, depart_scrollbox

SPHINX_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -219,4 +219,10 @@ def setup(app):
app.connect('env-before-read-docs', read_doxygen_configs)
app.add_html_theme('openvino_sphinx_theme', theme_path)
rst.directives.register_directive('doxygensnippet', DoxygenSnippet)
rst.directives.register_directive('scrollbox', Scrollbox)
app.add_node(
Nodescrollbox,
html=(visit_scrollbox, depart_scrollbox),
latex=(visit_scrollbox, depart_scrollbox)
)
return {'parallel_read_safe': True, 'parallel_write_safe': True}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from sphinx.directives.code import LiteralInclude, LiteralIncludeReader, container_wrapper
from sphinx.util import logging
from docutils.parsers.rst import directives
from docutils.parsers.rst import Directive, directives
from typing import List, Tuple
from docutils.nodes import Node
from docutils import nodes
Expand Down Expand Up @@ -74,3 +74,61 @@ def run(self) -> List[Node]:
return [retnode]
except Exception as exc:
return [document.reporter.warning(exc, line=self.lineno)]


def visit_scrollbox(self, node):
attrs = {}
attrs["style"] = (
(("height:" + "".join(c for c in str(node["height"]) if c.isdigit()) + "px!important; " ) if "height" in node is not None else "")
+ (("width:" + "".join(c for c in str(node["width"]) if c.isdigit()) ) if "width" in node is not None else "")
+ (("px; " if node["width"].find("px") != -1 else "%;") if "width" in node is not None else "")
+ ( ("border-left:solid "+"".join(c for c in str(node["delimiter"]) if c.isdigit())+ "px " + (("".join(str(node["delimiter-color"]))) if "delimiter-color" in node is not None else "#dee2e6") +"; ") if "delimiter" in node is not None else "")
)
attrs["class"] = "scrollbox"
self.body.append(self.starttag(node, "div", **attrs))


def depart_scrollbox(self, node):
self.body.append("</div>\n")


class Nodescrollbox(nodes.container):
def create_scrollbox_component(
rawtext: str = "",
**attributes,
) -> nodes.container:
node = nodes.container(rawtext, is_div=True, **attributes)
return node


class Scrollbox(Directive):
has_content = True
required_arguments = 0
optional_arguments = 1
final_argument_whitespace = True
option_spec = {
'name': directives.unchanged,
'width': directives.length_or_percentage_or_unitless,
'height': directives.length_or_percentage_or_unitless,
'style': directives.unchanged,
'delimiter': directives.length_or_percentage_or_unitless,
'delimiter-color': directives.unchanged,
}

has_content = True

def run(self):
classes = ['scrollbox','']
node = Nodescrollbox("div", rawtext="\n".join(self.content), classes=classes)
if 'height' in self.options:
node['height'] = self.options['height']
if 'width' in self.options:
node['width'] = self.options['width']
if 'delimiter' in self.options:
node['delimiter'] = self.options['delimiter']
if 'delimiter-color' in self.options:
node['delimiter-color'] = self.options['delimiter-color']
self.add_name(node)
if self.content:
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ body {
border-color: rgb(var(--ost-color-primary));
}

/* Scrollbox Extension */

.scrollbox {
overflow-y:scroll;
height:300px;
}

/* Syntax Highlighting */

code {
Expand Down
13 changes: 5 additions & 8 deletions src/core/src/runtime/itensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,7 @@ std::shared_ptr<ITensor> make_tensor(const element::Type element_type, const Sha
*/
class RoiTensor : public ITensor {
public:
RoiTensor(const std::shared_ptr<ITensor>& owner, const Coordinate& begin, const Coordinate& end)
: m_owner{owner},
m_offsets{begin} {
RoiTensor(const std::shared_ptr<ITensor>& owner, const Coordinate& begin, const Coordinate& end) : m_owner{owner} {
OPENVINO_ASSERT(owner->get_element_type().bitwidth() >= 8,
"ROI Tensor for types with bitwidths less then 8 bit is not implemented. Tensor type: ",
owner->get_element_type());
Expand All @@ -231,6 +229,8 @@ class RoiTensor : public ITensor {
m_shape[i] = end[i] - begin[i];
OPENVINO_ASSERT(m_shape[i] <= owner_shape[i]);
}
auto& strides = get_strides();
m_offset = std::inner_product(begin.begin(), begin.end(), strides.begin(), static_cast<size_t>(0));
}

const element::Type& get_element_type() const override {
Expand All @@ -251,15 +251,12 @@ class RoiTensor : public ITensor {

void* data(const element::Type& element_type) const override {
auto owner_data = m_owner->data(element_type);
auto& strides = get_strides();
size_t byte_offset =
std::inner_product(m_offsets.begin(), m_offsets.end(), strides.begin(), static_cast<size_t>(0));
return static_cast<uint8_t*>(owner_data) + byte_offset;
return static_cast<uint8_t*>(owner_data) + m_offset;
}

private:
std::shared_ptr<ITensor> m_owner;
Coordinate m_offsets;
size_t m_offset;
Shape m_shape;
};

Expand Down
26 changes: 18 additions & 8 deletions src/inference/src/dev/iremote_tensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ class BlobTensor : public ITensor {
mutable Shape m_shape;
mutable Strides m_strides;

void update_strides() {
if (get_element_type().bitwidth() >= 8) {
const auto& element_strides = blob->getTensorDesc().getBlockingDesc().getStrides();
const size_t elem_size = get_element_type().size();
m_strides.clear();
m_strides.resize(element_strides.size());
std::transform(element_strides.begin(),
element_strides.end(),
m_strides.begin(),
[&elem_size](size_t stride) {
return stride * elem_size;
});
}
}

public:
std::shared_ptr<ie::Blob> blob;

Expand All @@ -33,6 +48,7 @@ class BlobTensor : public ITensor {
OPENVINO_ASSERT(!remote_impl);
OPENVINO_ASSERT(blob);
m_shape = blob->getTensorDesc().getBlockingDesc().getBlockDims();
update_strides();
}

const element::Type& get_element_type() const override {
Expand All @@ -42,6 +58,7 @@ class BlobTensor : public ITensor {

void set_shape(ov::Shape shape) override {
blob->setShape({shape.begin(), shape.end()});
update_strides();
}

const Shape& get_shape() const override {
Expand All @@ -53,13 +70,6 @@ class BlobTensor : public ITensor {
OPENVINO_ASSERT(get_element_type().bitwidth() >= 8,
"Could not get strides for types with bitwidths less then 8 bit. Tensor type: ",
get_element_type());
const auto& element_strides = blob->getTensorDesc().getBlockingDesc().getStrides();
const size_t elem_size = get_element_type().size();
m_strides.clear();
m_strides.resize(element_strides.size());
std::transform(element_strides.begin(), element_strides.end(), m_strides.begin(), [&elem_size](size_t stride) {
return stride * elem_size;
});
return m_strides;
}

Expand All @@ -81,7 +91,7 @@ class BlobTensor : public ITensor {
#undef TYPE_CHECK
OPENVINO_ASSERT(host_accesable_implementation,
"Tensor implementation type dose not contains host accessable data");
if (element_type != element::undefined) {
if (element_type != element::undefined && element_type.is_static()) {
OPENVINO_ASSERT(element_type == get_element_type(),
"Tensor data with element type ",
get_element_type(),
Expand Down

0 comments on commit 9a1a427

Please sign in to comment.