aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver_library/include/ethosu.hpp7
-rw-r--r--driver_library/python/src/ethosu_driver/__init__.py5
-rw-r--r--driver_library/python/src/ethosu_driver/swig/driver.i15
-rw-r--r--driver_library/python/test/test_driver.py13
-rw-r--r--driver_library/src/ethosu.cpp35
-rw-r--r--utils/inference_runner/inference_runner.cpp1
6 files changed, 67 insertions, 9 deletions
diff --git a/driver_library/include/ethosu.hpp b/driver_library/include/ethosu.hpp
index 15957f4..4dba469 100644
--- a/driver_library/include/ethosu.hpp
+++ b/driver_library/include/ethosu.hpp
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: Copyright 2020-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ * SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -40,6 +40,9 @@
namespace EthosU {
+constexpr uint32_t MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION = 1;
+constexpr uint32_t MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION = 1;
+
class Exception : public std::exception {
public:
Exception(const char *msg);
@@ -134,9 +137,11 @@ public:
int ioctl(unsigned long cmd, void *data = nullptr) const;
Capabilities capabilities() const;
+ const SemanticVersion &getDriverVersion() const;
private:
int fd;
+ SemanticVersion driverVersion;
};
class Buffer {
diff --git a/driver_library/python/src/ethosu_driver/__init__.py b/driver_library/python/src/ethosu_driver/__init__.py
index ee6ea1f..a804c13 100644
--- a/driver_library/python/src/ethosu_driver/__init__.py
+++ b/driver_library/python/src/ethosu_driver/__init__.py
@@ -1,6 +1,7 @@
-# SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
# SPDX-License-Identifier: Apache-2.0
-from ._generated.driver import Device, Inference, Network, Buffer
+from ._generated.driver import Device, Inference, Network, Buffer, \
+ MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION, MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION
from ._utilities import open_device, load_model, populate_buffers, \
allocate_buffers, get_results, InferenceRunner
diff --git a/driver_library/python/src/ethosu_driver/swig/driver.i b/driver_library/python/src/ethosu_driver/swig/driver.i
index 4cd8bdf..558c22e 100644
--- a/driver_library/python/src/ethosu_driver/swig/driver.i
+++ b/driver_library/python/src/ethosu_driver/swig/driver.i
@@ -1,5 +1,5 @@
//
-// SPDX-FileCopyrightText: Copyright 2020, 2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+// SPDX-FileCopyrightText: Copyright 2020, 2022-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
// SPDX-License-Identifier: Apache-2.0
//
%module driver
@@ -29,7 +29,6 @@
%shared_ptr(EthosU::Buffer);
%shared_ptr(EthosU::Network);
-
namespace std {
%template(UintVector) vector<unsigned int>;
%template(SizeTVector) vector<size_t>;
@@ -39,6 +38,9 @@ namespace std {
namespace EthosU
{
+constexpr uint32_t MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION;
+constexpr uint32_t MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION;
+
%feature("docstring",
"
Semantic Version : major.minor.patch
@@ -166,6 +168,15 @@ public:
Capabilities: Return capabilities of device.
") capabilities;
Capabilities capabilities() const;
+
+ %feature("docstring",
+ "
+ Returns kernel driver version information.
+
+ Returns:
+ SemanticVersion: kernel driver version.
+ ") getDriverVersion;
+ const SemanticVersion &getDriverVersion() const;
};
%extend Device {
diff --git a/driver_library/python/test/test_driver.py b/driver_library/python/test/test_driver.py
index 5496aed..e4e276a 100644
--- a/driver_library/python/test/test_driver.py
+++ b/driver_library/python/test/test_driver.py
@@ -1,5 +1,5 @@
#
-# SPDX-FileCopyrightText: Copyright 2021-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+# SPDX-FileCopyrightText: Copyright 2021-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
# SPDX-License-Identifier: Apache-2.0
#
import pytest
@@ -177,3 +177,14 @@ def test_capabilities(device):
assert cap.hwId
assert cap.hwCfg
assert cap.driver
+
+@pytest.mark.parametrize('device_name', ['ethosu0'])
+def test_kernel_driver_version(device):
+ version = device.getDriverVersion()
+ zero_version = [0, 0, 0]
+ # Validate that a version was returned
+ assert zero_version != [version.major, version.minor, version.patch]
+ # Check that supported kernel driver major versions are available in Python API
+ assert driver.MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION
+ assert driver.MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION
+
diff --git a/driver_library/src/ethosu.cpp b/driver_library/src/ethosu.cpp
index e425e52..1758b07 100644
--- a/driver_library/src/ethosu.cpp
+++ b/driver_library/src/ethosu.cpp
@@ -1,5 +1,5 @@
/*
- * SPDX-FileCopyrightText: Copyright 2020-2022 Arm Limited and/or its affiliates <open-source-office@arm.com>
+ * SPDX-FileCopyrightText: Copyright 2020-2023 Arm Limited and/or its affiliates <open-source-office@arm.com>
*
* SPDX-License-Identifier: Apache-2.0
*
@@ -25,6 +25,7 @@
#include <fstream>
#include <iomanip>
#include <iostream>
+#include <utility>
#include <fcntl.h>
#include <poll.h>
@@ -36,6 +37,9 @@
using namespace std;
namespace {
+std::string driverVersionToString(const EthosU::ethosu_uapi_kernel_driver_version &version) {
+ return std::to_string(version.major) + "." + std::to_string(version.minor) + "." + std::to_string(version.patch);
+}
enum class Severity { Error, Warning, Info, Debug };
@@ -214,9 +218,27 @@ ostream &operator<<(ostream &out, const SemanticVersion &v) {
/****************************************************************************
* Device
****************************************************************************/
-Device::Device(const char *device) {
- fd = eopen(device, O_RDWR | O_NONBLOCK);
+Device::Device(const char *device) : fd(eopen(device, O_RDWR | O_NONBLOCK)) {
+ ethosu_uapi_kernel_driver_version version = {};
+
Log(Severity::Info) << "Device(\"" << device << "\"). this=" << this << ", fd=" << fd << endl;
+
+ try {
+ eioctl(fd, ETHOSU_IOCTL_DRIVER_VERSION_GET, &version);
+
+ if (MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION < version.major ||
+ MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION > version.major) {
+ throw Exception(
+ std::string("Unsupported kernel driver version: ").append(driverVersionToString(version)).c_str());
+ }
+ } catch (std::exception &e) {
+ try {
+ eclose(fd);
+ } catch (...) { std::throw_with_nested(e); }
+ throw;
+ }
+
+ driverVersion = {version.major, version.minor, version.patch};
}
Device::~Device() noexcept(false) {
@@ -228,6 +250,10 @@ int Device::ioctl(unsigned long cmd, void *data) const {
return eioctl(fd, cmd, data);
}
+const SemanticVersion &Device::getDriverVersion() const {
+ return driverVersion;
+}
+
Capabilities Device::capabilities() const {
ethosu_uapi_device_capabilities uapi;
(void)eioctl(fd, ETHOSU_IOCTL_CAPABILITIES_REQ, static_cast<void *>(&uapi));
@@ -568,4 +594,7 @@ vector<shared_ptr<Buffer>> &Inference::getOfmBuffers() {
return ofmBuffers;
}
+static_assert(MAX_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION >= ETHOSU_KERNEL_DRIVER_VERSION_MAJOR &&
+ MIN_SUPPORTED_KERNEL_DRIVER_MAJOR_VERSION <= ETHOSU_KERNEL_DRIVER_VERSION_MAJOR,
+ "Unsupported major kernel driver version in UAPI");
} // namespace EthosU
diff --git a/utils/inference_runner/inference_runner.cpp b/utils/inference_runner/inference_runner.cpp
index 42b89fc..d53ab8c 100644
--- a/utils/inference_runner/inference_runner.cpp
+++ b/utils/inference_runner/inference_runner.cpp
@@ -211,6 +211,7 @@ int main(int argc, char *argv[]) {
try {
Device device;
+ cout << "Driver version:" << device.getDriverVersion() << endl;
cout << "Send Ping" << endl;
device.ioctl(ETHOSU_IOCTL_PING);