Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 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 | #include <message_process.hpp> |
| 20 | |
Per Åstrand | d9afc08 | 2020-10-06 13:25:08 +0200 | [diff] [blame] | 21 | #include "cmsis_compiler.h" |
| 22 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 23 | #include <cstddef> |
| 24 | #include <cstdio> |
Kristofer Jonsson | 2548014 | 2020-09-03 12:35:21 +0200 | [diff] [blame] | 25 | #include <cstring> |
Per Åstrand | 91a9173 | 2020-09-25 15:04:26 +0200 | [diff] [blame] | 26 | #include <inttypes.h> |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 27 | |
Kristofer Jonsson | 72fa50b | 2020-09-10 13:26:41 +0200 | [diff] [blame] | 28 | using namespace std; |
| 29 | using namespace InferenceProcess; |
| 30 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 31 | namespace MessageProcess { |
| 32 | |
Kristofer Jonsson | 68b4ad5 | 2020-12-10 15:11:27 +0100 | [diff] [blame] | 33 | QueueImpl::QueueImpl(ethosu_core_queue &_queue) : queue(_queue) { |
| 34 | cleanHeaderData(); |
| 35 | } |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 36 | |
| 37 | bool QueueImpl::empty() const { |
Kristofer Jonsson | 2cda7fb | 2021-02-01 11:22:59 +0100 | [diff] [blame^] | 38 | invalidateHeaderData(); |
| 39 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 40 | return queue.header.read == queue.header.write; |
| 41 | } |
| 42 | |
| 43 | size_t QueueImpl::available() const { |
Kristofer Jonsson | 2cda7fb | 2021-02-01 11:22:59 +0100 | [diff] [blame^] | 44 | invalidateHeaderData(); |
| 45 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 46 | size_t avail = queue.header.write - queue.header.read; |
| 47 | |
| 48 | if (queue.header.read > queue.header.write) { |
| 49 | avail += queue.header.size; |
| 50 | } |
| 51 | |
| 52 | return avail; |
| 53 | } |
| 54 | |
| 55 | size_t QueueImpl::capacity() const { |
| 56 | return queue.header.size - available(); |
| 57 | } |
| 58 | |
| 59 | bool QueueImpl::read(uint8_t *dst, uint32_t length) { |
| 60 | const uint8_t *end = dst + length; |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 61 | |
Kristofer Jonsson | 2cda7fb | 2021-02-01 11:22:59 +0100 | [diff] [blame^] | 62 | // Available will invalidate the cache |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 63 | if (length > available()) { |
| 64 | return false; |
| 65 | } |
| 66 | |
Kristofer Jonsson | 2cda7fb | 2021-02-01 11:22:59 +0100 | [diff] [blame^] | 67 | uint32_t rpos = queue.header.read; |
| 68 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 69 | while (dst < end) { |
| 70 | *dst++ = queue.data[rpos]; |
| 71 | rpos = (rpos + 1) % queue.header.size; |
| 72 | } |
| 73 | |
| 74 | queue.header.read = rpos; |
| 75 | |
Kristofer Jonsson | 2cbaaa9 | 2020-11-19 16:14:46 +0100 | [diff] [blame] | 76 | cleanHeader(); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 77 | |
| 78 | return true; |
| 79 | } |
| 80 | |
| 81 | bool QueueImpl::write(const Vec *vec, size_t length) { |
| 82 | size_t total = 0; |
| 83 | |
| 84 | for (size_t i = 0; i < length; i++) { |
| 85 | total += vec[i].length; |
| 86 | } |
| 87 | |
Kristofer Jonsson | 2cbaaa9 | 2020-11-19 16:14:46 +0100 | [diff] [blame] | 88 | invalidateHeader(); |
| 89 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 90 | if (total > capacity()) { |
| 91 | return false; |
| 92 | } |
| 93 | |
| 94 | uint32_t wpos = queue.header.write; |
| 95 | |
| 96 | for (size_t i = 0; i < length; i++) { |
| 97 | const uint8_t *src = reinterpret_cast<const uint8_t *>(vec[i].base); |
| 98 | const uint8_t *end = src + vec[i].length; |
| 99 | |
| 100 | while (src < end) { |
| 101 | queue.data[wpos] = *src++; |
| 102 | wpos = (wpos + 1) % queue.header.size; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | // Update the write position last |
| 107 | queue.header.write = wpos; |
| 108 | |
Kristofer Jonsson | 2cbaaa9 | 2020-11-19 16:14:46 +0100 | [diff] [blame] | 109 | cleanHeaderData(); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 110 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 111 | return true; |
| 112 | } |
| 113 | |
| 114 | bool QueueImpl::write(const uint32_t type, const void *src, uint32_t length) { |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 115 | ethosu_core_msg msg = {ETHOSU_CORE_MSG_MAGIC, type, length}; |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 116 | Vec vec[2] = {{&msg, sizeof(msg)}, {src, length}}; |
| 117 | |
| 118 | return write(vec, 2); |
| 119 | } |
| 120 | |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 121 | // Skip to magic or end of queue |
| 122 | void QueueImpl::reset() { |
Kristofer Jonsson | 2cbaaa9 | 2020-11-19 16:14:46 +0100 | [diff] [blame] | 123 | invalidateHeader(); |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 124 | queue.header.read = queue.header.write; |
Kristofer Jonsson | 2cbaaa9 | 2020-11-19 16:14:46 +0100 | [diff] [blame] | 125 | cleanHeader(); |
Per Åstrand | dc28b13 | 2020-09-28 13:02:18 +0200 | [diff] [blame] | 126 | } |
| 127 | |
Kristofer Jonsson | 2cbaaa9 | 2020-11-19 16:14:46 +0100 | [diff] [blame] | 128 | void QueueImpl::cleanHeader() const { |
| 129 | #if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) |
| 130 | SCB_CleanDCache_by_Addr(reinterpret_cast<uint32_t *>(&queue.header), sizeof(queue.header)); |
| 131 | #endif |
| 132 | } |
| 133 | |
| 134 | void QueueImpl::cleanHeaderData() const { |
| 135 | #if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) |
| 136 | SCB_CleanDCache_by_Addr(reinterpret_cast<uint32_t *>(&queue.header), sizeof(queue.header)); |
Bhavik Patel | 97906eb | 2020-12-17 15:32:16 +0100 | [diff] [blame] | 137 | uintptr_t queueDataPtr = reinterpret_cast<uintptr_t>(&queue.data[0]); |
| 138 | SCB_CleanDCache_by_Addr(reinterpret_cast<uint32_t *>(queueDataPtr & ~3), queue.header.size + (queueDataPtr & 3)); |
Kristofer Jonsson | 2cbaaa9 | 2020-11-19 16:14:46 +0100 | [diff] [blame] | 139 | #endif |
| 140 | } |
| 141 | |
| 142 | void QueueImpl::invalidateHeader() const { |
| 143 | #if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) |
| 144 | SCB_InvalidateDCache_by_Addr(reinterpret_cast<uint32_t *>(&queue.header), sizeof(queue.header)); |
| 145 | #endif |
| 146 | } |
| 147 | |
| 148 | void QueueImpl::invalidateHeaderData() const { |
| 149 | #if defined(__DCACHE_PRESENT) && (__DCACHE_PRESENT == 1U) |
| 150 | SCB_InvalidateDCache_by_Addr(reinterpret_cast<uint32_t *>(&queue.header), sizeof(queue.header)); |
Bhavik Patel | 97906eb | 2020-12-17 15:32:16 +0100 | [diff] [blame] | 151 | uintptr_t queueDataPtr = reinterpret_cast<uintptr_t>(&queue.data[0]); |
| 152 | SCB_InvalidateDCache_by_Addr(reinterpret_cast<uint32_t *>(queueDataPtr & ~3), |
| 153 | queue.header.size + (queueDataPtr & 3)); |
Kristofer Jonsson | 2cbaaa9 | 2020-11-19 16:14:46 +0100 | [diff] [blame] | 154 | #endif |
| 155 | } |
| 156 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 157 | MessageProcess::MessageProcess(ethosu_core_queue &in, |
| 158 | ethosu_core_queue &out, |
Jonny Svärd | 44398c8 | 2020-10-06 14:18:28 +0200 | [diff] [blame] | 159 | Mailbox::Mailbox &mbox, |
Per Åstrand | bbd9c8f | 2020-09-25 15:07:35 +0200 | [diff] [blame] | 160 | ::InferenceProcess::InferenceProcess &_inferenceProcess) : |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 161 | queueIn(in), |
Jonny Svärd | 44398c8 | 2020-10-06 14:18:28 +0200 | [diff] [blame] | 162 | queueOut(out), mailbox(mbox), inferenceProcess(_inferenceProcess) { |
| 163 | mailbox.registerCallback(mailboxCallback, reinterpret_cast<void *>(this)); |
| 164 | } |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 165 | |
| 166 | void MessageProcess::run() { |
| 167 | while (true) { |
| 168 | // Handle all messages in queue |
| 169 | while (handleMessage()) |
| 170 | ; |
| 171 | |
| 172 | // Wait for event |
| 173 | __WFE(); |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void MessageProcess::handleIrq() { |
| 178 | __SEV(); |
| 179 | } |
| 180 | |
| 181 | bool MessageProcess::handleMessage() { |
| 182 | ethosu_core_msg msg; |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 183 | |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 184 | if (queueIn.available() == 0) { |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 185 | return false; |
| 186 | } |
| 187 | |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 188 | // Read msg header |
| 189 | // Only process a complete message header, else send error message |
| 190 | // and reset queue |
| 191 | if (!queueIn.read(msg)) { |
| 192 | sndErrorRspAndResetQueue(ETHOSU_CORE_MSG_ERR_INVALID_SIZE, "Failed to read a complete header"); |
| 193 | return false; |
| 194 | } |
| 195 | |
| 196 | printf("Msg: header magic=%" PRIX32 ", type=%" PRIu32 ", length=%" PRIu32 "\n", msg.magic, msg.type, msg.length); |
| 197 | |
| 198 | if (msg.magic != ETHOSU_CORE_MSG_MAGIC) { |
| 199 | sndErrorRspAndResetQueue(ETHOSU_CORE_MSG_ERR_INVALID_MAGIC, "Invalid magic"); |
| 200 | return false; |
| 201 | } |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 202 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 203 | switch (msg.type) { |
| 204 | case ETHOSU_CORE_MSG_PING: |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 205 | printf("Msg: Ping\n"); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 206 | sendPong(); |
| 207 | break; |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 208 | case ETHOSU_CORE_MSG_ERR: { |
| 209 | struct ethosu_core_msg_err error = {0}; |
| 210 | if (!queueIn.read(error)) { |
| 211 | printf("ERROR: Msg: Failed to receive error message\n"); |
| 212 | } else { |
| 213 | printf("Msg: Received an error response, type=%" PRIu32 ", msg=\"%s\"\n", error.type, error.msg); |
| 214 | } |
| 215 | queueIn.reset(); |
| 216 | return false; |
| 217 | } |
| 218 | case ETHOSU_CORE_MSG_VERSION_REQ: |
| 219 | printf("Msg: Version request\n"); |
| 220 | sendVersionRsp(); |
| 221 | break; |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 222 | case ETHOSU_CORE_MSG_INFERENCE_REQ: { |
Per Åstrand | dc28b13 | 2020-09-28 13:02:18 +0200 | [diff] [blame] | 223 | ethosu_core_inference_req req; |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 224 | |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 225 | if (!queueIn.read(req)) { |
| 226 | sndErrorRspAndResetQueue(ETHOSU_CORE_MSG_ERR_INVALID_PAYLOAD, "InferenceReq. Failed to read payload"); |
Per Åstrand | dc28b13 | 2020-09-28 13:02:18 +0200 | [diff] [blame] | 227 | return false; |
| 228 | } |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 229 | |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 230 | printf("Msg: InferenceReq. user_arg=0x%" PRIx64 ", network={0x%" PRIx32 ", %" PRIu32 "}", |
Per Åstrand | 91a9173 | 2020-09-25 15:04:26 +0200 | [diff] [blame] | 231 | req.user_arg, |
| 232 | req.network.ptr, |
| 233 | req.network.size); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 234 | |
Per Åstrand | 91a9173 | 2020-09-25 15:04:26 +0200 | [diff] [blame] | 235 | printf(", ifm_count=%" PRIu32 ", ifm=[", req.ifm_count); |
Kristofer Jonsson | 72fa50b | 2020-09-10 13:26:41 +0200 | [diff] [blame] | 236 | for (uint32_t i = 0; i < req.ifm_count; ++i) { |
| 237 | if (i > 0) { |
| 238 | printf(", "); |
| 239 | } |
| 240 | |
Per Åstrand | 91a9173 | 2020-09-25 15:04:26 +0200 | [diff] [blame] | 241 | printf("{0x%" PRIx32 ", %" PRIu32 "}", req.ifm[i].ptr, req.ifm[i].size); |
Kristofer Jonsson | 72fa50b | 2020-09-10 13:26:41 +0200 | [diff] [blame] | 242 | } |
| 243 | printf("]"); |
| 244 | |
Per Åstrand | 91a9173 | 2020-09-25 15:04:26 +0200 | [diff] [blame] | 245 | printf(", ofm_count=%" PRIu32 ", ofm=[", req.ofm_count); |
Kristofer Jonsson | 72fa50b | 2020-09-10 13:26:41 +0200 | [diff] [blame] | 246 | for (uint32_t i = 0; i < req.ofm_count; ++i) { |
| 247 | if (i > 0) { |
| 248 | printf(", "); |
| 249 | } |
| 250 | |
Per Åstrand | 91a9173 | 2020-09-25 15:04:26 +0200 | [diff] [blame] | 251 | printf("{0x%" PRIx32 ", %" PRIu32 "}", req.ofm[i].ptr, req.ofm[i].size); |
Kristofer Jonsson | 72fa50b | 2020-09-10 13:26:41 +0200 | [diff] [blame] | 252 | } |
| 253 | printf("]\n"); |
| 254 | |
| 255 | DataPtr networkModel(reinterpret_cast<void *>(req.network.ptr), req.network.size); |
| 256 | |
| 257 | vector<DataPtr> ifm; |
| 258 | for (uint32_t i = 0; i < req.ifm_count; ++i) { |
| 259 | ifm.push_back(DataPtr(reinterpret_cast<void *>(req.ifm[i].ptr), req.ifm[i].size)); |
| 260 | } |
| 261 | |
| 262 | vector<DataPtr> ofm; |
| 263 | for (uint32_t i = 0; i < req.ofm_count; ++i) { |
| 264 | ofm.push_back(DataPtr(reinterpret_cast<void *>(req.ofm[i].ptr), req.ofm[i].size)); |
| 265 | } |
| 266 | |
| 267 | vector<DataPtr> expectedOutput; |
| 268 | |
Jonny Svärd | e9f57dc | 2020-12-10 11:12:44 +0100 | [diff] [blame] | 269 | vector<uint8_t> pmuEventConfig(ETHOSU_CORE_PMU_MAX); |
Bhavik Patel | ffe845d | 2020-11-16 12:13:56 +0100 | [diff] [blame] | 270 | for (uint32_t i = 0; i < ETHOSU_CORE_PMU_MAX; i++) { |
| 271 | pmuEventConfig[i] = req.pmu_event_config[i]; |
| 272 | } |
| 273 | |
| 274 | InferenceJob job( |
| 275 | "job", networkModel, ifm, ofm, expectedOutput, -1, pmuEventConfig, req.pmu_cycle_counter_enable); |
Kristofer Jonsson | 34e2496 | 2020-11-23 16:22:10 +0100 | [diff] [blame] | 276 | job.invalidate(); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 277 | |
| 278 | bool failed = inferenceProcess.runJob(job); |
Kristofer Jonsson | 34e2496 | 2020-11-23 16:22:10 +0100 | [diff] [blame] | 279 | job.clean(); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 280 | |
Bhavik Patel | ffe845d | 2020-11-16 12:13:56 +0100 | [diff] [blame] | 281 | sendInferenceRsp(req.user_arg, |
| 282 | job.output, |
| 283 | failed, |
| 284 | job.pmuEventConfig, |
| 285 | job.pmuCycleCounterEnable, |
| 286 | job.pmuEventCount, |
| 287 | job.pmuCycleCounterCount); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 288 | break; |
| 289 | } |
Per Åstrand | dc28b13 | 2020-09-28 13:02:18 +0200 | [diff] [blame] | 290 | default: { |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 291 | char errMsg[128] = {0}; |
| 292 | snprintf(&errMsg[0], |
| 293 | sizeof(errMsg), |
| 294 | "Msg: Unknown type: %" PRIu32 " with payload length %" PRIu32 " bytes\n", |
| 295 | msg.type, |
| 296 | msg.length); |
| 297 | sndErrorRspAndResetQueue(ETHOSU_CORE_MSG_ERR_UNSUPPORTED_TYPE, errMsg); |
| 298 | return false; |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 299 | } |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 300 | } |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 301 | return true; |
| 302 | } |
| 303 | |
| 304 | void MessageProcess::sendPong() { |
| 305 | if (!queueOut.write(ETHOSU_CORE_MSG_PONG)) { |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 306 | printf("ERROR: Msg: Failed to write pong response. No mailbox message sent\n"); |
| 307 | } else { |
| 308 | mailbox.sendMessage(); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 309 | } |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 310 | } |
| 311 | |
| 312 | void MessageProcess::sendVersionRsp() { |
| 313 | struct ethosu_core_msg_version ver = {.major = ETHOSU_CORE_MSG_VERSION_MAJOR, |
| 314 | .minor = ETHOSU_CORE_MSG_VERSION_MINOR, |
| 315 | .patch = ETHOSU_CORE_MSG_VERSION_PATCH, |
| 316 | ._reserved = 0}; |
| 317 | |
| 318 | if (!queueOut.write(ETHOSU_CORE_MSG_VERSION_RSP, ver)) { |
| 319 | printf("ERROR: Failed to write version response. No mailbox message sent\n"); |
| 320 | } else { |
| 321 | mailbox.sendMessage(); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | void MessageProcess::sndErrorRspAndResetQueue(ethosu_core_msg_err_type type, const char *message) { |
| 326 | ethosu_core_msg_err error = {0}; |
| 327 | error.type = type; |
| 328 | unsigned int i = 0; |
| 329 | |
| 330 | if (message) { |
| 331 | for (; i < (sizeof(error.msg) - 1) && message[i]; i++) { |
| 332 | error.msg[i] = message[i]; |
| 333 | } |
| 334 | } |
| 335 | printf("ERROR: Msg: \"%s\"\n", message); |
| 336 | if (!queueOut.write(ETHOSU_CORE_MSG_ERR, &error)) { |
| 337 | printf("ERROR: Msg: Failed to write error response. No mailbox message sent\n"); |
| 338 | return; |
| 339 | } |
| 340 | queueIn.reset(); |
Jonny Svärd | 44398c8 | 2020-10-06 14:18:28 +0200 | [diff] [blame] | 341 | mailbox.sendMessage(); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 342 | } |
| 343 | |
Bhavik Patel | ffe845d | 2020-11-16 12:13:56 +0100 | [diff] [blame] | 344 | void MessageProcess::sendInferenceRsp(uint64_t userArg, |
| 345 | vector<DataPtr> &ofm, |
| 346 | bool failed, |
| 347 | vector<uint8_t> &pmuEventConfig, |
| 348 | uint32_t pmuCycleCounterEnable, |
| 349 | vector<uint32_t> &pmuEventCount, |
| 350 | uint64_t pmuCycleCounterCount) { |
| 351 | ethosu_core_inference_rsp rsp = { |
| 352 | .pmu_event_count = |
| 353 | { |
| 354 | 0, |
| 355 | }, |
| 356 | }; |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 357 | |
Kristofer Jonsson | 72fa50b | 2020-09-10 13:26:41 +0200 | [diff] [blame] | 358 | rsp.user_arg = userArg; |
| 359 | rsp.ofm_count = ofm.size(); |
| 360 | rsp.status = failed ? ETHOSU_CORE_STATUS_ERROR : ETHOSU_CORE_STATUS_OK; |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 361 | |
Kristofer Jonsson | 72fa50b | 2020-09-10 13:26:41 +0200 | [diff] [blame] | 362 | for (size_t i = 0; i < ofm.size(); ++i) { |
| 363 | rsp.ofm_size[i] = ofm[i].size; |
| 364 | } |
| 365 | |
Bhavik Patel | ffe845d | 2020-11-16 12:13:56 +0100 | [diff] [blame] | 366 | for (size_t i = 0; i < pmuEventConfig.size(); i++) { |
| 367 | rsp.pmu_event_config[i] = pmuEventConfig[i]; |
| 368 | } |
| 369 | rsp.pmu_cycle_counter_enable = pmuCycleCounterEnable; |
| 370 | for (size_t i = 0; i < pmuEventCount.size(); i++) { |
| 371 | rsp.pmu_event_count[i] = pmuEventCount[i]; |
| 372 | } |
| 373 | rsp.pmu_cycle_counter_count = pmuCycleCounterCount; |
| 374 | |
Per Åstrand | 91a9173 | 2020-09-25 15:04:26 +0200 | [diff] [blame] | 375 | printf("Sending inference response. userArg=0x%" PRIx64 ", ofm_count=%" PRIu32 ", status=%" PRIu32 "\n", |
Kristofer Jonsson | 72fa50b | 2020-09-10 13:26:41 +0200 | [diff] [blame] | 376 | rsp.user_arg, |
| 377 | rsp.ofm_count, |
| 378 | rsp.status); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 379 | |
| 380 | if (!queueOut.write(ETHOSU_CORE_MSG_INFERENCE_RSP, rsp)) { |
Jonny Svärd | dc84f4f | 2021-01-14 19:54:54 +0100 | [diff] [blame] | 381 | printf("ERROR: Msg: Failed to write inference response. No mailbox message sent\n"); |
| 382 | } else { |
| 383 | mailbox.sendMessage(); |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 384 | } |
| 385 | } |
Jonny Svärd | 44398c8 | 2020-10-06 14:18:28 +0200 | [diff] [blame] | 386 | |
| 387 | void MessageProcess::mailboxCallback(void *userArg) { |
| 388 | MessageProcess *_this = reinterpret_cast<MessageProcess *>(userArg); |
| 389 | _this->handleIrq(); |
| 390 | } |
| 391 | |
Kristofer Jonsson | 641c091 | 2020-08-31 11:34:14 +0200 | [diff] [blame] | 392 | } // namespace MessageProcess |