Parallel, non-blocking access to an inference module
This sample shows how an instance of FB_MllPrediction
can be accessed from two tasks running concurrently.
The sample can be downloaded here: concurrent sample.
The instance fbpredict
is declared in the GVL_ML. All programs in the PLC thus have access to the instance. The following are created as programs:
- P_InitML: The step sequence for initializing/loading an ML model is described here.
- P_Predict_Task1: The Predict method of the
fbpredict
is called, wherein PRG is executed on Core 1. - P_Predict_Task2: The Predict method of the
fbpredict
is called, wherein PRG is executed on Core 2.
The essential components for the concurrent execution of 2 Predict calls are:
- The maximum number of concurrent accesses must be specified with the Configure method:
GVL_ML.fbpredict.stPredictionParameter.MaxConcurrency := nMaxConcurrency;
with nMaxConcurrency = 2.
The instance then keeps this number of independent inference machines available. - A unique ID of the calling context must be specified when calling the Predict method. These are declared as constants in P_Predict_Task1 and P_Predict_Task2, see
nConcurrencyId
.
The user must ensure that each calling context transfers a unique ID with the Predict call. - The remainder of the source code is largely identical to the Quick start sample.