aboutsummaryrefslogtreecommitdiff
path: root/applications/driver_unit_tests/command_stream.hpp
diff options
context:
space:
mode:
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 */