Publishing 2019 R1 content
[platform/upstream/dldt.git] / inference-engine / tests / unit / engines / gna / gna_api_stub.cpp
1 //*****************************************************************************
2 //
3 // INTEL CONFIDENTIAL
4 // Copyright (C) 2018-2019 Intel Corporation
5 //
6 // The source code contained or described herein and all documents related
7 // to the source code ("Material") are owned by Intel Corporation or its suppliers
8 // or licensors. Title to the Material remains with Intel Corporation or its suppliers
9 // and licensors. The Material contains trade secrets and proprietary
10 // and confidential information of Intel or its suppliers and licensors.
11 // The Material is protected by worldwide copyright and trade secret laws and treaty
12 // provisions. No part of the Material may be used, copied, reproduced, modified,
13 // published, uploaded, posted, transmitted, distributed, or disclosed in any way
14 // without Intel's prior express written permission.
15 //
16 // No license under any patent, copyright, trade secret or other intellectual
17 // property right is granted to or conferred upon you by disclosure or delivery
18 // of the Materials, either expressly, by implication, inducement, estoppel
19 // or otherwise. Any license under such intellectual property rights must
20 // be express and approved by Intel in writing.
21 //*****************************************************************************
22
23 #define INTEL_GNA_DLLEXPORT 1
24 #include <gna-api.h>
25 #include <gna-api-dumper.h>
26 #include <gna-api-instrumentation.h>
27 #include "gna_mock_api.hpp"
28
29 static GNACppApi * current = nullptr;
30
31 GNACppApi :: GNACppApi() {
32     current = this;
33 }
34
35 GNACppApi :: ~GNACppApi() {
36     current = nullptr;
37 }
38
39 #ifdef __cplusplus
40 extern "C" {  // API uses C linkage so that it can be used by C and C++ applications
41 #endif
42
43
44 /**
45  * intel_gna_status_t members printable descriptions
46  *   Size: NUMGNASTATUS + 1
47  */
48 DLLDECL const char *GNAStatusName[] = {"status"};
49
50 /**
51  * intel_gmm_mode_t members printable descriptions
52  *   Size: NUMGMMMODES + 1
53  */
54 DLLDECL const char *GMMModeName[] = {"model"};
55
56 /**
57  * // TODO: fill
58  */
59 DLLDECL intel_gna_status_t GNAScoreGaussians(
60     intel_gna_handle_t          handle,
61     const intel_feature_type_t* pFeatureType,
62     const intel_feature_t*      pFeatureData,
63     const intel_gmm_type_t*     pModelType,
64     const intel_gmm_t*          pModelData,
65     const uint32_t*             pActiveGMMIndices,
66     uint32_t                    nActiveGMMIndices,
67     uint32_t                    uMaximumScore,
68     intel_gmm_mode_t            nGMMMode,
69     uint32_t*                   pScores,
70     uint32_t*                   pReqId,
71     intel_gna_proc_t            nAccelerationType
72 ) {
73     if (current != nullptr) {
74         return current->GNAScoreGaussians(
75             //handle,
76             //pFeatureType,
77             pFeatureData,
78             pModelType,
79             pModelData,
80             pActiveGMMIndices,
81             nActiveGMMIndices,
82             uMaximumScore,
83             nGMMMode,
84             pScores,
85             pReqId,
86             nAccelerationType);
87     }
88     return GNA_NOERROR;
89 }
90
91 DLLDECL intel_gna_status_t GNAPropagateForward(
92     intel_gna_handle_t          handle,
93     const intel_nnet_type_t*    pNeuralNetwork,
94     const uint32_t*             pActiveIndices,
95     uint32_t                    nActiveIndices,
96     uint32_t*                   pReqId,
97     intel_gna_proc_t            nAccelerationType
98 ) {
99     if (current != nullptr) {
100         return current->GNAPropagateForward(
101             handle,
102             pNeuralNetwork,
103             pActiveIndices,
104             nActiveIndices,
105             pReqId,
106             nAccelerationType);
107     }
108     return GNA_NOERROR;
109 }
110
111 // TODO: add output status
112 /**
113  * // TODO: fill
114  */
115 DLLDECL void *GNAAlloc(
116     intel_gna_handle_t nGNADevice,   // handle to GNA accelerator
117     uint32_t           sizeRequested,
118     uint32_t*          sizeGranted
119 ) {
120     if (current != nullptr) {
121         return current->GNAAlloc(nGNADevice, sizeRequested, sizeGranted);
122     }
123     if (sizeGranted != nullptr) {
124         *sizeGranted = sizeRequested;
125     }
126     return (void*)1;
127 }
128
129 /**
130  * // TODO: fill
131  */
132 DLLDECL intel_gna_status_t GNAFree(
133     intel_gna_handle_t nGNADevice   // handle to GNA accelerator
134 ) {
135     if (current != nullptr) {
136         return current->GNAFree(nGNADevice);
137     }
138     return GNA_NOERROR;
139 }
140
141 /**
142  * // TODO: fill
143  */
144 DLLDECL intel_gna_handle_t GNADeviceOpen(
145     intel_gna_status_t* status          // Status of the call
146 ) {
147     if (current != nullptr) {
148         return current->GNADeviceOpen(status);
149     }
150     return 0;
151
152 }
153
154 /**
155 * // TODO: fill
156 */
157 DLLDECL intel_gna_handle_t GNADeviceOpenSetThreads(
158     intel_gna_status_t* status,         // Status of the call
159     uint8_t n_threads                           // Number of worker threads
160 ) {
161     if (current != nullptr) {
162         return current->GNADeviceOpenSetThreads(status, n_threads);
163     }
164     return GNA_NOERROR;
165
166 }
167
168 /**
169  * // TODO: fill
170  */
171 DLLDECL intel_gna_status_t GNADeviceClose(
172     intel_gna_handle_t nGNADevice // handle to GNA accelerator
173 ) {
174     if (current != nullptr) {
175         return current->GNADeviceClose(nGNADevice);
176     }
177     return GNA_NOERROR;
178
179 }
180
181 /**
182  * // TODO: fill
183  */
184 DLLDECL intel_gna_status_t GNAWait(
185     intel_gna_handle_t nGNADevice,            // handle to GNA accelerator
186     uint32_t           nTimeoutMilliseconds,
187     uint32_t           reqId                  // IN score request ID
188 ) {
189     if (current != nullptr) {
190         return current->GNAWait(nGNADevice, nTimeoutMilliseconds, reqId);
191     }
192     return GNA_NOERROR;
193 }
194
195 DLLDECL intel_gna_status_t GNAWaitPerfRes(
196     intel_gna_handle_t nGNADevice,            // handle to GNA accelerator
197     uint32_t           nTimeoutMilliseconds,
198     uint32_t           reqId,                 // IN score request ID
199     intel_gna_perf_t*  nGNAPerfResults
200 ) {
201     if (current != nullptr) {
202         return current->GNAWaitPerfRes(nGNADevice,
203                                        nTimeoutMilliseconds,
204                                        reqId,
205                                        nGNAPerfResults);
206     }
207     return GNA_NOERROR;
208 }
209
210 DLLDECL void* GNADumpXnn(
211     const intel_nnet_type_t*    neuralNetwork,
212     const uint32_t*             activeIndices,
213     uint32_t                    activeIndicesCount,
214     intel_gna_model_header*     modelHeader,
215     intel_gna_status_t*         status,
216     intel_gna_alloc_cb          customAlloc) {
217         if (current != nullptr) {
218             return current->GNADumpXnn(neuralNetwork,
219                                         activeIndices,
220                                         activeIndicesCount,
221                                         modelHeader,
222                                         status,
223                                         customAlloc);
224         }
225         return nullptr;
226 }
227
228 DLLDECL void gmmSetThreads(
229     int num
230 ) {
231     current->gmmSetThreads((num != 0) ? num : 1);
232 }
233 #ifdef __cplusplus
234 }
235 #endif
236