blob: 53b9331a635eaa282f30832f23cbe5c8e52a36ba [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);
32};
33
34struct InferenceJob {
35 std::string name;
36 DataPtr networkModel;
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020037 std::vector<DataPtr> input;
38 std::vector<DataPtr> output;
39 std::vector<DataPtr> expectedOutput;
Kristofer Jonsson641c0912020-08-31 11:34:14 +020040 size_t numBytesToPrint;
41
42 InferenceJob();
43 InferenceJob(const std::string &name,
44 const DataPtr &networkModel,
Kristofer Jonsson72fa50b2020-09-10 13:26:41 +020045 const std::vector<DataPtr> &input,
46 const std::vector<DataPtr> &output,
47 const std::vector<DataPtr> &expectedOutput,
Kristofer Jonsson641c0912020-08-31 11:34:14 +020048 size_t numBytesToPrint);
49};
50
51class InferenceProcess {
52public:
53 InferenceProcess();
54
55 bool push(const InferenceJob &job);
56 bool runJob(InferenceJob &job);
57 bool run(bool exitOnEmpty = true);
58
59private:
60 volatile uint32_t lock;
61 std::queue<InferenceJob> inferenceJobQueue;
62
63 void getLock();
64 void freeLock();
65};
66} // namespace InferenceProcess