Skip to main content

M_compileModel

Function M_compileModel 

Source
pub unsafe extern "C" fn M_compileModel(
    context: *const M_RuntimeContext,
    compileConfig: *mut *mut M_CompileConfig,
    status: *mut M_Status,
) -> *mut M_AsyncCompiledModel
Expand description

Compiles a model.

This immediately returns an M_AsyncCompiledModel, with compilation happening asynchronously. If you need to block to await compilation, you can then call M_waitForCompilation().

You must call M_setModelPath() before you call this. For example:

M_CompileConfig *compileConfig = M_newCompileConfig();
M_setModelPath(compileConfig, modelPath);
M_AsyncCompiledModel *compiledModel =
    M_compileModel(context, &compileConfig, status);
if (M_isError(status)) {
  logError(M_getError(status));
  return EXIT_FAILURE;
}

The M_AsyncCompiledModel returned here is not ready for inference yet. You need to then initialize the model with M_initModel().

@param context The runtime context, from M_newRuntimeContext(). @param compileConfig Address of compilation configuration for your model created with M_newCompileConfig(), and with the model set via M_setModelPath(). Ownership of configuration is handed over to API. @param status The status used to report errors in the case of failures during model compilation.

@returns A pointer to an M_AsyncCompiledModel. You are responsible for the memory associated with the pointer returned. You can deallocate the memory by calling M_freeCompiledModel(). If the config is invalid, it returns a NULL pointer. If the model compilation fails, the pointer is NULL and the status parameter contains an error message. compileConfig will be reset to NULL after this call irrespective of status and cannot be reused, and any subsequent calls must take a new M_CompileConfig.