blob: ec682d1d7770515e0c9f03fa177ab2ef43e3397f [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
21#include <queue>
22#include <stdlib.h>
23#include <string>
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020024#include <vector>
Kristofer Jonsson641c0912020-08-31 11:34:14 +020025
26namespace InferenceProcess {
27struct DataPtr {
28 void *data;
29 size_t size;
30
31 DataPtr(void *data = nullptr, size_t size = 0);
Kristofer Jonsson34e24962020-11-23 16:22:10 +010032
33 void invalidate();
34 void clean();
Kristofer Jonsson641c0912020-08-31 11:34:14 +020035};
36
37struct InferenceJob {
38 std::string name;
39 DataPtr networkModel;
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020040 std::vector<DataPtr> input;
41 std::vector<DataPtr> output;
42 std::vector<DataPtr> expectedOutput;
Kristofer Jonsson641c0912020-08-31 11:34:14 +020043 size_t numBytesToPrint;
44
45 InferenceJob();
46 InferenceJob(const std::string &name,
47 const DataPtr &networkModel,
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020048 const std::vector<DataPtr> &input,
49 const std::vector<DataPtr> &output,
50 const std::vector<DataPtr> &expectedOutput,
Kristofer Jonsson641c0912020-08-31 11:34:14 +020051 size_t numBytesToPrint);
Kristofer Jonsson34e24962020-11-23 16:22:10 +010052
53 void invalidate();
54 void clean();
Kristofer Jonsson641c0912020-08-31 11:34:14 +020055};
56
57class InferenceProcess {
58public:
59 InferenceProcess();
60
61 bool push(const InferenceJob &job);
62 bool runJob(InferenceJob &job);
63 bool run(bool exitOnEmpty = true);
64
65private:
66 volatile uint32_t lock;
67 std::queue<InferenceJob> inferenceJobQueue;
68
69 void getLock();
70 void freeLock();
71};
72} // namespace InferenceProcess