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 
25 #ifndef MXNET_C_PREDICT_API_H_
26 #define MXNET_C_PREDICT_API_H_
27 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif // __cplusplus
32 
33 #ifdef _WIN32
34 #ifdef MXNET_EXPORTS
35 #define MXNET_DLL __declspec(dllexport)
36 #else
37 #define MXNET_DLL __declspec(dllimport)
38 #endif
39 #else
40 #define MXNET_DLL
41 #endif
42 
44 typedef uint32_t mx_uint;
46 typedef float mx_float;
48 typedef void *PredictorHandle;
50 typedef void *NDListHandle;
52 typedef void *NDArrayHandle;
54 typedef void (*PredMonitorCallback)(const char*,
56  void*);
57 
62 MXNET_DLL const char* MXGetLastError();
63 
83 MXNET_DLL int MXPredCreate(const char* symbol_json_str,
84  const void* param_bytes,
85  int param_size,
86  int dev_type, int dev_id,
87  uint32_t num_input_nodes,
88  const char** input_keys,
89  const uint32_t* input_shape_indptr,
90  const uint32_t* input_shape_data,
91  PredictorHandle* out);
92 
118 MXNET_DLL int MXPredCreateEx(const char* symbol_json_str,
119  const void* param_bytes,
120  int param_size,
121  int dev_type, int dev_id,
122  const uint32_t num_input_nodes,
123  const char** input_keys,
124  const uint32_t* input_shape_indptr,
125  const uint32_t* input_shape_data,
126  const uint32_t num_provided_arg_dtypes,
127  const char** provided_arg_dtype_names,
128  const int* provided_arg_dtypes,
129  PredictorHandle* out);
130 
154 MXNET_DLL int MXPredCreatePartialOut(const char* symbol_json_str,
155  const void* param_bytes,
156  int param_size,
157  int dev_type, int dev_id,
158  uint32_t num_input_nodes,
159  const char** input_keys,
160  const uint32_t* input_shape_indptr,
161  const uint32_t* input_shape_data,
162  uint32_t num_output_nodes,
163  const char** output_keys,
164  PredictorHandle* out);
165 
187 MXNET_DLL int MXPredCreateMultiThread(const char* symbol_json_str,
188  const void* param_bytes,
189  int param_size,
190  int dev_type, int dev_id,
191  uint32_t num_input_nodes,
192  const char** input_keys,
193  const uint32_t* input_shape_indptr,
194  const uint32_t* input_shape_data,
195  int num_threads,
196  PredictorHandle* out);
197 
213 MXNET_DLL int MXPredReshape(uint32_t num_input_nodes,
214  const char** input_keys,
215  const uint32_t* input_shape_indptr,
216  const uint32_t* input_shape_data,
217  PredictorHandle handle,
218  PredictorHandle* out);
228 MXNET_DLL int MXPredGetOutputShape(PredictorHandle handle,
229  uint32_t index,
230  uint32_t** shape_data,
231  uint32_t* shape_ndim);
232 
240 MXNET_DLL int MXPredGetOutputType(PredictorHandle handle,
241  uint32_t out_index,
242  int* out_dtype);
243 
253 MXNET_DLL int MXPredSetInput(PredictorHandle handle,
254  const char* key,
255  const float* data,
256  uint32_t size);
262 MXNET_DLL int MXPredForward(PredictorHandle handle);
279 MXNET_DLL int MXPredPartialForward(PredictorHandle handle, int step, int* step_left);
288 MXNET_DLL int MXPredGetOutput(PredictorHandle handle,
289  uint32_t index,
290  float* data,
291  uint32_t size);
297 MXNET_DLL int MXPredFree(PredictorHandle handle);
307 MXNET_DLL int MXNDListCreate(const char* nd_file_bytes,
308  int nd_file_size,
309  NDListHandle *out,
310  uint32_t* out_length);
321 MXNET_DLL int MXNDListGet(NDListHandle handle,
322  uint32_t index,
323  const char** out_key,
324  const float** out_data,
325  const uint32_t** out_shape,
326  uint32_t* out_ndim);
327 
332 MXNET_DLL int MXPredSetMonitorCallback(PredictorHandle handle,
333  PredMonitorCallback callback,
334  void* callback_handle,
335  bool monitor_all);
341 MXNET_DLL int MXNDListFree(NDListHandle handle);
342 
343 #ifdef __cplusplus
344 }
345 #endif // __cplusplus
346 
347 #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:44
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:52
void * PredictorHandle
handle to Predictor
Definition: c_predict_api.h:48
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:46
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:50
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:54
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:40
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.