mxnet
c_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 
24 #ifndef MXNET_C_API_H_
25 #define MXNET_C_API_H_
26 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif // __cplusplus
31 
33 #ifdef __cplusplus
34 #define DEFAULT(x) = x
35 #else
36 #define DEFAULT(x)
37 #endif // __cplusplus
38 
39 #include <stdint.h>
40 
41 #include <stdint.h>
42 #include <stddef.h>
43 #include <stdbool.h>
44 
46 #ifdef _WIN32
47 #ifdef MXNET_EXPORTS
48 #define MXNET_DLL __declspec(dllexport)
49 #else
50 #define MXNET_DLL __declspec(dllimport)
51 #endif
52 #else
53 #define MXNET_DLL
54 #endif
55 
57 typedef unsigned int mx_uint;
59 typedef float mx_float;
60 // all the handles are simply void *
61 // will be casted internally to specific pointers types
62 // these typedefs are mainly used for readablity reasons
64 typedef void *NDArrayHandle;
66 typedef const void *FunctionHandle;
68 typedef void *AtomicSymbolCreator;
70 typedef void *CachedOpHandle;
72 typedef void *SymbolHandle;
74 typedef void *AtomicSymbolHandle;
76 typedef void *ExecutorHandle;
78 typedef void *DataIterCreator;
80 typedef void *DataIterHandle;
82 typedef void *KVStoreHandle;
84 typedef void *RecordIOHandle;
86 typedef void *RtcHandle;
88 typedef void *CudaModuleHandle;
90 typedef void *CudaKernelHandle;
91 
92 typedef void (*ExecutorMonitorCallback)(const char*,
94  void *);
95 
96 struct NativeOpInfo {
97  void (*forward)(int, float**, int*, unsigned**, int*, void*);
98  void (*backward)(int, float**, int*, unsigned**, int*, void*);
99  void (*infer_shape)(int, int*, unsigned**, void*);
100  void (*list_outputs)(char***, void*);
101  void (*list_arguments)(char***, void*);
102  // all functions also pass a payload void* pointer
103  void* p_forward;
104  void* p_backward;
108 };
109 
111  bool (*forward)(int, void**, int*, void*);
112  bool (*backward)(int, void**, int*, void*);
113  bool (*infer_shape)(int, int*, unsigned**, void*);
114  bool (*list_outputs)(char***, void*);
115  bool (*list_arguments)(char***, void*);
116  bool (*declare_backward_dependency)(const int*, const int*, const int*,
117  int*, int**, void*);
118  // all functions also pass a payload void* pointer
119  void* p_forward;
120  void* p_backward;
125 };
126 
127 typedef int (*MXGenericCallback)(void);
128 
131  int (**callbacks)(void);
132  void **contexts;
133 };
134 
139 };
140 
150 };
151 
152 
153 typedef int (*CustomOpFBFunc)(int /*size*/, void** /*ptrs*/, int* /*tags*/,
154  const int* /*reqs*/, const int /*is_train*/,
155  void* /*state*/);
156 typedef int (*CustomOpDelFunc)(void* /*state*/);
157 typedef int (*CustomOpListFunc)(char*** /*args*/, void* /*state*/);
158 typedef int (*CustomOpInferShapeFunc)(int /*num_input*/, int* /*ndims*/,
159  unsigned** /*shapes*/, void* /*state*/);
160 typedef int (*CustomOpInferTypeFunc)(int /*num_input*/, int* /*types*/, void* /*state*/);
161 typedef int (*CustomOpBwdDepFunc)(const int* /*out_grad*/, const int* /*in_data*/,
162  const int* /*out_data*/, int* /*num_deps*/,
163  int** /*rdeps*/, void* /*state*/);
164 typedef int (*CustomOpCreateFunc)(const char* /*ctx*/, int /*num_inputs*/,
165  unsigned** /*shapes*/, const int* /*ndims*/,
166  const int* /*dtypes*/, struct MXCallbackList* /*ret*/,
167  void* /*state*/);
168 typedef int (*CustomOpPropCreator)(const char* /*op_type*/, const int /*num_kwargs*/,
169  const char** /*keys*/, const char** /*values*/,
170  struct MXCallbackList* /*ret*/);
171 
172 
176 };
177 
178 typedef int (*CustomFunctionBwdFunc)(int /*num_ograds*/, int /*num_igrads*/, void** /*ptrs*/,
179  const int* /*reqs*/, const int /*is_train*/,
180  void* /*state*/);
181 typedef int (*CustomFunctionDelFunc)(void* /*state*/);
182 
192 MXNET_DLL const char *MXGetLastError();
193 
194 //-------------------------------------
195 // Part 0: Global State setups
196 //-------------------------------------
202 MXNET_DLL int MXRandomSeed(int seed);
219 MXNET_DLL int MXSetProfilerConfig(int mode, const char* filename);
227 MXNET_DLL int MXSetProfilerState(int state);
228 
231 
233 MXNET_DLL int MXSetNumOMPThreads(int thread_num);
234 
240 MXNET_DLL int MXGetVersion(int *out);
241 
242 //-------------------------------------
243 // Part 1: NDArray creation and deletion
244 //-------------------------------------
252 MXNET_DLL int MXNDArrayCreateNone(NDArrayHandle *out);
264 MXNET_DLL int MXNDArrayCreate(const mx_uint *shape,
265  mx_uint ndim,
266  int dev_type,
267  int dev_id,
268  int delay_alloc,
269  NDArrayHandle *out);
270 
283 MXNET_DLL int MXNDArrayCreateEx(const mx_uint *shape,
284  mx_uint ndim,
285  int dev_type,
286  int dev_id,
287  int delay_alloc,
288  int dtype,
289  NDArrayHandle *out);
290 
291 
309 MXNET_DLL int MXNDArrayCreateSparseEx(int storage_type,
310  const mx_uint *shape,
311  mx_uint ndim,
312  int dev_type,
313  int dev_id,
314  int delay_alloc,
315  int dtype,
316  mx_uint num_aux,
317  int *aux_type,
318  mx_uint *aux_ndims,
319  const mx_uint *aux_shape,
320  NDArrayHandle *out);
321 
329 MXNET_DLL int MXNDArrayLoadFromRawBytes(const void *buf,
330  size_t size,
331  NDArrayHandle *out);
339 MXNET_DLL int MXNDArraySaveRawBytes(NDArrayHandle handle,
340  size_t *out_size,
341  const char **out_buf);
350 MXNET_DLL int MXNDArraySave(const char* fname,
351  mx_uint num_args,
352  NDArrayHandle* args,
353  const char** keys);
363 MXNET_DLL int MXNDArrayLoad(const char* fname,
364  mx_uint *out_size,
365  NDArrayHandle** out_arr,
366  mx_uint *out_name_size,
367  const char*** out_names);
379 MXNET_DLL int MXNDArraySyncCopyFromCPU(NDArrayHandle handle,
380  const void *data,
381  size_t size);
393 MXNET_DLL int MXNDArraySyncCopyToCPU(NDArrayHandle handle,
394  void *data,
395  size_t size);
403 MXNET_DLL int MXNDArraySyncCopyFromNDArray(NDArrayHandle handle_dst,
404  const NDArrayHandle handle_src,
405  const int i);
406 
413 MXNET_DLL int MXNDArrayWaitToRead(NDArrayHandle handle);
420 MXNET_DLL int MXNDArrayWaitToWrite(NDArrayHandle handle);
432 MXNET_DLL int MXNDArrayFree(NDArrayHandle handle);
441 MXNET_DLL int MXNDArraySlice(NDArrayHandle handle,
442  mx_uint slice_begin,
443  mx_uint slice_end,
444  NDArrayHandle *out);
445 
453 MXNET_DLL int MXNDArrayAt(NDArrayHandle handle,
454  mx_uint idx,
455  NDArrayHandle *out);
456 
460 MXNET_DLL int MXNDArrayGetStorageType(NDArrayHandle handle,
461  int *out_storage_type);
462 
471 MXNET_DLL int MXNDArrayReshape(NDArrayHandle handle,
472  int ndim,
473  int *dims,
474  NDArrayHandle *out);
482 MXNET_DLL int MXNDArrayGetShape(NDArrayHandle handle,
483  mx_uint *out_dim,
484  const mx_uint **out_pdata);
491 MXNET_DLL int MXNDArrayGetData(NDArrayHandle handle,
492  void **out_pdata);
499 MXNET_DLL int MXNDArrayGetDType(NDArrayHandle handle,
500  int *out_dtype);
501 
509 MXNET_DLL int MXNDArrayGetAuxType(NDArrayHandle handle,
510  mx_uint i,
511  int *out_type);
512 
518 MXNET_DLL int MXNDArrayGetAuxNDArray(NDArrayHandle handle,
519  mx_uint i,
520  NDArrayHandle *out);
521 
527 MXNET_DLL int MXNDArrayGetDataNDArray(NDArrayHandle handle,
528  NDArrayHandle *out);
536 MXNET_DLL int MXNDArrayGetContext(NDArrayHandle handle,
537  int *out_dev_type,
538  int *out_dev_id);
544 MXNET_DLL int MXNDArrayGetGrad(NDArrayHandle handle, NDArrayHandle *out);
550 MXNET_DLL int MXNDArrayDetach(NDArrayHandle handle, NDArrayHandle *out);
557 MXNET_DLL int MXNDArraySetGradState(NDArrayHandle handle, int state);
564 MXNET_DLL int MXNDArrayGetGradState(NDArrayHandle handle, int *out);
565 //--------------------------------
566 // Part 2: functions on NDArray
567 //--------------------------------
575 MXNET_DLL int MXListFunctions(mx_uint *out_size,
576  FunctionHandle **out_array);
583 MXNET_DLL int MXGetFunction(const char *name,
584  FunctionHandle *out);
597 MXNET_DLL int MXFuncGetInfo(FunctionHandle fun,
598  const char **name,
599  const char **description,
600  mx_uint *num_args,
601  const char ***arg_names,
602  const char ***arg_type_infos,
603  const char ***arg_descriptions,
604  const char **return_type DEFAULT(NULL));
615 MXNET_DLL int MXFuncDescribe(FunctionHandle fun,
616  mx_uint *num_use_vars,
617  mx_uint *num_scalars,
618  mx_uint *num_mutate_vars,
619  int *type_mask);
630 MXNET_DLL int MXFuncInvoke(FunctionHandle fun,
631  NDArrayHandle *use_vars,
632  mx_float *scalar_args,
633  NDArrayHandle *mutate_vars);
647 MXNET_DLL int MXFuncInvokeEx(FunctionHandle fun,
648  NDArrayHandle *use_vars,
649  mx_float *scalar_args,
650  NDArrayHandle *mutate_vars,
651  int num_params,
652  char **param_keys,
653  char **param_vals);
666 MXNET_DLL int MXImperativeInvoke(AtomicSymbolCreator creator,
667  int num_inputs,
668  NDArrayHandle *inputs,
669  int *num_outputs,
670  NDArrayHandle **outputs,
671  int num_params,
672  const char **param_keys,
673  const char **param_vals);
687 MXNET_DLL int MXImperativeInvokeEx(AtomicSymbolCreator creator,
688  int num_inputs,
689  NDArrayHandle *inputs,
690  int *num_outputs,
691  NDArrayHandle **outputs,
692  int num_params,
693  const char **param_keys,
694  const char **param_vals,
695  const int **out_stypes);
702 MXNET_DLL int MXAutogradSetIsRecording(int is_recording, int* prev);
709 MXNET_DLL int MXAutogradSetIsTraining(int is_training, int* prev);
715 MXNET_DLL int MXAutogradIsRecording(bool* curr);
721 MXNET_DLL int MXAutogradIsTraining(bool* curr);
728 MXNET_DLL int MXAutogradMarkVariables(mx_uint num_var,
729  NDArrayHandle *var_handles,
730  mx_uint *reqs_array,
731  NDArrayHandle *grad_handles);
738 MXNET_DLL int MXAutogradComputeGradient(mx_uint num_output,
739  NDArrayHandle* output_handles);
748 MXNET_DLL int MXAutogradBackward(mx_uint num_output,
749  NDArrayHandle* output_handles,
750  NDArrayHandle* ograd_handles,
751  int retain_graph);
763 MXNET_DLL int MXAutogradBackwardEx(mx_uint num_output,
764  NDArrayHandle *output_handles,
765  NDArrayHandle *ograd_handles,
766  mx_uint num_variables,
767  NDArrayHandle *var_handles,
768  int retain_graph,
769  int create_graph,
770  int is_train,
771  NDArrayHandle **grad_handles,
772  int **grad_stypes);
773 /*
774  * \brief get the graph constructed by autograd.
775  * \param handle ndarray handle
776  * \param out output symbol handle
777  */
778 MXNET_DLL int MXAutogradGetSymbol(NDArrayHandle handle, SymbolHandle *out);
782 MXNET_DLL int MXCreateCachedOp(SymbolHandle handle,
783  CachedOpHandle *out);
787 MXNET_DLL int MXFreeCachedOp(CachedOpHandle handle);
791 MXNET_DLL int MXInvokeCachedOp(CachedOpHandle handle,
792  int num_inputs,
793  NDArrayHandle *inputs,
794  int *num_outputs,
795  NDArrayHandle **outputs);
806 MXNET_DLL int MXInvokeCachedOpEx(CachedOpHandle handle,
807  int num_inputs,
808  NDArrayHandle *inputs,
809  int *num_outputs,
810  NDArrayHandle **outputs,
811  const int** out_stypes);
815 MXNET_DLL int MXInvokeCachedOp(CachedOpHandle handle,
816  int num_inputs,
817  NDArrayHandle *inputs,
818  int *num_outputs,
819  NDArrayHandle **outputs);
820 //--------------------------------------------
821 // Part 3: symbolic configuration generation
822 //--------------------------------------------
829 MXNET_DLL int MXListAllOpNames(mx_uint *out_size,
830  const char ***out_array);
837 MXNET_DLL int MXSymbolListAtomicSymbolCreators(mx_uint *out_size,
838  AtomicSymbolCreator **out_array);
839 
845 MXNET_DLL int MXSymbolGetAtomicSymbolName(AtomicSymbolCreator creator,
846  const char **name);
864 MXNET_DLL int MXSymbolGetAtomicSymbolInfo(AtomicSymbolCreator creator,
865  const char **name,
866  const char **description,
867  mx_uint *num_args,
868  const char ***arg_names,
869  const char ***arg_type_infos,
870  const char ***arg_descriptions,
871  const char **key_var_num_args,
872  const char **return_type DEFAULT(NULL));
882 MXNET_DLL int MXSymbolCreateAtomicSymbol(AtomicSymbolCreator creator,
883  mx_uint num_param,
884  const char **keys,
885  const char **vals,
886  SymbolHandle *out);
893 MXNET_DLL int MXSymbolCreateVariable(const char *name, SymbolHandle *out);
901 MXNET_DLL int MXSymbolCreateGroup(mx_uint num_symbols,
902  SymbolHandle *symbols,
903  SymbolHandle *out);
910 MXNET_DLL int MXSymbolCreateFromFile(const char *fname, SymbolHandle *out);
917 MXNET_DLL int MXSymbolCreateFromJSON(const char *json, SymbolHandle *out);
924 MXNET_DLL int MXSymbolSaveToFile(SymbolHandle symbol, const char *fname);
931 MXNET_DLL int MXSymbolSaveToJSON(SymbolHandle symbol, const char **out_json);
937 MXNET_DLL int MXSymbolFree(SymbolHandle symbol);
944 MXNET_DLL int MXSymbolCopy(SymbolHandle symbol, SymbolHandle *out);
951 MXNET_DLL int MXSymbolPrint(SymbolHandle symbol, const char **out_str);
959 MXNET_DLL int MXSymbolGetName(SymbolHandle symbol,
960  const char** out,
961  int *success);
970 MXNET_DLL int MXSymbolGetAttr(SymbolHandle symbol,
971  const char* key,
972  const char** out,
973  int *success);
990 MXNET_DLL int MXSymbolSetAttr(SymbolHandle symbol,
991  const char* key,
992  const char* value);
1000 MXNET_DLL int MXSymbolListAttr(SymbolHandle symbol,
1001  mx_uint *out_size,
1002  const char*** out);
1010 MXNET_DLL int MXSymbolListAttrShallow(SymbolHandle symbol,
1011  mx_uint *out_size,
1012  const char*** out);
1020 MXNET_DLL int MXSymbolListArguments(SymbolHandle symbol,
1021  mx_uint *out_size,
1022  const char ***out_str_array);
1030 MXNET_DLL int MXSymbolListOutputs(SymbolHandle symbol,
1031  mx_uint *out_size,
1032  const char ***out_str_array);
1039 MXNET_DLL int MXSymbolGetInternals(SymbolHandle symbol,
1040  SymbolHandle *out);
1047 MXNET_DLL int MXSymbolGetChildren(SymbolHandle symbol,
1048  SymbolHandle *out);
1056 MXNET_DLL int MXSymbolGetOutput(SymbolHandle symbol,
1057  mx_uint index,
1058  SymbolHandle *out);
1066 MXNET_DLL int MXSymbolListAuxiliaryStates(SymbolHandle symbol,
1067  mx_uint *out_size,
1068  const char ***out_str_array);
1083 MXNET_DLL int MXSymbolCompose(SymbolHandle sym,
1084  const char *name,
1085  mx_uint num_args,
1086  const char** keys,
1087  SymbolHandle* args);
1097 MXNET_DLL int MXSymbolGrad(SymbolHandle sym,
1098  mx_uint num_wrt,
1099  const char** wrt,
1100  SymbolHandle* out);
1123 MXNET_DLL int MXSymbolInferShape(SymbolHandle sym,
1124  mx_uint num_args,
1125  const char** keys,
1126  const mx_uint *arg_ind_ptr,
1127  const mx_uint *arg_shape_data,
1128  mx_uint *in_shape_size,
1129  const mx_uint **in_shape_ndim,
1130  const mx_uint ***in_shape_data,
1131  mx_uint *out_shape_size,
1132  const mx_uint **out_shape_ndim,
1133  const mx_uint ***out_shape_data,
1134  mx_uint *aux_shape_size,
1135  const mx_uint **aux_shape_ndim,
1136  const mx_uint ***aux_shape_data,
1137  int *complete);
1162 MXNET_DLL int MXSymbolInferShapePartial(SymbolHandle sym,
1163  mx_uint num_args,
1164  const char** keys,
1165  const mx_uint *arg_ind_ptr,
1166  const mx_uint *arg_shape_data,
1167  mx_uint *in_shape_size,
1168  const mx_uint **in_shape_ndim,
1169  const mx_uint ***in_shape_data,
1170  mx_uint *out_shape_size,
1171  const mx_uint **out_shape_ndim,
1172  const mx_uint ***out_shape_data,
1173  mx_uint *aux_shape_size,
1174  const mx_uint **aux_shape_ndim,
1175  const mx_uint ***aux_shape_data,
1176  int *complete);
1177 
1196 MXNET_DLL int MXSymbolInferType(SymbolHandle sym,
1197  mx_uint num_args,
1198  const char** keys,
1199  const int *arg_type_data,
1200  mx_uint *in_type_size,
1201  const int **in_type_data,
1202  mx_uint *out_type_size,
1203  const int **out_type_data,
1204  mx_uint *aux_type_size,
1205  const int **aux_type_data,
1206  int *complete);
1207 
1208 
1209 
1210 
1211 //--------------------------------------------
1212 // Part 4: Executor interface
1213 //--------------------------------------------
1219 MXNET_DLL int MXExecutorFree(ExecutorHandle handle);
1226 MXNET_DLL int MXExecutorPrint(ExecutorHandle handle, const char **out_str);
1234 MXNET_DLL int MXExecutorForward(ExecutorHandle handle, int is_train);
1244 MXNET_DLL int MXExecutorBackward(ExecutorHandle handle,
1245  mx_uint len,
1246  NDArrayHandle *head_grads);
1257 MXNET_DLL int MXExecutorBackwardEx(ExecutorHandle handle,
1258  mx_uint len,
1259  NDArrayHandle *head_grads,
1260  int is_train);
1269 MXNET_DLL int MXExecutorOutputs(ExecutorHandle handle,
1270  mx_uint *out_size,
1271  NDArrayHandle **out);
1272 
1288 MXNET_DLL int MXExecutorBind(SymbolHandle symbol_handle,
1289  int dev_type,
1290  int dev_id,
1291  mx_uint len,
1292  NDArrayHandle *in_args,
1293  NDArrayHandle *arg_grad_store,
1294  mx_uint *grad_req_type,
1295  mx_uint aux_states_len,
1296  NDArrayHandle *aux_states,
1297  ExecutorHandle *out);
1319 MXNET_DLL int MXExecutorBindX(SymbolHandle symbol_handle,
1320  int dev_type,
1321  int dev_id,
1322  mx_uint num_map_keys,
1323  const char** map_keys,
1324  const int* map_dev_types,
1325  const int* map_dev_ids,
1326  mx_uint len,
1327  NDArrayHandle *in_args,
1328  NDArrayHandle *arg_grad_store,
1329  mx_uint *grad_req_type,
1330  mx_uint aux_states_len,
1331  NDArrayHandle *aux_states,
1332  ExecutorHandle *out);
1355 MXNET_DLL int MXExecutorBindEX(SymbolHandle symbol_handle,
1356  int dev_type,
1357  int dev_id,
1358  mx_uint num_map_keys,
1359  const char** map_keys,
1360  const int* map_dev_types,
1361  const int* map_dev_ids,
1362  mx_uint len,
1363  NDArrayHandle *in_args,
1364  NDArrayHandle *arg_grad_store,
1365  mx_uint *grad_req_type,
1366  mx_uint aux_states_len,
1367  NDArrayHandle *aux_states,
1368  ExecutorHandle shared_exec,
1369  ExecutorHandle *out);
1370 
1371 MXNET_DLL int MXExecutorSimpleBind(SymbolHandle symbol_handle,
1372  int dev_type,
1373  int dev_id,
1374  const mx_uint num_g2c_keys,
1375  const char** g2c_keys,
1376  const int* g2c_dev_types,
1377  const int* g2c_dev_ids,
1378  const mx_uint provided_grad_req_list_len,
1379  const char** provided_grad_req_names,
1380  const char** provided_grad_req_types,
1381  const mx_uint num_provided_arg_shapes,
1382  const char** provided_arg_shape_names,
1383  const mx_uint* provided_arg_shape_data,
1384  const mx_uint* provided_arg_shape_idx,
1385  const mx_uint num_provided_arg_dtypes,
1386  const char** provided_arg_dtype_names,
1387  const int* provided_arg_dtypes,
1388  const mx_uint num_provided_arg_stypes,
1389  const char** provided_arg_stype_names,
1390  const int* provided_arg_stypes,
1391  const mx_uint num_shared_arg_names,
1392  const char** shared_arg_name_list,
1393  int* shared_buffer_len,
1394  const char** shared_buffer_name_list,
1395  NDArrayHandle* shared_buffer_handle_list,
1396  const char*** updated_shared_buffer_name_list,
1397  NDArrayHandle** updated_shared_buffer_handle_list,
1398  mx_uint* num_in_args,
1399  NDArrayHandle** in_args,
1400  NDArrayHandle** arg_grads,
1401  mx_uint* num_aux_states,
1402  NDArrayHandle** aux_states,
1403  ExecutorHandle shared_exec_handle,
1404  ExecutorHandle* out);
1408 MXNET_DLL int MXExecutorSetMonitorCallback(ExecutorHandle handle,
1409  ExecutorMonitorCallback callback,
1410  void* callback_handle);
1411 //--------------------------------------------
1412 // Part 5: IO Interface
1413 //--------------------------------------------
1420 MXNET_DLL int MXListDataIters(mx_uint *out_size,
1421  DataIterCreator **out_array);
1432 MXNET_DLL int MXDataIterCreateIter(DataIterCreator handle,
1433  mx_uint num_param,
1434  const char **keys,
1435  const char **vals,
1436  DataIterHandle *out);
1448 MXNET_DLL int MXDataIterGetIterInfo(DataIterCreator creator,
1449  const char **name,
1450  const char **description,
1451  mx_uint *num_args,
1452  const char ***arg_names,
1453  const char ***arg_type_infos,
1454  const char ***arg_descriptions);
1460 MXNET_DLL int MXDataIterFree(DataIterHandle handle);
1467 MXNET_DLL int MXDataIterNext(DataIterHandle handle,
1468  int *out);
1474 MXNET_DLL int MXDataIterBeforeFirst(DataIterHandle handle);
1475 
1482 MXNET_DLL int MXDataIterGetData(DataIterHandle handle,
1483  NDArrayHandle *out);
1491 MXNET_DLL int MXDataIterGetIndex(DataIterHandle handle,
1492  uint64_t **out_index,
1493  uint64_t *out_size);
1500 MXNET_DLL int MXDataIterGetPadNum(DataIterHandle handle,
1501  int *pad);
1502 
1509 MXNET_DLL int MXDataIterGetLabel(DataIterHandle handle,
1510  NDArrayHandle *out);
1511 //--------------------------------------------
1512 // Part 6: basic KVStore interface
1513 //--------------------------------------------
1520 MXNET_DLL int MXInitPSEnv(mx_uint num_vars,
1521  const char **keys,
1522  const char **vals);
1523 
1524 
1531 MXNET_DLL int MXKVStoreCreate(const char *type,
1532  KVStoreHandle *out);
1538 MXNET_DLL int MXKVStoreFree(KVStoreHandle handle);
1547 MXNET_DLL int MXKVStoreInit(KVStoreHandle handle,
1548  mx_uint num,
1549  const int* keys,
1550  NDArrayHandle* vals);
1551 
1560 MXNET_DLL int MXKVStoreInitEx(KVStoreHandle handle,
1561  mx_uint num,
1562  const char** keys,
1563  NDArrayHandle* vals);
1564 
1574 MXNET_DLL int MXKVStorePush(KVStoreHandle handle,
1575  mx_uint num,
1576  const int* keys,
1577  NDArrayHandle* vals,
1578  int priority);
1588 MXNET_DLL int MXKVStorePushEx(KVStoreHandle handle,
1589  mx_uint num,
1590  const char** keys,
1591  NDArrayHandle* vals,
1592  int priority);
1602 MXNET_DLL int MXKVStorePull(KVStoreHandle handle,
1603  mx_uint num,
1604  const int* keys,
1605  NDArrayHandle* vals,
1606  int priority);
1616 MXNET_DLL int MXKVStorePullEx(KVStoreHandle handle,
1617  mx_uint num,
1618  const char** keys,
1619  NDArrayHandle* vals,
1620  int priority);
1621 
1634 MXNET_DLL int MXKVStorePullRowSparse(KVStoreHandle handle,
1635  mx_uint num,
1636  const int* keys,
1637  NDArrayHandle* vals,
1638  const NDArrayHandle* row_ids,
1639  int priority);
1652 MXNET_DLL int MXKVStorePullRowSparseEx(KVStoreHandle handle,
1653  mx_uint num,
1654  const char** keys,
1655  NDArrayHandle* vals,
1656  const NDArrayHandle* row_ids,
1657  int priority);
1658 
1667 typedef void (MXKVStoreUpdater)(int key,
1668  NDArrayHandle recv,
1669  NDArrayHandle local,
1670  void *handle);
1679 typedef void (MXKVStoreStrUpdater)(const char* key,
1680  NDArrayHandle recv,
1681  NDArrayHandle local,
1682  void *handle);
1690 MXNET_DLL int MXKVStoreSetUpdater(KVStoreHandle handle,
1691  MXKVStoreUpdater updater,
1692  void *updater_handle);
1701 MXNET_DLL int MXKVStoreSetUpdaterEx(KVStoreHandle handle,
1702  MXKVStoreUpdater updater,
1703  MXKVStoreStrUpdater str_updater,
1704  void *updater_handle);
1711 MXNET_DLL int MXKVStoreGetType(KVStoreHandle handle,
1712  const char** type);
1713 //--------------------------------------------
1714 // Part 6: advanced KVStore for multi-machines
1715 //--------------------------------------------
1716 
1724 MXNET_DLL int MXKVStoreGetRank(KVStoreHandle handle,
1725  int *ret);
1726 
1736 MXNET_DLL int MXKVStoreGetGroupSize(KVStoreHandle handle,
1737  int *ret);
1738 
1744 MXNET_DLL int MXKVStoreIsWorkerNode(int *ret);
1745 
1746 
1752 MXNET_DLL int MXKVStoreIsServerNode(int *ret);
1753 
1754 
1760 MXNET_DLL int MXKVStoreIsSchedulerNode(int *ret);
1761 
1768 MXNET_DLL int MXKVStoreBarrier(KVStoreHandle handle);
1769 
1777 MXNET_DLL int MXKVStoreSetBarrierBeforeExit(KVStoreHandle handle,
1778  const int barrier_before_exit);
1779 
1786 typedef void (MXKVStoreServerController)(int head,
1787  const char *body,
1788  void *controller_handle);
1789 
1798 MXNET_DLL int MXKVStoreRunServer(KVStoreHandle handle,
1799  MXKVStoreServerController controller,
1800  void *controller_handle);
1801 
1810 MXNET_DLL int MXKVStoreSendCommmandToServers(KVStoreHandle handle,
1811  int cmd_id,
1812  const char* cmd_body);
1813 
1824 MXNET_DLL int MXKVStoreGetNumDeadNode(KVStoreHandle handle,
1825  const int node_id,
1826  int *number,
1827  const int timeout_sec DEFAULT(60));
1828 
1835 MXNET_DLL int MXRecordIOWriterCreate(const char *uri, RecordIOHandle *out);
1836 
1842 MXNET_DLL int MXRecordIOWriterFree(RecordIOHandle handle);
1843 
1851 MXNET_DLL int MXRecordIOWriterWriteRecord(RecordIOHandle handle,
1852  const char *buf, size_t size);
1853 
1860 MXNET_DLL int MXRecordIOWriterTell(RecordIOHandle handle, size_t *pos);
1861 
1868 MXNET_DLL int MXRecordIOReaderCreate(const char *uri, RecordIOHandle *out);
1869 
1875 MXNET_DLL int MXRecordIOReaderFree(RecordIOHandle handle);
1876 
1884 MXNET_DLL int MXRecordIOReaderReadRecord(RecordIOHandle handle,
1885  char const **buf, size_t *size);
1886 
1893 MXNET_DLL int MXRecordIOReaderSeek(RecordIOHandle handle, size_t pos);
1894 
1901 MXNET_DLL int MXRecordIOReaderTell(RecordIOHandle handle, size_t *pos);
1902 
1906 MXNET_DLL int MXRtcCreate(char* name, mx_uint num_input, mx_uint num_output,
1907  char** input_names, char** output_names,
1908  NDArrayHandle* inputs, NDArrayHandle* outputs,
1909  char* kernel, RtcHandle *out);
1910 
1914 MXNET_DLL int MXRtcPush(RtcHandle handle, mx_uint num_input, mx_uint num_output,
1915  NDArrayHandle* inputs, NDArrayHandle* outputs,
1916  mx_uint gridDimX,
1917  mx_uint gridDimY,
1918  mx_uint gridDimZ,
1919  mx_uint blockDimX,
1920  mx_uint blockDimY,
1921  mx_uint blockDimZ);
1922 
1926 MXNET_DLL int MXRtcFree(RtcHandle handle);
1927 /*
1928  * \brief register custom operators from frontend.
1929  * \param op_type name of custom op
1930  * \param creator
1931  */
1932 MXNET_DLL int MXCustomOpRegister(const char* op_type, CustomOpPropCreator creator);
1933 /*
1934  * \brief record custom function for backward later.
1935  * \param num_inputs number of input NDArrays.
1936  * \param inputs handle to input NDArrays.
1937  * \param num_outputs number of output NDArrays.
1938  * \param outputs handle to output NDArrays.
1939  * \param callbacks callbacks for backward function.
1940  */
1941 MXNET_DLL int MXCustomFunctionRecord(int num_inputs, NDArrayHandle *inputs,
1942  int num_outputs, NDArrayHandle *outputs,
1943  struct MXCallbackList *callbacks);
1944 /*
1945  * \brief create cuda rtc module
1946  * \param source cuda source code
1947  * \param num_options number of compiler flags
1948  * \param options compiler flags
1949  * \param num_exports number of exported function names
1950  * \param exported function names
1951  * \param out handle to created module
1952  */
1953 MXNET_DLL int MXRtcCudaModuleCreate(const char* source, int num_options,
1954  const char** options, int num_exports,
1955  const char** exports, CudaModuleHandle *out);
1956 /*
1957  * \brief delete cuda rtc module
1958  * \param handle handle to cuda module
1959  */
1960 MXNET_DLL int MXRtcCudaModuleFree(CudaModuleHandle handle);
1961 /*
1962  * \brief get kernel from module
1963  * \param handle handle to cuda module
1964  * \param name name of kernel function
1965  * \param num_args number of arguments
1966  * \param is_ndarray whether argument is ndarray
1967  * \param is_const whether argument is constant
1968  * \param arg_types data type of arguments
1969  * \param out created kernel
1970  */
1971 MXNET_DLL int MXRtcCudaKernelCreate(CudaModuleHandle handle, const char* name,
1972  int num_args, int* is_ndarray, int* is_const,
1973  int* arg_types, CudaKernelHandle *out);
1974 /*
1975  * \brief delete kernel
1976  * \param handle handle to previously created kernel
1977  */
1978 MXNET_DLL int MXRtcCudaKernelFree(CudaKernelHandle handle);
1979 /*
1980  * \brief launch cuda kernel
1981  * \param handle handle to kernel
1982  * \param dev_id (GPU) device id
1983  * \param args pointer to arguments
1984  * \param grid_dim_x grid dimension x
1985  * \param grid_dim_y grid dimension y
1986  * \param grid_dim_z grid dimension z
1987  * \param block_dim_x block dimension x
1988  * \param block_dim_y block dimension y
1989  * \param block_dim_z block dimension z
1990  * \param shared_mem size of dynamically allocated shared memory
1991  */
1992 MXNET_DLL int MXRtcCudaKernelCall(CudaKernelHandle handle, int dev_id, void** args,
1993  mx_uint grid_dim_x, mx_uint grid_dim_y,
1994  mx_uint grid_dim_z, mx_uint block_dim_x,
1995  mx_uint block_dim_y, mx_uint block_dim_z,
1996  mx_uint shared_mem);
1997 
1998 #ifdef __cplusplus
1999 }
2000 #endif // __cplusplus
2001 
2002 #endif // MXNET_C_API_H_
MXNET_DLL int MXKVStoreSendCommmandToServers(KVStoreHandle handle, int cmd_id, const char *cmd_body)
int(* CustomFunctionDelFunc)(void *)
Definition: c_api.h:181
MXNET_DLL int MXNDArrayDetach(NDArrayHandle handle, NDArrayHandle *out)
detach and ndarray from computation graph by clearing entry_
MXNET_DLL int MXListAllOpNames(mx_uint *out_size, const char ***out_array)
list all the available operator names, include entries.
MXNET_DLL int MXNDArrayGetAuxType(NDArrayHandle handle, mx_uint i, int *out_type)
get the type of the ith aux data in NDArray
MXNET_DLL int MXKVStoreSetUpdater(KVStoreHandle handle, MXKVStoreUpdater updater, void *updater_handle)
register a push updater
MXNET_DLL int MXKVStoreBarrier(KVStoreHandle handle)
global barrier among all worker machines
void * DataIterHandle
handle to a DataIterator
Definition: c_api.h:80
MXNET_DLL int MXSymbolListAtomicSymbolCreators(mx_uint *out_size, AtomicSymbolCreator **out_array)
list all the available AtomicSymbolEntry
Definition: c_api.h:136
MXNET_DLL int MXDataIterCreateIter(DataIterCreator handle, mx_uint num_param, const char **keys, const char **vals, DataIterHandle *out)
Init an iterator, init with parameters the array size of passed in arguments.
MXNET_DLL int MXDataIterNext(DataIterHandle handle, int *out)
Move iterator to next position.
MXNET_DLL int MXNDArrayReshape(NDArrayHandle handle, int ndim, int *dims, NDArrayHandle *out)
Reshape the NDArray.
void * p_infer_shape
Definition: c_api.h:121
MXNET_DLL int MXAutogradMarkVariables(mx_uint num_var, NDArrayHandle *var_handles, mx_uint *reqs_array, NDArrayHandle *grad_handles)
mark NDArrays as variables to compute gradient for autograd
Definition: c_api.h:146
MXNET_DLL int MXExecutorPrint(ExecutorHandle handle, const char **out_str)
Print the content of execution plan, used for debug.
MXNET_DLL int MXKVStoreRunServer(KVStoreHandle handle, MXKVStoreServerController controller, void *controller_handle)
void(* list_arguments)(char ***, void *)
Definition: c_api.h:101
MXNET_DLL int MXSymbolSaveToJSON(SymbolHandle symbol, const char **out_json)
Save a symbol into a json string.
MXNET_DLL int MXSymbolInferShape(SymbolHandle sym, mx_uint num_args, const char **keys, const mx_uint *arg_ind_ptr, const mx_uint *arg_shape_data, mx_uint *in_shape_size, const mx_uint **in_shape_ndim, const mx_uint ***in_shape_data, mx_uint *out_shape_size, const mx_uint **out_shape_ndim, const mx_uint ***out_shape_data, mx_uint *aux_shape_size, const mx_uint **aux_shape_ndim, const mx_uint ***aux_shape_data, int *complete)
infer shape of unknown input shapes given the known one. The shapes are packed into a CSR matrix repr...
MXNET_DLL int MXSymbolGetAttr(SymbolHandle symbol, const char *key, const char **out, int *success)
Get string attribute from symbol.
MXNET_DLL int MXRtcCreate(char *name, mx_uint num_input, mx_uint num_output, char **input_names, char **output_names, NDArrayHandle *inputs, NDArrayHandle *outputs, char *kernel, RtcHandle *out)
Create a MXRtc object.
MXNET_DLL int MXSymbolGetAtomicSymbolName(AtomicSymbolCreator creator, const char **name)
Get the name of an atomic symbol.
MXNET_DLL int MXKVStorePull(KVStoreHandle handle, mx_uint num, const int *keys, NDArrayHandle *vals, int priority)
pull a list of (key, value) pairs from the kvstore
MXNET_DLL int MXNDArrayWaitToRead(NDArrayHandle handle)
Wait until all the pending writes with respect NDArray are finished. Always call this before read dat...
MXNET_DLL int MXExecutorBind(SymbolHandle symbol_handle, int dev_type, int dev_id, mx_uint len, NDArrayHandle *in_args, NDArrayHandle *arg_grad_store, mx_uint *grad_req_type, mx_uint aux_states_len, NDArrayHandle *aux_states, ExecutorHandle *out)
Generate Executor from symbol.
void * p_forward
Definition: c_api.h:119
MXNET_DLL int MXKVStorePullRowSparse(KVStoreHandle handle, mx_uint num, const int *keys, NDArrayHandle *vals, const NDArrayHandle *row_ids, int priority)
pull a list of (key, value) pairs from the kvstore, where each key is an integer. The NDArray pulled ...
MXNET_DLL int MXDataIterFree(DataIterHandle handle)
Free the handle to the IO module.
MXNET_DLL int MXKVStoreSetUpdaterEx(KVStoreHandle handle, MXKVStoreUpdater updater, MXKVStoreStrUpdater str_updater, void *updater_handle)
register a push updater with int keys and one with string keys
MXNET_DLL int MXInvokeCachedOp(CachedOpHandle handle, int num_inputs, NDArrayHandle *inputs, int *num_outputs, NDArrayHandle **outputs)
invoke cached operator
MXNET_DLL int MXFreeCachedOp(CachedOpHandle handle)
free cached operator
void * RecordIOHandle
handle to RecordIO
Definition: c_api.h:84
CustomOpCallbacks
Definition: c_api.h:135
MXNET_DLL int MXSymbolGetChildren(SymbolHandle symbol, SymbolHandle *out)
Get a symbol that contains only direct children.
MXNET_DLL int MXRecordIOReaderFree(RecordIOHandle handle)
Delete a RecordIO reader object.
MXNET_DLL int MXExecutorOutputs(ExecutorHandle handle, mx_uint *out_size, NDArrayHandle **out)
Get executor&#39;s head NDArray.
MXNET_DLL int MXNDArrayGetContext(NDArrayHandle handle, int *out_dev_type, int *out_dev_id)
get the context of the NDArray
MXNET_DLL int MXFuncDescribe(FunctionHandle fun, mx_uint *num_use_vars, mx_uint *num_scalars, mx_uint *num_mutate_vars, int *type_mask)
get the argument requirements of the function
MXNET_DLL int MXKVStoreIsServerNode(int *ret)
return whether or not this process is a server node.
MXNET_DLL int MXNDArraySlice(NDArrayHandle handle, mx_uint slice_begin, mx_uint slice_end, NDArrayHandle *out)
Slice the NDArray along axis 0.
void * ExecutorHandle
handle to an Executor
Definition: c_api.h:76
CustomFunctionCallbacks
Definition: c_api.h:173
MXNET_DLL int MXSymbolSaveToFile(SymbolHandle symbol, const char *fname)
Save a symbol into a json file.
void * AtomicSymbolHandle
handle to a AtomicSymbol
Definition: c_api.h:74
void * p_backward
Definition: c_api.h:104
MXNET_DLL int MXFuncGetInfo(FunctionHandle fun, const char **name, const char **description, mx_uint *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions, const char **return_type DEFAULT(NULL))
Get the information of the function handle.
MXNET_DLL int MXAutogradSetIsTraining(int is_training, int *prev)
set whether to record operator for autograd
MXNET_DLL int MXNDArrayFree(NDArrayHandle handle)
free the narray handle
MXNET_DLL int MXSymbolCreateFromJSON(const char *json, SymbolHandle *out)
Load a symbol from a json string.
CustomOpPropCallbacks
Definition: c_api.h:141
int(* CustomOpInferTypeFunc)(int, int *, void *)
Definition: c_api.h:160
MXNET_DLL int MXKVStoreIsSchedulerNode(int *ret)
return whether or not this process is a scheduler node.
MXNET_DLL int MXInvokeCachedOpEx(CachedOpHandle handle, int num_inputs, NDArrayHandle *inputs, int *num_outputs, NDArrayHandle **outputs, const int **out_stypes)
invoke a cached op
MXNET_DLL int MXSymbolGetAtomicSymbolInfo(AtomicSymbolCreator creator, const char **name, const char **description, mx_uint *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions, const char **key_var_num_args, const char **return_type DEFAULT(NULL))
Get the detailed information about atomic symbol.
#define DEFAULT(x)
Inhibit C++ name-mangling for MXNet functions.
Definition: c_api.h:36
MXNET_DLL int MXSetProfilerState(int state)
Set up state of profiler.
MXNET_DLL int MXImperativeInvoke(AtomicSymbolCreator creator, int num_inputs, NDArrayHandle *inputs, int *num_outputs, NDArrayHandle **outputs, int num_params, const char **param_keys, const char **param_vals)
invoke a nnvm op and imperative function
MXNET_DLL int MXSymbolListAttr(SymbolHandle symbol, mx_uint *out_size, const char ***out)
Get all attributes from symbol, including all descendents.
MXNET_DLL int MXRtcCudaKernelFree(CudaKernelHandle handle)
MXNET_DLL int MXNDArrayAt(NDArrayHandle handle, mx_uint idx, NDArrayHandle *out)
Index the NDArray along axis 0.
MXNET_DLL int MXNDArrayGetAuxNDArray(NDArrayHandle handle, mx_uint i, NDArrayHandle *out)
Get a deep copy of the ith aux data blob in the form of an NDArray of default storage type...
MXNET_DLL int MXNDArrayLoad(const char *fname, mx_uint *out_size, NDArrayHandle **out_arr, mx_uint *out_name_size, const char ***out_names)
Load list of narray from the file.
MXNET_DLL int MXRtcCudaKernelCreate(CudaModuleHandle handle, const char *name, int num_args, int *is_ndarray, int *is_const, int *arg_types, CudaKernelHandle *out)
MXNET_DLL int MXNDArraySyncCopyFromCPU(NDArrayHandle handle, const void *data, size_t size)
Perform a synchronize copy from a continugous CPU memory region.
MXNET_DLL int MXSymbolCreateFromFile(const char *fname, SymbolHandle *out)
Load a symbol from a json file.
MXNET_DLL int MXKVStorePushEx(KVStoreHandle handle, mx_uint num, const char **keys, NDArrayHandle *vals, int priority)
Push a list of (key,value) pairs to kvstore, where each key is a string.
void( MXKVStoreStrUpdater)(const char *key, NDArrayHandle recv, NDArrayHandle local, void *handle)
user-defined updater for the kvstore with string keys It&#39;s this updater&#39;s responsibility to delete re...
Definition: c_api.h:1679
Definition: c_api.h:110
MXNET_DLL int MXNDArrayCreateSparseEx(int storage_type, const mx_uint *shape, mx_uint ndim, int dev_type, int dev_id, int delay_alloc, int dtype, mx_uint num_aux, int *aux_type, mx_uint *aux_ndims, const mx_uint *aux_shape, NDArrayHandle *out)
create an empty sparse NDArray with specified shape and data type
MXNET_DLL int MXExecutorSimpleBind(SymbolHandle symbol_handle, int dev_type, int dev_id, const mx_uint num_g2c_keys, const char **g2c_keys, const int *g2c_dev_types, const int *g2c_dev_ids, const mx_uint provided_grad_req_list_len, const char **provided_grad_req_names, const char **provided_grad_req_types, const mx_uint num_provided_arg_shapes, const char **provided_arg_shape_names, const mx_uint *provided_arg_shape_data, const mx_uint *provided_arg_shape_idx, const mx_uint num_provided_arg_dtypes, const char **provided_arg_dtype_names, const int *provided_arg_dtypes, const mx_uint num_provided_arg_stypes, const char **provided_arg_stype_names, const int *provided_arg_stypes, const mx_uint num_shared_arg_names, const char **shared_arg_name_list, int *shared_buffer_len, const char **shared_buffer_name_list, NDArrayHandle *shared_buffer_handle_list, const char ***updated_shared_buffer_name_list, NDArrayHandle **updated_shared_buffer_handle_list, mx_uint *num_in_args, NDArrayHandle **in_args, NDArrayHandle **arg_grads, mx_uint *num_aux_states, NDArrayHandle **aux_states, ExecutorHandle shared_exec_handle, ExecutorHandle *out)
void(* ExecutorMonitorCallback)(const char *, NDArrayHandle, void *)
Definition: c_api.h:92
void * p_forward
Definition: c_api.h:103
MXNET_DLL int MXNDArrayCreateEx(const mx_uint *shape, mx_uint ndim, int dev_type, int dev_id, int delay_alloc, int dtype, NDArrayHandle *out)
create a NDArray with specified shape and data type
void * p_list_arguments
Definition: c_api.h:107
MXNET_DLL int MXKVStoreCreate(const char *type, KVStoreHandle *out)
Create a kvstore.
int(* CustomOpDelFunc)(void *)
Definition: c_api.h:156
void * p_declare_backward_dependency
Definition: c_api.h:124
MXNET_DLL int MXNDArrayCreateNone(NDArrayHandle *out)
create a NDArray handle that is not initialized can be used to pass in as mutate variables to hold th...
MXNET_DLL int MXKVStoreFree(KVStoreHandle handle)
Delete a KVStore handle.
void * p_list_arguments
Definition: c_api.h:123
MXNET_DLL int MXCustomOpRegister(const char *op_type, CustomOpPropCreator creator)
MXNET_DLL int MXExecutorBackwardEx(ExecutorHandle handle, mx_uint len, NDArrayHandle *head_grads, int is_train)
Excecutor run backward.
void * SymbolHandle
handle to a symbol that can be bind as operator
Definition: c_api.h:72
void * CudaModuleHandle
handle to rtc cuda module
Definition: c_api.h:88
MXNET_DLL int MXSymbolCopy(SymbolHandle symbol, SymbolHandle *out)
Copy the symbol to another handle.
MXNET_DLL int MXGetVersion(int *out)
get the MXNet library version as an integer
int(** callbacks)(void)
Definition: c_api.h:131
void * CachedOpHandle
handle to cached operator
Definition: c_api.h:70
MXNET_DLL int MXSymbolSetAttr(SymbolHandle symbol, const char *key, const char *value)
Set string attribute from symbol. NOTE: Setting attribute to a symbol can affect the semantics(mutabl...
MXNET_DLL int MXSetNumOMPThreads(int thread_num)
Set the number of OMP threads to use.
MXNET_DLL int MXDataIterBeforeFirst(DataIterHandle handle)
Call iterator.Reset.
MXNET_DLL int MXSymbolInferShapePartial(SymbolHandle sym, mx_uint num_args, const char **keys, const mx_uint *arg_ind_ptr, const mx_uint *arg_shape_data, mx_uint *in_shape_size, const mx_uint **in_shape_ndim, const mx_uint ***in_shape_data, mx_uint *out_shape_size, const mx_uint **out_shape_ndim, const mx_uint ***out_shape_data, mx_uint *aux_shape_size, const mx_uint **aux_shape_ndim, const mx_uint ***aux_shape_data, int *complete)
partially infer shape of unknown input shapes given the known one.
MXNET_DLL int MXSymbolListOutputs(SymbolHandle symbol, mx_uint *out_size, const char ***out_str_array)
List returns in the symbol.
MXNET_DLL int MXListDataIters(mx_uint *out_size, DataIterCreator **out_array)
List all the available iterator entries.
MXNET_DLL int MXNDArrayGetShape(NDArrayHandle handle, mx_uint *out_dim, const mx_uint **out_pdata)
get the shape of the array
MXNET_DLL int MXDataIterGetPadNum(DataIterHandle handle, int *pad)
Get the padding number in current data batch.
MXNET_DLL int MXAutogradComputeGradient(mx_uint num_output, NDArrayHandle *output_handles)
compute the gradient of outputs w.r.t variabels
MXNET_DLL int MXFuncInvokeEx(FunctionHandle fun, NDArrayHandle *use_vars, mx_float *scalar_args, NDArrayHandle *mutate_vars, int num_params, char **param_keys, char **param_vals)
invoke a function, the array size of passed in arguments must match the values in the ...
MXNET_DLL int MXRtcCudaModuleCreate(const char *source, int num_options, const char **options, int num_exports, const char **exports, CudaModuleHandle *out)
int num_callbacks
Definition: c_api.h:130
MXNET_DLL int MXRandomSeed(int seed)
Seed the global random number generators in mxnet.
MXNET_DLL int MXSymbolGetOutput(SymbolHandle symbol, mx_uint index, SymbolHandle *out)
Get index-th outputs of the symbol.
MXNET_DLL int MXNDArrayGetDType(NDArrayHandle handle, int *out_dtype)
get the type of the data in NDArray
MXNET_DLL int MXAutogradIsTraining(bool *curr)
get whether training mode is on
MXNET_DLL int MXAutogradBackwardEx(mx_uint num_output, NDArrayHandle *output_handles, NDArrayHandle *ograd_handles, mx_uint num_variables, NDArrayHandle *var_handles, int retain_graph, int create_graph, int is_train, NDArrayHandle **grad_handles, int **grad_stypes)
compute the gradient of outputs w.r.t variabels
void(* forward)(int, float **, int *, unsigned **, int *, void *)
Definition: c_api.h:97
int(* MXGenericCallback)(void)
Definition: c_api.h:127
Definition: c_api.h:174
MXNET_DLL int MXSymbolGetInternals(SymbolHandle symbol, SymbolHandle *out)
Get a symbol that contains all the internals.
MXNET_DLL int MXNDArrayGetDataNDArray(NDArrayHandle handle, NDArrayHandle *out)
Get a deep copy of the data blob in the form of an NDArray of default storage type. This function blocks. Do not use it in performance critical code.
MXNET_DLL int MXInitPSEnv(mx_uint num_vars, const char **keys, const char **vals)
Initialized ps-lite environment variables.
MXNET_DLL int MXDataIterGetData(DataIterHandle handle, NDArrayHandle *out)
Get the handle to the NDArray of underlying data.
MXNET_DLL int MXRtcFree(RtcHandle handle)
Delete a MXRtc object.
MXNET_DLL int MXNDArraySyncCopyToCPU(NDArrayHandle handle, void *data, size_t size)
Perform a synchronize copyto a continugous CPU memory region.
MXNET_DLL int MXAutogradSetIsRecording(int is_recording, int *prev)
set whether to record operator for autograd
void( MXKVStoreServerController)(int head, const char *body, void *controller_handle)
the prototype of a server controller
Definition: c_api.h:1786
Definition: c_api.h:137
void * KVStoreHandle
handle to KVStore
Definition: c_api.h:82
MXNET_DLL int MXSetProfilerConfig(int mode, const char *filename)
Set up configuration of profiler.
void * NDArrayHandle
handle to NDArray
Definition: c_api.h:64
MXNET_DLL int MXNotifyShutdown()
Notify the engine about a shutdown, This can help engine to print less messages into display...
void * p_list_outputs
Definition: c_api.h:122
MXNET_DLL int MXDataIterGetIndex(DataIterHandle handle, uint64_t **out_index, uint64_t *out_size)
Get the image index by array.
MXNET_DLL int MXDataIterGetLabel(DataIterHandle handle, NDArrayHandle *out)
Get the handle to the NDArray of underlying label.
Definition: c_api.h:143
int(* CustomOpCreateFunc)(const char *, int, unsigned **, const int *, const int *, struct MXCallbackList *, void *)
Definition: c_api.h:164
int(* CustomOpFBFunc)(int, void **, int *, const int *, const int, void *)
Definition: c_api.h:153
MXNET_DLL int MXNDArraySyncCopyFromNDArray(NDArrayHandle handle_dst, const NDArrayHandle handle_src, const int i)
Copy src.data() to dst.data() if i = -1, else dst.aux_data(i) if i >= 0 This function blocks...
MXNET_DLL int MXSymbolCreateGroup(mx_uint num_symbols, SymbolHandle *symbols, SymbolHandle *out)
Create a Symbol by grouping list of symbols together.
MXNET_DLL int MXNDArrayCreate(const mx_uint *shape, mx_uint ndim, int dev_type, int dev_id, int delay_alloc, NDArrayHandle *out)
create a NDArray with specified shape
MXNET_DLL int MXKVStoreSetBarrierBeforeExit(KVStoreHandle handle, const int barrier_before_exit)
whether to do barrier when finalize
MXNET_DLL int MXFuncInvoke(FunctionHandle fun, NDArrayHandle *use_vars, mx_float *scalar_args, NDArrayHandle *mutate_vars)
invoke a function, the array size of passed in arguments must match the values in the ...
MXNET_DLL int MXSymbolListArguments(SymbolHandle symbol, mx_uint *out_size, const char ***out_str_array)
List arguments in the symbol.
MXNET_DLL int MXNDArrayGetStorageType(NDArrayHandle handle, int *out_storage_type)
get the storage type of the array
MXNET_DLL int MXRecordIOWriterCreate(const char *uri, RecordIOHandle *out)
Create a RecordIO writer object.
void * p_infer_shape
Definition: c_api.h:105
MXNET_DLL int MXKVStorePullRowSparseEx(KVStoreHandle handle, mx_uint num, const char **keys, NDArrayHandle *vals, const NDArrayHandle *row_ids, int priority)
pull a list of (key, value) pairs from the kvstore, where each key is a string. The NDArray pulled ba...
MXNET_DLL int MXNDArrayWaitAll()
wait until all delayed operations in the system is completed
MXNET_DLL int MXKVStorePullEx(KVStoreHandle handle, mx_uint num, const char **keys, NDArrayHandle *vals, int priority)
pull a list of (key, value) pairs from the kvstore, where each key is a string
MXNET_DLL int MXRecordIOReaderCreate(const char *uri, RecordIOHandle *out)
Create a RecordIO reader object.
MXNET_DLL int MXKVStoreGetNumDeadNode(KVStoreHandle handle, const int node_id, int *number, const int timeout_sec DEFAULT(60))
Get the number of ps dead node(s) specified by {node_id}.
unsigned int mx_uint
manually define unsigned int
Definition: c_api.h:57
Definition: c_api.h:138
MXNET_DLL int MXRecordIOWriterTell(RecordIOHandle handle, size_t *pos)
Get the current writer pointer position.
Definition: c_api.h:149
MXNET_DLL int MXRecordIOReaderTell(RecordIOHandle handle, size_t *pos)
Get the current writer pointer position.
MXNET_DLL int MXNDArraySaveRawBytes(NDArrayHandle handle, size_t *out_size, const char **out_buf)
save the NDArray into raw bytes.
MXNET_DLL int MXSymbolGetName(SymbolHandle symbol, const char **out, int *success)
Get string name from symbol.
void * p_backward
Definition: c_api.h:120
Definition: c_api.h:142
MXNET_DLL int MXExecutorBindEX(SymbolHandle symbol_handle, int dev_type, int dev_id, mx_uint num_map_keys, const char **map_keys, const int *map_dev_types, const int *map_dev_ids, mx_uint len, NDArrayHandle *in_args, NDArrayHandle *arg_grad_store, mx_uint *grad_req_type, mx_uint aux_states_len, NDArrayHandle *aux_states, ExecutorHandle shared_exec, ExecutorHandle *out)
Generate Executor from symbol, This is advanced function, allow specify group2ctx map...
MXNET_DLL int MXAutogradIsRecording(bool *curr)
get whether autograd recording is on
Definition: c_api.h:175
MXNET_DLL int MXRecordIOWriterFree(RecordIOHandle handle)
Delete a RecordIO writer object.
MXNET_DLL int MXExecutorBackward(ExecutorHandle handle, mx_uint len, NDArrayHandle *head_grads)
Excecutor run backward.
MXNET_DLL int MXKVStoreGetRank(KVStoreHandle handle, int *ret)
return The rank of this node in its group, which is in [0, GroupSize).
MXNET_DLL int MXCustomFunctionRecord(int num_inputs, NDArrayHandle *inputs, int num_outputs, NDArrayHandle *outputs, struct MXCallbackList *callbacks)
MXNET_DLL int MXKVStoreGetGroupSize(KVStoreHandle handle, int *ret)
return The number of nodes in this group, which is
MXNET_DLL int MXRecordIOWriterWriteRecord(RecordIOHandle handle, const char *buf, size_t size)
Write a record to a RecordIO object.
int(* CustomOpPropCreator)(const char *, const int, const char **, const char **, struct MXCallbackList *)
Definition: c_api.h:168
MXNET_DLL int MXSymbolCreateVariable(const char *name, SymbolHandle *out)
Create a Variable Symbol.
MXNET_DLL int MXExecutorSetMonitorCallback(ExecutorHandle handle, ExecutorMonitorCallback callback, void *callback_handle)
set a call back to notify the completion of operation
int(* CustomFunctionBwdFunc)(int, int, void **, const int *, const int, void *)
Definition: c_api.h:178
MXNET_DLL int MXAutogradBackward(mx_uint num_output, NDArrayHandle *output_handles, NDArrayHandle *ograd_handles, int retain_graph)
compute the gradient of outputs w.r.t variabels
void * CudaKernelHandle
handle to rtc cuda kernel
Definition: c_api.h:90
MXNET_DLL int MXKVStoreIsWorkerNode(int *ret)
return whether or not this process is a worker node.
MXNET_DLL int MXSymbolPrint(SymbolHandle symbol, const char **out_str)
Print the content of symbol, used for debug.
MXNET_DLL int MXSymbolCompose(SymbolHandle sym, const char *name, mx_uint num_args, const char **keys, SymbolHandle *args)
Compose the symbol on other symbols.
MXNET_DLL int MXSymbolGrad(SymbolHandle sym, mx_uint num_wrt, const char **wrt, SymbolHandle *out)
Get the gradient graph of the symbol.
float mx_float
manually define float
Definition: c_api.h:59
MXNET_DLL int MXCreateCachedOp(SymbolHandle handle, CachedOpHandle *out)
create cached operator
MXNET_DLL int MXRecordIOReaderSeek(RecordIOHandle handle, size_t pos)
Set the current reader pointer position.
#define MXNET_DLL
MXNET_DLL prefix for windows.
Definition: c_api.h:53
MXNET_DLL int MXSymbolCreateAtomicSymbol(AtomicSymbolCreator creator, mx_uint num_param, const char **keys, const char **vals, SymbolHandle *out)
Create an AtomicSymbol.
MXNET_DLL int MXNDArraySetGradState(NDArrayHandle handle, int state)
set the flag for gradient array state.
MXNET_DLL const char * MXGetLastError()
return str message of the last error all function in this file will return 0 when success and -1 when...
MXNET_DLL int MXNDArrayGetGradState(NDArrayHandle handle, int *out)
set the flag for gradient array state.
void ** contexts
Definition: c_api.h:132
void * AtomicSymbolCreator
handle to a function that takes param and creates symbol
Definition: c_api.h:68
MXNET_DLL int MXKVStoreInitEx(KVStoreHandle handle, mx_uint num, const char **keys, NDArrayHandle *vals)
Init a list of (key,value) pairs in kvstore, where each key is a string.
MXNET_DLL int MXAutogradGetSymbol(NDArrayHandle handle, SymbolHandle *out)
MXNET_DLL int MXExecutorBindX(SymbolHandle symbol_handle, int dev_type, int dev_id, mx_uint num_map_keys, const char **map_keys, const int *map_dev_types, const int *map_dev_ids, mx_uint len, NDArrayHandle *in_args, NDArrayHandle *arg_grad_store, mx_uint *grad_req_type, mx_uint aux_states_len, NDArrayHandle *aux_states, ExecutorHandle *out)
Generate Executor from symbol, This is advanced function, allow specify group2ctx map...
void(* infer_shape)(int, int *, unsigned **, void *)
Definition: c_api.h:99
void * p_list_outputs
Definition: c_api.h:106
MXNET_DLL int MXNDArraySave(const char *fname, mx_uint num_args, NDArrayHandle *args, const char **keys)
Save list of narray into the file.
MXNET_DLL int MXNDArrayLoadFromRawBytes(const void *buf, size_t size, NDArrayHandle *out)
create a NDArray handle that is loaded from raw bytes.
MXNET_DLL int MXRtcPush(RtcHandle handle, mx_uint num_input, mx_uint num_output, NDArrayHandle *inputs, NDArrayHandle *outputs, mx_uint gridDimX, mx_uint gridDimY, mx_uint gridDimZ, mx_uint blockDimX, mx_uint blockDimY, mx_uint blockDimZ)
Run cuda kernel.
void( MXKVStoreUpdater)(int key, NDArrayHandle recv, NDArrayHandle local, void *handle)
user-defined updater for the kvstore It&#39;s this updater&#39;s responsibility to delete recv and local ...
Definition: c_api.h:1667
MXNET_DLL int MXSymbolListAuxiliaryStates(SymbolHandle symbol, mx_uint *out_size, const char ***out_str_array)
List auxiliary states in the symbol.
MXNET_DLL int MXGetFunction(const char *name, FunctionHandle *out)
get the function handle by name
MXNET_DLL int MXSymbolListAttrShallow(SymbolHandle symbol, mx_uint *out_size, const char ***out)
Get all attributes from symbol, excluding descendents.
void * DataIterCreator
handle a dataiter creator
Definition: c_api.h:78
MXNET_DLL int MXDataIterGetIterInfo(DataIterCreator creator, const char **name, const char **description, mx_uint *num_args, const char ***arg_names, const char ***arg_type_infos, const char ***arg_descriptions)
Get the detailed information about data iterator.
MXNET_DLL int MXKVStoreGetType(KVStoreHandle handle, const char **type)
get the type of the kvstore
void * RtcHandle
handle to MXRtc
Definition: c_api.h:86
MXNET_DLL int MXNDArrayGetGrad(NDArrayHandle handle, NDArrayHandle *out)
return gradient buffer attached to this NDArray
int(* CustomOpBwdDepFunc)(const int *, const int *, const int *, int *, int **, void *)
Definition: c_api.h:161
MXNET_DLL int MXSymbolInferType(SymbolHandle sym, mx_uint num_args, const char **keys, const int *arg_type_data, mx_uint *in_type_size, const int **in_type_data, mx_uint *out_type_size, const int **out_type_data, mx_uint *aux_type_size, const int **aux_type_data, int *complete)
infer type of unknown input types given the known one. The types are packed into a CSR matrix represe...
Definition: c_api.h:144
MXNET_DLL int MXKVStoreInit(KVStoreHandle handle, mx_uint num, const int *keys, NDArrayHandle *vals)
Init a list of (key,value) pairs in kvstore.
void(* backward)(int, float **, int *, unsigned **, int *, void *)
Definition: c_api.h:98
MXNET_DLL int MXDumpProfile()
Save profile and stop profiler.
Definition: c_api.h:129
MXNET_DLL int MXImperativeInvokeEx(AtomicSymbolCreator creator, int num_inputs, NDArrayHandle *inputs, int *num_outputs, NDArrayHandle **outputs, int num_params, const char **param_keys, const char **param_vals, const int **out_stypes)
invoke a nnvm op and imperative function
MXNET_DLL int MXRtcCudaModuleFree(CudaModuleHandle handle)
const void * FunctionHandle
handle to a mxnet narray function that changes NDArray
Definition: c_api.h:66
Definition: c_api.h:96
MXNET_DLL int MXRecordIOReaderReadRecord(RecordIOHandle handle, char const **buf, size_t *size)
Write a record to a RecordIO object.
MXNET_DLL int MXKVStorePush(KVStoreHandle handle, mx_uint num, const int *keys, NDArrayHandle *vals, int priority)
Push a list of (key,value) pairs to kvstore.
MXNET_DLL int MXListFunctions(mx_uint *out_size, FunctionHandle **out_array)
list all the available functions handles most user can use it to list all the needed functions ...
void(* list_outputs)(char ***, void *)
Definition: c_api.h:100
Definition: c_api.h:145
Definition: c_api.h:148
MXNET_DLL int MXRtcCudaKernelCall(CudaKernelHandle handle, int dev_id, void **args, mx_uint grid_dim_x, mx_uint grid_dim_y, mx_uint grid_dim_z, mx_uint block_dim_x, mx_uint block_dim_y, mx_uint block_dim_z, mx_uint shared_mem)
int(* CustomOpInferShapeFunc)(int, int *, unsigned **, void *)
Definition: c_api.h:158
MXNET_DLL int MXSymbolFree(SymbolHandle symbol)
Free the symbol handle.
MXNET_DLL int MXExecutorFree(ExecutorHandle handle)
Delete the executor.
MXNET_DLL int MXNDArrayWaitToWrite(NDArrayHandle handle)
Wait until all the pending read/write with respect NDArray are finished. Always call this before writ...
int(* CustomOpListFunc)(char ***, void *)
Definition: c_api.h:157
MXNET_DLL int MXExecutorForward(ExecutorHandle handle, int is_train)
Executor forward method.
MXNET_DLL int MXNDArrayGetData(NDArrayHandle handle, void **out_pdata)
get the content of the data in NDArray