Accelerator API (C++)#

class MxAccl : public MX::Runtime::MxAcclBase#

Public Functions

inline MxAccl(const std::filesystem::path &dfp_path, std::vector<int> device_ids_to_use = {0}, std::array<bool, 2> use_model_shape = {true, true}, bool local_mode = false, SchedulerOptions sched_options = SchedulerOptions(), ClientOptions client_options = ClientOptions(), std::string server_addr = "/run/mxa_manager/", unsigned int server_port_base = 10000, bool ignore_server_ = false)#

All-in-one constructor that initializes the MxAccl object, loads the provided DFP, and applies runtime configuration options.

This constructor streamlines the setup of a MemryX accelerator instance by combining DFP loading, device selection, scheduler setup, and client/server configuration into a single step.

Warning

Setting ignore_server_ to true disables coordination with other processes and may result in device conflicts if multiple clients or containers access the same device concurrently. Use with caution.

Parameters:
  • dfp_path – Path to the compiled DFP (Dataflow Program) file. Accepts std::filesystem::path, const char*, or std::string.

  • device_ids_to_use – List of MXA device IDs to use for execution. Specify {-1} to indicate that all available devices should be used. Default is {0}.

  • use_model_shape – A pair of boolean flags {input, output} indicating whether to preserve the original model input/output shapes (true), or to use the shape as interpreted by the MXA runtime (false). Default is {true, true}.

  • local_mode – If set to true, the DFP runs in local (non-shared) mode. This mode may improve performance for single-process applications but does not support multi-process or multi-DFP usage. Default is false.

  • sched_options – Runtime scheduler configuration used when operating in shared mode. See MX::RPC::SchedulerOptions for detailed field descriptions.

  • client_options – Client-specific execution options such as FPS smoothing and target frame rate. See MX::RPC::ClientOptions for detailed field descriptions.

  • server_addr – Server address or UNIX socket file path for manager communication. On Linux, the default is "/run/mxa_manager/" (UNIX socket). On Windows or remote setups, use an IP address (e.g., "localhost").

  • server_port_base – Base port number used for socket or IP-based communication. Applies to both socket filenames and IP addresses. Default is 10000.

  • ignore_server_ – (Advanced) If set to true, the MxAccl instance will ignore the manager server and operate in local mode only.

inline MxAccl(uint8_t *dfp_bytes, size_t dfp_byte_size, std::vector<int> device_ids_to_use = {0}, std::array<bool, 2> use_model_shape = {true, true}, bool local_mode = false, SchedulerOptions sched_options = SchedulerOptions(), ClientOptions client_options = ClientOptions(), std::string server_addr = "/run/mxa_manager/", unsigned int server_port_base = 10000, bool ignore_server_ = false)#

All-in-one constructor that initializes the MxAccl object, loads the provided DFP, and applies runtime configuration options.

This constructor streamlines the setup of a MemryX accelerator instance by combining DFP loading, device selection, scheduler setup, and client/server configuration into a single step.

Warning

Setting ignore_server_ to true disables coordination with other processes and may result in device conflicts if multiple clients or containers access the same device concurrently. Use with caution.

Parameters:
  • dfp_bytes – Raw uint8_t* pointer to memory containing the already-loaded DFP file data.

  • dfp_byte_size – Size of the DFP data in bytes.

  • device_ids_to_use – List of MXA device IDs to use for execution. Specify {-1} to indicate that all available devices should be used. Default is {0}.

  • use_model_shape – A pair of boolean flags {input, output} indicating whether to preserve the original model input/output shapes (true), or to use the shape as interpreted by the MXA runtime (false). Default is {true, true}.

  • local_mode – If set to true, the DFP runs in local (non-shared) mode. This mode may improve performance for single-process applications but does not support multi-process or multi-DFP usage. Default is false.

  • sched_options – Runtime scheduler configuration used when operating in shared mode. See MX::RPC::SchedulerOptions for detailed field descriptions.

  • client_options – Client-specific execution options such as FPS smoothing and target frame rate. See MX::RPC::ClientOptions for detailed field descriptions.

  • server_addr – Server address or UNIX socket file path for manager communication. On Linux, the default is "/run/mxa_manager/" (UNIX socket). On Windows or remote setups, use an IP address (e.g., "localhost").

  • server_port_base – Base port number used for socket or IP-based communication. Applies to both socket filenames and IP addresses. Default is 10000.

  • ignore_server_ – (Advanced) If set to true, the MxAccl instance will ignore the manager server and operate in local mode only.

void connect_stream(in_callback_t in_cb, out_callback_t out_cb, int stream_id, int model_id = 0)#

Connects a stream to a model using the specified input and output callback functions.

This method registers a data stream for the given model and binds it to both input and output callback functions. Streams are uniquely identified using stream_id. This function must be called before start().

  • in_callback_t is a function pointer type with the following signature: bool in_callback(std::vector<const MX::Types::FeatureMap*>, int stream_id);

  • out_callback_t is a function pointer type with the following signature: void out_callback(std::vector<const MX::Types::FeatureMap*>, int stream_id);

  • FeatureMap pointers (FeatureMap*) passed to out_cb are valid only during the callback. To use them later or outside the callback, copy the data with get_data() before returning.

  • If the input callback (in_cb) returns false, the corresponding stream is stopped. When all registered streams have stopped, wait() is invoked automatically.

Parameters:
  • in_cb – Input callback function that supplies data to the model. Must match in_callback_t signature.

  • out_cb – Output callback function invoked with the model’s output feature maps. Must match out_callback_t signature.

  • stream_id – Unique identifier for this stream. It is passed to the callback functions to distinguish streams.

  • model_id – Index of the model to which this stream is connected. Default is 0.

void start(int model_id = -1)#

Starts execution for the specified model or models.

This function initiates processing for the given model ID. All streams associated with the model must be connected beforehand via connect_stream(). Use -1 to indicate that all available DFPs and models should be started.

Parameters:

model_id – Index of the model to start. Use -1 to start all models. Default is -1.

Pre:

connect_stream() must be called before this method.

void wait(int model_id = -1)#

Blocks until all streams for the specified model(s) have completed execution.

This function waits until all active input callbacks for the given model have returned false, indicating the end of their respective streams. It should only be called after start() has been invoked for the target model(s).

Use -1 to wait for all models and DFPs currently in execution.

Parameters:

model_id – Index of the model to wait on. Use -1 to wait on all active models. Default is -1.

void set_num_workers(int input_num_workers, int output_num_workers, int model_id = 0)#

Configures the number of worker threads for input and output streams for a given model.

By default, the number of input and output workers is equal to the number of connected streams, which typically yields maximum performance. This method allows overriding that behavior to fine-tune parallelism.

This method should be called after all required streams have been connected, and before start() is invoked. If not explicitly set, the accelerator will operate using default worker counts.

Parameters:
  • input_num_workers – Number of worker threads to assign for input processing.

  • output_num_workers – Number of worker threads to assign for output processing.

  • model_id – Index of the model to apply the worker configuration to. Default is 0.

Pre:

connect_stream() must be called before this method

int get_num_streams(int model_id = 0)#

Returns the number of streams currently connected to the specified model.

This method can be used to query how many streams have been registered for a given model using connect_stream(). It is useful for debugging, monitoring, or configuring worker allocation.

Parameters:

model_id – Index of the model to query. Default is 0.

Returns:

int Number of streams connected to the specified model.

bool all_tasks_done(int model_id) const#

Returns true if all streams for this model are done.

class MxAcclMT : public MX::Runtime::MxAcclBase#

Public Functions

inline MxAcclMT(const std::filesystem::path &dfp_path, std::vector<int> device_ids_to_use = {0}, std::array<bool, 2> use_model_shape = {true, true}, bool local_mode = false, SchedulerOptions sched_options = SchedulerOptions(), ClientOptions client_options = ClientOptions(), std::string server_addr = "/run/mxa_manager/", unsigned int server_port_base = 10000, bool ignore_server_ = false)#

All-in-one constructor that initializes the MxAcclMT object in manual threading mode, connects the provided DFP, and applies runtime configuration options.

This constructor sets up the accelerator by loading the specified DFP, configuring device assignments, scheduling behavior, and communication options. It builds on the functionality of the base class MxAcclBase.

Warning

Setting ignore_server_ to true disables coordination with other processes and may result in device conflicts if multiple clients or containers access the same device concurrently. Use with caution.

Parameters:
  • dfp_path – Path to the compiled DFP (Dataflow Program) file. Accepts std::filesystem::path, const char*, or std::string.

  • device_ids_to_use – List of MXA device IDs to use for execution. Specify {-1} to indicate that all available devices should be used. Default is {0}.

  • use_model_shape – A pair of boolean flags {input, output} indicating whether to preserve the original model input/output shapes (true) or use the shape interpreted by the MXA runtime (false). Default is {true, true}.

  • local_mode – If true, the DFP will be executed in local (non-shared) mode. This may offer better performance in single-process environments, but it disables multi-process and multi-DFP coordination. Default is false.

  • sched_options – Scheduler options used during shared execution mode. Configures frame limits, timeouts, and queue sizes. Default is {frame_limit = 20, timeout = 250, input_queue_size = 16, output_queue_size = 21}. See MX::RPC::SchedulerOptions for detailed field descriptions.

  • client_options – Client-side behavior options such as FPS smoothing and throttling. Default is {smoothing = false, fps_target = 0}. See MX::RPC::ClientOptions for detailed field descriptions.

  • server_addr – Address of the manager server. On Linux, this is typically a UNIX socket path (e.g., "/run/mxa_manager/"). On Windows or remote setups, this should be an IP address such as "localhost".

  • server_port_base – Base port number used by the manager server for communication. Applies to both socket filenames and IP-based addressing. Default is 10000.

  • ignore_server_ – (Advanced) If set to true, the object will bypass the manager server and run the DFP in local mode.

inline MxAcclMT(uint8_t *dfp_bytes, size_t dfp_byte_size, std::vector<int> device_ids_to_use = {0}, std::array<bool, 2> use_model_shape = {true, true}, bool local_mode = false, SchedulerOptions sched_options = SchedulerOptions(), ClientOptions client_options = ClientOptions(), std::string server_addr = "/run/mxa_manager/", unsigned int server_port_base = 10000, bool ignore_server_ = false)#

All-in-one constructor that initializes the MxAcclMT object in manual threading mode, connects the provided DFP from a raw byte array, and applies runtime configuration options.

This constructor is intended for cases where the DFP (Dataflow Program) is already loaded in memory and represented as a raw byte buffer. It sets up the accelerator by configuring device usage, scheduling options, and client/server communication in a single step.

Warning

Setting ignore_server_ to true disables coordination with other processes and may result in device conflicts if multiple clients or containers access the same device concurrently. Use with caution.

Warning

The memory pointed to by dfp_bytes must remain valid throughout object construction. Passing a dangling or temporary buffer may lead to undefined behavior.

Parameters:
  • dfp_bytes – Pointer to the raw, in-memory representation of the compiled DFP (uint8_t*). This buffer must remain valid and accessible throughout the initialization phase.

  • dfp_byte_size – Size of the DFP data in bytes.

  • device_ids_to_use – List of MXA device IDs to use for execution. Specify {-1} to indicate that all available devices should be used. Default is {0}.

  • use_model_shape – A pair of boolean flags {input, output} indicating whether to preserve the original model input/output shapes (true) or use the shape interpreted by the MXA runtime (false). Default is {true, true}.

  • local_mode – If true, the DFP will be executed in local (non-shared) mode. This may offer better performance in single-process environments but disables multi-process and multi-DFP coordination. Default is false.

  • sched_options – Scheduler options used during shared execution mode. Configures frame limits, timeouts, and queue sizes. Default is {frame_limit = 20, timeout = 250, input_queue_size = 16, output_queue_size = 21}. See MX::RPC::SchedulerOptions for detailed field descriptions.

  • client_options – Client-side behavior options such as FPS smoothing and throttling. Default is {smoothing = false, fps_target = 0}. See MX::RPC::ClientOptions for detailed field descriptions.

  • server_addr – Address of the manager server. On Linux, this is typically a UNIX socket path (e.g., "/run/mxa_manager/"). On Windows or remote setups, this should be an IP address such as "localhost".

  • server_port_base – Base port number used by the manager server for communication. Applies to both socket filenames and IP-based addressing. Default is 10000.

  • ignore_server_ – (Advanced) If set to true, the object will bypass the manager server and run the DFP in local mode. Default is false.

bool send_input(std::vector<float*> in_data, int stream_id, int model_id = 0, int32_t timeout = 0)#

Sends input data to the accelerator in user-threaded (Manual Threading) mode.

This method submits input data to a specific model and stream instance using user-managed threading. It optionally waits for buffer availability based on the provided timeout.

Parameters:
  • in_data – A vector of pointers to input data buffers. Each float* corresponds to a model input port.

  • stream_id – Index of the stream associated with this input. This must match the stream ID used during stream setup.

  • model_id – Index of the model the input data is targeted to. Default is 0.

  • timeout – Maximum time to wait (in milliseconds) for the input to be accepted. A value of 0 indicates that the call will block indefinitely until space is available. Default is 0.

Returns:

Returns true if the input was accepted and inference started successfully. Returns false if the operation timed out before data could be submitted.

bool receive_output(std::vector<float*> &out_data, int stream_id, int model_id = 0, int32_t timeout = 0)#

Receives output data from the accelerator in user-threaded (manual threading) mode.

This method retrieves output feature maps from the accelerator for a given model and stream. It is intended for use in MxAcclMT mode, where the user manages threading and stream lifecycle manually. The call will block until output is available or the specified timeout is reached.

Parameters:
  • out_data – A vector of pointers where the output data will be written. Each float* must point to a preallocated buffer matching the size of the corresponding model output.

  • stream_id – Index of the stream associated with this output. It can be any user-defined stream ID that the application uses to manage context.

  • model_id – Index of the model the input data is targeted to. Default is 0.

  • timeout – Maximum time to wait (in milliseconds) for output data to become available. A value of 0 indicates that the call will block indefinitely until data is ready. Default is 0.

Returns:

Returns true if output was successfully received. Returns false if the operation timed out before data was available.

bool run(std::vector<float*> in_data, std::vector<float*> &out_data, int stream_id, int model_id = 0, int32_t timeout = 0)#

Runs inference on a batch of inputs in user-threaded (manual threading) mode.

This method sends input data to the accelerator and waits for the corresponding outputs in a single call. It is designed for use in MxAcclMT mode, where the user manages threading and stream assignment manually. The call blocks until inference completes or the specified timeout expires.

Note

This method combines send_input() and receive_output() into one operation yet send and receive to the accelerator is performed asynchronously internally.

Parameters:
  • in_data – A vector of pointers to input data buffers. Each float* corresponds to one input port of the model.

  • out_data – A vector of pointers where the output data will be written. Each float* must point to a preallocated buffer matching the expected size of the corresponding model output.

  • stream_id – Index of the stream used to run inference. This can be any user-defined ID that the application uses to track context.

  • model_id – Index of the model the input data is targeted to. Default is 0.

  • timeout – Maximum wait time (in milliseconds) for inference to complete. A value of 0 indicates that the function blocks indefinitely until results are ready. Default is 0.

Returns:

Returns true if inference was successful and output was received. Returns false if the operation timed out.

class MxAcclBase#

MxAcclBase class is the base class for MxAccl. It provides the basic functionality to connect to a DFP. It is not intended to be used directly, but rather as a base class for MxAccl and MxAcclMT.

Subclassed by MX::Runtime::MxAccl, MX::Runtime::MxAcclMT

Public Functions

MxAcclBase(const std::filesystem::path &dfp_path, std::vector<int> device_ids_to_use = {0}, std::array<bool, 2> use_model_shape = {true, true}, bool local_mode = false, SchedulerOptions sched_options = SchedulerOptions(), ClientOptions client_options = ClientOptions(), std::string server_addr = "/run/mxa_manager/", unsigned int server_port_base = 10000, bool ignore_server_ = false)#

The “all-in-one” Constructor that inits the object, connects the provided DFP, and sets options.

Parameters:
  • dfp_path – Path to the DFP file. char* and String types can also be passed.

  • device_ids_to_use – IDs of MXA devices this object will use. Set to {-1} to mean “all”.

  • use_model_shape – Set of {input, output} bools to indicate whether to exactly match original model shape, or the shape used by the MXA.

  • local_mode – If true, the DFP will be run in Local mode, which may be faster for some applications but doesn’t support simultaneous use.

  • sched_options – Scheduler options for the DFP. See MX::RPC::SchedulerOptions for detailed field descriptions.

  • client_options – Client options for the DFP. See MX::RPC::ClientOptions for detailed field descriptions.

  • server_addr – Socket file path or IP address of the server. Default is “/run/mxa_manager/” (socketfile, Linux) or “localhost” (IP, Windows).

  • server_port_base – Base port number for the server. Default is 10000. Applies to both socket filenames and IP addresses.

  • ignore_server_ – (ADVANCED) If true, the server connection is ignored and the DFP is run in Local mode, without consideration for other processes on the system. Will lead to crashes if multiple objects / processes / containers try to use the same device.

MxAcclBase(uint8_t *dfp_bytes, size_t dfp_byte_size, std::vector<int> device_ids_to_use = {0}, std::array<bool, 2> use_model_shape = {true, true}, bool local_mode = false, SchedulerOptions sched_options = SchedulerOptions(), ClientOptions client_options = ClientOptions(), std::string server_addr = "/run/mxa_manager/", unsigned int server_port_base = 10000, bool ignore_server_ = false)#

The “all-in-one” Constructor that inits the object, connects the provided DFP (from bytes array), and sets options.

Parameters:
  • dfp_bytes – Raw uint8_t* pointer to loaded DFP file data.

  • device_ids_to_use – IDs of MXA devices this object will use. Set to {-1} to mean “all”.

  • use_model_shape – Set of {input, output} bools to indicate whether to exactly match original model shape, or the shape used by the MXA.

  • local_mode – If true, the DFP will be run in Local mode, which may be faster for some applications but doesn’t support simultaneous use.

  • sched_options – Scheduler options for the DFP. See MX::RPC::SchedulerOptions for detailed field descriptions.

  • client_options – Client options for the DFP. See MX::RPC::ClientOptions for detailed field descriptions.

  • server_addr – Socket file path or IP address of the server. Default is “/run/mxa_manager/” (socketfile, Linux) or “localhost” (IP, Windows).

  • server_port_base – Base port number for the server. Default is 10000. Applies to both socket filenames and IP addresses.

  • ignore_server_ – (ADVANCED) If true, the server connection is ignored and the DFP is run in Local mode, without consideration for other processes on the system. Will lead to crashes if multiple objects / processes / containers try to use the same device.

MxAcclBase(std::string server_addr, unsigned int server_port_base, bool ignore_server_ = false)#

Constructor for MxAcclBase class. It initializes the MxAcclBase object with the given server IP and port info, etc., and creates a DeviceManager object.

Parameters:
  • server_addr – Socket file path or IP address of the server.

  • server_port_base – Base port number for the server. Applies to both socket filenames and IP addresses.

  • ignore_server_ – (ADVANCED) If true, the server connection is ignored and the DFP is run in Local mode, without consideration for other processes on the system. Will lead to crashes if multiple objects / processes / containers try to use the same device.

int get_num_models()#

Get number of models in the compiled DFP.

Returns:

Number of models

int get_dfp_num_chips()#

Get number of chips the dfp is compiled for.

Returns:

Number of chips

MX::Types::MxModelInfo get_model_info(int model_id = 0) const#

get information of a particular model such as number of in out featureMaps and in out layer names

Parameters:

model_id – model ID or the index for the required information

Returns:

if valid model_id then MxModelInfo model_info with necessary information else throw runtime error invalid model_id

MX::Types::MxModelInfo get_pre_model_info(int model_id = 0) const#

get information of the pre-processing model set to a particular model such as number of in out featureMaps and their sizes and shapes

Parameters:

model_id – model ID or the index for the required information

Returns:

if valid model_id then MxModelInfo model_info with necessary information else throw runtime error invalid model_id

MX::Types::MxModelInfo get_post_model_info(int model_id = 0) const#

get information of the post-processing model set to a particular model such as number of in out featureMaps and their sizes and shapes

Parameters:

model_id – model ID or the index for the required information

Returns:

if valid model_id then MxModelInfo model_info with necessary information else throw runtime error invalid model_id

void connect_post_model(std::filesystem::path post_model_path, int model_id = 0, const std::vector<size_t> &post_size_list = {})#

Connect the information of the post-processing model that has been cropped by the neural compiler.

Parameters:
  • post_model_path – Abosulte path of the post-processing model. (Can be onnx/tflite etc)

  • model_id – The index of model for which the post-processing is intended to be connected to. The default is set to 0

  • post_size_list – If the output of the post-processing has a variable size or if the ouput sizes are not deduced, the maximum possible sizes of the output need to be passed. The default is an empty vector.

void connect_pre_model(std::filesystem::path pre_model_path, int model_id = 0)#

Connect the information of the pre-processing model that has been cropped by the neural compiler.

Parameters:
  • pre_model_path – Abosulte path of the pre-processing model. (Can be onnx/tflite etc)

  • model_id – The index of model for which the post-processing is intended to be connected to. The default is set to 0

void set_parallel_fmap_convert(int num_threads, int model_id = 0)#

Configure multi-threaded FeatureMap data conversion using the given number of threads. Conversion multithreading is mainly intended for high FPS single-stream scenarios, or userThreading mode. In multi-stream autoThreading scenarios, this option should not be necessary, and may even degrade performance due to increased CPU load.

Parameters:
  • num_threads – Number of worker threads for FeatureMaps. Use >= 2 to enable. Values < 2 disable.

  • model_id – Index of model to enable the feature The default is set to 0

bool can_get_power_consumption(int device_id = 0)#

Checks if power consumption data can be retrieved for the connected modules.

Returns:

true if power consumption data is available, false otherwise.

float get_power(int device_id = 0)#

Retrieves the current power consumption of the specified device.

Returns:

The current power consumption value (in milliwatts) of the device.

MX::Types::Pressure get_pressure(int device_id = 0)#

Retrieves the current Pressure (“Throughput Utilization”) of the specified device.

See also

See value descriptions here: MX::Types::Pressure

Note

Pressure represents how “full” the MXA’s pipeline is.

This does NOT represent things like Core utilization or % of maximum FPS.

Returns:

The current Pressure value of the device.

float get_max_temperature(int device_id = 0)#

Retrieves the current maximum temperature of the specified device.

Returns:

The current maximum temperature value (in degrees Celsius) of the device.

std::vector<float> get_chip_temperatures(int device_id = 0)#

Retrieves temperatures of each chip on the specified device.

Returns:

A reference to a vector<vector> containing the current temperature values (in degrees Celsius) of each chip on the device.

bool set_operating_frequency(int device_id, MX::Types::MxFrequencyOption freq_option = MX::Types::MxFrequencyOption::FREQ_USE_CONF)#

Sets the operating frequency of the device. Can be called at any time after construction.

Parameters:
  • device_id – Device to set the power mode for.

  • freq_option – The desired frequency option. Defaults 600 MHz for x86_64, 500 MHz for Arm. See /etc/memryx/power.conf for the default value.

Returns:

true if the frequency was successfully set, false otherwise.

bool is_ready()#

Returns True if we have any valid DFPRunners, or if ignore_server_ is set to true then we check if the device manager has > 0 devices.

std::vector<int> get_converted_device_ids_to_use() const#

Returns the list of converted device IDs that this MxAccl object is using.

Returns:

A vector of integers representing the device IDs in use (after conversion).

int suggested_max_pending_frames() const#

Returns the suggested maximum number of pending frames to keep in the pipeline for optimal performance, based on the current load and performance of the system.

Returns:

The suggested maximum number of pending frames to keep in the pipeline for optimal performance.

enum class MX::RPC::ModelType#

Values:

enumerator NORMAL#
enumerator PARENT#
enumerator CHILD#
struct SchedulerOptions#

Configures scheduling behavior for a DFP (Dataflow Program) instance.

The SchedulerOptions struct defines runtime scheduling policies for a DFP when operating in shared mode. These options determine when and how the DFP instance should be swapped out based on input availability, queue capacities, or time constraints. They provide fine-grained control over input/output buffering and processing efficiency. These options also include settings for automatic frequency tuning on supported hardware.

Public Members

uint32_t max_queue_size = 100#

Maximum number of feature maps buffered between clients and mxa-manager (applies to both input and output queues). Default: 100.

uint32_t driver_depth = 4#

Driver-level buffer depth for ifmap/ofmap transfers to the device. A deeper value may improve throughput at the cost of more memory. Default: 4

bool is_latency_sensitive = false#

Scheduler optimization goal.

NOTE:

  • Currently supported only by the C++ Runtime API.

  • Python support is planned for SDK v3.0 and later.

When enabled, the scheduler prioritizes minimizing end-to-end latency (input-to-output delay). To achieve this, applications should call suggested_max_pending_frames() in the frame producer and drop excess frames when the system is overloaded. This keeps results as up-to-date as possible, potentially at the cost of lower throughput (FPS).

See example: <link>

When disabled, the scheduler prioritizes throughput (FPS). The scheduler attempts to maximize the number of frames processed per second and does not intentionally drop frames, which may increase input-to-output latency under heavy load.

Typical use cases:

  • true : Real-time applications (e.g. robotics, interactive use cases)

  • false : Throughput-oriented workloads (e.g. video analytics)

std::array<ModelType, MAX_MODELS> model_types = {ModelType::NORMAL}#

An array specifying the type of each model in the DFP, with possible values defined by the ModelType enum (NORMAL, PARENT, CHILD). This allows the scheduler to apply different policies or optimizations based on model roles. Default is {ModelType::NORMAL} for all models. MAX_MODELS is set to 32.

MX::Types::MxFrequencyOption op_freq = MX::Types::MxFrequencyOption::FREQ_USE_CONF#

Operating frequency for this DFP. FREQ_USE_CONF uses the value in /etc/memryx/power.conf. Cannot be set together with autoclock_enabled. Can be changed later with set_operating_frequency(). Default: FREQ_USE_CONF

bool autoclock_enabled = false#

Enable automatic frequency up/down-clocking when starting DFP, if supported by the target MX3 hardware. Default: false

uint32_t autoclock_power_limit_mw = 11500#

Power limit in milliwatts. Autoclocking will increase frequency until this power limit is reached. Range: [1000, 14700]. Default: 11500 mW

bool autoclock_check_fps_saturation = false#

EXPERIMENTAL If true, autoclocking will stop increasing, even if there’s still power headroom, if FPS has not increased over the last 3 frequency steps. Default: false

uint32_t autoclock_sample_interval_ms = 50#

Interval in milliseconds between power samples while testing autoclocking steps. Default: 50 ms

uint32_t autoclock_num_samples = 6#

Number of power samples to collect (and find the maximum of) before making a decision to stay at the current frequency or increase it. Default: 6

struct ClientOptions#

Configures client-side execution behavior, such as FPS smoothing and pacing.

The ClientOptions struct defines optional runtime behaviors for individual clients, including frame rate smoothing and target pacing. These settings help regulate how frequently input frames are submitted, which can be important for latency-sensitive or performance-constrained applications.

Public Members

float fps_target = 0#

Target FPS used for frame-rate smoothing. 0 means disabled, any positive value sets the target FPS for smoothing. Default is 0 (disabled).

class FeatureMap#

Encapsulates data buffers used by MxAccl for input and output feature maps.

The FeatureMap class represents a data container used internally by MxAccl to manage tensor data across the accelerator interface. It provides methods to safely send (set_data) and retrieve (get_data) data while abstracting low-level memory management.

Public Functions

FeatureMap(size_t size, MX_data_format format = MX_FMT_FP32, uint16_t dim_h = 0, uint16_t dim_w = 0, uint16_t dim_z = 0, uint32_t num_chan = 0, int fmap_convert_threads = 1, bool use_model_shape = false, Dfp::PortInfo *port_info = nullptr)#

Constructs a FeatureMap by allocating a data block of the given size and setting its dimensions and format.

Parameters:
  • size – Size of the feature map buffer (in bytes or elements, depending on format).

  • format – Data format (e.g., FP32, INT8).

  • dim_h – Height dimension.

  • dim_w – Width dimension.

  • dim_z – Depth (Z) dimension.

  • num_chan – Number of channels.

  • fmap_convert_threads – Number of threads used for format conversion or transposition.

  • use_model_shape – Whether to use the model-defined shape instead of explicit dimensions.

  • port_info – Optional port metadata for alignment with model I/O configuration.

FeatureMap(float *input, size_t size, MX_data_format format = MX_FMT_FP32, uint16_t dim_h = 0, uint16_t dim_w = 0, uint16_t dim_z = 0, uint32_t num_chan = 0, int fmap_convert_threads = 1, bool use_model_shape = false, Dfp::PortInfo *port_info = nullptr)#

Constructs a FeatureMap and initializes it with the provided input data.

A new data block is allocated and populated with the contents of input. Dimensions and format are configured as specified.

Parameters:
  • input – Pointer to input data to copy into the feature map.

  • size – Size of the feature map buffer.

  • format – Data format.

  • dim_h – Height dimension.

  • dim_w – Width dimension.

  • dim_z – Depth (Z) dimension.

  • num_chan – Number of channels.

  • fmap_convert_threads – Number of threads used for format conversion or transposition.

  • use_model_shape – Whether to use the model-defined shape.

  • port_info – Optional port metadata for model alignment.

FeatureMap(const FeatureMap &rhs)#

Copy constructor.

Creates a deep copy of the provided FeatureMap instance, duplicating all internal metadata and buffer content.

Parameters:

rhs – FeatureMap instance to copy from.

MX::Utils::MX_status get_data(float *out_data) const#

Retrieves the data from the accelerator’s output buffer into the given destination.

This method copies data from the internal feature map buffer into the user-provided memory pointed to by out_data.

Parameters:

out_data – Pointer to the destination buffer for the output data.

Returns:

MX_Status indicating success or failure.

MX::Utils::MX_status set_data(float *in_data) const#

Sets the input data to be sent to the accelerator.

Copies data from the user-provided in_data pointer into the feature map’s internal buffer.

Parameters:

in_data – Pointer to the source input data.

Returns:

MX_Status indicating success or failure.

class Pressure#

Level for approximating how busy the device is. Think of it like “throughput utilization of the running DFP(s)”.

There are 4 levels of pressure:

  • LOW: The device is mostly idle. Feel free to assign more work/streams.

  • MEDIUM: The device is moderately busy. You can assign additional streams, but don’t get too crazy.

  • HIGH: The device is nearing full utilization. Assign more streams with caution.

  • FULL: The device is fully occupied. Assigning more streams will lower per-stream performance.

The levels can be compared against either strings or integers.

  • LOW is “low” or 0

  • MEDIUM is “medium” or 1

  • HIGH is “high” or 2

  • FULL is “full” or 3

struct MxModelInfo#

Holds metadata and configuration details for a compiled model.

The MxModelInfo struct contains essential information about a model compiled for execution, including the number of input and output feature maps, their shapes and sizes, and the associated layer names. This metadata is typically used during runtime setup, validation, or for constructing input/output buffers.

Public Members

int model_index#

Unique index identifying the model instance.

int num_in_featuremaps#

Number of input feature maps required by the model.

int num_out_featuremaps#

Number of output feature maps produced by the model.

std::vector<std::string> input_layer_names#

Names of the model’s input layers, listed in the order expected by the runtime.

std::vector<std::string> output_layer_names#

Names of the model’s output layers, listed in the order produced by the model.

std::vector<MX::Types::ShapeVector> in_featuremap_shapes#

Shapes of the input feature maps, represented as a vector of ShapeVector objects.

std::vector<MX::Types::ShapeVector> out_featuremap_shapes#

Shapes of the output feature maps, represented as a vector of ShapeVector objects.

std::vector<size_t> in_featuremap_sizes#

Sizes (in bytes or elements, depending on context) of each input feature map.

std::vector<size_t> out_featuremap_sizes#

Sizes (in bytes or elements, depending on context) of each output feature map.

class ShapeVector#

Handles tensor shapes in both model and device formats.

Supports two kinds of shapes:

  1. model_shape: Original shape from external models (e.g., ONNX/TF)

  2. mx_shape: Internal device shape (H, W, Z, C)

If use_model_shape[0] is true, the input feature map from the application should match model_shape(). Otherwise, it should match mx_shape().

Also provides utilities to convert between channel-first [C, H, W, Z] and channel-last [H, W, Z, C] formats, supporting both standard 4D and custom tensor shapes.

Public Functions

inline int64_t h() const#

Get height dimension.

Returns:

Height value

inline int64_t w() const#

Get width dimension.

Returns:

Width value

inline int64_t z() const#

Get batch size dimension.

Returns:

Batch size value

inline int64_t c() const#

Get channel count.

Returns:

Channel count value

ShapeVector(int64_t h, int64_t w, int64_t z, int64_t c)#

Construct ShapeVector from explicit dimensions. Computes internal mx_shape (channel-last) for MX devices.

Parameters:
  • h – Height

  • w – Width

  • z – Batch size

  • c – Channel count

ShapeVector(std::vector<int64_t> model_shape)#

Construct ShapeVector from model shape only.

Parameters:

model_shape – Shape from external model (e.g., ONNX/TFLite)

ShapeVector(std::vector<int64_t> model_shape, int64_t h, int64_t w, int64_t z, int64_t c)#

Construct ShapeVector from model shape and explicit dimensions. Computes internal mx_shape (channel-last) for MX devices.

Parameters:
  • model_shape – Shape from external model (e.g., ONNX/TFLite)

  • h – Height

  • w – Width

  • z – Batch size

  • c – Channel count

int64_t &operator[](int64_t index)#

Returns mx_shape [H, W, Z, C] at the given index. Used only when ShapeVector is initialized with explicit dimensions.

Parameters:

index – Dimension index.

Returns:

Reference to the dimension value at the given index.

std::vector<int64_t> chfirst_shape() const#

Returns the shape in channel-first format (e.g., [C, H, W, Z]). Used only when ShapeVector is initialized with explicit dimensions.

Returns:

A vector of dimensions in channel-first order.

std::vector<int64_t> chlast_shape() const#

Returns the shape in channel-last format (e.g., [H, W, Z, C]). Used only when ShapeVector is initialized with explicit dimensions.

Returns:

A vector of dimensions in channel-last order.

bool matches_dimensions(const ShapeVector &other) const#

Checks if the dimensions (H, W, Z, C) of this ShapeVector match those of another ShapeVector.

Parameters:

other – The other ShapeVector to compare against.

Returns:

True if dimensions match, false otherwise.

std::vector<int64_t> mx_shape() const#

Returns mx shape [H, W, Z, C] that used for mx deivces internally (channel-last). This values matches the corresponding input/output feature map when use_model_shape is set false. Used only when ShapeVector is initialized with explicit dimensions.

Returns:

mx shape vector.

std::vector<int64_t> model_shape() const#

Returns original model shape from external model (e.g. onnx/tflite). This values matches the corresponding input/output feature map when use_model_shape is set true.

Returns:

model shape vector.

std::string mx_shape_str() const#

Returns string of mx shape for debugging purposes.

Returns:

mx shape vector.

std::string model_shape_str() const#

Returns string of model shape for debugging purposes.

Returns:

model shape vector.

bool operator==(const ShapeVector &other) const#

equality operator to compare two ShapeVector objects. mx_shape must match but model_shape is only checked if both are set.

std::string to_string() const#

Alias for mx_shape_str(), used by MxPrepost.