aboutsummaryrefslogtreecommitdiff
path: root/driver_library/python/src/ethosu_driver/swig/driver.i
diff options
context:
space:
mode:
authorMikael Olsson <mikael.olsson@arm.com>2023-10-30 11:10:56 +0100
committerMikael Olsson <mikael.olsson@arm.com>2023-11-06 09:36:00 +0100
commitc081e5954cd92165b139488e76bdfef1402acee6 (patch)
tree32bc237c124e21f12287150cba040c87c8e8b7e3 /driver_library/python/src/ethosu_driver/swig/driver.i
parent9c999fdd40c0bf2ae420f6f3bfe013dc6baa73c1 (diff)
downloadethos-u-linux-driver-stack-c081e5954cd92165b139488e76bdfef1402acee6.tar.gz
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>
Diffstat (limited to 'driver_library/python/src/ethosu_driver/swig/driver.i')
-rw-r--r--driver_library/python/src/ethosu_driver/swig/driver.i51
1 files changed, 31 insertions, 20 deletions
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 @@ public:
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 @@ public:
%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 @@ public:
};
%extend Network {
- Network(const Device &device, std::shared_ptr<Buffer> &buffer)
+
+ Network(const Device &device, const std::string& filename)
{
- if(buffer == nullptr){
- throw EthosU::Exception(std::string("Failed to create the network, buffer is nullptr.").c_str());
+ std::ifstream stream(filename, std::ios::binary);
+ if (!stream.is_open()) {
+ throw EthosU::Exception(std::string("Failed to open file: ").append(filename).c_str());
}
- auto network = new EthosU::Network(device, buffer);
- return network;
+
+ 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);
}
-}
-%extend Network {
+ %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);
}
}