mxnet
c_runtime_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 
20 /*
21  * \file c_runtime_api.h
22  * \brief MXNet runtime library.
23  */
24 // Acknowledgement: This file originates from incubator-tvm
25 #ifndef MXNET_RUNTIME_C_RUNTIME_API_H_
26 #define MXNET_RUNTIME_C_RUNTIME_API_H_
27 
28 #include <dlpack/dlpack.h>
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 #include <mxnet/c_api.h>
34 #include <stdint.h>
35 #include <stddef.h>
36 
41 typedef enum {
42  // The type code of other types are compatible with DLPack.
43  // The next few fields are extension types
44  // that is used by MXNet API calls.
45  kHandle = 3U,
46  kNull = 4U,
47  kMXNetType = 5U,
50  kStr = 8U,
51  kBytes = 9U,
52  kPyArg = 10U,
54  // Extension codes for other frameworks to integrate MXNet PackedFunc.
55  // To make sure each framework's id do not conflict, use first and
56  // last sections to mark ranges.
57  // Open an issue at the repo if you need a section of code.
58  kExtBegin = 15U,
59  kNNVMFirst = 16U,
60  kNNVMLast = 20U,
61  // The following section of code is used for non-reserved types.
63  kExtEnd = 128U,
64  // The rest of the space is used for custom, user-supplied datatypes
65  kCustomBegin = 129U,
67 
72 typedef union {
73  int64_t v_int64;
74  double v_float64;
75  void* v_handle;
76  const char* v_str;
77  uint64_t v_uint64;
79 } MXNetValue;
80 
85 typedef struct {
86  const char* data;
87  size_t size;
89 
91 typedef void* MXNetFunctionHandle;
93 typedef void* MXNetObjectHandle;
94 
101 
123  MXNetValue* arg_values,
124  int* type_codes,
125  int num_args,
126  MXNetValue* ret_val,
127  int* ret_type_code);
128 
138 MXNET_DLL int MXNetFuncGetGlobal(const char* name, MXNetFunctionHandle* out);
139 
146 MXNET_DLL int MXNetFuncListGlobalNames(int* out_size, const char*** out_array);
147 
157 
165 MXNET_DLL int MXNetObjectGetTypeIndex(MXNetObjectHandle obj, unsigned* out_tindex);
166 
173 MXNET_DLL int MXNetObjectTypeKey2Index(const char* type_key, unsigned* out_tindex);
174 
175 #ifdef __cplusplus
176 } // extern "C"
177 #endif
178 #endif // MXNET_RUNTIME_C_RUNTIME_API_H_
DLDataType
The data type the tensor can hold.
Definition: dlpack.h:94
MXNetValue
Union type of values being passed through API and function calls.
Definition: c_runtime_api.h:72
kExtEnd
@ kExtEnd
Definition: c_runtime_api.h:63
MXNetObjectHandle
void * MXNetObjectHandle
Handle to Object.
Definition: c_runtime_api.h:93
MXNetValue::v_handle
void * v_handle
Definition: c_runtime_api.h:75
MXNetObjectFree
MXNET_DLL int MXNetObjectFree(MXNetObjectHandle obj)
Free the object.
kStr
@ kStr
Definition: c_runtime_api.h:50
MXNetByteArray::size
size_t size
Definition: c_runtime_api.h:87
kExtReserveEnd
@ kExtReserveEnd
Definition: c_runtime_api.h:62
kNDArrayHandle
@ kNDArrayHandle
Definition: c_runtime_api.h:53
kCustomBegin
@ kCustomBegin
Definition: c_runtime_api.h:65
MXNetValue::v_str
const char * v_str
Definition: c_runtime_api.h:76
MXNetFuncGetGlobal
MXNET_DLL int MXNetFuncGetGlobal(const char *name, MXNetFunctionHandle *out)
Get a global function.
kExtBegin
@ kExtBegin
Definition: c_runtime_api.h:58
kNull
@ kNull
Definition: c_runtime_api.h:46
MXNetByteArray::data
const char * data
Definition: c_runtime_api.h:86
MXNetTypeCode
MXNetTypeCode
The type code in MXNetType.
Definition: c_runtime_api.h:41
kObjectHandle
@ kObjectHandle
Definition: c_runtime_api.h:49
MXNetValue::v_float64
double v_float64
Definition: c_runtime_api.h:74
kMXNetType
@ kMXNetType
Definition: c_runtime_api.h:47
c_api.h
C API of mxnet.
MXNET_DLL
#define MXNET_DLL
MXNET_DLL prefix for windows.
Definition: c_api.h:53
MXNetValue::v_type
DLDataType v_type
Definition: c_runtime_api.h:78
MXNetFuncFree
MXNET_DLL int MXNetFuncFree(MXNetFunctionHandle func)
Free the function when it is no longer needed.
MXNetFuncListGlobalNames
MXNET_DLL int MXNetFuncListGlobalNames(int *out_size, const char ***out_array)
List all the globally registered function name.
kHandle
@ kHandle
Definition: c_runtime_api.h:45
kPyArg
@ kPyArg
Definition: c_runtime_api.h:52
MXNetFunctionHandle
void * MXNetFunctionHandle
Handle to packed function handle.
Definition: c_runtime_api.h:91
MXNetObjectTypeKey2Index
MXNET_DLL int MXNetObjectTypeKey2Index(const char *type_key, unsigned *out_tindex)
Convert type key to type index.
kMXNetContext
@ kMXNetContext
Definition: c_runtime_api.h:48
MXNetObjectGetTypeIndex
MXNET_DLL int MXNetObjectGetTypeIndex(MXNetObjectHandle obj, unsigned *out_tindex)
Get the type_index from an object.
kNNVMFirst
@ kNNVMFirst
Definition: c_runtime_api.h:59
MXNetFuncCall
MXNET_DLL int MXNetFuncCall(MXNetFunctionHandle func, MXNetValue *arg_values, int *type_codes, int num_args, MXNetValue *ret_val, int *ret_type_code)
Call a Packed MXNet Function.
kNNVMLast
@ kNNVMLast
Definition: c_runtime_api.h:60
kBytes
@ kBytes
Definition: c_runtime_api.h:51
dlpack.h
The common header of DLPack.
MXNetValue::v_uint64
uint64_t v_uint64
Definition: c_runtime_api.h:77
MXNetValue::v_int64
int64_t v_int64
Definition: c_runtime_api.h:73
MXNetByteArray
Byte array type used to pass in byte array When kBytes is used as data type.
Definition: c_runtime_api.h:85