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 <mikael.olsson@arm.com>
diff --git a/driver_library/python/src/ethosu_driver/swig/driver.i b/driver_library/python/src/ethosu_driver/swig/driver.i
index 3e4e384..6e0ad25 100644
--- a/driver_library/python/src/ethosu_driver/swig/driver.i
+++ b/driver_library/python/src/ethosu_driver/swig/driver.i
@@ -293,12 +293,12 @@
         buffer: data to be copied to the mapped memory.
 
     ") from_buffer;
-    %mutable_buffer(char* buffer, size_t size);
+    %buffer_in(char* buffer, size_t size, BUFFER_FLAG_RW);
     void from_buffer(char* buffer, size_t size) {
         char* data = $self->data();
         std::memcpy(data, buffer, size);
     }
-    %clear_mutable_buffer(char* buffer, size_t size);
+    %clear_buffer_in(char* buffer, size_t size);
 }
 
 %feature("docstring",
@@ -329,15 +329,6 @@
 
     %feature("docstring",
     "
-    Returns associated memory buffer.
-
-    Returns:
-        `Buffer`: buffer object used during initialisation.
-    ") getBuffer;
-    std::shared_ptr<Buffer> getBuffer();
-
-    %feature("docstring",
-    "
     Returns saved sizes of the neural network model input feature maps.
 
     Returns:
@@ -374,21 +365,41 @@
 };
 
 %extend Network {
-    Network(const Device &device, std::shared_ptr<Buffer> &buffer)
-    {
-        if(buffer == nullptr){
-            throw EthosU::Exception(std::string("Failed to create the network, buffer is nullptr.").c_str());
-        }
-        auto network = new EthosU::Network(device, buffer);
-        return network;
-    }
-}
 
-%extend Network {
+    Network(const Device &device, const std::string& filename)
+    {
+        std::ifstream stream(filename, std::ios::binary);
+        if (!stream.is_open()) {
+            throw EthosU::Exception(std::string("Failed to open file: ").append(filename).c_str());
+        }
+
+        stream.seekg(0, std::ios_base::end);
+        size_t size = stream.tellg();
+        stream.seekg(0, std::ios_base::beg);
+
+        std::unique_ptr<unsigned char[]> buffer = std::make_unique<unsigned char[]>(size);
+        stream.read(reinterpret_cast<char*>(buffer.get()), size);
+        return new EthosU::Network(device, buffer.get(), size);
+    }
+
+    %buffer_in(const unsigned char* networkData, size_t networkSize, BUFFER_FLAG_RO);
+    Network(const Device &device, const unsigned char* networkData, size_t networkSize)
+    {
+        if(networkData == nullptr){
+            throw EthosU::Exception(std::string("Failed to create the network, networkData is nullptr.").c_str());
+        }
+
+        if(networkSize == 0U){
+            throw EthosU::Exception(std::string("Failed to create the network, networkSize is zero.").c_str());
+        }
+
+        return new EthosU::Network(device, networkData, networkSize);
+    }
+    %clear_buffer_in(const unsigned char* networkData, size_t networkSize);
+
     Network(const Device &device, const unsigned int index)
     {
-        auto network = new EthosU::Network(device, index);
-        return network;
+        return new EthosU::Network(device, index);
     }
 }