aboutsummaryrefslogtreecommitdiff
path: root/driver_library
diff options
context:
space:
mode:
Diffstat (limited to 'driver_library')
-rw-r--r--driver_library/include/ethosu.hpp14
-rw-r--r--driver_library/python/src/ethosu_driver/_utilities/driver_utilities.py11
-rw-r--r--driver_library/python/src/ethosu_driver/swig/driver.i46
-rw-r--r--driver_library/python/test/test_driver.py18
-rw-r--r--driver_library/python/test/test_driver_utilities.py8
-rw-r--r--driver_library/src/ethosu.cpp36
6 files changed, 27 insertions, 106 deletions
diff --git a/driver_library/include/ethosu.hpp b/driver_library/include/ethosu.hpp
index 491dc28..47c1868 100644
--- a/driver_library/include/ethosu.hpp
+++ b/driver_library/include/ethosu.hpp
@@ -1,6 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
- *
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
@@ -40,12 +39,12 @@
namespace EthosU {
-constexpr uint32_t DRIVER_LIBRARY_VERSION_MAJOR = 1;
+constexpr uint32_t DRIVER_LIBRARY_VERSION_MAJOR = 2;
constexpr uint32_t DRIVER_LIBRARY_VERSION_MINOR = 0;
constexpr uint32_t DRIVER_LIBRARY_VERSION_PATCH = 0;
-constexpr uint32_t MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION = 1;
-constexpr uint32_t MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION = 1;
+constexpr uint32_t MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION = 2;
+constexpr uint32_t MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION = 2;
class Exception : public std::exception {
public:
@@ -152,14 +151,11 @@ private:
class Buffer {
public:
- Buffer(const Device &device, const size_t capacity);
+ Buffer(const Device &device, const size_t size);
virtual ~Buffer() noexcept(false);
- size_t capacity() const;
void clear() const;
char *data() const;
- void resize(size_t size, size_t offset = 0) const;
- size_t offset() const;
size_t size() const;
int getFd() const;
@@ -167,7 +163,7 @@ public:
private:
int fd;
char *dataPtr;
- const size_t dataCapacity;
+ const size_t dataSize;
};
class Network {
diff --git a/driver_library/python/src/ethosu_driver/_utilities/driver_utilities.py b/driver_library/python/src/ethosu_driver/_utilities/driver_utilities.py
index 216895a..fcea91f 100644
--- a/driver_library/python/src/ethosu_driver/_utilities/driver_utilities.py
+++ b/driver_library/python/src/ethosu_driver/_utilities/driver_utilities.py
@@ -1,4 +1,4 @@
-# SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
# SPDX-License-Identifier: Apache-2.0
import logging
import time
@@ -49,12 +49,11 @@ def populate_buffers(input_data: List[bytearray], buffers: List[Buffer]):
raise RuntimeError("Incorrect number of inputs, expected {}, got {}.".format(number_of_buffers, len(input_data)))
for index, (buffer, data_chunk) in enumerate(zip(buffers, input_data)):
- cap = buffer.capacity()
- logging.info("Copying data to a buffer {} of {} with size = {}".format(index + 1, number_of_buffers, cap))
+ size = buffer.size()
+ logging.info("Copying data to a buffer {} of {} with size = {}".format(index + 1, number_of_buffers, size))
- if len(data_chunk) > cap:
- raise RuntimeError("Buffer expects {} bytes, got {} bytes.".format(cap, len(data_chunk)))
- buffer.resize(len(data_chunk))
+ if len(data_chunk) > size:
+ raise RuntimeError("Buffer expects {} bytes, got {} bytes.".format(size, len(data_chunk)))
buffer.from_buffer(data_chunk)
diff --git a/driver_library/python/src/ethosu_driver/swig/driver.i b/driver_library/python/src/ethosu_driver/swig/driver.i
index 1ff8ded..3e4e384 100644
--- a/driver_library/python/src/ethosu_driver/swig/driver.i
+++ b/driver_library/python/src/ethosu_driver/swig/driver.i
@@ -210,31 +210,22 @@ public:
Buffer object represents a RW mapping in the virtual address space of the caller.
Created mapping is shareable, updates to the mapping are visible to other processes mapping the same region.
- Issues ETHOSU_IOCTL_BUFFER_CREATE I/O request to the device with given Maximum capacity.
+ Issues ETHOSU_IOCTL_BUFFER_CREATE I/O request to the device with given size.
- Buffer could be created for a device with given maximum capacity or instantiated directly from
+ Buffer could be created for a device with given size or instantiated directly from
a file containing binary data.
Examples:
>>> import ethosu_driver as driver
>>> # from file:
>>> buf = driver.Buffer(device, '/path/to/file')
- >>> # Empty, with maximum capacity:
+ >>> # Empty, with size:
>>> buf = driver.Buffer(device, 1024)
") Buffer;
%nodefaultctor Buffer;
class Buffer {
public:
- Buffer(const Device &device, const size_t capacity);
-
- %feature("docstring",
- "
- Returns maximum buffer capacity set during initialisation.
-
- Returns:
- int: maximum buffer capacity.
- ") capacity;
- size_t capacity() const;
+ Buffer(const Device &device, const size_t size);
%feature("docstring",
"
@@ -255,32 +246,6 @@ public:
%feature("docstring",
"
- Sets a size of the memory buffer for the device.
-
- 'offset + size' must not exceed the capacity of the buffer.
- Does not change the size of the mapped region.
-
- Issues ETHOSU_IOCTL_BUFFER_SET I/O request with a given size and offset.
-
- Args:
- size (int): Device buffer size.
- offset (int): Offset to where the data starts.
- ") resize;
- void resize(size_t size, size_t offset = 0) const;
-
- %feature("docstring",
- "
- Queries device and returns buffer data offset.
-
- Issues ETHOSU_IOCTL_BUFFER_GET I/O request.
-
- Returns:
- int: data offset
- ") offset;
- size_t offset() const;
-
- %feature("docstring",
- "
Queries device and returns buffer data size.
Issues ETHOSU_IOCTL_BUFFER_GET I/O request.
@@ -313,7 +278,6 @@ public:
stream.seekg(0, std::ios_base::beg);
auto buffer = new EthosU::Buffer(device, size);
- buffer->resize(size);
stream.read(buffer->data(), size);
return buffer;
@@ -324,7 +288,6 @@ public:
Fills the buffer from python buffer.
Copies python buffer data to the mapped memory region.
- Input buffer size must be within `Buffer` maximum capacity.
Args:
buffer: data to be copied to the mapped memory.
@@ -332,7 +295,6 @@ public:
") from_buffer;
%mutable_buffer(char* buffer, size_t size);
void from_buffer(char* buffer, size_t size) {
- self->resize(size);
char* data = $self->data();
std::memcpy(data, buffer, size);
}
diff --git a/driver_library/python/test/test_driver.py b/driver_library/python/test/test_driver.py
index 28d0a29..0dd207f 100644
--- a/driver_library/python/test/test_driver.py
+++ b/driver_library/python/test/test_driver.py
@@ -67,12 +67,6 @@ def test_check_buffer_swig_ownership(network_buffer):
@pytest.mark.parametrize('device_name', ['ethosu0'])
@pytest.mark.parametrize('model_name', ['model.tflite'])
-def test_check_buffer_capacity(network_buffer):
- assert network_buffer.capacity() > 0
-
-
-@pytest.mark.parametrize('device_name', ['ethosu0'])
-@pytest.mark.parametrize('model_name', ['model.tflite'])
def test_check_buffer_size(network_buffer):
assert network_buffer.size() > 0
@@ -81,16 +75,8 @@ def test_check_buffer_size(network_buffer):
@pytest.mark.parametrize('model_name', ['model.tflite'])
def test_check_buffer_clear(network_buffer):
network_buffer.clear()
- assert network_buffer.size() == 0
-
-
-@pytest.mark.parametrize('device_name', ['ethosu0'])
-@pytest.mark.parametrize('model_name', ['model.tflite'])
-def test_check_buffer_resize(network_buffer):
- offset = 1
- new_size = network_buffer.capacity() - offset
- network_buffer.resize(new_size, offset)
- assert network_buffer.size() == new_size
+ for i in range(network_buffer.size()):
+ assert network_buffer.data()[i] == 0
@pytest.mark.parametrize('device_name', ['ethosu0'])
diff --git a/driver_library/python/test/test_driver_utilities.py b/driver_library/python/test/test_driver_utilities.py
index fc8e921..fe44b0e 100644
--- a/driver_library/python/test/test_driver_utilities.py
+++ b/driver_library/python/test/test_driver_utilities.py
@@ -1,5 +1,5 @@
#
-# SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
# SPDX-License-Identifier: Apache-2.0
#
import pytest
@@ -53,10 +53,8 @@ def test_check_network_ifm_size(network):
def test_allocate_buffers(device):
buffers = driver.allocate_buffers(device, [128, 256])
assert len(buffers) == 2
- assert buffers[0].size() == 0
- assert buffers[0].capacity() == 128
- assert buffers[1].size() == 0
- assert buffers[1].capacity() == 256
+ assert buffers[0].size() == 128
+ assert buffers[1].size() == 256
@pytest.mark.parametrize('device_name', ['ethosu0'])
diff --git a/driver_library/src/ethosu.cpp b/driver_library/src/ethosu.cpp
index dcdde8c..3c7dc31 100644
--- a/driver_library/src/ethosu.cpp
+++ b/driver_library/src/ethosu.cpp
@@ -1,6 +1,5 @@
/*
* SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
- *
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the License); you may
@@ -279,13 +278,13 @@ Capabilities Device::capabilities() const {
* Buffer
****************************************************************************/
-Buffer::Buffer(const Device &device, const size_t capacity) : fd(-1), dataPtr(nullptr), dataCapacity(capacity) {
- ethosu_uapi_buffer_create uapi = {static_cast<uint32_t>(dataCapacity)};
+Buffer::Buffer(const Device &device, const size_t size) : fd(-1), dataPtr(nullptr), dataSize(size) {
+ ethosu_uapi_buffer_create uapi = {static_cast<uint32_t>(dataSize)};
fd = device.ioctl(ETHOSU_IOCTL_BUFFER_CREATE, static_cast<void *>(&uapi));
void *d;
try {
- d = emmap(nullptr, dataCapacity, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
+ d = emmap(nullptr, dataSize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
} catch (std::exception &e) {
try {
eclose(fd);
@@ -295,13 +294,13 @@ Buffer::Buffer(const Device &device, const size_t capacity) : fd(-1), dataPtr(nu
dataPtr = reinterpret_cast<char *>(d);
- Log(Severity::Info) << "Buffer(" << &device << ", " << dec << capacity << "), this=" << this << ", fd=" << fd
+ Log(Severity::Info) << "Buffer(" << &device << ", " << dec << size << "), this=" << this << ", fd=" << fd
<< ", dataPtr=" << static_cast<void *>(dataPtr) << endl;
}
Buffer::~Buffer() noexcept(false) {
try {
- emunmap(dataPtr, dataCapacity);
+ emunmap(dataPtr, dataSize);
} catch (std::exception &e) {
try {
eclose(fd);
@@ -314,35 +313,16 @@ Buffer::~Buffer() noexcept(false) {
Log(Severity::Info) << "~Buffer(). this=" << this << endl;
}
-size_t Buffer::capacity() const {
- return dataCapacity;
-}
-
void Buffer::clear() const {
- resize(0, 0);
+ memset(dataPtr, 0, dataSize);
}
char *Buffer::data() const {
- return dataPtr + offset();
-}
-
-void Buffer::resize(size_t size, size_t offset) const {
- ethosu_uapi_buffer uapi;
- uapi.offset = offset;
- uapi.size = size;
- eioctl(fd, ETHOSU_IOCTL_BUFFER_SET, static_cast<void *>(&uapi));
-}
-
-size_t Buffer::offset() const {
- ethosu_uapi_buffer uapi;
- eioctl(fd, ETHOSU_IOCTL_BUFFER_GET, static_cast<void *>(&uapi));
- return uapi.offset;
+ return dataPtr;
}
size_t Buffer::size() const {
- ethosu_uapi_buffer uapi;
- eioctl(fd, ETHOSU_IOCTL_BUFFER_GET, static_cast<void *>(&uapi));
- return uapi.size;
+ return dataSize;
}
int Buffer::getFd() const {