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