Common

Preview 0.4.0

This is a preview of the Modular AI Engine. It is not publicly available yet and APIs are subject to change.

If you’re interested, please sign up for early access.

#include "modular/c/common.h"

Functions

const char *M_version()

Gets the AI Engine version.

Returns:

A string containing the semantic version of the AI Engine.

M_Status *M_newStatus()

Creates a new status object.

This is required as an argument for several functions, such as M_newRuntimeContext() and M_compileModel(). They will update the status object and you can check for errors with M_isError() and get the status message with M_getError(). 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;
}

Returns:

A pointer to the new status object. You are responsible for the memory associated with the pointer returned. You can deallocate the memory by calling M_freeStatus().

const char *M_getError(const M_Status *status)

Gets an error message from the M_Status parameter.

You should call this only if M_isError() is true.

Parameters:

status – The status object for reporting errors and other messages.

Returns:

A pointer to a null-terminated string containing the error message.

int M_isError(const M_Status *status)

Checks if status holds an error value.

Parameters:

status – The status object for reporting errors and other messages.

Returns:

0 if there is no error, 1 otherwise.

void M_freeStatus(M_Status *status)

Deallocates the memory for the status object. No-op if status is NULL.

Parameters:

status – The status object for reporting errors and other messages.

size_t M_sizeOf(M_Dtype type)

Gets the size (in bytes) of a data type.

Parameters:

type – The data type.

Returns:

Size in bytes of the given data type. If the data type is M_UNKNOWN, then 0.