diff options
Diffstat (limited to 'driver_library/python/src/ethosu_driver')
-rw-r--r-- | driver_library/python/src/ethosu_driver/_utilities/driver_utilities.py | 11 | ||||
-rw-r--r-- | driver_library/python/src/ethosu_driver/swig/driver.i | 46 |
2 files changed, 9 insertions, 48 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); } |