Skip to main content

M_initModel

Function M_initModel 

Source
pub unsafe extern "C" fn M_initModel(
    context: *const M_RuntimeContext,
    compiledModel: *const M_AsyncCompiledModel,
    weightsRegistry: *const M_WeightsRegistry,
    status: *mut M_Status,
) -> *mut M_AsyncModel
Expand description

Sets up a model for execution.

You can call this immediately after M_compileModel()—you don’t need to wait for the async compilation.

This function also returns immediately with model initialization happening asynchronously. For example:

M_AsyncModel *model = M_initModel(
  context, compiledModel, weightsRegistry, status);
if (M_isError(status)) {
  logError(M_getError(status));
  return EXIT_FAILURE;
}

If you want to block until M_AsyncModel is initialized, you can call M_waitForModel(), but that’s not necessary and you can immediately call M_executeModelSync().

@param context The runtime context, from M_newRuntimeContext(). @param compiledModel The compiled model, from M_compileModel(). @param weightsRegistry A mapping from weights’ names to their data. The weights registry is used to update weights or otherwise pass weights to the model init block at runtime, without recompiling the model graph. If the model doesn’t use the weights registry, it is safe to pass as NULL @param status The status used to report errors in the case of failures. The status contains an error only if the given context or compiled model is invalid. Other errors will not surface until the next synchronization point.

@returns A pointer to an M_AsyncModel that holds an async value to a compiled model. You are responsible for the memory associated with the pointer returned. You can deallocate the memory by calling M_freeModel(). If model initialization fails, the status parameter contains an error message.