blob: 67b30c5fd7075b2a637e173f74024b8c6fa8a413 [file] [log] [blame]
Kristofer Jonsson641c0912020-08-31 11:34:14 +02001/*
2 * Copyright (c) 2019-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#pragma once
20
Bhavik Patelffe845d2020-11-16 12:13:56 +010021#include <array>
Kristofer Jonsson641c0912020-08-31 11:34:14 +020022#include <queue>
23#include <stdlib.h>
24#include <string>
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020025#include <vector>
Kristofer Jonsson641c0912020-08-31 11:34:14 +020026
27namespace InferenceProcess {
28struct DataPtr {
29 void *data;
30 size_t size;
31
32 DataPtr(void *data = nullptr, size_t size = 0);
Kristofer Jonsson34e24962020-11-23 16:22:10 +010033
34 void invalidate();
35 void clean();
Kristofer Jonsson641c0912020-08-31 11:34:14 +020036};
37
38struct InferenceJob {
39 std::string name;
40 DataPtr networkModel;
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020041 std::vector<DataPtr> input;
42 std::vector<DataPtr> output;
43 std::vector<DataPtr> expectedOutput;
Kristofer Jonsson641c0912020-08-31 11:34:14 +020044 size_t numBytesToPrint;
Bhavik Patelffe845d2020-11-16 12:13:56 +010045 std::vector<uint8_t> pmuEventConfig;
46 uint32_t pmuCycleCounterEnable;
47 std::vector<uint32_t> pmuEventCount;
48 uint64_t pmuCycleCounterCount;
Kristofer Jonsson641c0912020-08-31 11:34:14 +020049
50 InferenceJob();
51 InferenceJob(const std::string &name,
52 const DataPtr &networkModel,
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020053 const std::vector<DataPtr> &input,
54 const std::vector<DataPtr> &output,
55 const std::vector<DataPtr> &expectedOutput,
Bhavik Patelffe845d2020-11-16 12:13:56 +010056 size_t numBytesToPrint,
57 const std::vector<uint8_t> &pmuEventConfig,
58 const uint32_t pmuCycleCounterEnable);
Kristofer Jonsson34e24962020-11-23 16:22:10 +010059
60 void invalidate();
61 void clean();
Kristofer Jonsson641c0912020-08-31 11:34:14 +020062};
63
64class InferenceProcess {
65public:
66 InferenceProcess();
67
68 bool push(const InferenceJob &job);
69 bool runJob(InferenceJob &job);
70 bool run(bool exitOnEmpty = true);
71
72private:
73 volatile uint32_t lock;
74 std::queue<InferenceJob> inferenceJobQueue;
75
76 void getLock();
77 void freeLock();
78};
79} // namespace InferenceProcess