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> |
| 27 | #include <stddef.h> |
| 28 | #include <ethosu_driver.h> |
| 29 | #include <pmu_ethosu.h> |
| 30 | |
| 31 | /**************************************************************************** |
| 32 | * Types |
| 33 | ****************************************************************************/ |
| 34 | |
| 35 | namespace EthosU { |
| 36 | namespace CommandStream { |
| 37 | |
| 38 | /**************************************************************************** |
| 39 | * DataPointer |
| 40 | ****************************************************************************/ |
| 41 | |
| 42 | struct 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 | |
| 56 | using PmuEvents = std::array<ethosu_pmu_event_type, ETHOSU_PMU_NCOUNTERS>; |
| 57 | |
| 58 | class Pmu { |
| 59 | public: |
| 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 | |
| 68 | private: |
| 69 | ethosu_driver *drv; |
| 70 | PmuEvents config; |
| 71 | }; |
| 72 | |
| 73 | /**************************************************************************** |
| 74 | * CommandStream |
| 75 | ****************************************************************************/ |
| 76 | |
| 77 | using BasePointers = std::array<DataPointer, ETHOSU_DRIVER_BASEP_INDEXES>; |
| 78 | |
| 79 | class CommandStream { |
| 80 | public: |
| 81 | CommandStream(const DataPointer &_commandStream, |
| 82 | const BasePointers &_pointers = {}, |
| 83 | const PmuEvents &_pmuEvents = {}); |
| 84 | virtual ~CommandStream(); |
| 85 | |
| 86 | int run(size_t repeat = 1); |
| 87 | |
| 88 | DataPointer &getCommandStream(); |
| 89 | BasePointers &getBasePointers(); |
| 90 | Pmu &getPmu(); |
| 91 | |
| 92 | private: |
| 93 | ethosu_driver *drv; |
| 94 | DataPointer commandStream; |
| 95 | BasePointers basePointers; |
| 96 | Pmu pmu; |
| 97 | }; |
| 98 | |
| 99 | #define DRIVER_ACTION_MAGIC() \ |
| 100 | 'C', 'O', 'P', '1', |
| 101 | |
| 102 | #define DRIVER_ACTION_COMMAND_STREAM(length) \ |
| 103 | 0x02, (length >> 16) & 0xff, length & 0xff, (length >> 8) & 0xff, |
| 104 | |
| 105 | #define DRIVER_ACTION_NOP() \ |
| 106 | 0x05, 0x00, 0x00, 0x00, |
| 107 | |
| 108 | #define NPU_OP_STOP(mask) \ |
| 109 | (mask >> 8) && 0xff, mask & 0xff, 0x08, 0x00, |
| 110 | |
| 111 | }; // namespace CommandStream |
| 112 | }; // namespace EthosU |
| 113 | |
| 114 | #endif /* COMMAND_STREAM_HPP */ |