Multi-DFP#
Starting in SDK 2.0, the MemryX runtime supports using multiple DFPs in a single application, or across multiple applications.
Though the hardware can only execute one DFP at a time, the MXA-Manager is able to queue up input/output data for multiple DFPs and “swap” the executing DFP.
The end result is that applications can appear to run simultaneously, even though the hardware is only executing one DFP at a time.
Important
If your models are able to co-map into a single DFP, you should always try to do so for best performance.
Co-mapped DFPs can even support applications accessing contained models separately, in full parallel.
Scheduling multiple DFPs is for scenarios where co-mapping models in advance is not possible.
With the runtime APIs, using multiple DFPs is very simple; however, extracting the best performance requires some manual tuning.
Using Multiple DFPs#
To use multiple DFPs, you simply create multiple Accelerator objects, each with its own DFP file.
Same Application#
# Create Accelerator objects for each DFP
accl1 = AsyncAccl("model1.dfp")
accl2 = AsyncAccl("model2.dfp")
# Connect callbacks as needed
accl1.connect_input(input_callback1)
accl1.connect_output(output_callback1)
accl2.connect_input(input_callback2)
accl2.connect_output(output_callback2)
// Create Accelerator objects for each DFP
MxAccl accl1("model1.dfp");
MxAccl accl2("model2.dfp");
// Connect callbacks as needed
accl1.connect_stream(&input_callback1, &output_callback1, 0);
accl2.connect_stream(&input_callback2, &output_callback2, 0);
Multiple Applications#
To use different DFPs in different applications and have them run simultaneously, you can simply start multiple processes, each with its own Accelerator object.
As long as the default args are used (Shared Mode), the MXA-Manager will handle the scheduling of these DFPs across the available hardware.
Improving Performance#
Although the default parameters will work, the scheduler config requires you to try different values and find what works best for your specific application.
The following parameters can be adjusted for your DFPs.
DFP Scheduler Options#
When submitting a DFP to the MXA-Manager (i.e., creating an Accelerator object), you can specify a scheduler config to control how the DFP is executed.
The SDK 3.0 scheduler accepts these options:
max_queue_sizebounds the input and output feature-map queues. The default is 100.driver_depthcontrols device-transfer buffering. The default is 4.is_latency_sensitiveselects latency-oriented scheduling. The default prioritizes throughput.model_typesassigns each model a role (normal, parent, or child).op_freqselects the operating frequency. Zero uses the configured system frequency. Alternatively, enable automatic clocking on supported hardware.
See the Python MxAccl API for the automatic clocking options.
Important
The first application (or Accelerator object) to submit a DFP will set its config options. Subsequent applications submitting the same DFP (identified by SHA512 hash) will have their config options ignored.
Client Options#
DFP config options are shared across all client applications using the same DFP, but each client app also has unique options that can differ per-client.
Frame Smoothing#
When the MXA-Manager has multiple DFPs to run, it will accumulate input frames from clients for non-executing DFPs, and then swap in the next DFP when the current one yields control.
From a client app’s perspective, this will look like the DFP is stopped for a short time, then a rapid burst of frames are processed, then the DFP is stopped again.
While this may be acceptable for many applications, it can lead to a “jittery” frame rate, which may not be desirable for real-time applications.
Set ClientOptions.fps_target to a positive frame rate to enable smoothing for
that client. The default of zero disables smoothing.
Usage#
from memryx import mxapi
scheduler = mxapi.SchedulerOptions(max_queue_size=100, driver_depth=4)
client = mxapi.ClientOptions(fps_target=30)
accl = mxapi.MxAccl("model1.dfp", sched_options=scheduler, client_options=client)
MX::RPC::SchedulerOptions scheduler{};
scheduler.max_queue_size = 100;
scheduler.driver_depth = 4;
MX::RPC::ClientOptions client{};
client.fps_target = 30;
MxAccl accl("model1.dfp", {0}, {true, true}, false, scheduler, client);
Important
Each combination of DFPs and clients will likely need different tuning for peak performance. So before deploying your application, be sure to test it alongside all other expected DFPs and apps.
In this release, you can’t adjust the DFP config options after the DFP is started. So to adjust on-the-fly, you’ll need to first stop all clients using that DFP, then restart them with the new config options.
