blob: a5fef2c5d099ba7bfd9f02556259e9ac2adbfb4a [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>
24
25namespace InferenceProcess {
26struct DataPtr {
27 void *data;
28 size_t size;
29
30 DataPtr(void *data = nullptr, size_t size = 0);
31};
32
33struct InferenceJob {
34 std::string name;
35 DataPtr networkModel;
36 DataPtr input;
37 DataPtr output;
38 DataPtr expectedOutput;
39 size_t numBytesToPrint;
40
41 InferenceJob();
42 InferenceJob(const std::string &name,
43 const DataPtr &networkModel,
44 const DataPtr &input,
45 const DataPtr &output,
46 const DataPtr &expectedOutput,
47 size_t numBytesToPrint);
48};
49
50class InferenceProcess {
51public:
52 InferenceProcess();
53
54 bool push(const InferenceJob &job);
55 bool runJob(InferenceJob &job);
56 bool run(bool exitOnEmpty = true);
57
58private:
59 volatile uint32_t lock;
60 std::queue<InferenceJob> inferenceJobQueue;
61
62 void getLock();
63 void freeLock();
64};
65} // namespace InferenceProcess