aboutsummaryrefslogtreecommitdiff
path: root/driver_library/src/ethosu.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'driver_library/src/ethosu.cpp')
-rw-r--r--driver_library/src/ethosu.cpp35
1 files changed, 32 insertions, 3 deletions
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