aboutsummaryrefslogtreecommitdiff
path: root/applications/driver_unit_tests/command_stream.hpp
diff options
context:
space:
mode:
authorKristofer Jonsson <kristofer.jonsson@arm.com>2021-03-10 17:13:52 +0100
committerKristofer Jonsson <kristofer.jonsson@arm.com>2021-03-26 09:27:44 +0100
commitb5f7cfe253dfeadd83caf60fde34b5b66f356782 (patch)
treef2286d8d1b7e1010c61277a80bdf344130c7322f /applications/driver_unit_tests/command_stream.hpp
parentd66709083f08b4c32792d4a93e1e5b3c6b913fb2 (diff)
downloadethos-u-core-platform-b5f7cfe253dfeadd83caf60fde34b5b66f356782.tar.gz
Driver unit tests
Add driver unit tests that runs simple command streams directly on top of the NPU driver. Change-Id: I3fcce2a2bfbd458d14186b8fd13ba47174f49562
Diffstat (limited to 'applications/driver_unit_tests/command_stream.hpp')
-rw-r--r--applications/driver_unit_tests/command_stream.hpp114
1 files changed, 114 insertions, 0 deletions
diff --git a/applications/driver_unit_tests/command_stream.hpp b/applications/driver_unit_tests/command_stream.hpp
new file mode 100644
index 0000000..ec55d5e
--- /dev/null
+++ b/applications/driver_unit_tests/command_stream.hpp
@@ -0,0 +1,114 @@
+/*
+ * Copyright (c) 2021 Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ *
+ * Licensed under the Apache License, Version 2.0 (the License); you may
+ * not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an AS IS BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef COMMAND_STREAM_HPP
+#define COMMAND_STREAM_HPP
+
+/****************************************************************************
+ * Includes
+ ****************************************************************************/
+
+#include <array>
+#include <stddef.h>
+#include <ethosu_driver.h>
+#include <pmu_ethosu.h>
+
+/****************************************************************************
+ * Types
+ ****************************************************************************/
+
+namespace EthosU {
+namespace CommandStream {
+
+/****************************************************************************
+ * DataPointer
+ ****************************************************************************/
+
+struct DataPointer {
+ DataPointer();
+ DataPointer(const char *_data, size_t _size);
+
+ bool operator!=(const DataPointer &other);
+
+ const char *data;
+ size_t size;
+};
+
+/****************************************************************************
+ * Pmu
+ ****************************************************************************/
+
+using PmuEvents = std::array<ethosu_pmu_event_type, ETHOSU_PMU_NCOUNTERS>;
+
+class Pmu {
+public:
+ Pmu(ethosu_driver *_drv, const PmuEvents &_config = {});
+
+ void clear();
+ void print();
+
+ uint64_t getCycleCount() const;
+ uint32_t getEventCount(size_t index) const;
+
+private:
+ ethosu_driver *drv;
+ PmuEvents config;
+};
+
+/****************************************************************************
+ * CommandStream
+ ****************************************************************************/
+
+using BasePointers = std::array<DataPointer, ETHOSU_DRIVER_BASEP_INDEXES>;
+
+class CommandStream {
+public:
+ CommandStream(const DataPointer &_commandStream,
+ const BasePointers &_pointers = {},
+ const PmuEvents &_pmuEvents = {});
+ virtual ~CommandStream();
+
+ int run(size_t repeat = 1);
+
+ DataPointer &getCommandStream();
+ BasePointers &getBasePointers();
+ Pmu &getPmu();
+
+private:
+ ethosu_driver *drv;
+ DataPointer commandStream;
+ BasePointers basePointers;
+ Pmu pmu;
+};
+
+#define DRIVER_ACTION_MAGIC() \
+ 'C', 'O', 'P', '1',
+
+#define DRIVER_ACTION_COMMAND_STREAM(length) \
+ 0x02, (length >> 16) & 0xff, length & 0xff, (length >> 8) & 0xff,
+
+#define DRIVER_ACTION_NOP() \
+ 0x05, 0x00, 0x00, 0x00,
+
+#define NPU_OP_STOP(mask) \
+ (mask >> 8) && 0xff, mask & 0xff, 0x08, 0x00,
+
+}; // namespace CommandStream
+}; // namespace EthosU
+
+#endif /* COMMAND_STREAM_HPP */