blob: b8b27751dc02a22f34106d77f83899c637161e34 [file] [log] [blame]
Kristofer Jonsson641c0912020-08-31 11:34:14 +02001/*
Anton Moberge348f8f2021-03-31 11:08:58 +02002 * Copyright (c) 2019-2021 Arm Limited. All rights reserved.
Kristofer Jonsson641c0912020-08-31 11:34:14 +02003 *
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;
Jonny Svärd4c11a482021-12-17 17:04:08 +010046 bool pmuCycleCounterEnable;
Bhavik Patelffe845d2020-11-16 12:13:56 +010047 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,
Jonny Svärd4c11a482021-12-17 17:04:08 +010058 const bool 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:
Kristofer Jonsson40d886e2021-12-15 11:16:26 +010066 InferenceProcess(uint8_t *_tensorArena, size_t _tensorArenaSize);
Kristofer Jonsson641c0912020-08-31 11:34:14 +020067
Kristofer Jonsson641c0912020-08-31 11:34:14 +020068 bool runJob(InferenceJob &job);
Kristofer Jonsson641c0912020-08-31 11:34:14 +020069
70private:
Anton Moberg66ed1822021-02-10 08:49:28 +010071 uint8_t *tensorArena;
72 const size_t tensorArenaSize;
Kristofer Jonsson641c0912020-08-31 11:34:14 +020073};
74} // namespace InferenceProcess