forked from projectceladon/nn_gpu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbase_executor.h
executable file
·102 lines (83 loc) · 3.7 KB
/
base_executor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*
* Copyright @2017 Intel Corporation
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Guo Yejun <[email protected]>
*/
#ifndef ANDROID_HARDWARE_NEURALNETWORKS_V1_0_BASE_EXECUTOR_H
#define ANDROID_HARDWARE_NEURALNETWORKS_V1_0_BASE_EXECUTOR_H
#include <algorithm>
#include <memory.h>
#include <string.h>
#include <utils/RefBase.h>
#include <android/log.h>
#include <android-base/logging.h>
#include <hidl/LegacySupport.h>
#include <thread>
#include "hal_types.h"
namespace android {
namespace hardware {
namespace neuralnetworks {
namespace V1_0 {
namespace implementation {
#define UNUSED(x) (void)(x);
#define ASSERT(v) \
do \
{ \
if (!(v)) \
{ \
ALOGE("ASSERT failed at %s:%d - %s", __FILE__, __LINE__, #v); \
abort(); \
} \
} while(0)
#define NOT_REACH_HERE ASSERT(!"should not reach here");
#define NOT_IMPLEMENTED ASSERT(!"not implemented");
#define ALIGN(size_, align) (((size_) + (align) - 1) / (align) * (align))
// Macro to check if the input parameters for operation are valid or not.
#define NN_CHECK(v) \
do { \
if (!(v)) { \
LOG(ERROR) << "NN_CHECK failed: " << #v << ", " << __FILE__ << ":" << __LINE__ << "\n"; \
return false; \
} \
} while(0);
#define NN_CHECK_EQ(actual, expected) \
NN_CHECK((actual) == (expected))
#define NN_OPS_CHECK NN_CHECK
inline size_t getSizeFromInts(int lower, int higher) {
return (uint32_t)(lower) + ((uint64_t)(uint32_t)(higher) << 32);
}
class BaseExecutor : public RefBase
{
public:
BaseExecutor(const Model& m) : model(m) { UNUSED(model); }
virtual ~BaseExecutor() {}
virtual bool initPerModel() { NOT_REACH_HERE; return true; }
virtual void deinitPerModel() { NOT_REACH_HERE; }
// why not merge these two functions into function run?
// just for a clear logic for cleanup(deinit) in case something wrong within run
virtual bool initPerExecThread() { NOT_REACH_HERE; return true; }
virtual void deinitPerExecThread() { NOT_REACH_HERE; }
virtual bool run(const Request& request) { NOT_REACH_HERE; UNUSED(request); return true;}
static std::string getOpName(const Operation& op);
protected:
const Model& model;
};
} // namespace implementation
} // namespace V1_0
} // namespace neuralnetworks
} // namespace hardware
} // namespace android
#endif