blob: 4a0b602a8af8e2d3502864953ca2daa1f658410a [file] [log] [blame]
Kristofer Jonssonb5f7cfe2021-03-10 17:13:52 +01001/*
2 * Copyright (c) 2021 Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 *
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19#ifndef COMMAND_STREAM_HPP
20#define COMMAND_STREAM_HPP
21
22/****************************************************************************
23 * Includes
24 ****************************************************************************/
25
26#include <array>
Kristofer Jonssonb5f7cfe2021-03-10 17:13:52 +010027#include <ethosu_driver.h>
28#include <pmu_ethosu.h>
Anton Moberg908a07c2021-04-08 09:50:57 +020029#include <stddef.h>
Kristofer Jonssonb5f7cfe2021-03-10 17:13:52 +010030
31/****************************************************************************
32 * Types
33 ****************************************************************************/
34
35namespace EthosU {
36namespace CommandStream {
37
38/****************************************************************************
39 * DataPointer
40 ****************************************************************************/
41
42struct DataPointer {
43 DataPointer();
44 DataPointer(const char *_data, size_t _size);
45
46 bool operator!=(const DataPointer &other);
47
48 const char *data;
49 size_t size;
50};
51
52/****************************************************************************
53 * Pmu
54 ****************************************************************************/
55
56using PmuEvents = std::array<ethosu_pmu_event_type, ETHOSU_PMU_NCOUNTERS>;
57
58class Pmu {
59public:
60 Pmu(ethosu_driver *_drv, const PmuEvents &_config = {});
61
62 void clear();
63 void print();
64
65 uint64_t getCycleCount() const;
66 uint32_t getEventCount(size_t index) const;
67
68private:
69 ethosu_driver *drv;
70 PmuEvents config;
71};
72
73/****************************************************************************
74 * CommandStream
75 ****************************************************************************/
76
77using BasePointers = std::array<DataPointer, ETHOSU_DRIVER_BASEP_INDEXES>;
78
79class CommandStream {
80public:
81 CommandStream(const DataPointer &_commandStream,
82 const BasePointers &_pointers = {},
Anton Moberg908a07c2021-04-08 09:50:57 +020083 const PmuEvents &_pmuEvents = {});
Kristofer Jonssonb5f7cfe2021-03-10 17:13:52 +010084 virtual ~CommandStream();
85
86 int run(size_t repeat = 1);
87
88 DataPointer &getCommandStream();
89 BasePointers &getBasePointers();
90 Pmu &getPmu();
91
92private:
93 ethosu_driver *drv;
94 DataPointer commandStream;
95 BasePointers basePointers;
96 Pmu pmu;
97};
98
Anton Moberg908a07c2021-04-08 09:50:57 +020099#define DRIVER_ACTION_MAGIC() 'C', 'O', 'P', '1',
Kristofer Jonssonb5f7cfe2021-03-10 17:13:52 +0100100
Anton Moberg908a07c2021-04-08 09:50:57 +0200101#define DRIVER_ACTION_COMMAND_STREAM(length) 0x02, (length >> 16) & 0xff, length & 0xff, (length >> 8) & 0xff,
Kristofer Jonssonb5f7cfe2021-03-10 17:13:52 +0100102
Anton Moberg908a07c2021-04-08 09:50:57 +0200103#define DRIVER_ACTION_NOP() 0x05, 0x00, 0x00, 0x00,
Kristofer Jonssonb5f7cfe2021-03-10 17:13:52 +0100104
Anton Moberg908a07c2021-04-08 09:50:57 +0200105#define NPU_OP_STOP(mask) (mask >> 8) && 0xff, mask & 0xff, 0x08, 0x00,
Kristofer Jonssonb5f7cfe2021-03-10 17:13:52 +0100106
107}; // namespace CommandStream
108}; // namespace EthosU
109
110#endif /* COMMAND_STREAM_HPP */