Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 1 | /* |
| 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 Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 27 | #include <ethosu_driver.h> |
| 28 | #include <pmu_ethosu.h> |
Anton Moberg | 908a07c | 2021-04-08 09:50:57 +0200 | [diff] [blame] | 29 | #include <stddef.h> |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 30 | |
| 31 | /**************************************************************************** |
Jonny Svärd | bec9ac1 | 2021-10-15 10:35:57 +0200 | [diff] [blame] | 32 | * Defines |
| 33 | ****************************************************************************/ |
| 34 | |
| 35 | #ifndef ETHOSU_BASEP_INDEXES |
| 36 | #define ETHOSU_BASEP_INDEXES 8 |
| 37 | #endif |
| 38 | |
| 39 | /**************************************************************************** |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 40 | * Types |
| 41 | ****************************************************************************/ |
| 42 | |
| 43 | namespace EthosU { |
| 44 | namespace CommandStream { |
| 45 | |
| 46 | /**************************************************************************** |
| 47 | * DataPointer |
| 48 | ****************************************************************************/ |
| 49 | |
| 50 | struct DataPointer { |
| 51 | DataPointer(); |
| 52 | DataPointer(const char *_data, size_t _size); |
| 53 | |
| 54 | bool operator!=(const DataPointer &other); |
| 55 | |
| 56 | const char *data; |
| 57 | size_t size; |
| 58 | }; |
| 59 | |
| 60 | /**************************************************************************** |
| 61 | * Pmu |
| 62 | ****************************************************************************/ |
| 63 | |
| 64 | using PmuEvents = std::array<ethosu_pmu_event_type, ETHOSU_PMU_NCOUNTERS>; |
| 65 | |
| 66 | class Pmu { |
| 67 | public: |
| 68 | Pmu(ethosu_driver *_drv, const PmuEvents &_config = {}); |
| 69 | |
| 70 | void clear(); |
| 71 | void print(); |
| 72 | |
| 73 | uint64_t getCycleCount() const; |
| 74 | uint32_t getEventCount(size_t index) const; |
| 75 | |
| 76 | private: |
| 77 | ethosu_driver *drv; |
| 78 | PmuEvents config; |
| 79 | }; |
| 80 | |
| 81 | /**************************************************************************** |
| 82 | * CommandStream |
| 83 | ****************************************************************************/ |
| 84 | |
Jonny Svärd | c5941c4 | 2021-06-01 18:40:45 +0200 | [diff] [blame] | 85 | using BasePointers = std::array<DataPointer, ETHOSU_BASEP_INDEXES>; |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 86 | |
| 87 | class CommandStream { |
| 88 | public: |
| 89 | CommandStream(const DataPointer &_commandStream, |
| 90 | const BasePointers &_pointers = {}, |
Anton Moberg | 908a07c | 2021-04-08 09:50:57 +0200 | [diff] [blame] | 91 | const PmuEvents &_pmuEvents = {}); |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 92 | virtual ~CommandStream(); |
| 93 | |
| 94 | int run(size_t repeat = 1); |
| 95 | |
| 96 | DataPointer &getCommandStream(); |
| 97 | BasePointers &getBasePointers(); |
| 98 | Pmu &getPmu(); |
| 99 | |
| 100 | private: |
| 101 | ethosu_driver *drv; |
| 102 | DataPointer commandStream; |
| 103 | BasePointers basePointers; |
| 104 | Pmu pmu; |
| 105 | }; |
| 106 | |
Anton Moberg | 908a07c | 2021-04-08 09:50:57 +0200 | [diff] [blame] | 107 | #define DRIVER_ACTION_MAGIC() 'C', 'O', 'P', '1', |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 108 | |
Anton Moberg | 908a07c | 2021-04-08 09:50:57 +0200 | [diff] [blame] | 109 | #define DRIVER_ACTION_COMMAND_STREAM(length) 0x02, (length >> 16) & 0xff, length & 0xff, (length >> 8) & 0xff, |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 110 | |
Anton Moberg | 908a07c | 2021-04-08 09:50:57 +0200 | [diff] [blame] | 111 | #define DRIVER_ACTION_NOP() 0x05, 0x00, 0x00, 0x00, |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 112 | |
Anton Moberg | 908a07c | 2021-04-08 09:50:57 +0200 | [diff] [blame] | 113 | #define NPU_OP_STOP(mask) (mask >> 8) && 0xff, mask & 0xff, 0x08, 0x00, |
Kristofer Jonsson | b5f7cfe | 2021-03-10 17:13:52 +0100 | [diff] [blame] | 114 | |
| 115 | }; // namespace CommandStream |
| 116 | }; // namespace EthosU |
| 117 | |
| 118 | #endif /* COMMAND_STREAM_HPP */ |