Introduce ITensor instead of Blob (#16048)
* Introduce ITensor * Added new allocator * Hide ITensor from dev api * Changed some python tests * Remove deprecated API from sample * Fixed warnings * Skiped unsupported tests * Fixed exception message * Fixed template func tests * Fixed incorrect tests * Fixed comments and move ITensor to developer API * Fixed CI issue * Fixed allocated tensor * Fixed docs and windows warning * Fixed set shape for strided tensors * Fixed build and some comments * Introduce remote tensor * Fixed code style * Fixed build * Remove static assert method * Remove fail type * Added device name API * Try to fix GPU remote tests * Added debug output * Try to fix GPU tests * Fixed comments * Fixed build * Added additional element type check * Revert some comment changes
This commit is contained in:
1 parent
596036a2db
commit
95faa573ed
27 files changed
+1122
-285
No files matched your search
@@ -15,7 +15,6 @@
|
||||
|
||||
#include "format_reader_ptr.h"
|
||||
#include "samples/slog.hpp"
|
||||
#include "shared_tensor_allocator.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
template <typename T>
|
||||
@@ -31,10 +30,8 @@ ov::Tensor create_tensor_from_image(const std::vector<std::string>& files,
|
||||
const benchmark_app::InputInfo& inputInfo,
|
||||
const std::string& inputName,
|
||||
std::string* filenames_used = nullptr) {
|
||||
size_t tensor_size =
|
||||
std::accumulate(inputInfo.dataShape.begin(), inputInfo.dataShape.end(), 1, std::multiplies<size_t>());
|
||||
auto allocator = std::make_shared<SharedTensorAllocator>(tensor_size * sizeof(T));
|
||||
auto data = reinterpret_cast<T*>(allocator->get_buffer());
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape);
|
||||
auto data = tensor.data<T>();
|
||||
|
||||
/** Collect images data ptrs **/
|
||||
std::vector<std::shared_ptr<uint8_t>> vreader;
|
||||
@@ -90,7 +87,6 @@ ov::Tensor create_tensor_from_image(const std::vector<std::string>& files,
|
||||
}
|
||||
}
|
||||
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape, ov::Allocator(allocator));
|
||||
return tensor;
|
||||
}
|
||||
|
||||
@@ -103,8 +99,8 @@ ov::Tensor create_tensor_from_numpy(const std::vector<std::string>& files,
|
||||
std::string* filenames_used = nullptr) {
|
||||
size_t tensor_size =
|
||||
std::accumulate(inputInfo.dataShape.begin(), inputInfo.dataShape.end(), 1, std::multiplies<size_t>());
|
||||
auto allocator = std::make_shared<SharedTensorAllocator>(tensor_size * sizeof(T));
|
||||
auto data = reinterpret_cast<T*>(allocator->get_buffer());
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape);
|
||||
auto data = tensor.data<T>();
|
||||
|
||||
std::vector<std::shared_ptr<unsigned char>> numpy_array_pointers;
|
||||
numpy_array_pointers.reserve(batchSize);
|
||||
@@ -150,7 +146,7 @@ ov::Tensor create_tensor_from_numpy(const std::vector<std::string>& files,
|
||||
}
|
||||
}
|
||||
|
||||
return ov::Tensor(inputInfo.type, inputInfo.dataShape, ov::Allocator(allocator));
|
||||
return tensor;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -160,8 +156,8 @@ ov::Tensor create_tensor_im_info(const std::pair<size_t, size_t>& image_size,
|
||||
const std::string& inputName) {
|
||||
size_t tensor_size =
|
||||
std::accumulate(inputInfo.dataShape.begin(), inputInfo.dataShape.end(), 1, std::multiplies<size_t>());
|
||||
auto allocator = std::make_shared<SharedTensorAllocator>(tensor_size * sizeof(T));
|
||||
auto data = reinterpret_cast<T*>(allocator->get_buffer());
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape);
|
||||
char* data = static_cast<char*>(tensor.data());
|
||||
|
||||
size_t infoBatchSize = 1;
|
||||
if (!inputInfo.layout.empty() && ov::layout::has_batch(inputInfo.layout)) {
|
||||
@@ -176,15 +172,14 @@ ov::Tensor create_tensor_im_info(const std::pair<size_t, size_t>& image_size,
|
||||
for (size_t i = 0; i < iminfoSize; i++) {
|
||||
size_t index = b * iminfoSize + i;
|
||||
if (0 == i)
|
||||
data[index] = static_cast<T>(image_size.first);
|
||||
data[index] = static_cast<char>(image_size.first);
|
||||
else if (1 == i)
|
||||
data[index] = static_cast<T>(image_size.second);
|
||||
data[index] = static_cast<char>(image_size.second);
|
||||
else
|
||||
data[index] = 1;
|
||||
data[index] = static_cast<char>(1);
|
||||
}
|
||||
}
|
||||
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape, ov::Allocator(allocator));
|
||||
return tensor;
|
||||
}
|
||||
|
||||
@@ -197,8 +192,8 @@ ov::Tensor create_tensor_from_binary(const std::vector<std::string>& files,
|
||||
std::string* filenames_used = nullptr) {
|
||||
size_t tensor_size =
|
||||
std::accumulate(inputInfo.dataShape.begin(), inputInfo.dataShape.end(), 1, std::multiplies<size_t>());
|
||||
auto allocator = std::make_shared<SharedTensorAllocator>(tensor_size * sizeof(T));
|
||||
char* data = allocator->get_buffer();
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape);
|
||||
char* data = static_cast<char*>(tensor.data());
|
||||
size_t binaryBatchSize = 1;
|
||||
if (!inputInfo.layout.empty() && ov::layout::has_batch(inputInfo.layout)) {
|
||||
binaryBatchSize = batchSize;
|
||||
@@ -245,7 +240,6 @@ ov::Tensor create_tensor_from_binary(const std::vector<std::string>& files,
|
||||
}
|
||||
}
|
||||
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape, ov::Allocator(allocator));
|
||||
return tensor;
|
||||
}
|
||||
|
||||
@@ -255,8 +249,8 @@ ov::Tensor create_tensor_random(const benchmark_app::InputInfo& inputInfo,
|
||||
T rand_max = std::numeric_limits<uint8_t>::max()) {
|
||||
size_t tensor_size =
|
||||
std::accumulate(inputInfo.dataShape.begin(), inputInfo.dataShape.end(), 1, std::multiplies<size_t>());
|
||||
auto allocator = std::make_shared<SharedTensorAllocator>(tensor_size * sizeof(T));
|
||||
auto data = reinterpret_cast<T*>(allocator->get_buffer());
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape);
|
||||
auto data = tensor.data<T>();
|
||||
|
||||
std::mt19937 gen(0);
|
||||
uniformDistribution<T2> distribution(rand_min, rand_max);
|
||||
@@ -264,7 +258,6 @@ ov::Tensor create_tensor_random(const benchmark_app::InputInfo& inputInfo,
|
||||
data[i] = static_cast<T>(distribution(gen));
|
||||
}
|
||||
|
||||
auto tensor = ov::Tensor(inputInfo.type, inputInfo.dataShape, ov::Allocator(allocator));
|
||||
return tensor;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright (C) 2018-2023 Intel Corporation
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "openvino/runtime/allocator.hpp"
|
||||
|
||||
class SharedTensorAllocator : public ov::AllocatorImpl {
|
||||
public:
|
||||
SharedTensorAllocator(size_t sizeBytes) : size(sizeBytes) {
|
||||
data = new char[size];
|
||||
}
|
||||
|
||||
~SharedTensorAllocator() {
|
||||
delete[] data;
|
||||
}
|
||||
|
||||
virtual void* allocate(const size_t bytes, const size_t) override {
|
||||
return bytes <= this->size ? (void*)data : nullptr;
|
||||
}
|
||||
|
||||
void deallocate(void* handle, const size_t bytes, const size_t) override {
|
||||
if (handle == data) {
|
||||
delete[] data;
|
||||
data = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool is_equal(const AllocatorImpl& other) const override {
|
||||
auto other_tensor_allocator = dynamic_cast<const SharedTensorAllocator*>(&other);
|
||||
return other_tensor_allocator != nullptr && other_tensor_allocator == this;
|
||||
}
|
||||
|
||||
char* get_buffer() {
|
||||
return data;
|
||||
}
|
||||
|
||||
private:
|
||||
char* data;
|
||||
size_t size;
|
||||
};
|
||||
Reference in new issue
Block a user