From c081e5954cd92165b139488e76bdfef1402acee6 Mon Sep 17 00:00:00 2001 From: Mikael Olsson Date: Mon, 30 Oct 2023 11:10:56 +0100 Subject: Change create network UAPI to take a user buffer To not allow the buffer for a network instance to be changed after creation, the create network UAPI will now take the network model data as a user buffer. The content of the user buffer is copied into an internally allocated DMA buffer that cannot be accessed by the user. This breaks the current API so the Linux kernel NPU driver version and the driver library version have been given major version bumps. All the tests, documentation and other applications affected by the changes have been updated accordingly. Change-Id: I25c785d75a24794c3db632e4abe5cfbb1c7ac190 Signed-off-by: Mikael Olsson --- driver_library/src/ethosu.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'driver_library/src/ethosu.cpp') diff --git a/driver_library/src/ethosu.cpp b/driver_library/src/ethosu.cpp index 3c7dc31..7aec696 100644 --- a/driver_library/src/ethosu.cpp +++ b/driver_library/src/ethosu.cpp @@ -333,12 +333,13 @@ int Buffer::getFd() const { * Network ****************************************************************************/ -Network::Network(const Device &device, shared_ptr &buffer) : fd(-1), buffer(buffer) { +Network::Network(const Device &device, const unsigned char *networkData, size_t networkSize) : fd(-1) { // Create buffer handle ethosu_uapi_network_create uapi; - uapi.type = ETHOSU_UAPI_NETWORK_BUFFER; - uapi.fd = buffer->getFd(); - fd = device.ioctl(ETHOSU_IOCTL_NETWORK_CREATE, static_cast(&uapi)); + uapi.type = ETHOSU_UAPI_NETWORK_USER_BUFFER; + uapi.network.data_ptr = reinterpret_cast(networkData); + uapi.network.size = networkSize; + fd = device.ioctl(ETHOSU_IOCTL_NETWORK_CREATE, static_cast(&uapi)); try { collectNetworkInfo(); } catch (std::exception &e) { @@ -348,7 +349,7 @@ Network::Network(const Device &device, shared_ptr &buffer) : fd(-1), buf throw; } - Log(Severity::Info) << "Network(" << &device << ", " << &*buffer << "), this=" << this << ", fd=" << fd << endl; + Log(Severity::Info) << "Network(" << &device << "), this=" << this << ", fd=" << fd << endl; } Network::Network(const Device &device, const unsigned index) : fd(-1) { @@ -391,10 +392,6 @@ int Network::ioctl(unsigned long cmd, void *data) { return eioctl(fd, cmd, data); } -shared_ptr Network::getBuffer() { - return buffer; -} - const std::vector &Network::getIfmDims() const { return ifmDims; } -- cgit v1.2.1