blob: 51f474dd747614c2de6e8537ca95c029ba873489 [file] [log] [blame]
Kristofer Jonsson641c0912020-08-31 11:34:14 +02001/*
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#ifndef MESSAGE_PROCESS_H
20#define MESSAGE_PROCESS_H
21
22#include <ethosu_core_interface.h>
23#include <inference_process.hpp>
24
25#include <cstddef>
26#include <cstdio>
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020027#include <vector>
Kristofer Jonsson641c0912020-08-31 11:34:14 +020028
29namespace MessageProcess {
30
31template <uint32_t SIZE>
32struct Queue {
33 ethosu_core_queue_header header;
34 uint8_t data[SIZE];
35
36 constexpr Queue() : header({SIZE, 0, 0}) {}
37
38 constexpr ethosu_core_queue *toQueue() {
39 return reinterpret_cast<ethosu_core_queue *>(&header);
40 }
41};
42
43class QueueImpl {
44public:
45 struct Vec {
46 const void *base;
47 size_t length;
48 };
49
50 QueueImpl(ethosu_core_queue &queue);
51
52 bool empty() const;
53 size_t available() const;
54 size_t capacity() const;
55 bool read(uint8_t *dst, uint32_t length);
56 bool write(const Vec *vec, size_t length);
57 bool write(const uint32_t type, const void *src = nullptr, uint32_t length = 0);
58
59 template <typename T>
60 bool read(T &dst) {
61 return read(reinterpret_cast<uint8_t *>(&dst), sizeof(dst));
62 }
63
64 template <typename T>
65 bool write(const uint32_t type, const T &src) {
66 return write(type, reinterpret_cast<const void *>(&src), sizeof(src));
67 }
68
69private:
70 ethosu_core_queue &queue;
71};
72
73class MessageProcess {
74public:
75 MessageProcess(ethosu_core_queue &in, ethosu_core_queue &out, InferenceProcess::InferenceProcess &inferenceProcess);
76
77 void run();
78 void handleIrq();
79 bool handleMessage();
80 void sendPong();
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020081 void sendInferenceRsp(uint64_t userArg, std::vector<InferenceProcess::DataPtr> &ofm, bool failed);
Kristofer Jonsson641c0912020-08-31 11:34:14 +020082
83private:
84 QueueImpl queueIn;
85 QueueImpl queueOut;
86 InferenceProcess::InferenceProcess &inferenceProcess;
87};
88
89} // namespace MessageProcess
90
91#endif