1 //*****************************************************************************
4 // Copyright (C) 2018-2019 Intel Corporation
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.
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 //*****************************************************************************
23 #define INTEL_GNA_DLLEXPORT 1
25 #include <gna-api-dumper.h>
26 #include <gna-api-instrumentation.h>
27 #include "gna_mock_api.hpp"
29 static GNACppApi * current = nullptr;
31 GNACppApi :: GNACppApi() {
35 GNACppApi :: ~GNACppApi() {
40 extern "C" { // API uses C linkage so that it can be used by C and C++ applications
45 * intel_gna_status_t members printable descriptions
46 * Size: NUMGNASTATUS + 1
48 DLLDECL const char *GNAStatusName[] = {"status"};
51 * intel_gmm_mode_t members printable descriptions
52 * Size: NUMGMMMODES + 1
54 DLLDECL const char *GMMModeName[] = {"model"};
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,
71 intel_gna_proc_t nAccelerationType
73 if (current != nullptr) {
74 return current->GNAScoreGaussians(
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,
97 intel_gna_proc_t nAccelerationType
99 if (current != nullptr) {
100 return current->GNAPropagateForward(
111 // TODO: add output status
115 DLLDECL void *GNAAlloc(
116 intel_gna_handle_t nGNADevice, // handle to GNA accelerator
117 uint32_t sizeRequested,
118 uint32_t* sizeGranted
120 if (current != nullptr) {
121 return current->GNAAlloc(nGNADevice, sizeRequested, sizeGranted);
123 if (sizeGranted != nullptr) {
124 *sizeGranted = sizeRequested;
132 DLLDECL intel_gna_status_t GNAFree(
133 intel_gna_handle_t nGNADevice // handle to GNA accelerator
135 if (current != nullptr) {
136 return current->GNAFree(nGNADevice);
144 DLLDECL intel_gna_handle_t GNADeviceOpen(
145 intel_gna_status_t* status // Status of the call
147 if (current != nullptr) {
148 return current->GNADeviceOpen(status);
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
161 if (current != nullptr) {
162 return current->GNADeviceOpenSetThreads(status, n_threads);
171 DLLDECL intel_gna_status_t GNADeviceClose(
172 intel_gna_handle_t nGNADevice // handle to GNA accelerator
174 if (current != nullptr) {
175 return current->GNADeviceClose(nGNADevice);
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
189 if (current != nullptr) {
190 return current->GNAWait(nGNADevice, nTimeoutMilliseconds, reqId);
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
201 if (current != nullptr) {
202 return current->GNAWaitPerfRes(nGNADevice,
203 nTimeoutMilliseconds,
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,
228 DLLDECL void gmmSetThreads(
231 current->gmmSetThreads((num != 0) ? num : 1);