mxnet
c_predict_api.h
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
26 #ifndef MXNET_C_PREDICT_API_H_
27 #define MXNET_C_PREDICT_API_H_
28 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif // __cplusplus
33 
34 #ifdef _WIN32
35 #ifdef MXNET_EXPORTS
36 #define MXNET_DLL __declspec(dllexport)
37 #else
38 #define MXNET_DLL __declspec(dllimport)
39 #endif
40 #else
41 #define MXNET_DLL
42 #endif
43 
45 typedef uint32_t mx_uint;
47 typedef float mx_float;
49 typedef void *PredictorHandle;
51 typedef void *NDListHandle;
53 typedef void *NDArrayHandle;
55 typedef void (*PredMonitorCallback)(const char*,
57  void*);
58 
63 MXNET_DLL const char* MXGetLastError();
64 
84 MXNET_DLL int MXPredCreate(const char* symbol_json_str,
85  const void* param_bytes,
86  int param_size,
87  int dev_type, int dev_id,
88  uint32_t num_input_nodes,
89  const char** input_keys,
90  const uint32_t* input_shape_indptr,
91  const uint32_t* input_shape_data,
92  PredictorHandle* out);
93 
119 MXNET_DLL int MXPredCreateEx(const char* symbol_json_str,
120  const void* param_bytes,
121  int param_size,
122  int dev_type, int dev_id,
123  const uint32_t num_input_nodes,
124  const char** input_keys,
125  const uint32_t* input_shape_indptr,
126  const uint32_t* input_shape_data,
127  const uint32_t num_provided_arg_dtypes,
128  const char** provided_arg_dtype_names,
129  const int* provided_arg_dtypes,
130  PredictorHandle* out);
131 
155 MXNET_DLL int MXPredCreatePartialOut(const char* symbol_json_str,
156  const void* param_bytes,
157  int param_size,
158  int dev_type, int dev_id,
159  uint32_t num_input_nodes,
160  const char** input_keys,
161  const uint32_t* input_shape_indptr,
162  const uint32_t* input_shape_data,
163  uint32_t num_output_nodes,
164  const char** output_keys,
165  PredictorHandle* out);
166 
188 MXNET_DLL int MXPredCreateMultiThread(const char* symbol_json_str,
189  const void* param_bytes,
190  int param_size,
191  int dev_type, int dev_id,
192  uint32_t num_input_nodes,
193  const char** input_keys,
194  const uint32_t* input_shape_indptr,
195  const uint32_t* input_shape_data,
196  int num_threads,
197  PredictorHandle* out);
198 
214 MXNET_DLL int MXPredReshape(uint32_t num_input_nodes,
215  const char** input_keys,
216  const uint32_t* input_shape_indptr,
217  const uint32_t* input_shape_data,
218  PredictorHandle handle,
219  PredictorHandle* out);
229 MXNET_DLL int MXPredGetOutputShape(PredictorHandle handle,
230  uint32_t index,
231  uint32_t** shape_data,
232  uint32_t* shape_ndim);
233 
241 MXNET_DLL int MXPredGetOutputType(PredictorHandle handle,
242  uint32_t out_index,
243  int* out_dtype);
244 
254 MXNET_DLL int MXPredSetInput(PredictorHandle handle,
255  const char* key,
256  const float* data,
257  uint32_t size);
263 MXNET_DLL int MXPredForward(PredictorHandle handle);
280 MXNET_DLL int MXPredPartialForward(PredictorHandle handle, int step, int* step_left);
289 MXNET_DLL int MXPredGetOutput(PredictorHandle handle,
290  uint32_t index,
291  float* data,
292  uint32_t size);
298 MXNET_DLL int MXPredFree(PredictorHandle handle);
308 MXNET_DLL int MXNDListCreate(const char* nd_file_bytes,
309  int nd_file_size,
310  NDListHandle *out,
311  uint32_t* out_length);
322 MXNET_DLL int MXNDListGet(NDListHandle handle,
323  uint32_t index,
324  const char** out_key,
325  const float** out_data,
326  const uint32_t** out_shape,
327  uint32_t* out_ndim);
328 
333 MXNET_DLL int MXPredSetMonitorCallback(PredictorHandle handle,
334  PredMonitorCallback callback,
335  void* callback_handle,
336  bool monitor_all);
342 MXNET_DLL int MXNDListFree(NDListHandle handle);
343 
344 #ifdef __cplusplus
345 }
346 #endif // __cplusplus
347 
348 #endif // MXNET_C_PREDICT_API_H_
MXNET_DLL int MXPredForward(PredictorHandle handle)
Run a forward pass to get the output.
MXNET_DLL int MXPredCreate(const char *symbol_json_str, const void *param_bytes, int param_size, int dev_type, int dev_id, uint32_t num_input_nodes, const char **input_keys, const uint32_t *input_shape_indptr, const uint32_t *input_shape_data, PredictorHandle *out)
create a predictor
MXNET_DLL int MXPredCreatePartialOut(const char *symbol_json_str, const void *param_bytes, int param_size, int dev_type, int dev_id, uint32_t num_input_nodes, const char **input_keys, const uint32_t *input_shape_indptr, const uint32_t *input_shape_data, uint32_t num_output_nodes, const char **output_keys, PredictorHandle *out)
create a predictor wich customized outputs
MXNET_DLL int MXNDListGet(NDListHandle handle, uint32_t index, const char **out_key, const float **out_data, const uint32_t **out_shape, uint32_t *out_ndim)
Get an element from list.
uint32_t mx_uint
manually define unsigned int
Definition: c_predict_api.h:45
MXNET_DLL int MXPredGetOutputType(PredictorHandle handle, uint32_t out_index, int *out_dtype)
Get the dtype of output node. The returned data type is only valid before next call to MXPred functio...
MXNET_DLL int MXNDListFree(NDListHandle handle)
Free a MXAPINDList.
MXNET_DLL int MXPredGetOutputShape(PredictorHandle handle, uint32_t index, uint32_t **shape_data, uint32_t *shape_ndim)
Get the shape of output node. The returned shape_data and shape_ndim is only valid before next call t...
void * NDArrayHandle
handle to NDArray
Definition: c_predict_api.h:53
void * PredictorHandle
handle to Predictor
Definition: c_predict_api.h:49
MXNET_DLL int MXPredSetMonitorCallback(PredictorHandle handle, PredMonitorCallback callback, void *callback_handle, bool monitor_all)
set a call back to notify the completion of operation and allow for additional monitoring ...
MXNET_DLL int MXPredFree(PredictorHandle handle)
Free a predictor handle.
float mx_float
manually define float
Definition: c_predict_api.h:47
MXNET_DLL int MXPredSetInput(PredictorHandle handle, const char *key, const float *data, uint32_t size)
Set the input data of predictor.
void * NDListHandle
handle to NDArray list
Definition: c_predict_api.h:51
MXNET_DLL int MXNDListCreate(const char *nd_file_bytes, int nd_file_size, NDListHandle *out, uint32_t *out_length)
Create a NDArray List by loading from ndarray file. This can be used to load mean image file...
MXNET_DLL const char * MXGetLastError()
Get the last error happeneed.
void(* PredMonitorCallback)(const char *, NDArrayHandle, void *)
callback used for add monitoring to nodes in the graph
Definition: c_predict_api.h:55
MXNET_DLL int MXPredCreateMultiThread(const char *symbol_json_str, const void *param_bytes, int param_size, int dev_type, int dev_id, uint32_t num_input_nodes, const char **input_keys, const uint32_t *input_shape_indptr, const uint32_t *input_shape_data, int num_threads, PredictorHandle *out)
create predictors for multiple threads. One predictor for a thread.
MXNET_DLL int MXPredCreateEx(const char *symbol_json_str, const void *param_bytes, int param_size, int dev_type, int dev_id, const uint32_t num_input_nodes, const char **input_keys, const uint32_t *input_shape_indptr, const uint32_t *input_shape_data, const uint32_t num_provided_arg_dtypes, const char **provided_arg_dtype_names, const int *provided_arg_dtypes, PredictorHandle *out)
create a predictor
MXNET_DLL int MXPredGetOutput(PredictorHandle handle, uint32_t index, float *data, uint32_t size)
Get the output value of prediction.
#define MXNET_DLL
Inhibit C++ name-mangling for MXNet functions.
Definition: c_predict_api.h:41
MXNET_DLL int MXPredPartialForward(PredictorHandle handle, int step, int *step_left)
Run a interactive forward pass to get the output. This is helpful for displaying progress of predicti...
MXNET_DLL int MXPredReshape(uint32_t num_input_nodes, const char **input_keys, const uint32_t *input_shape_indptr, const uint32_t *input_shape_data, PredictorHandle handle, PredictorHandle *out)
Change the input shape of an existing predictor.