Publishing R5 content (#72)
[platform/upstream/dldt.git] / inference-engine / tests / unit / engines / gna / gna_api_stub.cpp
1 // Copyright (C) 2018 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #define INTEL_GNA_DLLEXPORT 1
6 #include <gna-api.h>
7 #include <gna-api-dumper.h>
8 #include <gna-api-instrumentation.h>
9 #include "gna_mock_api.hpp"
10
11 static GNACppApi * current = nullptr;
12
13 GNACppApi :: GNACppApi() {
14     current = this;
15 }
16
17 GNACppApi :: ~GNACppApi() {
18     current = nullptr;
19 }
20
21 #ifdef __cplusplus
22 extern "C" {  // API uses C linkage so that it can be used by C and C++ applications
23 #endif
24
25
26 /**
27  * intel_gna_status_t members printable descriptions
28  *   Size: NUMGNASTATUS + 1
29  */
30 DLLDECL const char *GNAStatusName[] = {"status"};
31
32 /**
33  * intel_gmm_mode_t members printable descriptions
34  *   Size: NUMGMMMODES + 1
35  */
36 DLLDECL const char *GMMModeName[] = {"model"};
37
38 /**
39  * // TODO: fill
40  */
41 DLLDECL intel_gna_status_t GNAScoreGaussians(
42     intel_gna_handle_t          handle,
43     const intel_feature_type_t* pFeatureType,
44     const intel_feature_t*      pFeatureData,
45     const intel_gmm_type_t*     pModelType,
46     const intel_gmm_t*          pModelData,
47     const uint32_t*             pActiveGMMIndices,
48     uint32_t                    nActiveGMMIndices,
49     uint32_t                    uMaximumScore,
50     intel_gmm_mode_t            nGMMMode,
51     uint32_t*                   pScores,
52     uint32_t*                   pReqId,
53     intel_gna_proc_t            nAccelerationType
54 ) {
55     if (current != nullptr) {
56         return current->GNAScoreGaussians(
57             //handle,
58             //pFeatureType,
59             pFeatureData,
60             pModelType,
61             pModelData,
62             pActiveGMMIndices,
63             nActiveGMMIndices,
64             uMaximumScore,
65             nGMMMode,
66             pScores,
67             pReqId,
68             nAccelerationType);
69     }
70     return GNA_NOERROR;
71 }
72
73 DLLDECL intel_gna_status_t GNAPropagateForward(
74     intel_gna_handle_t          handle,
75     const intel_nnet_type_t*    pNeuralNetwork,
76     const uint32_t*             pActiveIndices,
77     uint32_t                    nActiveIndices,
78     uint32_t*                   pReqId,
79     intel_gna_proc_t            nAccelerationType
80 ) {
81     if (current != nullptr) {
82         return current->GNAPropagateForward(
83             handle,
84             pNeuralNetwork,
85             pActiveIndices,
86             nActiveIndices,
87             pReqId,
88             nAccelerationType);
89     }
90     return GNA_NOERROR;
91 }
92
93 // TODO: add output status
94 /**
95  * // TODO: fill
96  */
97 DLLDECL void *GNAAlloc(
98     intel_gna_handle_t nGNADevice,   // handle to GNA accelerator
99     uint32_t           sizeRequested,
100     uint32_t*          sizeGranted
101 ) {
102     if (current != nullptr) {
103         return current->GNAAlloc(nGNADevice, sizeRequested, sizeGranted);
104     }
105     if (sizeGranted != nullptr) {
106         *sizeGranted = sizeRequested;
107     }
108     return (void*)1;
109 }
110
111 /**
112  * // TODO: fill
113  */
114 DLLDECL intel_gna_status_t GNAFree(
115     intel_gna_handle_t nGNADevice   // handle to GNA accelerator
116 ) {
117     if (current != nullptr) {
118         return current->GNAFree(nGNADevice);
119     }
120     return GNA_NOERROR;
121 }
122
123 /**
124  * // TODO: fill
125  */
126 DLLDECL intel_gna_handle_t GNADeviceOpen(
127     intel_gna_status_t* status          // Status of the call
128 ) {
129     if (current != nullptr) {
130         return current->GNADeviceOpen(status);
131     }
132     return 0;
133
134 }
135
136 /**
137 * // TODO: fill
138 */
139 DLLDECL intel_gna_handle_t GNADeviceOpenSetThreads(
140     intel_gna_status_t* status,         // Status of the call
141     uint8_t n_threads                           // Number of worker threads
142 ) {
143     if (current != nullptr) {
144         return current->GNADeviceOpenSetThreads(status, n_threads);
145     }
146     return GNA_NOERROR;
147
148 }
149
150 /**
151  * // TODO: fill
152  */
153 DLLDECL intel_gna_status_t GNADeviceClose(
154     intel_gna_handle_t nGNADevice // handle to GNA accelerator
155 ) {
156     if (current != nullptr) {
157         return current->GNADeviceClose(nGNADevice);
158     }
159     return GNA_NOERROR;
160
161 }
162
163 /**
164  * // TODO: fill
165  */
166 DLLDECL intel_gna_status_t GNAWait(
167     intel_gna_handle_t nGNADevice,            // handle to GNA accelerator
168     uint32_t           nTimeoutMilliseconds,
169     uint32_t           reqId                  // IN score request ID
170 ) {
171     if (current != nullptr) {
172         return current->GNAWait(nGNADevice, nTimeoutMilliseconds, reqId);
173     }
174     return GNA_NOERROR;
175 }
176
177 DLLDECL intel_gna_status_t GNAWaitPerfRes(
178     intel_gna_handle_t nGNADevice,            // handle to GNA accelerator
179     uint32_t           nTimeoutMilliseconds,
180     uint32_t           reqId,                 // IN score request ID
181     intel_gna_perf_t*  nGNAPerfResults
182 ) {
183     if (current != nullptr) {
184         return current->GNAWaitPerfRes(nGNADevice,
185                                        nTimeoutMilliseconds,
186                                        reqId,
187                                        nGNAPerfResults);
188     }
189     return GNA_NOERROR;
190 }
191
192 DLLDECL void* GNADumpXnn(
193     const intel_nnet_type_t*    neuralNetwork,
194     const uint32_t*             activeIndices,
195     uint32_t                    activeIndicesCount,
196     intel_gna_model_header*     modelHeader,
197     intel_gna_status_t*         status,
198     intel_gna_alloc_cb          customAlloc) {
199         if (current != nullptr) {
200             return current->GNADumpXnn(neuralNetwork,
201                                         activeIndices,
202                                         activeIndicesCount,
203                                         modelHeader,
204                                         status,
205                                         customAlloc);
206         }
207         return nullptr;
208 }
209
210 DLLDECL void gmmSetThreads(
211     int num
212 ) {
213     current->gmmSetThreads((num != 0) ? num : 1);
214 }
215 #ifdef __cplusplus
216 }
217 #endif
218