Skip to main content

M_newRuntimeContext

Function M_newRuntimeContext 

Source
pub unsafe extern "C" fn M_newRuntimeContext(
    config: *const M_RuntimeConfig,
    status: *mut M_Status,
) -> *mut M_RuntimeContext
Expand description

Creates a runtime context.

The context is an application-level object that sets up various resources such as threadpool and allocators during inference. You need this before you can call M_compileModel().

It’s expected that there’s only one runtime context active in an inference session at a time. We recommended you create one context and use it throughout your application.

For example:

M_Status *status = M_newStatus();
M_RuntimeConfig *runtimeConfig = M_newRuntimeConfig();
M_RuntimeContext *context = M_newRuntimeContext(runtimeConfig, status);
if (M_isError(status)) {
  logError(M_getError(status));
  return EXIT_FAILURE;
}

@param config The runtime config, from M_newRuntimeConfig(). @param status The status object for reporting errors. It is filled with an error message if construction of the runtime context fails.

@returns A pointer to the runtime context object. On success, this is a valid pointer. On failure, this is a NULL pointer with an error message in the status. You are responsible for the memory associated with the pointer returned. You can deallocate the memory by calling M_freeRuntimeContext().