C API
You can use the following C APIs to run inference with MAX Engine.
API headers
Each of the following pages represents one of the C API header files:
-
M_newCompileConfig()M_cloneCompileConfig()M_setModelPath()M_newModelSource()M_setModelSource()M_compileModel()M_waitForCompilation()M_compileModelSync()M_initModel()M_getInputNames()M_getOutputNames()M_getTensorNameAt()M_getModelInputSpecByName()M_getModelOutputSpecByName()M_waitForModel()M_executeModelSync()M_getNumModelInputs()M_getNumModelOutputs()M_freeModel()M_freeCompiledModel()M_freeCompileConfig()M_freeModelSource()M_exportCompiledModel()
-
M_newTensorSpec()M_isDynamicRanked()M_getDimAt()M_getRank()M_getDtype()M_getName()M_newAsyncTensorMap()M_borrowTensorInto()M_createBorrowedTensor()M_getTensorByNameFrom()M_getTensorFromValue()M_getTensorNumElements()M_getTensorType()M_getTensorData()M_getTensorSpec()M_freeTensor()M_freeTensorNameArray()M_freeTensorSpec()M_freeAsyncTensorMap()
-
-
M_UNKNOWNmIsIntegermIsFloatmIsComplexmIsSignedkIntWidthShiftM_INT1M_UINT1M_INT2M_UINT2M_INT4M_UINT4M_INT8M_UINT8M_INT16M_UINT16M_INT32M_UINT32M_INT64M_UINT64M_INT128M_UINT128M_FLOAT4_E2M1FNM_FLOAT8_E3M4M_FLOAT8_E4M3FNM_FLOAT8_E4M3FNUZM_FLOAT8_E5M2M_FLOAT8_E5M2FNUZM_FLOAT16M_BFLOAT16M_FLOAT32M_FLOAT64M_BOOL
Async API usage
Our C API allows for compiling and executing models asynchronously. In general, effective use of asynchronous APIs may be difficult, but rewarding for performance. To help with this, we’re going to explain some important concepts and mental models to keep in mind with the API.
Our APIs are async-safe unless stated otherwise, typically with a Sync in the
function identifier name. For example, we have M_executeModel and
M_executeModelSync().
Types
Our API describes the underlying async-holding types with a “value or error” concept. Conceptually, this means that the type is in one of three states:
Constructed- the value is not yet there, but there is no errorAvailable- the value is there and ready for useError- the value is not there and there is an error
Synchronization points
When using async APIs, it is a good idea to be mindful of the synchronization
point APIs currently provided below. This is useful for discerning between the
Constructed and Available states mentioned above. After calling the
synchronization point, the input will never be in a Constructed state: it will
always resolve to either being Available or Error.
M_waitForCompilation()M_waitForModel()M_waitForTensors
Errors
Errors surface immediately when using our synchronous APIs. Otherwise, in the
case of async APIs, errors will not surface until the next synchronization
point. You can query the error message by calling M_getError().
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!