diff options
Diffstat (limited to 'driver_library/python')
4 files changed, 14 insertions, 69 deletions
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']) |