2022-01-19 01:07:49 +03:00
|
|
|
// Copyright (C) 2018-2022 Intel Corporation
|
2021-12-30 19:09:12 +03:00
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "openvino/runtime/allocator.hpp"
|
|
|
|
|
|
2022-01-20 16:17:57 +03:00
|
|
|
class SharedTensorAllocator : public ov::AllocatorImpl {
|
2021-12-30 19:09:12 +03:00
|
|
|
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 {
|
2022-02-03 01:47:46 +03:00
|
|
|
auto other_tensor_allocator = dynamic_cast<const SharedTensorAllocator*>(&other);
|
|
|
|
|
return other_tensor_allocator != nullptr && other_tensor_allocator == this;
|
2021-12-30 19:09:12 +03:00
|
|
|
}
|
|
|
|
|
|
2022-01-19 01:08:07 +03:00
|
|
|
char* get_buffer() {
|
2021-12-30 19:09:12 +03:00
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
char* data;
|
|
|
|
|
size_t size;
|
|
|
|
|
};
|