diff options
Diffstat (limited to 'driver_library/src/ethosu.cpp')
-rw-r--r-- | driver_library/src/ethosu.cpp | 36 |
1 files changed, 8 insertions, 28 deletions
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 { |