diff options
author | Mikael Olsson <mikael.olsson@arm.com> | 2023-10-30 11:10:56 +0100 |
---|---|---|
committer | Mikael Olsson <mikael.olsson@arm.com> | 2023-11-06 09:36:00 +0100 |
commit | c081e5954cd92165b139488e76bdfef1402acee6 (patch) | |
tree | 32bc237c124e21f12287150cba040c87c8e8b7e3 /utils | |
parent | 9c999fdd40c0bf2ae420f6f3bfe013dc6baa73c1 (diff) | |
download | ethos-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 'utils')
-rw-r--r-- | utils/inference_runner/inference_runner.cpp | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/utils/inference_runner/inference_runner.cpp b/utils/inference_runner/inference_runner.cpp index c7a18b0..721cd57 100644 --- a/utils/inference_runner/inference_runner.cpp +++ b/utils/inference_runner/inference_runner.cpp @@ -25,6 +25,7 @@ #include <stdio.h> #include <string> #include <unistd.h> +#include <utility> using namespace std; using namespace EthosU; @@ -56,7 +57,7 @@ void rangeCheck(const int i, const int argc, const string arg) { } } -shared_ptr<Buffer> allocAndFill(Device &device, const string filename) { +pair<unique_ptr<unsigned char[]>, size_t> getNetworkData(const string filename) { ifstream stream(filename, ios::binary); if (!stream.is_open()) { cerr << "Error: Failed to open '" << filename << "'" << endl; @@ -67,10 +68,10 @@ shared_ptr<Buffer> allocAndFill(Device &device, const string filename) { size_t size = stream.tellg(); stream.seekg(0, ios_base::beg); - shared_ptr<Buffer> buffer = make_shared<Buffer>(device, size); - stream.read(buffer->data(), size); + unique_ptr<unsigned char[]> data = std::make_unique<unsigned char[]>(size); + stream.read(reinterpret_cast<char *>(data.get()), size); - return buffer; + return make_pair(std::move(data), size); } shared_ptr<Inference> createInference(Device &device, @@ -234,8 +235,8 @@ int main(int argc, char *argv[]) { shared_ptr<Network> network; if (networkIndex < 0) { - shared_ptr<Buffer> networkBuffer = allocAndFill(device, networkArg); - network = make_shared<Network>(device, networkBuffer); + auto networkData = getNetworkData(networkArg); + network = make_shared<Network>(device, networkData.first.get(), networkData.second); } else { network = make_shared<Network>(device, networkIndex); } |