Intelligent reasoning scheduling method for industrial control systems

By acquiring input data characteristics, model parameters, and system status information from industrial control systems, and utilizing time prediction models and dynamic time windows for admission judgment and segmented execution, the problem of scan cycle timeout caused by the uncertainty of AI inference task execution time is solved. This achieves tight coupling and collaboration between AI inference and real-time control tasks, ensuring the real-time performance and determinism of the system.

CN123113772APending Publication Date: 2026-11-17ZHEJIANG NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611467030.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-20
Publication Date
2026-11-17

AI Technical Summary

Technical Problem

When introducing AI inference tasks into industrial control systems, existing technologies suffer from scanning cycle timeouts due to uncertain execution times, making it difficult to achieve tight coupling and collaboration between intelligent inference tasks and real-time control tasks while ensuring system real-time performance and determinism.

Method used

By acquiring the input data characteristics, model structure parameters, and system status information of the target controller during the current scanning cycle of the intelligent inference task, the predicted time value is determined using a preset time prediction model. A dynamic time window is determined by combining a fixed time budget and the remaining time of the scanning cycle for admission judgment. The intelligent inference task is executed in segments to ensure its safe and efficient operation within the scanning cycle.

Benefits of technology

It achieves tight coupling and low-latency collaboration between intelligent inference tasks and real-time control tasks without compromising the determinism of the scanning cycle of industrial control systems, balancing the execution efficiency of inference tasks with system throughput.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123113772A_ABST
    Figure CN123113772A_ABST
Patent Text Reader

Abstract

This application provides an intelligent inference scheduling method for industrial control systems. The method includes: acquiring the input data characteristics, model structure parameters, and system state information of the target controller within the current scan cycle of the intelligent inference task; determining the predicted time consumption value of the intelligent inference task using a preset time prediction model based on the input data characteristics, model structure parameters, and system state information; acquiring the dynamic time window of the target controller's current scan cycle; performing an admission judgment on the intelligent inference task based on the comparison result between the predicted time consumption value and the dynamic time window to determine whether the intelligent inference task is allowed to start execution within the current scan cycle; and, in response to the intelligent inference task passing the admission judgment, executing the intelligent inference task in segments within the current scan cycle. This method improves the real-time performance and determinism of the industrial control system when executing intelligent inference tasks, and avoids scan cycle timeouts caused by inference time fluctuations.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the fields of industrial control and artificial intelligence technology, and in particular to an intelligent reasoning and scheduling method for industrial control systems. Background Technology

[0002] With the deep integration of intelligent manufacturing and industrial automation, the demand for artificial intelligence (AI) applications such as machine vision inspection, intelligent decision optimization, and predictive maintenance is becoming increasingly urgent. Deploying AI model inference tasks in industrial control systems, such as programmable logic controllers (PLCs), has become an important development trend in industrial intelligent control. As the core control equipment of industrial automation systems, industrial control systems generally adopt a fixed scan cycle working mechanism of "input sampling—program execution—output refresh," possessing inherent characteristics of deterministic logic execution and predictable timing, providing deterministic guarantees for hard real-time scenarios such as interlocking control, emergency stop response, and motion control. However, the execution time of intelligent inference (i.e., AI inference) tasks fluctuates significantly due to factors such as the scale of input data, model branch selection, and processor cache status. This characteristic creates a natural tension with the deterministic requirements of the scan cycle in industrial control systems, posing a fundamental challenge to the collaborative execution of AI inference tasks and real-time control tasks on the same controller platform.

[0003] Currently, existing technologies mainly employ two architectures to integrate AI inference with industrial control systems. One is the "direct embedding in the scan cycle" architecture, which treats the AI ​​inference task as an execution step within the industrial control system's scan cycle. After the real-time control task is completed, a preset interface is called to execute the AI ​​model inference, and the inference result is returned to the controller via shared memory to participate in subsequent control decisions. The other is the "physical isolation between real-time and non-real-time kernels" architecture, which is a dual-core independent process mode based on heterogeneous multi-core asymmetric processing. Real-time control tasks (logic operations, motion control, IO refresh) are bound to a high-priority real-time kernel, while the AI ​​inference task is deployed in an independent non-real-time kernel. The two interact asynchronously through shared memory or dual buffers.

[0004] However, existing methods for introducing AI inference tasks into industrial control systems suffer from scanning cycle timeouts due to the uncertainty of AI inference execution time, making it difficult to achieve tight coupling and collaboration while ensuring system real-time performance and determinism. Summary of the Invention

[0005] The intelligent inference scheduling method for industrial control systems provided in this application aims to solve the problem of scanning cycle timeout caused by the uncertainty of AI inference execution time, which in turn destroys the real-time performance and determinism of the system, and realizes tight coupling and low-latency collaboration between intelligent inference tasks and real-time control tasks within the same scanning cycle.

[0006] In a first aspect, embodiments of this application provide an intelligent reasoning scheduling method for industrial control systems, including:

[0007] Acquire the input data characteristics, model structure parameters, and system state information of the target controller during the current scanning cycle of the intelligent inference task;

[0008] Based on the characteristics of the input data, model structure parameters, and system status information, the predicted time consumption of the intelligent reasoning task is determined using a preset time prediction model.

[0009] Obtain the dynamic time window of the target controller's current scan cycle. The dynamic time window is the time quota for executing intelligent inference tasks, determined based on a preset fixed time budget and the remaining time of the scan cycle, after the periodic real-time control tasks in the target controller are completed within the current scan cycle.

[0010] Based on the comparison between the predicted time consumption value and the dynamic time window, an admission judgment is made on the intelligent inference task to determine whether the intelligent inference task is allowed to start execution in the current scanning cycle.

[0011] In response to the intelligent inference task, the intelligent inference task is executed in segments within the current scanning cycle through admission judgment. The intelligent inference task includes multiple inference segments pre-divided according to the computation graph structure. The segmented execution includes: dynamically selecting whether to execute each inference segment based on a dynamic time window.

[0012] In one possible implementation, obtaining the dynamic time window of the current scan cycle of the target controller includes: obtaining a preset fixed time budget, which is determined by the preset total scan cycle duration, the worst-case execution time of the real-time control task, and the system safety margin time; obtaining the remaining scan cycle time of the target controller after executing the real-time control task within the current scan cycle; and taking the smaller of the fixed time budget and the remaining scan cycle time to obtain the dynamic time window.

[0013] In one possible implementation, multiple inference segments are pre-divided as follows: the initial computation graph of the intelligent inference task is parsed to obtain a computation graph structure containing multi-layer neural networks; a reference time limit for the inference segment is determined based on the preset scan cycle duration and preset scaling factor of the target controller; based on the reference time limit, the computational load of the computation graph structure is accumulated layer by layer to determine the estimated accumulated time value, and when the estimated accumulated time value reaches the reference time limit, a split point is set at the current accumulation position to pre-divide the intelligent inference task into multiple inference segments; the worst execution time is marked for each inference segment to obtain a set of worst execution times for the segments, which is used for judgment during segmented execution.

[0014] In one possible implementation, based on the comparison result between the predicted time consumption value and the dynamic time window, an admission judgment is made on the intelligent inference task to determine whether the intelligent inference task is allowed to start execution in the current scan cycle. This includes: obtaining a preset safety margin coefficient, where the safety margin coefficient is a value greater than 0 and less than 1; correcting the dynamic time window according to the safety margin coefficient to obtain a corrected time window; performing a first comparison process on the predicted time consumption value and the corrected time window to obtain a first comparison result; when the first comparison result indicates that the predicted time consumption value is greater than the corrected time window, it is determined that the intelligent inference task has not passed the admission judgment, and the intelligent inference task is postponed to the next scan cycle.

[0015] In one possible implementation, the method further includes: when a first comparison result indicates that the predicted time consumption value is less than or equal to the correction time window, determining the first inference segment to be executed by the intelligent inference task from a pre-divided plurality of inference segments, and the worst-case execution time corresponding to the first inference segment; performing a second comparison process on the worst-case execution time corresponding to the first inference segment and the correction time window to obtain a second comparison result; when the second comparison result indicates that the worst-case execution time is greater than the correction time window, determining that the intelligent inference task has not passed the admission judgment, and postponing the intelligent inference task to the next scan cycle; when the second comparison result indicates that the worst-case execution time is less than or equal to the correction time window, determining that the intelligent inference task has passed the admission judgment, and allowing the intelligent inference task to start execution in the current scan cycle.

[0016] In one possible implementation, based on a dynamic time window, the dynamic selection of whether to execute each inference segment includes: obtaining the target inference segment currently to be executed in the intelligent inference task, and the worst-case execution time corresponding to the target inference segment; obtaining the current remaining time of the target controller in the current scan cycle, and the remaining budget value of the fixed time budget at the current moment; taking the smaller of the current remaining time and the remaining budget value to obtain the current available time window; comparing the worst-case execution time corresponding to the target inference segment with the current available time window to obtain a segment execution judgment result; executing the target inference segment when the segment execution judgment result indicates that the worst-case execution time is less than or equal to the current available time window; pausing the execution of the target inference segment and saving the checkpoint information of the current inference state when the segment execution judgment result indicates that the worst-case execution time is greater than the current available time window, and using the checkpoint information to restore the execution state of the intelligent inference task in the next scan cycle.

[0017] In one possible implementation, after the target inference segment is executed, the method further includes: performing checkpoint saving processing on the current inference state of the intelligent inference task to obtain updated checkpoint information, the updated checkpoint information including the layer index that has been calculated, the intermediate activation value tensor, and the inference time consumed in the current scan cycle; and persistently storing the updated checkpoint information in the storage unit of the target controller.

[0018] In one possible implementation, before acquiring the input data features, model structure parameters, and system state information of the target controller during the current scanning cycle of the intelligent inference task, the method further includes: acquiring multiple model versions corresponding to the intelligent inference task, wherein the multiple model versions exhibit a gradient distribution in terms of inference accuracy and execution time; for each model version, acquiring the worst-case execution time set of segments calibrated at each inference segment granularity to obtain the version segment time set corresponding to the model version; correspondingly, after acquiring the dynamic time window of the target controller's current scanning cycle, the method further includes: acquiring a preset first time threshold and a second time threshold, wherein the first time threshold is less than the second time threshold; performing a matching process between the dynamic time window and the first and second time thresholds to obtain a model version selection result; and determining the target model version from the multiple model versions based on the model version selection result to execute the intelligent inference task, wherein the prediction time value and the worst-case execution time set of segments both correspond to the target model version.

[0019] In one possible implementation, the dynamic time window is matched with a first time threshold and a second time threshold to obtain a model version selection result, including: when the dynamic time window is less than the first time threshold, selecting the lightweight model with the shortest inference execution time from multiple model versions and determining the lightweight model as the target model version; when the dynamic time window is greater than or equal to the first time threshold and less than the second time threshold, selecting the standard model from multiple model versions and determining the standard model as the target model version; when the dynamic time window is greater than or equal to the second time threshold, selecting the high-precision model with the highest inference accuracy from multiple model versions and determining the high-precision model as the target model version.

[0020] In one possible implementation, the method further includes: monitoring the operating status of the target controller during the execution of the intelligent inference task and obtaining monitoring results; when the monitoring results indicate the existence of a preset abnormal event, pausing the execution of the intelligent inference task and maintaining the normal operation of the real-time control task; and performing recovery processing operations according to the abnormal type corresponding to the abnormal event, the recovery processing operations including at least one of the following: reloading the most recently saved valid checkpoint information, switching to the lightweight model with the least inference execution time to re-execute the intelligent inference task, abandoning the intelligent inference task in the current scan cycle and delaying it to the next scan cycle to re-perform the admission judgment, and switching the target controller to traditional control logic.

[0021] The intelligent inference scheduling method for industrial control systems provided in this application obtains the input data characteristics, model structure parameters, and system state information of the target controller within the current scanning cycle of the intelligent inference task. It uses a preset time prediction model to determine the predicted time consumption value and combines it with a dynamic time window determined based on a fixed time budget and the remaining time of the scanning cycle for admission judgment. It also uses a method to execute the intelligent inference task that passes the admission judgment in segments according to multiple pre-divided inference segments. Under the premise of ensuring the determinism of the scanning cycle of the industrial control system, it can safely embed the intelligent inference task into the real-time control loop for execution, avoid scanning cycle timeout caused by inference time fluctuations, and thus achieve tight coupling and low-latency collaboration between the intelligent inference task and the real-time control task on the same controller platform, while taking into account the execution efficiency of the inference task and the system throughput. Attached Figure Description

[0022] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0023] Figure 1 A flowchart illustrating the intelligent reasoning scheduling method for industrial control systems provided in this application. Figure 1 ;

[0024] Figure 2 A flowchart illustrating the intelligent reasoning scheduling method for industrial control systems provided in this application. Figure 2 ;

[0025] Figure 3 A schematic diagram of the two-stage access control decision-making process provided for this application;

[0026] Figure 4 This application provides a schematic diagram of the execution flow of the inference task across scan cycles.

[0027] Figure 5 A schematic diagram of the PLC scanning cycle and AI model segment execution timing provided for this application;

[0028] Figure 6 A schematic diagram of the structure of the intelligent reasoning scheduling system for industrial control systems provided in this application;

[0029] Figure 7 A schematic diagram of the structure of the electronic device provided in this application.

[0030] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation

[0031] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application.

[0032] In existing technologies, the integration of AI inference and industrial control systems is achieved using either a "directly embedded scan cycle" architecture or a "physical isolation between real-time and non-real-time kernels" architecture. Specifically, while the "directly embedded scan cycle" architecture achieves tight coupling and collaboration between AI inference and real-time control tasks within the same scan cycle, the AI ​​inference time jitter can reach the millisecond level. If the inference time exceeds the remaining time of the scan cycle, it will cause the scan cycle to time out, triggering a watchdog reset or output malfunction in the control system. This architecture lacks an effective prediction and admission control mechanism for AI inference execution time. It cannot determine whether the AI ​​task can be safely completed within the current scan cycle before it begins, nor can it dynamically monitor and schedule the remaining time during inference execution. This exposes the determinism and real-time performance of the control system to the risk of being overwhelmed by the uncertainty of AI inference time.

[0033] While the "physical isolation between real-time and non-real-time kernels" architecture ensures the security of the real-time kernel by isolating AI inference tasks in the non-real-time kernel, the timing uncertainty of cross-core data interaction makes the timing of AI inference result output random and unpredictable relative to the PLC scan cycle. When the real-time kernel reads the shared data area early in the cycle, it may retrieve stale results from the previous frame. If blocking or polling is used, additional instruction overhead and microsecond to millisecond jitter are introduced. Simultaneously, in the dual-core shared DDR memory architecture, the latest inference results written by the non-real-time kernel reside in its private cache. If the cache misses when the real-time kernel reads shared memory, a remote memory access must be initiated, drastically increasing memory access latency by several to tens of times. The unpredictability of memory access time further undermines the determinism of the real-time control loop. These problems make it difficult to stably compress the closed-loop cycle from vision acquisition to motion control to within a fixed period (e.g., 10ms), sacrificing the determinism of deep integration of AI and real-time control.

[0034] In summary, when introducing AI inference tasks into industrial control systems, existing technologies suffer from scanning cycle timeouts due to the uncertainty of AI inference execution time, making it difficult to achieve tight coupling and collaboration while ensuring system real-time performance and determinism.

[0035] To address the aforementioned issues, this application provides an intelligent inference scheduling method for industrial control systems. This method divides the execution process of an intelligent inference task into three collaborative stages: time prediction, admission judgment, and segmented execution. After the intelligent inference task is ready, its input data characteristics, model structure parameters, and system state information of the target controller within the current scan cycle are acquired. A preset time prediction model is used to estimate the overall prediction time of the task. Simultaneously, a dynamic time window for the current scan cycle is acquired. This dynamic time window is a time quota specifically allocated to the intelligent inference task, determined after the real-time control task has been completed, based on the smaller of a preset fixed time budget and the remaining time of the scan cycle. Subsequently, the comparison between the predicted time and the dynamic time window is used as the admission judgment criterion to determine whether the intelligent inference task is allowed to start within the current scan cycle. For tasks that pass the admission judgment, multiple inference segments pre-divided according to the computation graph structure are executed segmentally within the current scan cycle. Before each segment is executed, a safety check is performed based on the dynamic time window, dynamically selecting whether to execute that segment. This method utilizes the predictive capability of the time prediction model and the dual constraints of the dynamic time window to limit the execution of intelligent reasoning tasks within the available time margin of the scanning cycle, thereby achieving tight coupling and collaboration between intelligent reasoning and real-time control tasks without compromising the determinism of real-time control.

[0036] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.

[0037] The execution entity of the intelligent reasoning scheduling method for industrial control systems provided in this application embodiment can be a computing device such as a server or server cluster. The server can be a mobile phone, computer, tablet, or other similar device. This application embodiment does not impose any particular restrictions on the implementation method of the execution subject, as long as the execution subject can obtain the input data characteristics, model structure parameters, and system status information of the target controller in the current scanning cycle of the intelligent inference task; determine the predicted time consumption value of the intelligent inference task using a preset time prediction model based on the input data characteristics, model structure parameters, and system status information; obtain the dynamic time window of the target controller in the current scanning cycle, which is the time quota for executing the intelligent inference task determined based on a preset fixed time budget and the remaining time of the scanning cycle after the periodic real-time control task in the target controller is completed in the current scanning cycle; perform an admission judgment on the intelligent inference task based on the comparison result of the predicted time consumption value and the dynamic time window to determine whether the intelligent inference task is allowed to start execution in the current scanning cycle; and execute the intelligent inference task in segments in the current scanning cycle in response to the intelligent inference task passing the admission judgment, wherein the intelligent inference task includes multiple inference segments pre-divided according to the computation graph structure, and the segmented execution includes: dynamically selecting whether to execute each inference segment based on the dynamic time window.

[0038] Figure 1 This is a flowchart illustrating the intelligent inference scheduling method for industrial control systems provided in this application. The executing entity of this method can be a controller in the industrial control system (such as a PLC, PAC, edge intelligent controller, etc.), or a scheduling module, middleware, or daemon running on the controller. For example, an inference scheduling component deployed in the real-time kernel of the PLC, or a scheduling service running on a coprocessor / acceleration unit sharing memory with the PLC. This embodiment does not impose any particular limitation on the specific hardware form of the executing entity, such as... Figure 1 As shown, the method may include:

[0039] S101. Obtain the input data characteristics, model structure parameters, and system status information of the target controller during the current scanning cycle of the intelligent reasoning task.

[0040] Intelligent reasoning tasks (also known as AI reasoning tasks) refer to tasks deployed in industrial control systems that utilize pre-trained artificial intelligence models (such as convolutional neural networks, Transformers, decision tree ensemble models, etc.) to perform forward computation on input data. These tasks can be applied to scenarios such as machine vision defect detection, equipment health status prediction, visual servo pose estimation, and predictive maintenance. These tasks typically have clearly defined input data (such as an image captured by an industrial camera or a sequence of vibration signals) and desired outputs (such as defect category, predicted remaining life, or target pose coordinates).

[0041] Input data features refer to quantitative metrics that describe the attributes of the input data to be processed in an intelligent inference task, rather than the raw input data itself. For example, for image inputs, input data features may include image resolution (e.g., 1920×1080), number of channels (e.g., 3-channel RGB or 1-channel grayscale), and data precision (e.g., FP32 / INT8); for sequence signal inputs, they may include sequence length and sampling rate; for sparse models (e.g., pruned networks), they may include the number of non-zero elements or the sparsity ratio; and they may also include data distribution characteristics (e.g., pixel mean, variance, histogram entropy). This feature is used to provide a lightweight input description for time prediction models, avoiding direct processing of high-dimensional raw data.

[0042] Model structure parameters refer to quantitative parameters that describe the structural complexity of the AI ​​model to be executed. For convolutional neural networks, these can include the number of network layers, the number of channels in each layer, the kernel size, the number of groups, and whether an attention module is included. For Transformer-type models, these can include the number of encoder layers, the number of attention heads, and the upper limit of sequence length. Model structure parameters can be statically obtained from the model's structure description file (such as ONNX, OpenVINO IR, TensorRT engine).

[0043] System status information refers to the hardware and system operating status of the target controller within the current scan cycle, related to the AI ​​inference execution time. This may include current CPU / GPU / NPU utilization, available memory, last-level cache hit rate, the busy level of AI acceleration units (such as NPU, TPU), current temperature and power consumption (which may trigger frequency throttling), etc.

[0044] In this step, the system controls the timing of task completion in real time within each scan cycle to collect the above three types of information from a preset data interface. Specific acquisition methods may include:

[0045] Shared memory area reading: Input data features and model structure parameters are written into the task descriptor structure in shared memory by the initiator of the AI ​​inference task when the task is enqueued. The scheduling module reads directly during the admission judgment phase without parsing the original input data.

[0046] Register / Status Word Reading: Read system status information such as CPU utilization and cache hit rate directly from the controller's hardware performance counters, system status registers, or RTOS task status interface; read static structure parameters of the currently selected model version from the model registry.

[0047] Local cache / pre-computation table reading: The model structure parameters have been parsed from the ONNX / IR file and stored in the scheduling information table during the system initialization phase. At runtime, they can be directly retrieved by indexing through the model version ID, avoiding repeated parsing of the computation graph.

[0048] For example, in a PLC-based vision inspection system, a frame of the image to be inspected is generated every 50ms. During each scan cycle, after the motion control and IO refresh tasks are completed, the scheduling module reads the task descriptor from shared memory, obtaining: image resolution 1280×960, single-channel grayscale, current model is a convolutional neural network (24 layers), CPU utilization 35%, and L2 cache hit rate 92%. This information is assembled into a feature vector, which serves as the input to the time prediction model.

[0049] In another example, in a vibration monitoring system based on an edge intelligent controller, the input data consists of 1024 vibration signals, and the model is a lightweight version of 1D-CNN (4 convolutional layers + 2 fully connected layers). The NPU acceleration unit is currently idle. The system obtains the NPU utilization rate as 0% from the controller status interface and retrieves the 1D-CNN structural parameters from the model registry.

[0050] S102. Based on the characteristics of the input data, model structure parameters, and system status information, determine the prediction time value of the intelligent reasoning task using a preset time prediction model.

[0051] The preset time prediction model can refer to a lightweight regression model pre-trained during the system's offline phase. This model is used to predict the total time required for the AI ​​inference task to perform complete inference under the current conditions, based on the three types of information mentioned above. The computational cost of this model should be much smaller than the AI ​​inference task itself (in microseconds) to ensure that no significant time overhead is introduced during the admission judgment phase. Lightweight structures such as linear regression, decision trees, random forests, small fully connected neural networks, and gradient boosting trees can be used to implement this model.

[0052] The predicted execution time value can refer to the estimated total execution time of the AI ​​inference task output by the time prediction model (e.g., T_pred). This value is a scalar time value (e.g., 3.2ms), reflecting the expected execution time of the inference task under average or typical conditions, rather than the upper bound of the worst case.

[0053] In this step, the three types of information obtained above are assembled into an input feature vector according to a preset feature encoding method (such as numerical normalization, one-hot encoding of categories, and feature concatenation), and then fed into the time prediction model for forward computation to obtain the predicted time consumption value. Further, in one example, a lightweight neural network can be used for forward computation: when the time prediction model is a small fully connected network, a microsecond-level forward computation is performed on the controller CPU to output the predicted time consumption value. In another example, when the time prediction model is implemented using a decision tree or rule table, the time consumption prediction interval is quickly located through step-by-step comparison of feature vectors, and the specific predicted time consumption value is obtained through linear interpolation. Furthermore, when the system is equipped with an AI acceleration unit, the time prediction model can also be executed on the acceleration unit with extremely low latency, or the query can be completed in nanoseconds through a preset lookup table.

[0054] For example, in the aforementioned visual inspection system, the scheduling module normalizes [resolution 1280×960, number of channels 1, number of layers 24, CPU utilization 35%, cache hit rate 92%] into a feature vector [0.67, 0.33, 0.24, 0.35, 0.92], and feeds it into a 3-layer fully connected network (5-dimensional input, 16-dimensional hidden layer, 1-dimensional output), with an output T_pred=2.8ms.

[0055] As another example, in the vibration monitoring system described above, the scheduling module feeds [sequence length 1024, NPU utilization 0%, number of layers 6] into the trained LightGBM regression model (50 trees, depth 4), executes it on the controller CPU for about 15μs, and outputs T_pred=1.5ms.

[0056] It should be noted that the training of the time prediction model can be completed offline. In some examples, the preset time prediction model can be trained as follows: Historical execution data of the intelligent inference task is obtained, including historical input data features, historical model structure parameters, historical system state information, and corresponding actual inference time values. Using the historical input data features, historical model structure parameters, and historical system state information as training inputs, and the actual inference time values ​​as training labels, the initial prediction model is trained to obtain the preset time prediction model. The input data features include at least one of the following: input data dimension, number of non-zero elements, and data distribution characteristics. The model structure parameters include at least one of the following: number of network layers, number of channels, and convolutional kernel size. The system state information includes at least one of the following: processor utilization, available memory, and cache hit rate. After training, the model parameters are fixed in a format that the controller can load (such as a binary weight file or a decision tree rule table) and deployed to the target controller.

[0057] S103. Obtain the dynamic time window of the current scan cycle of the target controller. The dynamic time window is the time quota for executing intelligent inference tasks, determined based on a preset fixed time budget and the remaining time of the scan cycle, after the periodic real-time control tasks in the target controller are completed within the current scan cycle.

[0058] The scan cycle refers to the fixed time length of a complete work cycle of an industrial control system, from input sampling and execution of user programs (including real-time control tasks) to output refresh. For example, the scan cycle of a motion control PLC can be set to 1ms, 2ms, or 4ms. Correspondingly, the total scan cycle duration refers to the fixed time length for the industrial control system to complete a complete work cycle, that is, the total time from the start of input sampling in the current scan cycle to the completion of all user programs (including real-time control tasks and possible AI inference tasks) and the completion of output refresh. This value is determined during the system design phase and specified by the controller configuration parameters.

[0059] Periodic real-time control tasks refer to control tasks that must be executed at fixed intervals within each scan cycle, such as logic operations, motion control interpolation, PID regulation, IO refresh, and safety interlock checks, and have hard real-time characteristics.

[0060] The pre-defined fixed time budget can refer to a fixed amount of time (e.g., T_budget) pre-calculated during system initialization and reserved for AI inference tasks in each scan cycle. In one example, this budget can be obtained by subtracting the sum of the worst-case execution times (WCET) of all real-time control tasks and the system safety margin time from the total scan cycle duration, ensuring that AI inference still has a definite time window even in the worst-case scenario where all real-time control tasks reach their worst execution times.

[0061] The remaining time of the scan cycle can refer to the length of time from the completion of the real-time control task to the theoretical end time of the cycle in the current scan cycle (which can be denoted as T_remain). Specifically, this value is dynamically measured in each scan cycle: T_remain=T_cycle-(t_now-t_start), where T_cycle is the preset total duration of the scan cycle, t_start is the start time of the current scan cycle, and t_now is the completion time of the real-time control task.

[0062] The dynamic time window refers to the actual time quota available for performing AI inference tasks within the current scan cycle (e.g., denoted as T_avail). In a specific example, it is the smaller of the fixed time budget and the remaining time in the scan cycle, i.e., T_avail = min(T_remain, T_budget). This dual constraint ensures that when real-time control tasks execute quickly, the time bonus is not overused, and when execution is slow, the AI ​​time quota is automatically compressed, with never exceeding the scan cycle timeout as the highest priority.

[0063] In this step, the dynamic time window can be obtained through a combination of static budgeting and dynamic adjustment. For example, during initialization, the total scan cycle duration, the sum of all real-time control tasks, and the system safety margin time are read from the configuration file to calculate T_budget. After each real-time control task completes, the system timestamp is read to calculate T_remain, and the minimum value is taken to obtain T_avail. Alternatively, a high-precision hardware timer can be used, started at the beginning of the scan cycle. When the real-time control task completes, the timer value is read as the elapsed time; T_cycle minus this value gives T_remain, which is then divided by the preset T_budget. Alternatively, the completion status and remaining time estimate of the real-time control task can be directly obtained through the task status query interface provided by the RTOS, and the dynamic time window can be calculated in conjunction with the preset T_budget.

[0064] S104. Based on the comparison results between the predicted time consumption value and the dynamic time window, make an admission judgment on the intelligent inference task to determine whether the intelligent inference task is allowed to start execution in the current scanning cycle.

[0065] The admission judgment refers to the security judgment that needs to be performed before the AI ​​inference task is actually started. The core principle is: the inference task is only allowed to start if it will not cause the scanning cycle to time out after it is started in the current cycle.

[0066] The comparison result can refer to the numerical relationship between the predicted time value and the dynamic time window (or the modified dynamic time window).

[0067] In some specific examples, the admission criteria can be implemented in multiple ways, such as:

[0068] 1) Direct comparison: If T_pred>T_avail, admission is denied and postponed to the next cycle; if T_pred≤T_avail, startup is allowed.

[0069] 2) Comparison after correction of safety margin coefficient: Introduce a safety margin coefficient α (0 < α < 1), multiply the dynamic time window by α to obtain the corrected window, and then compare. α can be dynamically adjusted according to real-time requirements: the higher the requirement, the smaller α (more conservative); the lower the requirement, the larger α (more aggressive).

[0070] 3) Confidence interval comparison: The time prediction model outputs the prediction mean and uncertainty at the same time. When making admission judgment, the upper bound of the confidence interval is compared with the dynamic time window to ensure safety in a statistical sense.

[0071] For example, in a visual inspection system, T_pred=2.8ms, T_avail=1.5ms, α=0.8, and the correction window=1.2ms. Since 2.8ms>1.2ms, the admission judgment is not passed, and execution is postponed to the next scan cycle. In another example, in a vibration monitoring system, T_pred=1.5ms, T_avail=3.0ms, α=0.8, and the correction window=2.4ms. Since 1.5ms≤2.4ms, the admission judgment is passed, and execution is allowed to begin in the current cycle.

[0072] S105. In response to the intelligent inference task passing the admission judgment, the intelligent inference task is executed in segments within the current scanning cycle. The intelligent inference task includes multiple inference segments pre-divided according to the computation graph structure. The segmented execution includes: dynamically selecting whether to execute each inference segment based on a dynamic time window.

[0073] The computation graph structure refers to the network structure of an AI model described in the form of a computation graph. Nodes represent operators (convolution, activation, pooling, fully connected), and edges represent tensor data flows. The computation graph can be obtained by parsing model structure description files such as ONNX (Open Neural Network Exchange) and OpenVINO IR (Intermediate Representation).

[0074] Pre-divided inference segments refer to the offline stage's division of the complete inference task into several independently executable and pauseable sub-task units according to the computation graph structure. Each segment contains one or more layers of network computation. Furthermore, the division can be based on a target execution time limit for each segment (e.g., not exceeding 10%~30% of the AI's fixed time budget in the scan cycle), ensuring that a single segment does not excessively occupy the scan cycle. For example, a 50-layer CNN can be divided into 5 segments, each with approximately 10 layers.

[0075] Segmented execution refers to executing each segment sequentially according to a pre-defined sequence, rather than performing the entire inference process all at once. Furthermore, a dynamic safety check can be performed before each segment execution to determine if the segment can be safely completed within the current remaining time window. Dynamically selecting whether to execute each inference segment means comparing the current available time window with the segment's WCET (Time Between Errors). If the WCET is within the current available window, execution proceeds; otherwise, the process is paused, the checkpoint is saved, and the process continues until the next scan cycle.

[0076] In some specific examples, segmented execution can be implemented in multiple ways, such as:

[0077] 1) Segment-by-segment sequential execution with dynamic checks: Starting from the current pause position according to the preset segment sequence, for each segment to be executed: (a) Obtain the current remaining time and remaining budget, and take the smaller to obtain the current available time window; (b) Query the pre-calibrated WCET for the segment; (c) Compare the WCET with the corrected window; (d) If WCET ≤ corrected window, execute; otherwise, pause and save the checkpoint. After executing a segment, update the consumed time and continue to check the next segment.

[0078] 2) Budget Deduction Method: At the start of the scan cycle, a time budget counter is allocated to AI inference, with an initial value of a dynamic time window. The actual execution time is deducted after each segment is executed. Before executing the next segment, the remaining value of the counter is compared with the WCET of that segment to determine whether to continue.

[0079] 3) Checkpoint-based cross-cycle recovery: If not all segments are completed within the current cycle, save the checkpoint information (completed layer indexes, intermediate activation value tensors, etc.), and pause at the end of the cycle. In the next cycle, the inference state is restored based on the checkpoints, and execution of subsequent segments continues from the paused position until completion.

[0080] For example, in a vibration monitoring system, the 1D-CNN is pre-divided into three segments: Seg_1 (convolutional layers 1-2, WCET=0.6ms), Seg_2 (convolutional layers 3-4, WCET=0.5ms), and Seg_3 (fully connected + output, WCET=0.4ms). The current T_avail=3.0ms, α=0.8. Execution flow: Seg_1 pre-correction window=2.4ms, 0.6≤2.4, execution (time 0.5ms); Seg_2 pre-remaining budget=2.5ms, correction window=2.0ms, 0.5≤2.0, execution (time 0.4ms); Seg_3 pre-remaining budget=2.1ms, correction window=1.68ms, 0.4≤1.68, execution (time 0.3ms). The entire inference is completed within the current cycle.

[0081] In another example, the convolutional neural network in the visual inspection system is pre-divided into 8 segments. Currently, T_avail = 1.5ms, α = 0.8. After executing Seg_1 (0.4ms) and Seg_2 (0.3ms), the remaining window is 0.8ms, corrected to 0.64ms. Since the WCET of Seg_3 is 0.7ms > 0.64ms, execution of Seg_3 is paused, the checkpoint is saved (completed layer index = layer 12, intermediate activation values ​​are stored), and the cycle ends. The next cycle resumes from the checkpoint and continues execution from Seg_3.

[0082] The intelligent inference scheduling method for industrial control systems provided in this application introduces a collaborative scheduling strategy of "inference time prediction + dynamic time window + admission control + segmented execution" to achieve safe and efficient execution of intelligent inference tasks while ensuring the determinism of the scanning cycle of the industrial control system.

[0083] Furthermore, regarding deterministic assurance, a dynamic time window is formed by the dual constraints of a pre-set fixed time budget and the remaining time of the scan cycle. This ensures that AI inference only runs within the safe time quota after the real-time control task is completed, thus fundamentally avoiding the risk of scan cycle timeouts due to the uncertainty of AI inference time. Simultaneously, an admission judgment is performed based on a time prediction model before starting the inference task, intercepting tasks whose predicted time exceeds the available time window and postponing them to subsequent cycles, further preventing timeout events from the entry point. In terms of execution efficiency, by pre-dividing the complete inference task into multiple segments according to the computation graph structure and performing a dynamic safety check based on the current remaining time window before executing each segment, the inference task can be completed in one go if it can be completed within a single cycle. If it cannot be completed, it is automatically paused and resumed across cycles, avoiding the throughput loss caused by coarse-grained scheduling. This maximizes the execution opportunities of the AI ​​inference task while ensuring real-time determinism. Therefore, this method resolves the fundamental contradiction between the uncertainty of AI inference time and the determinism of the scan cycle in industrial control systems, achieving secure and tightly coupled collaboration between AI inference and real-time control tasks on the same controller platform.

[0084] Based on the above embodiments, the method for obtaining the dynamic time window of the current scan cycle of the target controller described in S103 may include: obtaining a preset fixed time budget, wherein the fixed time budget is determined by the sum of the preset total scan cycle duration, the worst-case execution time of the real-time control task, and the system safety margin time; obtaining the remaining scan cycle time of the target controller after executing the real-time control task within the current scan cycle; and taking the smaller of the fixed time budget and the remaining scan cycle time to obtain the dynamic time window.

[0085] Based on the above embodiments, obtaining the dynamic time window of the current scan cycle of the target controller includes: obtaining a preset fixed time budget, which is determined by the preset total scan cycle duration, the worst-case execution time of the real-time control task, and the system safety margin time; obtaining the remaining scan cycle time of the target controller after executing the real-time control task in the current scan cycle; and taking the smaller of the fixed time budget and the remaining scan cycle time to obtain the dynamic time window.

[0086] In this embodiment, the fixed time budget remains constant during system operation and does not fluctuate with the actual execution time of the real-time control tasks in each scan cycle. Its calculation relationship can be: Fixed time budget = Total scan cycle duration - Sum of WCETs for real-time control tasks - System safety margin time.

[0087] Worst-case execution time (WCET) refers to the maximum execution time of a given program segment on the target hardware platform, considering all the worst-case factors such as cache misses, bus arbitration delays, and interrupt responses. The sum of the worst-case execution times for real-time control tasks is the cumulative value of the WCETs of all real-time control tasks that must be executed at fixed intervals in each scan cycle (such as logic operations, motion control interpolation calculations, PID control, I / O status updates, and safety interlock checks). This value is obtained through offline WCET analysis tools (such as static code analysis and measurement-based extreme value statistics).

[0088] System safety margin time refers to the conservative allowance deducted from the total scan cycle time when calculating the fixed time budget. This allowance is used to absorb unexpected timing jitter (such as interrupt nesting delays, bus contention, and execution time fluctuations caused by temperature-induced frequency throttling). This value is preset by the system designer based on the timing jitter characteristics of the target hardware platform and the reliability level requirements of the control system.

[0089] The "smaller value" operation refers to comparing two time values ​​and selecting the smaller one as the output. In this embodiment, the smaller value operation applies to the fixed time budget and the remaining scan cycle time, and the output is a dynamic time window. Its significance is that when the remaining scan cycle time is greater than the fixed time budget, the fixed time budget takes precedence to prevent the AI ​​from excessively consuming time resources; when the remaining scan cycle time is less than the fixed time budget, the remaining scan cycle time takes precedence, prioritizing ensuring the scan cycle does not exceed its time limit.

[0090] In this embodiment, one way to obtain the preset fixed time budget is during the system initialization phase: reading the total scan cycle duration T_cycle from the configuration file, reading the sum of WCETs for real-time control tasks T_WCET_ctrl from the WCET analysis report, and reading the safety margin time T_margin from the system configuration parameters. The fixed time budget is then calculated using the formula T_budget = T_cycle - T_WCET_ctrl - T_margin, and the result is stored in the scheduling information table for direct lookup at runtime. Another approach is to calculate the fixed time budget directly by the integrated development environment during compilation and write it as a constant into the controller firmware. Yet another approach is for the host computer or cloud management platform to issue configuration parameters, and the controller calculates and updates the fixed time budget upon receiving the configuration.

[0091] One way to obtain the remaining time of a scan cycle is the timestamp difference method: record the system timestamp t_start at the beginning of each scan cycle, and read the system timestamp t_now again after all real-time control tasks have been executed, then calculate T_remain = T_cycle - (t_now - t_start). Another method is the hardware timer countdown method: initialize the hardware timer to the total scan cycle duration at the beginning of the scan cycle and start the countdown; after the real-time control tasks have been executed, read the current remaining value of the timer, which is the remaining time of the scan cycle. Yet another method is the scheduler status query method: when the controller is running the RTOS, obtain the total actual execution time of completed tasks within the current scan cycle through the task status query interface, and then calculate the remaining time.

[0092] One way to round down the fixed time budget and the remaining scan cycle time is through conditional branching: if T_remain > T_budget, then T_avail = T_budget; otherwise, T_avail = T_remain. This method is simple to implement and suitable for resource-constrained PLC environments. Another method is through a hardware MIN instruction: when the controller CPU supports SIMD or has hardware MIN / MAX instructions, the hardware instruction is directly called to complete the rounding operation. Yet another method is through lookup table mapping: when the time value is discretized at a fixed granularity, a two-dimensional lookup table is pre-computed, and T_avail is directly retrieved using the discretized values ​​of T_budget and T_remain as indexes.

[0093] By determining the dynamic time window by taking the smaller of the fixed time budget and the remaining time of the scan cycle, a dual-constraint time quota mechanism is formed. When the real-time control task executes quickly and the remaining time of the scan cycle is greater than the fixed budget, the dynamic time window is constrained within the upper limit of the fixed budget, preventing the AI ​​inference task from excessively consuming time resources and helping to maintain time margin for subsequent scan cycles. When the real-time control task executes abnormally slowly and the remaining time of the scan cycle is less than the fixed budget, the dynamic time window is automatically adjusted to the actual remaining time, ensuring that the time quota available for the AI ​​inference task does not exceed the actual remaining time of the cycle, reducing the possibility of scan cycle timeout. Thus, this embodiment achieves a dynamic balance between increasing the opportunity for AI inference execution and ensuring the determinism of scan cycle time, providing a definite time benchmark for subsequent admission judgments and segmented execution.

[0094] Based on the above embodiments, multiple inference segments are pre-divided as follows: the initial computation graph of the intelligent inference task is parsed to obtain a computation graph structure containing multiple neural networks; based on the preset scan cycle duration and preset scaling factor of the target controller, a reference time limit for the inference segment is determined; based on the reference time limit, the computational load of the computation graph structure is accumulated layer by layer to determine the estimated time accumulation value, and when the estimated time accumulation value reaches the reference time limit, a split point is set at the current accumulation position to pre-divide the intelligent inference task into multiple inference segments; the worst execution time is marked for each inference segment to obtain a set of worst execution times for the segments, which is used for judgment during segmented execution.

[0095] The initial computation graph can refer to the complete model structure of an AI inference task before any partitioning, described in computation graph form. Nodes in the computation graph represent operators (such as convolution, activation, pooling, fully connected, normalization, etc.), and edges represent the data flow of tensors between operators. The initial computation graph can be obtained by parsing the model's structure description file, which can be in ONNX format, OpenVINO IR format, or other neural network model exchange formats. In this embodiment, the computation graph structure can refer to the hierarchical network structure description, with layers as the basic organizational unit, obtained from the initial computation graph. Each layer corresponds to one or more operator nodes in the computation graph. For example, a typical convolutional neural network's computation graph structure can sequentially include: input layer, convolutional layer, batch normalization layer, activation layer, pooling layer, fully connected layer, and output layer. The parsed computation graph structure includes the type of each layer, parameter scale (such as the number of channels, convolutional kernel size), inter-layer connections, and data flow.

[0096] In this embodiment, the model structure description file for the AI ​​inference task can be loaded during the offline stage to parse the initial computation graph and obtain its structure. Specifically, the ONNX parser can be used to traverse the model's node list and topology sorting results, grouping nodes into layers according to operator type and extracting the type, parameter scale, and inter-layer connections of each layer. Alternatively, the hierarchical structure information of the network can be read using the OpenVINO Runtime API. Furthermore, the model structure export interface provided by the training framework can be used to directly export a computation graph description file in JSON or YAML format containing layer information and parameter scales.

[0097] The scaling factor refers to the multiplier factor used to determine the upper limit of the reference execution time for an inference segment. This factor is multiplied by the preset scan cycle duration to obtain the target upper limit of the execution time for a single inference segment. The scaling factor typically ranges from 10% to 30%. For example, when the scan cycle is 4ms and the scaling factor is 20%, the upper limit of the reference execution time is 0.8ms. The selection of the scaling factor requires a trade-off between two objectives: a smaller value results in finer segment granularity, making it easier for a single segment to complete within the time window, but increases the number of segments and the overhead of saving and restoring state across segments; a larger value results in coarser segment granularity and fewer segments, but longer execution time for a single segment, which may make it more difficult to pass dynamic security checks at runtime. The upper limit of the reference execution time refers to the upper limit of the target execution time set for each inference segment during the offline partitioning phase. This value is equal to the product of the preset scan cycle duration and the scaling factor. Its function is to provide an accumulation threshold during the offline partitioning process: when the estimated execution time accumulated layer by layer reaches this threshold, a split point is set at this point, forming a new inference segment. It should be noted that the reference execution time limit is a target value used to guide the partitioning. The actual worst-case execution time of each segment after partitioning may be slightly higher or slightly lower than this limit.

[0098] In this embodiment, one way to determine the upper limit of reference time is to directly multiply the two to obtain the upper limit of reference time. For example, if the scan cycle is 4ms and the scaling factor is 20%, then the upper limit of reference time is 0.8ms. Another way is to preset a mapping table of scan cycle duration, scaling factor and upper limit of reference time, and obtain it by looking up the table. This is suitable for scenarios where the scaling factor is dynamically adjusted with the scan cycle.

[0099] Layer-by-layer computational accumulation refers to the process of sequentially accumulating the computational cost (usually measured in multiply-accumulate operations) of each layer in a neural network, following the order of layers in the computational graph structure from front to back. The computational cost of each layer can be statically estimated based on its type and parameters. For example, for a convolutional layer, the number of multiply-accumulate operations = output feature map height × output feature map width × number of output channels × kernel height × kernel width × number of input channels; for a fully connected layer, the number of multiply-accumulate operations = number of input neurons × number of output neurons. Estimated execution time accumulation refers to the estimated execution time obtained by combining the computational cost of each layer accumulated during the layer-by-layer accumulation process with the measured throughput of the target hardware platform.

[0100] A split point refers to a boundary position set in the computation graph structure to divide a complete inference task into multiple inference segments. The split point is set at the current accumulation position, i.e., after the current layer has been computed. Each split point corresponds to a different inference segment before and after it. The position information of the split point can be recorded as the corresponding layer index (e.g., after layer 12) and stored in the scheduling information table. The worst-case execution time set for each segment refers to the set formed after marking the worst-case execution time of each pre-divided inference segment on the target hardware platform. The i-th element in the set corresponds to the worst-case execution time of the i-th inference segment. This set is used for dynamic safety checks during runtime during segmented execution, i.e., to determine whether a segment can be safely completed within the current available time window.

[0101] In some examples, starting from the model input layer, the multiply-accumulate operations of each layer can be calculated layer by layer. The multiply-accumulate operations of the current layer are added to the accumulated multiply-accumulate operations, and then divided by the measured throughput of the target hardware platform to obtain the estimated cumulative time value. When the estimated cumulative time value first reaches or exceeds the reference time limit, a split point is set after the current layer to form an inference segment. Then, the accumulation starts from the next layer again, and the above process is repeated until the entire network is traversed. The measured throughput of the target hardware platform can be obtained by running a set of benchmark inference tasks with different computational loads offline, recording the actual execution time of each task, and then performing linear regression or least squares fitting.

[0102] One way to calibrate the worst-case execution time (WCET) for each inference segment is to execute each segment multiple times on the target hardware platform, simulating adverse conditions before each execution by refreshing the cache and injecting bus contention load, and taking the maximum value or high percentile value of the multiple execution times as the WCET for that segment; another way is to first obtain the theoretical WCET value through static code analysis, and then calibrate and correct it by combining it with measured data; another way is to multiply the typical execution time of each segment by a safety amplification factor to obtain the WCET calibration value.

[0103] By analyzing the initial computation graph of the AI ​​inference task offline and determining a reference time limit based on the scan cycle duration and proportional coefficient, the complete inference task is divided into multiple inference segments using a layer-by-layer computational accumulation method. This provides a reasonable scheduling granularity for segmented execution at runtime. On the one hand, dividing the task based on the reference time limit ensures that the execution time of each inference segment is controlled within the safe range of the scan cycle. This allows for more flexible utilization of fragmented time windows for local computation of the inference task, increasing the utilization opportunities of time windows. On the other hand, dividing the task layer by layer rather than using a fixed number of layers allows for adaptive adjustment of segment boundaries based on the differences in the actual computational load of each layer. This results in a more balanced distribution of execution time for each segment, which is beneficial for the consistency and predictability of runtime admission judgment and dynamic safety checks. Furthermore, the worst-case execution time is marked for each inference segment and formed into a set, providing a segment-by-segment safety judgment basis for segmented execution at runtime.

[0104] Based on the above embodiments, an admission judgment is made on the intelligent inference task based on the comparison result of the predicted time consumption value and the dynamic time window to determine whether the intelligent inference task is allowed to start execution in the current scan cycle. This includes: obtaining a preset safety margin coefficient, which is a value greater than 0 and less than 1; correcting the dynamic time window according to the safety margin coefficient to obtain a corrected time window; performing a first comparison process on the predicted time consumption value and the corrected time window to obtain a first comparison result; when the first comparison result indicates that the predicted time consumption value is greater than the corrected time window, it is determined that the intelligent inference task has not passed the admission judgment, and the intelligent inference task is postponed to the next scan cycle.

[0105] In this embodiment, the safety margin coefficient can be a multiplier factor used to conservatively scale the dynamic time window, reserving buffer space for estimation bias and runtime jitter in the inference time prediction model. The corrected time window refers to a smaller conservative time value than the original window obtained by multiplying the dynamic time window by the safety margin coefficient, serving as a benchmark for comparison with the predicted time consumption value in the admission judgment. The first comparison process refers to the numerical comparison between the predicted time consumption value and the corrected time window, corresponding to the first stage of the admission judgment, namely, overall feasibility coarse screening. Delaying to the next scan cycle means that inference tasks that fail the coarse screening are kept in the execution queue and not started in the current scan cycle, waiting for the admission judgment to be re-performed in the next cycle.

[0106] There are several ways to obtain the safety margin coefficient. In one example, the safety margin coefficient is read from the configuration file during system initialization, pre-set by the system designer according to the real-time level of the control system, and stored in non-volatile memory. In another example, a mapping table between real-time level and safety margin coefficient can be pre-configured; for example, 0.6 corresponds to hard real-time level, 0.7 corresponds to strong real-time level, and 0.85 corresponds to soft real-time level. The coefficient is retrieved by looking up the table according to the configured real-time level when the system starts. In yet another example, the safety margin coefficient can be dynamically adjusted during runtime. When a large fluctuation in the remaining scan cycle time is detected recently, the coefficient is automatically reduced to increase the safety margin; when the system operation tends to be stable, the coefficient is appropriately increased to improve the admission chance of AI inference tasks.

[0107] The calculation of the corrected time window can also be implemented in several ways. In one example, the corrected time window is obtained by directly multiplying the dynamic time window by the safety margin coefficient. For example, if the dynamic time window is 2.0 ms and the safety margin coefficient is 0.8, then the corrected time window is 1.6 ms. In another example, the safety margin time can be calculated first, i.e., the dynamic time window multiplied by (1 minus the safety margin coefficient), and then the safety margin subtracted from the dynamic time window. This method is mathematically equivalent to direct multiplication, but it is easier to implement on a fixed-point computing platform. In yet another example, when the time value is discretized with a fixed granularity, a two-dimensional lookup table of the dynamic time window and the safety margin coefficient can be pre-computed. At runtime, the corrected time window can be obtained directly by looking up the table, reducing the overhead of multiplication operations.

[0108] For example, in a vision inspection PLC with a scan cycle of 4ms, the dynamic time window is 1.5ms, the preset safety margin coefficient is 0.8, and the correction time window is 1.2ms. If the predicted execution time for a certain AI inference task is 2.8ms, and after the first comparison, 2.8ms is greater than 1.2ms, the task is determined to have failed the admission check and is postponed to the next scan cycle. Even if the actual execution time of the task may be lower than the predicted value, it will not be started in the current cycle to reduce the possibility of scan cycle timeout due to prediction deviation.

[0109] In another example, in an edge intelligent controller with a scan cycle of 10ms, the dynamic time window is 5.0ms, the safety margin coefficient is 0.9, and the correction time window is 4.5ms. The prediction time of a certain inference task to be executed is 3.2ms. After the first comparison process, 3.2ms is less than or equal to 4.5ms. Therefore, the task passes the first stage of coarse screening and enters the subsequent judgment stage.

[0110] By introducing a safety margin coefficient to correct the dynamic time window, and using the corrected time window as a benchmark for comparison with the predicted execution time, this embodiment reserves buffer space for estimation deviations in the inference time prediction model and unpredictable execution jitter during runtime. When the predicted execution time exceeds the corrected time window, the inference task is postponed to the next scan cycle, reducing the risk that the actual execution time exceeds the remaining time of the scan cycle when the prediction result is close to the time window boundary. This improves the conservatism and reliability of the judgment result while maintaining the simplicity and efficiency of the admission judgment mechanism.

[0111] Based on the above embodiments, the method may further include: when the first comparison result indicates that the predicted time consumption value is less than or equal to the correction time window, determining the first inference segment to be executed by the intelligent inference task from a pre-divided plurality of inference segments, and the worst execution time corresponding to the first inference segment; performing a second comparison process on the worst execution time corresponding to the first inference segment and the correction time window to obtain a second comparison result; when the second comparison result indicates that the worst execution time is greater than the correction time window, determining that the intelligent inference task has not passed the admission judgment, and postponing the intelligent inference task to the next scan cycle; when the second comparison result indicates that the worst execution time is less than or equal to the correction time window, determining that the intelligent inference task has passed the admission judgment, and allowing the intelligent inference task to start execution in the current scan cycle.

[0112] In this embodiment, the first inference segment can refer to the first segment to be executed in the intelligent inference task among the pre-divided multiple inference segments, arranged from front to back in the computation graph. The corresponding worst-case execution time refers to the maximum execution time of this segment after considering adverse factors such as cache misses and bus arbitration latency, as calibrated in the offline stage; that is, the value corresponding to the first segment in the set of worst-case execution times for segments. The second comparison process refers to the comparison between the worst-case execution time of the first inference segment and the value of the correction time window, corresponding to the second stage of the admission judgment, namely, the fine screening judgment based on extreme values. Allowing execution to start means allowing the intelligent inference task to start its inference computation within the current scan cycle. It should be noted that allowing execution to start does not mean that the task will definitely be completed within the current scan cycle, but only that the task can at least safely execute its first inference segment. Whether subsequent segments continue to be executed is determined one by one by the dynamic safety checks in the segmented execution process.

[0113] There are several ways to determine the first inference segment and its worst-case execution time. In one example, each inference task is created with an index pointer to its segment sequence, initially pointing to the first segment. During admission judgment, the segment pointed to by this pointer and its corresponding worst-case execution time are directly read. In another example, when an inference task has been partially executed and then paused, the segment index pointer points to the next segment to be executed corresponding to the current pause position. In this case, the first inference segment is actually the first segment that has not yet been executed, not the initial first segment of the entire task. In yet another example, when the system supports multiple model versions, the segment sequence and its corresponding worst-case execution time set are bound to the selected model version and retrieved from a table based on the currently selected target model version during admission judgment.

[0114] For example, in a vibration monitoring scenario, the model is pre-divided into three inference segments, with WCET sets of 0.6ms, 0.5ms, and 0.4ms for each segment. In a certain scan cycle, the inference task passes the first stage of coarse screening, with a prediction time of 1.2ms and a correction time window of 2.4ms. Upon entering the second stage, the WCET of the first inference segment (Seg_1) is checked and found to be 0.6ms. A second comparison is performed: 0.6ms is less than or equal to 2.4ms, therefore the task passes the admission check and is allowed to start execution within the current scan cycle.

[0115] In another example, in a visual inspection scenario, the model is pre-divided into 8 inference segments. In a certain scan cycle, the correction time window is 1.2ms, and the prediction time passes the first stage of coarse screening. In the second stage, the WCET (Warning Time Interval) for the first inference segment (Seg_1) is 1.5ms. A second comparison process is performed: 1.5ms is greater than 1.2ms, indicating that the task has not passed the admission judgment and is postponed to the next scan cycle. Even if the overall prediction time of the task is low, the first segment has already exceeded the safe time window in the worst-case scenario. If it were started prematurely, the current scan cycle would time out if the first segment experienced the worst-case execution situation; therefore, execution is not initiated.

[0116] In another example, when an inference task is paused after executing the first two segments in the current scan cycle, its segment index pointer points to the third segment. When the admission decision is re-performed in the next scan cycle, the first segment to be executed for this task is the third segment, and the second comparison process uses the WCET of the third segment to compare with the corrected time window, instead of using the WCET of the initial first segment.

[0117] This embodiment implements a hierarchical admission control mechanism by adding a second stage based on the worst-case execution time of the first inference segment after the initial coarse screening based on the predicted time consumption in the first stage. The first stage determines whether the task is worth starting from the perspective of the overall average time consumption, while the second stage determines whether it is safe to start from the perspective of the worst-case execution time of the first segment. Even if the overall predicted time consumption of the task passes the coarse screening, if the first segment may exceed the safe time window in the worst case, the task is still postponed. This avoids the situation where the scan cycle times out due to the first segment's execution time exceeding expectations, and further improves the safety and determinism of the admission judgment while taking into account system throughput.

[0118] Based on the above embodiments, a method for dynamically selecting whether to execute each inference segment based on a dynamic time window may include: obtaining the target inference segment currently to be executed in the intelligent inference task, and the worst-case execution time corresponding to the target inference segment; obtaining the current remaining time of the target controller in the current scan cycle, and the remaining budget value of the fixed time budget at the current moment; taking the smaller of the current remaining time and the remaining budget value to obtain the current available time window; comparing the worst-case execution time corresponding to the target inference segment with the current available time window to obtain a segment execution judgment result; executing the target inference segment when the segment execution judgment result indicates that the worst-case execution time is less than or equal to the current available time window; pausing the execution of the target inference segment and saving the checkpoint information of the current inference state when the segment execution judgment result indicates that the worst-case execution time is greater than the current available time window, and using the checkpoint information to restore the execution state of the intelligent inference task in the next scan cycle.

[0119] In this embodiment, the target inference segment refers to the inference segment that is about to be executed in the segmented execution process of the intelligent inference task, according to the pre-divided segment sequence. This segment is determined by a segment index pointer, which initially points to the first inference segment, and the pointer moves forward after each segment is executed. When the task is paused and then resumed across cycles, the pointer points to the next segment to be executed corresponding to the paused position. The worst-case execution time refers to the maximum execution time of the target inference segment calibrated in the offline phase, which can be obtained by looking up a table by segment index from the set of worst-case execution times for segments.

[0120] In one example, obtaining the target inference segment and its worst-case execution time could be achieved by having the scheduling module maintain a state structure for each inference task, containing segment index pointers indicating the position of the currently to-be-executed segment in the segment sequence. The corresponding element in the worst-case execution time set for each segment can then be directly read using this index. In another example, when the inference task is executed across cycles, after the recovery checkpoint, the next segment to be executed is determined based on the completed layer index recorded in the checkpoint, and its worst-case execution time is then retrieved from a table.

[0121] The current remaining time refers to the length of time from the current moment to the theoretical end time of the current scan cycle. Similar to the definition of the remaining time of the scan cycle, but measured at different times: the remaining time of the scan cycle is measured after the real-time control task has finished executing, while the current remaining time is measured in real-time before each execution of the next inference segment, reflecting the latest remaining amount after the time consumed by the executed segments. In one example, the current remaining time can be obtained by reading the system timestamp, calculating the difference between the current moment and the start time of the scan cycle, and then subtracting this difference from the total scan cycle duration. Alternatively, when using a hardware timer countdown, the remaining count value of the timer can be directly read as the current remaining time.

[0122] The remaining budget value refers to the unused portion of the fixed-time budget at the current moment. It is initially the full fixed-time budget. After each inference segment is executed, the actual execution time of that segment is deducted from the remaining budget value. Its purpose is to impose a cumulative constraint on the total execution time of the AI ​​inference task within a single scan cycle. Furthermore, there are several ways to obtain the remaining budget value. In one example, the scheduling module maintains a budget counter for each scan cycle, initialized to the fixed-time budget value. After executing each inference segment, the actual execution time of that segment is deducted from the budget counter to obtain the latest remaining budget value. In another example, the remaining budget value is calculated by accumulating the actual time spent on all inference segments executed within the current scan cycle and then subtracting this accumulated value from the fixed-time budget.

[0123] The current available time window refers to the smaller of the current remaining time and the remaining budget value, representing the upper limit of the time that the AI ​​inference task can safely use to execute the next inference segment at the current moment. The segment execution judgment result is the conclusion obtained by comparing the worst execution time of the target inference segment with the current available time window, indicating whether the segment can be safely started and executed within the current scan cycle.

[0124] Checkpoint information refers to a data set used to record the execution status of intelligent inference tasks. Its content may include the layer indices that have been computed, intermediate activation value tensors, the current timestamp, and the inference time consumed in the current scan cycle. Checkpoint information is saved to storage when the task is paused, and is used to restore the task's execution status in the next scan cycle, allowing inference to continue from the paused point rather than starting from the beginning.

[0125] It should be noted that, in this embodiment, the comparison processing can be implemented as a conditional branch comparison, which compares the worst-case execution time of the target inference segment with the current available time window and outputs the comparison result. Alternatively, a difference calculation method can be used to calculate the difference between the worst-case execution time and the current available time window, using the sign of the difference as the criterion.

[0126] For example, in a vibration monitoring scenario, the inference model is divided into three segments with time-of-flight (WCET) times of 0.6ms, 0.5ms, and 0.4ms respectively, a fixed time budget of 1.5ms, and a total current scan cycle duration of 10ms. After the real-time control task is completed, the remaining scan cycle time is 4.0ms, and the dynamic time window is min(1.5, 4.0) = 1.5ms. The task begins segmented execution after passing the admission criteria. Before executing the first segment, the current remaining time is 4.0ms, the remaining budget is 1.5ms, the current available time window is min(4.0, 1.5) = 1.5ms, and the WCET of the first segment is 0.6ms, which is less than or equal to 1.5ms. Executing the first segment actually takes 0.5ms. Before executing the second segment, the remaining time is 3.5ms, the remaining budget is 1.0ms, the available time window is min(3.5, 1.0) = 1.0ms, and the WCET for the second segment is 0.5ms, which is less than or equal to 1.0ms. Executing the second segment takes 0.4ms. Before executing the third segment, the remaining time is 3.1ms, the remaining budget is 0.6ms, and the available time window is min(3.1, 0.6) = 0.6ms. The WCET for the third segment is 0.4ms, which is less than or equal to 0.6ms. Executing the third segment takes 0.3ms. This inference task completes all three segments within the current scan cycle.

[0127] In another example, in a visual inspection scenario, the inference model is divided into 8 segments with a fixed time budget of 1.5ms. The task begins execution after passing an admission check. After executing the first two segments, the remaining time is 0.9ms, the remaining budget is 0.7ms, and the available time window is min(0.9, 0.7) = 0.7ms. The WCET for the third segment is 0.8ms, which is greater than 0.7ms, so the segment execution check indicates a pause. The system saves checkpoint information, including the index of completed layers, intermediate activation value tensors, the current timestamp, and the consumed inference time. Execution pauses at the end of the current scan cycle. In the next scan cycle, the inference state is restored based on the checkpoints, and execution continues from the third segment.

[0128] This embodiment implements segment-level dynamic safety checks by calculating the current available time window based on the smaller of the current remaining time and the remaining budget value before executing each inference segment, and comparing the worst-case execution time of the target segment with this window to determine whether to execute it. The current available time window is constrained by both the actual remaining time of the scan cycle and the remaining fixed budget, providing time boundary guarantees at both the scan cycle and AI budget levels. Segments are executed when the worst-case execution time does not exceed the current available time window; when it does, execution is paused and checkpoints are saved. This allows the inference task to be safely segmented across multiple scan cycles, reducing the risk of scan cycle timeouts while maintaining the execution continuity of the inference task.

[0129] It should be noted that during the execution of an AI inference task, intermediate computation results (i.e., intermediate activation value tensors) are generated. These intermediate results are stored in the controller's memory during normal continuous execution and flow naturally with the inference process. However, in segmented execution mode, the inference task may pause at any segment boundary due to insufficient time in the current scan cycle, waiting for the next scan cycle to resume execution. If only the position information of "which segment has been executed" is recorded during the pause without saving the intermediate activation value tensors, then when execution resumes in the next scan cycle, the intermediate results of all completed segments need to be recalculated from the input layer of the inference task, resulting in redundant computation overhead and reducing the utilization efficiency of the time window. Therefore, based on the above embodiment, after the target inference segment is executed, the method may further include: performing checkpoint saving processing on the current inference state of the intelligent inference task to obtain updated checkpoint information, which includes the layer index of the completed calculation, the intermediate activation value tensor, and the inference time consumed in the current scan cycle; and persistently storing the updated checkpoint information in the storage unit of the target controller.

[0130] In this embodiment, the current inference state refers to the immediate execution state of the intelligent inference task after the target inference segment has been completed. This state may include the network layer position reached by the inference computation, the intermediate results output by each layer, and the time resources consumed. The layer index of completed computations refers to the position of the deepest layer in the network computation graph where the inference task has completed computation, such as the 12th layer or the last layer of the 3rd inference segment. This indicates from which layer to continue computation when execution resumes. The intermediate activation value tensor refers to the output tensors generated during the forward computation of each completed layer. These tensors are the input data upon which subsequent unexecuted layers rely for forward computation; storing them avoids recalculating the completed parts from scratch when execution resumes. The inference time consumed in the current scan cycle refers to the cumulative time actually occupied by the task from the start of execution in the current scan cycle to the current moment. This is used to update the remaining budget value in subsequent executions.

[0131] Checkpoint saving refers to the process of organizing, serializing, and writing the aforementioned state information into storage according to a preset data structure. Persistent storage refers to writing the checkpoint information into the target controller's non-volatile storage unit, such as Flash memory, ferroelectric memory, or SRAM with battery backup, to ensure that the checkpoint information remains available after unexpected power loss or system reset. The triggering timing of checkpoint saving can be varied. For example, checkpoint saving can be executed immediately after each inference segment is completed, forming incremental checkpoints segment by segment; another example is that checkpoint saving can only be executed when it is detected that the next segment cannot be completed within the current scan cycle and needs to be paused, in order to reduce the storage overhead caused by frequent saving.

[0132] In one example, checkpoint information can be stored using a full-scale storage method, saving complete checkpoint information each time. In another example, an incremental storage method can be used, saving only the data that has changed since the last checkpoint, such as only saving the layer index of newly completed segments and the newly added intermediate activation value tensors, to reduce storage overhead and saving latency.

[0133] Furthermore, the specific implementation of persistent storage can be as follows: checkpoint information can be serialized and written to a designated address area of ​​the controller's Flash memory, with the corresponding sector erased before writing. Alternatively, checkpoint information can be written to ferroelectric memory, utilizing its high durability and fast write characteristics to meet the requirements of high-frequency checkpoint storage. Another option is to simultaneously write checkpoint information to a working copy in RAM and a persistent copy in Flash, using the RAM copy during normal pauses to speed up recovery and the Flash copy during power-off recovery to ensure no data loss. This embodiment does not impose any particular restrictions on the specific implementation of persistent storage.

[0134] For example, in a vibration monitoring scenario, the inference model is divided into three segments. After the second segment is executed, the scheduling module immediately performs checkpoint saving. The updated checkpoint information includes: the layer index of the completed calculation is layer 4 (the second segment covers layers 3 to 4), the intermediate activation value tensor is the feature map data output from layer 4, and the inference time consumed in the current scan cycle is 0.9 ms. This checkpoint information is serialized and written to the controller's ferroelectric memory.

[0135] In another example, in a visual inspection scenario, the inference model is divided into eight segments. After the third segment is executed, incremental storage is used to save the data, recording only the layer index after the third segment is completed and the newly generated activation value tensor, without rewriting the data saved from the first two segments. When it is subsequently determined that the fourth segment cannot be safely executed within the current scan cycle, this incremental checkpoint becomes the latest valid recovery point.

[0136] By saving and persistently storing checkpoints after each inference segment is executed, this embodiment provides a reliable state basis for the cross-cycle recovery of the inference task. Even if the inference task is paused during execution due to insufficient time window or interrupted by system anomalies, execution can be resumed from the paused position based on the most recently saved checkpoint information, without having to recalculate the completed parts from the beginning. This reduces redundant calculation overhead and ensures the continuity of the inference task across multiple scan cycles.

[0137] Furthermore, the execution time of the same AI inference task can vary by several times or even orders of magnitude depending on the model version with different precision and scale. If a single fixed model version is always used during scheduling, when the available time window in the scanning cycle is large, using a lightweight model, although fast, results in limited inference accuracy, failing to fully utilize the ample time resources to obtain higher-quality inference results. When the available time window is small, using a high-precision model, although achieving higher inference accuracy, results in execution time exceeding the safe range, causing inference tasks to be frequently delayed or denied access, thus reducing the effective utilization rate of AI capabilities in the control system.

[0138] Therefore, based on the above embodiments, before acquiring the input data features, model structure parameters, and system state information of the target controller in the current scanning cycle of the intelligent inference task, the method may further include: acquiring multiple model versions corresponding to the intelligent inference task, wherein the multiple model versions exhibit a gradient distribution in terms of inference accuracy and execution time; for each model version, acquiring the worst-case execution time set of segments calibrated at each inference segment granularity to obtain the version segment time set corresponding to the model version; correspondingly, after acquiring the dynamic time window of the target controller in the current scanning cycle, the method further includes: acquiring a preset first time threshold and a second time threshold, wherein the first time threshold is less than the second time threshold; performing matching processing on the dynamic time window with the first time threshold and the second time threshold to obtain the model version selection result; and determining the target model version from the multiple model versions according to the model version selection result to execute the intelligent inference task, wherein the prediction time value and the worst-case execution time set of segments both correspond to the target model version.

[0139] In this embodiment, multiple model versions can refer to multiple AI model instances with different scales and accuracies that are pre-trained and maintained for the same intelligent inference task. These model versions exhibit a gradient distribution in terms of inference accuracy and execution time. For example, the lightweight model has the shortest inference time but the lowest accuracy, the high-precision model has the longest inference time but the highest accuracy, and the standard model lies in between. The gradient distribution means that the model versions form an ordered progressive relationship in terms of both accuracy and execution time, rather than random differences.

[0140] In one example, multiple model versions can be obtained through structure search, where a search is conducted within a predefined model structure search space, with inference accuracy and execution time as joint optimization objectives, to find model structures of varying complexity. In another example, they can be obtained through knowledge distillation, using a high-precision model as the teacher model and transferring its knowledge to a more streamlined student model, resulting in multiple model versions with gradient distributions. Yet another example demonstrates how applying different intensities of pruning and quantization operations to the same base model can yield model versions of varying scales and accuracies.

[0141] The version fragment timeout set refers to the dataset formed by pre-dividing each model version into multiple inference fragments according to its own computation graph structure, and then labeling the worst-case execution time of each fragment. Different model versions have different network structures and layers, resulting in different fragment partitioning results and corresponding worst-case execution time sets. Therefore, offline partitioning and labeling are required for each model version. Furthermore, the method for obtaining the version fragment timeout set for each model version can include: parsing the computation graph structure of each model version; determining a reference time limit based on the same fragment partitioning rules, i.e., based on a preset scan cycle duration and a proportional coefficient, accumulating computational load layer by layer and setting split points to divide each model version into multiple inference fragments; and then labeling the worst-case execution time of each inference fragment for each model version to form the version fragment timeout set corresponding to each model version.

[0142] The first and second time thresholds are two preset time thresholds used for model version selection, with the first threshold being smaller than the second. Their function is to divide the dynamic time window into three intervals, corresponding to the selection criteria for lightweight, standard, and high-precision models, respectively. These two thresholds are pre-calibrated based on the measured inference time distribution of each model version on the target hardware platform. There are several ways to calibrate the first and second time thresholds. In one example, the typical total inference time distribution of each model version on the target hardware platform is measured offline, with the upper bound of the typical time consumption of the lightweight model used as the first time threshold and the upper bound of the typical time consumption of the standard model used as the second time threshold. In another example, the median or average measured inference time of each model version is used as a reference, combined with the proportion of time budget reserved for AI in the scanning cycle to determine the threshold.

[0143] Matching refers to comparing the values ​​of a dynamic time window with a first time threshold and a second time threshold, and determining which model version to select based on the comparison result. The model version selection result is the output information obtained after matching, indicating which model version should be selected. The target model version is the model version determined from multiple model versions based on the model version selection result, which is actually used to perform the intelligent inference task within the current scan cycle. After selecting the target model version, the prediction time values ​​and worst-case execution time sets used in subsequent steps all correspond to this target model version.

[0144] For example, in a visual inspection scenario, three model versions are maintained for the same defect detection task: Lightweight Pruned Version A, with a typical inference time of 1.2ms and accuracy of 88%; Standard Version B, with a typical inference time of 3.0ms and accuracy of 93%; and High-Precision Version C, with a typical inference time of 5.5ms and accuracy of 96%. The three model versions are pre-divided into 4, 6, and 8 inference segments, respectively, and the worst-case execution time for each segment is calibrated and stored. The system presets a first time threshold of 1.5ms and a second time threshold of 4.0ms. In a certain scan cycle, the dynamic time window is 1.2ms. After matching, the dynamic time window is less than the first time threshold, so Lightweight Pruned Version A is selected as the target model version.

[0145] In another example, if the dynamic time window is 3.5ms in another scan cycle, which is greater than or equal to the first time threshold of 1.5ms and less than the second time threshold of 4.0ms, then Standard Version B is selected as the target model version. After selection, the time prediction model outputs the predicted time value for the structural parameters of Standard Version B, and the WCET set of the corresponding segment of Standard Version B is used in the admission judgment.

[0146] As another example, in a certain scan cycle, the dynamic time window is 6.0ms, which is greater than or equal to the second time threshold of 4.0ms. The high-precision version C is selected as the target model version to obtain higher inference accuracy under sufficient time conditions.

[0147] By pre-maintaining multiple model versions with gradient distributions in inference accuracy and execution time, and dynamically selecting the target model version in each scan cycle based on the matching result of a dynamic time window and a preset threshold, this embodiment enables the accuracy of the inference task to adaptively adjust according to changes in the system's available time resources. When the time window is ample, a high-precision model is selected to obtain more accurate inference results; when the time window is tight, it automatically downgrades to a lightweight model to ensure that the inference task is completed within a limited time. This mechanism maximizes inference accuracy while ensuring the time safety of the scan cycle, achieving a balance between time determinism and inference quality.

[0148] Based on the above embodiments, the method for matching the dynamic time window with the first time threshold and the second time threshold to obtain the model version selection result may include: when the dynamic time window is less than the first time threshold, selecting the lightweight model with the shortest inference execution time from multiple model versions and determining the lightweight model as the target model version; when the dynamic time window is greater than or equal to the first time threshold and less than the second time threshold, selecting the standard model from multiple model versions and determining the standard model as the target model version; when the dynamic time window is greater than or equal to the second time threshold, selecting the high-precision model with the highest inference accuracy from multiple model versions and determining the high-precision model as the target model version.

[0149] In this embodiment, the lightweight model refers to the model version with the shortest inference execution time but the lowest inference accuracy among multiple model versions; it has the simplest network structure and the fewest parameters and computational cost. The standard model refers to the model version whose inference execution time and inference accuracy fall between the lightweight model and the high-precision model. The high-precision model refers to the model version with the highest inference accuracy but the longest inference execution time among multiple model versions; it has the most complex network structure and the most parameters and computational cost.

[0150] There are several ways to implement the matching process. One example uses a conditional branching structure to make sequential judgments: first, check if the dynamic time window is less than a first time threshold; if so, select the lightweight model; otherwise, check if the dynamic time window is less than a second time threshold; if so, select the standard model; otherwise, select the high-precision model. This approach is logically intuitive and suitable for implementation in PLC ladder diagrams or structured text languages.

[0151] In another example, a lookup table is used for matching. When the dynamic time window is discretized with a fixed granularity, a model selection lookup table indexed by the discrete values ​​of the time window can be pre-defined. Each entry in the table directly corresponds to a model version identifier. At runtime, the selection result is obtained directly by looking up the table, avoiding multiple comparison operations. For example, if the dynamic time window is discretized with a granularity of 0.5ms, the lookup table corresponds to the lightweight model for 0.5ms, the lightweight model for 1.0ms, the standard model for 1.5ms, and so on.

[0152] In another example, a range coding method is used. Three range codes are preset: range 0 corresponds to values ​​less than the first time threshold, range 1 corresponds to values ​​between the two thresholds, and range 2 corresponds to values ​​greater than or equal to the second time threshold. At runtime, the range code to which the dynamic time window belongs is determined through two comparisons, and then the corresponding model version is indexed based on the range code.

[0153] For example, in a visual inspection scenario, the system maintains three versions: a lightweight model, a standard model, and a high-precision model. The first time threshold is 1.5ms, and the second time threshold is 4.0ms. In a certain scanning cycle, the dynamic time window is 1.0ms, which is less than the first time threshold of 1.5ms. Therefore, the matching process selects the lightweight model as the target model version to ensure that the inference task can be completed within a limited time.

[0154] In another example, in another scan cycle, the dynamic time window is 2.5ms, which is greater than or equal to the first time threshold of 1.5ms and less than the second time threshold of 4.0ms. The matching process selects the standard model as the target model version, and obtains higher inference accuracy than the lightweight model within the time limit.

[0155] In another example, the dynamic time window in another scan cycle is 5.0ms, which is greater than or equal to the second time threshold of 4.0ms. The matching process selects the high-precision model as the target model version to pursue the highest inference accuracy under the condition of sufficient time.

[0156] This embodiment provides a simple and deterministic model version switching rule by comparing a dynamic time window with two preset thresholds and mapping the comparison results to the selection of three model versions: lightweight, standard, and high-precision. When system time resources are limited, it automatically downgrades to the model with the shortest execution time to ensure inference completion. When time resources are sufficient, it upgrades to a higher-precision model to improve inference quality, allowing inference accuracy to adaptively adjust with changes in the available time window. This mechanism does not require complex runtime decision algorithms; it only requires two numerical comparisons to complete the selection, making it suitable for implementation on industrial controllers with limited computing resources.

[0157] Based on the above embodiments, the method further includes: monitoring the operating status of the target controller during the execution of the intelligent inference task and obtaining monitoring results; when the monitoring results indicate the existence of a preset abnormal event, pausing the execution of the intelligent inference task and maintaining the normal operation of the real-time control task; and performing recovery processing operations according to the abnormal type corresponding to the abnormal event, the recovery processing operations including at least one of the following: reloading the most recently saved valid checkpoint information, switching to the lightweight model with the least inference execution time to re-execute the intelligent inference task, abandoning the intelligent inference task in the current scan cycle and delaying it to the next scan cycle to re-perform the admission judgment, and switching the target controller to traditional control logic.

[0158] In this embodiment, operational status monitoring refers to the continuous or periodic observation and inspection of various operational indicators of the target controller during the execution of AI inference tasks. Monitoring objects may include the working status of the inference time prediction model, the integrity and recoverability of checkpoint data, the loading status of the model version, the availability of the AI ​​acceleration unit, and the changing trend of the remaining scan cycle time, etc.

[0159] There are several ways to implement runtime status monitoring. In one example, after the inference time prediction model finishes execution, its output value is checked to see if it is within a reasonable range. If the output value is abnormal or the model execution reports an error, an inference time prediction failure is determined. In another example, after each checkpoint is saved, the written checkpoint data is verified, for example, by checking the checksum or reading back to verify data integrity. If the verification fails, a checkpoint saving anomaly is determined. In yet another example, a periodic heartbeat detection mechanism monitors whether the AI ​​acceleration unit is responding normally. If no response is received within a preset timeout period, the AI ​​acceleration unit is determined to be unavailable.

[0160] Predefined abnormal events refer to a set of various abnormal operating events that may occur during the execution of inference tasks, predefined and configured during the system design phase. Each abnormal event corresponds to an abnormality type identifier. Specific types of abnormal events may include: inference time prediction failure, checkpoint recovery failure, model version loading failure, AI acceleration unit unavailable, and the system detecting insufficient remaining scan cycle time, etc. Monitoring results refer to the information output by the operational status monitoring stage, indicating whether abnormal events exist and their types.

[0161] Pausing the execution of an intelligent inference task means immediately halting the computation process of the current inference task upon detecting an anomaly, and ceasing execution of subsequent inference segments. The pause operation itself does not release saved checkpoint information, allowing resumption from the paused position upon recovery. Maintaining the normal operation of real-time control tasks means ensuring that the execution of periodic real-time control tasks in the target controller is not interrupted or degraded during the handling of AI inference anomalies. The scheduling and execution priority of real-time control tasks are unaffected by AI inference anomaly handling.

[0162] Recovery operations refer to one or more measures taken based on the anomaly type to restore the system from an abnormal state to a state where it can continue to operate safely. There is a correspondence between the types of recovery operations and the anomaly types. The specific implementation methods of recovery operations can be varied. In one example, when the anomaly type is corrupted checkpoint data, the most recently saved and validated valid checkpoint information is reloaded, and inference execution resumes from the position corresponding to that checkpoint. In another example, when the anomaly type is that the current model version fails to execute, the inference task is re-executed using a lightweight model with the shortest inference execution time to reduce inference complexity and the risk of execution failure. In yet another example, when the anomaly type is that the remaining time of the scan cycle suddenly becomes insufficient and it is no longer safe to execute any inference segment, the inference task in the current scan cycle is abandoned and postponed to the next scan cycle for re-admission judgment. In yet another example, when the AI ​​inference function is completely unavailable and cannot be restored in the short term, the target controller is switched to traditional control logic that does not rely on AI inference, such as rule-based control or PID control, to ensure the continuous operation of the control system.

[0163] Traditional control logic refers to control programs based on classical control theory or rules that do not rely on AI inference results. Examples include closed-loop control based on PID algorithms, interlocking logic based on threshold comparisons, and sequential control based on state machines. Traditional control logic typically involves low computational complexity and has a fixed execution time, serving as a fallback option to ensure the basic functionality of the control system when AI inference is unavailable.

[0164] In a practical application, for example, in a visual inspection scenario, when the inference task reaches the third segment, the scheduling module detects that the AI ​​acceleration unit has failed to respond to heartbeat signals three times consecutively, determining that the AI ​​acceleration unit is unavailable. The system immediately suspends the inference task, while the real-time control task continues to operate normally. Depending on the type of anomaly, the system switches the target controller to traditional control logic, which maintains basic control functions until the AI ​​acceleration unit becomes available again.

[0165] In another example, in a vibration monitoring scenario, during cross-cycle recovery of the inference task, checkpoint data verification fails, and checkpoint recovery is deemed unsuccessful. The system attempts to load the previously saved valid checkpoint. If loading is successful, execution resumes from that checkpoint; otherwise, the inference task is abandoned and delayed until the next scan cycle for re-admission judgment.

[0166] As another example, in a certain scan cycle, after the inference task completes the first segment, the system detects that the remaining time of the scan cycle has been significantly reduced due to a sudden interruption, and the current remaining time is less than the worst-case execution time of any subsequent segment. The system immediately pauses the inference task, saves the checkpoint information, and postpones the remaining segments to the next scan cycle. Throughout the entire process, the real-time control task is not affected in any way.

[0167] By monitoring the target controller's operational status during execution and pausing the AI ​​inference task while maintaining the real-time control task's normal operation when an anomaly occurs, and then performing corresponding recovery operations based on the anomaly type, this embodiment provides a systematic response mechanism for various anomalies that may occur after the introduction of AI inference tasks into industrial control systems. Anomalies in the AI ​​inference task will not propagate to the real-time control task, ensuring the core functions of the control system are always guaranteed. Furthermore, through multi-layered recovery strategies such as checkpoint recovery, model degradation, task delay, and traditional control logic fallback, the system can maintain the continuity of inference services or at least guarantee the availability of control functions after anomalies occur, improving the overall reliability and robustness of the integration of AI and industrial control systems.

[0168] As can be seen from the above embodiments, the intelligent inference scheduling method for industrial control systems provided in this application, under the constraint of the deterministic PLC scan cycle, achieves the safe collaborative operation of AI inference tasks and real-time control tasks on the same controller platform by constructing an inference time prediction model, designing a two-stage admission control mechanism for scan cycle awareness, adopting a cross-cycle segmentation execution strategy based on checkpoints, and combining dynamic adaptation selection of multi-level model versions. This method, through a combination of offline preprocessing and online dynamic decision-making, constrains the execution of AI inference tasks within a dynamic time window jointly determined by a fixed time budget and the remaining time of the scan cycle. Through mechanisms such as admission judgment, segmented execution, and anomaly recovery, it provides reasonable execution opportunities for AI inference tasks while ensuring the real-time performance and stability of the PLC scan cycle. This method is applicable to application scenarios in industrial control systems that require the integration of AI inference capabilities, such as machine vision quality inspection, predictive maintenance, and intelligent decision support.

[0169] Figure 2 A flowchart illustrating the intelligent reasoning scheduling method for industrial control systems provided in this application. Figure 2 ,like Figure 2 As shown, in this embodiment... Figure 1 Based on the examples, a detailed description of the intelligent reasoning scheduling method for industrial control systems is provided. This method includes:

[0170] S201, Construction of Offline Preprocessing and Inference Time Prediction Model.

[0171] Before the AI ​​inference task is deployed to the PLC, the following offline preprocessing operations are performed:

[0172] (1) Training the inference time prediction model: Obtain historical execution data of the AI ​​inference task. The historical execution data includes input data features, model structure parameters, processor load status, and corresponding actual inference time. Using the historical execution data as training samples, train a lightweight inference time prediction model to predict the total time T_pred of the entire AI inference task based on the current input data features and system status. Preferably, the input data features include input data dimension, number of non-zero elements (for sparse models), and data distribution characteristics; the model structure parameters include the number of network layers, number of channels, and convolution kernel size; the processor load status includes the current CPU utilization, available memory, and cache hit rate.

[0173] (2) Segmentation and WCET calibration of AI inference tasks:

[0174] 1) Obtain the network structure description file (such as ONNX or IR format) of the target AI model and parse its computation graph structure.

[0175] 2) Determine the target time limit T_seg_target for a single computation segment based on the sum of the PLC scan cycle T_cycle and the worst-case execution time (WCET) of all real-time control tasks, T_WCET_ctrl. In this embodiment, WCET refers to the maximum execution time measured or analyzed for a given program segment on the target hardware platform, considering all the most unfavorable factors such as cache misses, bus arbitration delays, and interrupt responses. Preferably, T_seg_target = β·T_cycle, where β is a preset proportionality coefficient, ranging from 10% to 30%, to ensure that a single segment does not excessively occupy the scan cycle time.

[0176] 3) Starting from the model input layer, the computational cost (multiply-accumulate operands MAC) of each neural network layer is accumulated layer by layer. Combined with the measured throughput of the target hardware platform, the time consumption of each layer is estimated.

[0177] 4) When the accumulated time reaches or exceeds T_seg_target for the first time, a split point is set at that layer to form a computation segment; then the accumulation starts again from the next layer, and the above process is repeated until the entire network is traversed.

[0178] 5) Assign the worst-case execution time T_WCET_i (i=1,2,…,n, where n is the total number of segments) to each partitioned computational segment, and store it in the scheduling information table for runtime lookup.

[0179] (3) Offline preparation of multi-level model versions: Pre-train and maintain multiple model versions of different scales and accuracies for the same AI inference task, including a lightweight model, a standard model, and a high-precision model, and calibrate T_WCET_i of each version at each segment granularity respectively for dynamic selection at runtime. Preferably, the multiple model versions are obtained through structure search, knowledge distillation or pruning and quantization, and are distributed in a gradient in terms of inference accuracy and execution time: the lightweight model has the shortest inference time but the lowest accuracy, the high-precision model has the longest inference time but the highest accuracy, and the standard model is between the two.

[0180] S202. Bandwidth reservation and time budget management.

[0181] Wherein, in the system initialization phase, the following budget configuration is performed:

[0182] According to the total duration T_cycle of the PLC scan cycle and the sum T_WCET_ctrl of the WCETs of all real-time control tasks, the fixed time budget T_budget available for AI inference tasks is calculated as T_budget=T_cycle-T_WCET_ctrl-T_margin; where T_margin is a preset system safety margin time for absorbing unexpected jitter. The meaning of this formula is that even in the worst case where all real-time control tasks reach their WCETs, the system can still reserve a determined fixed time window T_budget for AI inference.

[0183] In each scan cycle during operation, the actual time window T_avail available for AI inference is the smaller value of the dynamic remaining time T_remain of the current cycle and the fixed budget T_budget, that is, T_avail=min(T_remain, T_budget); where T_remain is dynamically measured and calculated in each scan cycle: T_remain=T_cycle-(t_now-t_start), t_start is the system timestamp at the start of the current scan cycle, and t_now is the system timestamp at the moment when all fixed-period real-time control tasks have just been executed.

[0184] The above design principle is: when T_remain>T_budget (that is, the real-time control tasks in the current cycle run faster than expected and there is an extra time bonus), the system strictly abides by the upper limit of T_budget to prevent AI from excessively occupying the time of future cycles; when T_remain<T_budget (that is, the real-time control tasks in the current cycle run slower than expected), the system automatically degrades to T_remain, with ensuring that the scan cycle never times out as the highest priority.

[0185] Through the above dual constraints, the AI inference task is executed within a fixed time budget and does not occupy the time budget of the real-time control task.

[0186] S203. Real-time adaptive selection of multi-level model versions.

[0187] In this step, when the AI inference task is waiting to be executed, the real-time adaptive selection of the model version is performed before admission control:

[0188] Obtain the actual available time window T_avail (defined in S202) of the current scan cycle, set two thresholds Th_A (i.e., the first time threshold) and Th_B (i.e., the second time threshold), where Th_A < Th_B. The model selection process is as follows:

[0189] When T_avail < Th_A, select the lightweight model to perform inference;

[0190] When Th_A ≤ T_avail < Th_B, select the standard model to perform inference;

[0191] When T_avail ≥ Th_B, select the high-precision model to perform inference.

[0192] It should be noted that the thresholds Th_A and Th_B are pre-calibrated according to the measured inference time distribution of each model version on the target hardware platform.

[0193] Preferably, the selection of the model version may also take into account the importance level of the current inference task: for inference related to critical real-time control tasks (such as visual servo feedback), real-time performance is prioritized and a lighter model is selected; for non-critical analysis tasks (such as offline quality statistics), accuracy is prioritized and a larger-scale model is selected.

[0194] After the model version is selected, the network structure of this version is locked, and the T_pred prediction and T_WCET_i calibration values in subsequent steps all correspond to the selected model version.

[0195] S204. Scan cycle-aware two-stage admission control.

[0196] In each PLC scan cycle, after all real-time control tasks with fixed cycles are executed, the two-stage admission control process is performed, as Figure 3 shown, which specifically includes:

[0197] (1) The first stage: admission judgment based on the predicted mean value (coarse screening).

[0198] Obtain the queue of AI inference tasks to be executed, and perform judgment on each inference task in the queue in turn: input the current input data features and system state into the inference time prediction model (from S201) to obtain the total prediction time T_pred for the entire AI inference task.

[0199] Set a safety margin factor α (0 < α < 1), and compare T_pred with the actual available time window T_avail for the current period (from S202):

[0200] If T_pred>α·T_avail, it means that the task is difficult to complete in the current cycle even under average conditions. Mark the inference instance as needing to be executed across cycles and postpone it to the next scan cycle.

[0201] If T_pred≤α·T_avail, then proceed to the second stage of judgment.

[0202] The safety margin coefficient α is dynamically adjusted according to the real-time requirements of the control system: when the control real-time requirements are high, α is reduced to increase the safety margin; when the control real-time requirements are low, α is increased to reduce the safety margin.

[0203] (2) Second stage: Admission judgment based on worst-case execution time of fragments (fine screening).

[0204] Query the offline calibrated worst-case execution time T_WCET_1 of the first computation segment of this inference task pre-stored in S201:

[0205] If T_WCET_1>α·T_avail, it means that even if only the first segment is executed, it may cause the scan cycle to time out in the worst case. The system rejects the task and postpones it to the next scan cycle.

[0206] If T_WCET_1≤α·T_avail, then the inference task is allowed to start execution in the current cycle and enter the segmented execution process of S205.

[0207] Through the above two-stage admission control, a layered decision-making process is achieved, which includes "mean coarse screening - judging whether the overall task is worth starting" and "extreme value fine screening - judging whether the first segment is safe to execute", thus taking into account both system throughput and hard real-time security.

[0208] S205, Checkpoint-based cross-cycle segmentation execution and dynamic fragment scheduling.

[0209] For AI inference tasks that pass S204 admission control, the following cross-cycle segmentation execution strategy is implemented:

[0210] (1) Obtain the computational segment sequence {Seg_1,Seg_2,…,Seg_n} of the inference task that is pre-divided and stored in S201, and the worst execution time {T_WCET_1,T_WCET_2,…,T_WCET_n} corresponding to each segment.

[0211] (2) Starting from the current pause position (Seg_1 on the first execution), execute the computation segments one by one. Before executing each segment, perform the following dynamic safety checks:

[0212] 1) Obtain the current remaining time window T_remain_current (from the current time to the end of this period) for the current scan cycle, and calculate the current actual available time T_avail_current=min(T_remain_current,T_budget_remaining), where T_budget_remaining is the remaining budget for the current period (initially T_budget, decreasing as the time consumed); 2) Query the worst execution time T_WCET_j for the next segment to be executed, Seg_j; 3) If T_WCET_j≤α·T_avail_current, then execute the segment; otherwise, pause execution and proceed to step (4).

[0213] (3) After each computation segment is executed, save the checkpoint information of the current inference state. The checkpoint information includes: the layer index that has been computed, the intermediate activation value tensor, the current timestamp, and the AI ​​budget time consumed in the current cycle.

[0214] (4) If the entire inference task has not been completed by the end of the current scan cycle, the execution is paused and the current checkpoint information is persisted. In the next scan cycle, the inference state is restored according to the saved checkpoint information, and the subsequent calculation segments are continued from the paused position until the entire inference task is completed.

[0215] (5) If the AI ​​inference task is not completed within the fixed time budget T_budget allocated in S202, the pause and save checkpoint operation in step (4) above will be forcibly executed, and the remaining segments will be postponed to the next cycle.

[0216] Preferably, the granularity of the calculation segment is dynamically adjusted according to the typical duration of the PLC scan cycle: a finer granularity (smaller β value) is used when the scan cycle is short, and a coarser granularity (larger β value) is used when the scan cycle is long, in order to balance the cross-cycle switching overhead and real-time requirements. Preferably, the checkpoint information adopts an incremental storage method, only saving data that has changed since the last checkpoint, in order to reduce storage overhead and storage latency.

[0217] S206, Anomaly Handling and Security Recovery Mechanism.

[0218] The system will enter the abnormal recovery process when any of the following situations occur during operation: (1) inference time prediction fails; (2) checkpoint recovery fails; (3) model version loading fails; (4) AI acceleration unit is unavailable; (5) the system detects that the remaining time of the scan cycle is insufficient.

[0219] Upon the occurrence of the above anomaly, the system immediately suspends the AI ​​inference task, while maintaining the PLC real-time control task. Based on the anomaly type, the system executes the corresponding recovery strategy: ① reload the most recent valid checkpoint; ② switch to the lightweight model and re-execute; ③ abandon the inference task for this cycle and delay it until the next scan cycle for re-admission; ④ if necessary, switch to the traditional PLC control logic to ensure continuous operation of the control system.

[0220] The above recovery process must not affect the determinism of the PLC scanning cycle.

[0221] The intelligent inference scheduling method for industrial control systems provided in this application estimates the total time of AI inference tasks by training an inference time prediction model offline. After the real-time control task is completed, a dynamic time window is determined based on the smaller of a fixed time budget and the remaining time of the scan cycle. The inference task is admitted based on the comparison between the predicted time and the dynamic time window. The admitted inference task is then executed in segments within the current scan cycle according to multiple pre-divided inference segments. Before executing each segment, the method dynamically decides whether to continue execution or pause and save checkpoints based on the currently available time window. This strictly constrains the execution of AI inference tasks within the safe time range of the scan cycle, ensuring the determinism of the PLC scan cycle and preventing AI inference tasks from causing the scan cycle to time out, thus maintaining the core characteristics of the PLC as a deterministic control device.

[0222] Meanwhile, this method enables AI inference to directly participate in the real-time control loop while ensuring real-time performance, achieving deep integration of AI and real-time control and improving the intelligence level of the control system. Through cross-cycle segmentation execution and fixed time budget mechanism, it makes full use of the fragmented remaining time after the real-time control task is completed in each scan cycle, improving the utilization rate of computing resources. Through dynamic adaptation selection of multi-level model versions, it can adaptively select the appropriate accuracy and time consumption model version according to the time window size of different scan cycles, enhancing the system's adaptability to different load scenarios and real-time requirements. Thus, a scan cycle-aware intelligent inference scheduling framework is formed. This framework does not simply segment AI inference time, but rather constitutes a unified scheduling mechanism through inference time prediction, budget constraints, admission control, cross-cycle recovery, and dynamic model version adaptation, enabling AI inference to run stably within the deterministic scan cycle of the PLC, improving the predictability, scalability, and engineering deployment capability of the industrial intelligent control system.

[0223] Figure 4 The schematic diagram of the cross-scan cycle execution flow of the inference task provided in this application is as follows: Figure 4 As shown, this process fully demonstrates the segmented scheduling and cross-cycle sequential operation logic of intelligent inference tasks for industrial control systems under hard constraints of the scan cycle. The process begins with system initialization. The initialization phase completes preparatory work such as configuring a fixed time budget, loading inference segment partitioning parameters and worst-case execution time calibration values, and deploying the inference time prediction model, providing deterministic benchmark parameters for subsequent real-time scheduling. When the AI ​​inference task arrives at the scheduling node, it first enters a two-stage admission judgment phase. This phase corresponds to the two-level admission control mechanism designed in the scheme: the first stage performs coarse-grained screening based on the overall predicted time of the task and a dynamic time window corrected by a safety margin coefficient to determine the overall feasibility of the task's execution in the current cycle; the second stage performs fine-grained safety verification based on the worst-case execution time of the first inference segment to confirm that the start of a single segment will not cause a scan cycle timeout. Only when both levels of judgment pass and the segment safety start evaluation passes is the inference task allowed to officially start execution in the current cycle; if any level of admission evaluation fails, the task is determined to be unable to run safely in the current cycle, and the task will wait for the next scan cycle to re-participate in the scheduling admission process.

[0224] After admission, the system executes the current inference segment within the available time quota of the current scan cycle, completing the inference computation of the corresponding network layer according to the pre-divided computation segment sequence. Upon completion of a single segment, the system immediately performs a checkpoint save operation, persistently storing state information such as the currently completed layer index, intermediate activation value tensors, and the inference budget time consumed in the current cycle to the controller's storage unit. This completely preserves the intermediate execution state of the inference task, providing a basis for cross-cycle recovery. After checkpoint saving, the process enters a branch decision: if the currently completed segment is the last computation of the inference task, then all computational stages of the entire intelligent inference task are completed, and the process enters the inference completion termination state; if the remaining available time in the current scan cycle is insufficient to support the worst-case execution cost of the next inference segment, the task pauses computation and enters a suspended state waiting for the next scan cycle.

[0225] Upon entering the next scan cycle, the system first performs a checkpoint recovery operation, reading the checkpoint information persistently stored from the previous cycle to fully restore the computational state and execution position of the inference task to their state before the pause. After state recovery, the system performs a dynamic check on the next segment. Based on the real-time remaining time of the current scan cycle and the remaining amount of the fixed time budget, it calculates the currently available time window and, combined with the worst-case execution time of the inference segment to be executed, determines whether the segment can be safely executed within the current cycle. The result of the dynamic check is fed back to the two-stage admission judgment stage. After passing the safety verification, the system continues to execute the next inference segment, thus forming a cyclical execution mechanism across scan cycles. Through a segment-by-segment, cross-cycle continuation scheduling method, the entire intelligent inference task is gradually completed while strictly ensuring the determinism of the industrial control scan cycle and not encroaching on the time resources of the real-time control task.

[0226] The following examples illustrate the specific scheduling process of the intelligent inference scheduling method for industrial control systems. In some embodiments, a PLC control system for an automotive parts assembly line equipped with machine vision quality inspection is used as a specific application scenario. The core business of this scenario is that the PLC receives workpiece image data from an industrial camera in real time, uses a target detection model to complete workpiece position recognition and appearance defect detection, and finally drives a robotic arm to complete automated and precise grasping operations based on the accurate detection results. The entire process requires balancing the hard real-time performance of industrial control with the computational accuracy of AI visual inference, thereby verifying the feasibility and superiority of this scheduling method. The system configuration is shown in the table below:

[0227]

[0228] The PLC's scan cycle T_cycle = 5ms, which includes 0.5ms for input sampling and the sum of the worst-case execution time (WCET) for real-time control tasks such as logic operations and motion control, T_WCET_ctrl = 3.5ms (0.5ms for input sampling + a maximum of 2.8ms for real-time control tasks + 0.2ms for output refresh). A system safety margin T_margin = 0.3ms is set. The inference time of the object detection model fluctuates between 1.2ms and 3.8ms, with a typical inference time of approximately 3.5ms.

[0229] Based on the above scenario, the specific scheduling process of the intelligent reasoning scheduling method may include:

[0230] I. Construction of Offline Preprocessing and Inference Time Prediction Model.

[0231] During the system deployment phase, offline configuration processing is performed on the AI ​​inference model to be deployed. Offline configuration processing includes: inference time prediction model construction, computation segment division, worst-case execution time (WCET) calibration of segments, and generation of multi-level model versions.

[0232] (1) Training of the inference time prediction model:

[0233] Collect at least 5000 sets of inference time data for the target detection model under different input images (different resolutions, different numbers of targets) and different system load conditions. Each set of data includes: input image size (640×480, 1280×720, etc.), number of targets (0-10), current CPU utilization (30%-90%), and actual inference time. Use 70% of the data as the training set and 30% as the test set to train a lightweight regression prediction model to establish an inference time predictor. LightGBM, XGBoost, Random Forest, or other machine learning regression models are preferred. This embodiment uses LightGBM, whose mean absolute percentage error (MAPE) is approximately 8.0%. This model is used to predict the total time T_pred of the entire AI inference task at runtime.

[0234] (2) Segmentation and WCET calibration of AI inference tasks:

[0235] The object detection model is a 24-layer convolutional neural network. Based on T_cycle=5ms and T_WCET_ctrl=3.5ms, the AI ​​time budget T_budget=1.2ms is fixed. The target time limit for a single computation segment is set to T_seg_target=0.95ms (not exceeding the budget of 1.2ms). Starting from the input layer, the computational cost of each layer is accumulated layer by layer. The 24-layer network is divided into 4 computation segments {Seg_1, Seg_2, ..., Seg_4}, with each segment containing 6 convolutional computations. Offline calibration was performed on the target hardware platform, and the worst-case execution time (WCET) and typical execution time for each segment were determined as follows. The WCET for each segment is less than the budget of 1.2ms and is stored in the scheduling information table for runtime lookup. For example, the table corresponds to segment-layer range-WCET(T_WCET_i)-typical execution time. For example, segment Seg_1 corresponds to layers 1-6 -0.82ms-0.74ms; segment Seg_2 corresponds to layers 7-12 -0.88ms-0.81ms; segment Seg_3 corresponds to layers 13-18 -0.91ms-0.84ms; segment Seg_4 corresponds to layers 19-24 -0.79ms-0.73ms.

[0236] (3) Offline preparation of multi-level model versions:

[0237] The system pre-maintains three versions of the object detection model, as shown in the table below:

[0238]

[0239] All versions complete the segmentation and WCET calibration using the method described above. Each model executes across cycles at a fixed budget of 1.2ms / cycle, differing only in the number of cycles required. The model versions described above are for illustrative purposes only and are not limited to three versions.

[0240] II. Bandwidth reservation and time budget management.

[0241] During system initialization, based on T_cycle=5ms, T_WCET_ctrl=3.5ms, and T_margin=0.3ms, the fixed time budget for the AI ​​inference task is calculated: T_budget=T_cycle-T_WCET_ctrl-T_margin=5-3.5-0.3=1.2ms. During operation, T_avail=min(T_remain,T_budget), where T_remain=T_cycle-(t_now-t_start), t_start is the start time of the cycle, and t_now is the completion time of the real-time control task. This design ensures a constant AI advancement rate and decouples it from the actual load of the current cycle control task.

[0242] III. Real-time adaptation selection of multi-level model versions.

[0243] When an AI inference task is pending execution, the model version is selected based on the task type before admission control:

[0244] Visual servo control task (requires real-time feedback) → Lite version (0.8~1.0ms, fastest);

[0245] Routine quality inspection task (default) → Standard version (2.5~3.2ms);

[0246] Offline statistical analysis task (non-real-time) → Accurate version (4.2~4.8ms).

[0247] Once the model is selected, its network structure and T_WCET_i table are locked, and subsequent admission decisions and sharding execution are based on this version.

[0248] IV. Two-stage admission control based on scanning cycle perception.

[0249] In each PLC scan cycle, after all fixed-cycle real-time control tasks have been completed, the following access control procedure is executed. Taking the Standard version (24 layers, total prediction time T_pred=2.9ms, first segment T_WCET_1=0.82ms) as an example: the actual time taken for a certain cycle real-time control task is 3.1ms, then T_remain=5.0-3.1=1.9ms, T_avail=min(1.9,1.2)=1.2ms, α=0.90, and the safe available window α×T_avail=0.90×1.2=1.08ms.

[0250] (1) First stage - Admission judgment based on predicted mean (coarse screening):

[0251] There is an image detection example in the queue of AI inference tasks to be executed. The input image is 640×480, and the current CPU utilization is 45%. Inputting these features into the inference time prediction model (from S201), the total prediction time for the entire inference task in the standard version is T_pred = 2.9ms. The condition is: T_pred = 2.9ms > α·T_avail = 0.9 × 1.2 = 1.08ms, which is not satisfied. Therefore, it is determined that the current scan cycle cannot complete the entire inference instance. This result shows that with a fixed budget of 1.2ms / cycle, the Standard version (2.9ms) requires at least 3 cycles to complete (2.9 ÷ 1.2 ≈ 2.42). For tasks that need to be executed across cycles, the coarse screening does not reject them, but marks them as "needs to be executed across cycles" and proceeds to the fine screening stage. The fine screening logic retained here is used to verify whether the first segment can be safely started in the current cycle.

[0252] If a task is marked as "requires execution across cycles", the system queries T_WCET_1 = 0.82ms. Comparing T_WCET_1 = 0.82ms ≤ α × T_avail = 1.08ms, it passes the fine screening. The system allows the task to start execution in the current cycle and enters the S205 sharding execution process.

[0253] When executing across cycles, the first segment in a subsequent cycle has already been completed, and the coarse screening is recalculated based on the predicted total time of the remaining tasks. For example, if there are 3 segments remaining in the second cycle (approximately 2.2ms), and T_pred_remaining = 2.2ms is still greater than α × T_avail = 1.08ms, the coarse screening fails. However, since the task is already in progress, it passes the fine screening and continues. The coarse screening is used for the initial admission decision. Once a task is started, it enters the execution state, and subsequent cycles do not repeat the complete admission control process. Instead, the segment-level dynamic safety check in S205 determines whether to continue.

[0254] (2) Second stage - Admission judgment based on worst-case execution time of fragments (fine screening):

[0255] The system queries the worst-case execution time T_WCET_1 of the first computation segment Seg_1, which is 0.82ms based on offline calibration. Judgment:

[0256] T_WCET_1 = 0.82ms ≤ α × T_avail = 1.08ms, the condition is met, and the screening passes. The system allows the inference task to start execution in the current cycle and enters the segmented execution flow of S205. The first segment, Seg_1, is executed in this cycle, and the inference context checkpoint is saved after completion. The remaining segments are postponed to subsequent cycles for execution.

[0257] If the fine screening also fails (i.e., T_WCET_1>α×T_avail), it means that the current cycle cannot even safely accommodate the worst case of the first segment. The system rejects the task, postpones it to the next scan cycle, and restarts the admission judgment from the first stage.

[0258] V. Checkpoint-based cross-cycle segmentation execution and dynamic fragment scheduling, such as Figure 5 As shown:

[0259] (1) First scan cycle: The real-time control task is completed (actual time 3.1ms), T_remain=1.9ms, T_avail=min(1.9,1.2)=1.2ms. The scheduler executes Seg_1 (6-layer convolution), which takes 0.74ms. After execution, the checkpoint is saved: current layer index=6, intermediate activation value tensor, timestamp. At this time, the remaining time of this cycle is 1.9-0.74=1.16ms, but T_budget has consumed 0.74ms, leaving a budget of 0.46ms. The scheduler queries the WCET of the next segment Seg_2, which is 0.88ms. It determines that 0.88>0.90×0.46=0.414ms, which does not meet the dynamic safety check, so execution is paused and the remaining segments are postponed to the next cycle.

[0260] (2) Second scan cycle: The real-time control task is completed (actual time 3.0ms), T_remain=2.0ms, T_avail=min(2.0,1.2)=1.2ms. The inference context checkpoint saved in the previous scan cycle is restored, and Seg_2 (6-layer convolution) is executed, with an actual time of 0.81ms. After execution, the checkpoint is saved, and the remaining budget for this cycle is 0.39ms. The scheduler queries the WCET of the next segment Seg_3, which is 0.91ms. It determines that 0.91>0.90×0.39=0.351ms and suspends execution.

[0261] (3) Third scan cycle: Real-time control task completed (actual time 2.9ms), T_remain=2.1ms, T_avail=min(2.1,1.2)=1.2ms. Restore state, execute Seg_3 (6-layer convolution), actual time 0.84ms. Save checkpoint (layer index=18), remaining budget 0.36ms. Query Seg_4 WCET=0.79ms, determine 0.79>0.90×0.36=0.324ms, pause.

[0262] (4) Fourth scan cycle: Real-time control task completed (actual time 3.2ms), T_remain=1.8ms, T_avail=min(1.8,1.2)=1.2ms. Restore state, execute Seg_4 (6-layer convolution), actual time 0.73ms. Inference completed, output detection results (workpiece coordinates, defect type) to motion control module, triggering the robotic arm to perform grasping action.

[0263] Furthermore, in some examples, this application also provides an intelligent reasoning scheduling system for industrial control systems, used to execute the intelligent reasoning scheduling method for industrial control systems as described in the above embodiments. This system may include:

[0264] (1) Offline preprocessing module: Deployed in the development environment or PLC offline configuration tool, used to perform the following before the AI ​​inference task is deployed: training of the inference time prediction model; parsing and segmenting of the AI ​​model computation graph structure; offline calibration and storage of the worst execution time (WCET) of each computation segment; offline preparation of multi-level model versions.

[0265] (2) Inference Time Prediction Module: Deployed in the PLC's coprocessor or embedded AI acceleration unit, this module predicts the total time T_pred for the entire AI inference task based on the characteristics of the input data and the system state. This module has a built-in pre-trained lightweight regression model.

[0266] (3) Time budget management module: It is used to calculate the fixed time budget T_budget of AI inference task based on T_cycle, T_WCET_ctrl and T_margin during system initialization, and calculate the actual available time window T_avail=min(T_remain,T_budget) during operation, monitor the actual execution time of AI inference task, and trigger task pause and checkpoint saving when the budget is exceeded.

[0267] (4) Model version management module: used to store and maintain multiple model versions (lightweight, standard, high precision) for the same AI inference task, and dynamically select the appropriate version according to the current T_avail and the preset threshold, and pass the selected result to the admission control module.

[0268] (5) Admission control module: Synchronized with the scanning cycle clock of PLC, after the real-time control task of each scanning cycle is completed, obtain the T_avail of the current cycle, and perform a two-stage admission judgment - the first stage is a coarse screening based on T_pred, and the second stage is a fine screening based on the first segment T_WCET_1 - to determine whether the reasoning task is started in the current cycle.

[0269] (6) Task Segmentation and Checkpoint Management Module: Used to obtain the sequence of computational segments pre-divided by the offline preprocessing module, save checkpoint information after executing each segment, perform dynamic safety checks based on the next segment T_WCET_{i+1} before executing each segment, persist checkpoints when the task is paused, load checkpoints when the task is resumed and continue execution from the paused position.

[0270] (7) Scheduling execution engine: Coupled with the PLC's real-time operating system, it is responsible for coordinating the work of the above modules, ensuring that the AI ​​inference task is executed in an orderly manner within the T_avail time window of the PLC scan cycle, and does not encroach on the time budget of the real-time control task.

[0271] Inter-module data flow: The offline preprocessing module passes the fragment sequence, the T_WCET_i table for each fragment, and multi-level model version information to the scheduling execution engine and the admission control module; the time budget management module passes T_budget and T_avail to the admission control module and the scheduling execution engine; the inference time prediction module passes the T_pred prediction results to the admission control module; the model version management module passes the selected model version to the admission control module and the scheduling execution engine; the admission control module passes the admission / rejection decision to the scheduling execution engine; the scheduling execution engine calls the task segmentation and checkpoint management module to execute inference based on the admission decision, queries the T_WCET_{i+1} of the next fragment before executing each fragment to perform dynamic safety checks, and triggers checkpoint saving when the cycle ends or the budget is exhausted; the model version management module dynamically switches the model version used for inference before the task starts based on the load assessment results of the scheduling execution engine.

[0272] Hardware Deployment: Preferably, the offline preprocessing module is deployed on the development environment PC; the inference time prediction module and model version management module are deployed on the PLC's ARM coprocessor; the time budget management module, admission control module, task segmentation and checkpoint management module, and scheduling execution engine are deployed on the PLC's main CPU, deeply integrated with the PLC's real-time operating system kernel. Preferably, the programmable logic controller also includes an AI acceleration unit (such as an NPU or FPGA) to accelerate the computation of AI inference tasks. The task segmentation and checkpoint management module dynamically adjusts the granularity of computational segmentation based on the computing power of the AI ​​acceleration unit and the current load.

[0273] Figure 6 A schematic diagram of the structure of the intelligent reasoning scheduling device for industrial control systems provided in this application is shown below. Figure 6 As shown, the intelligent reasoning scheduling device 60 for industrial control systems provided in this embodiment includes:

[0274] The first acquisition module 601 is used to acquire the input data characteristics, model structure parameters, and system status information of the target controller during the current scanning cycle of the intelligent reasoning task;

[0275] The determination module 602 is used to determine the prediction time value of the intelligent reasoning task based on the characteristics of the input data, model structure parameters and system status information, using a preset time prediction model.

[0276] The second acquisition module 603 is used to acquire the dynamic time window of the current scan cycle of the target controller. The dynamic time window is the time quota for executing intelligent inference tasks determined based on a preset fixed time budget and the remaining time of the scan cycle after the periodic real-time control tasks in the target controller are completed within the current scan cycle.

[0277] The judgment module 604 is used to make an admission judgment on the intelligent inference task based on the comparison result between the predicted time consumption value and the dynamic time window, and to determine whether the intelligent inference task is allowed to start execution in the current scanning cycle.

[0278] The processing module 605 is used to respond to the intelligent inference task by passing the admission judgment and to execute the intelligent inference task in segments within the current scanning cycle. The intelligent inference task includes multiple inference segments pre-divided according to the computation graph structure. The segmented execution includes: dynamically selecting whether to execute each inference segment based on a dynamic time window.

[0279] In one possible implementation, the second acquisition module 603 can also be used to: acquire a preset fixed time budget, which is determined by the sum of the preset total scan cycle duration, the worst-case execution time of the real-time control task, and the system safety margin time; acquire the remaining scan cycle time after the target controller executes the real-time control task in the current scan cycle; and take the smaller of the fixed time budget and the remaining scan cycle time to obtain a dynamic time window.

[0280] In one possible implementation, the processing module 605 can also be used to: parse the initial computation graph of the intelligent inference task to obtain a computation graph structure containing multiple neural networks; determine the reference time limit for the inference segment based on the preset scan cycle duration and preset scaling factor of the target controller; accumulate the computational load layer by layer on the computation graph structure based on the reference time limit to determine the estimated time accumulation value, and when the estimated time accumulation value reaches the reference time limit, set a segmentation point at the current accumulation position to pre-divide the intelligent inference task into multiple inference segments; and mark the worst execution time for each inference segment to obtain a set of worst execution times for the segments, which is used for judgment during segmented execution.

[0281] In one possible implementation, the processing module 605 can also be used to: obtain a preset safety margin coefficient, wherein the safety margin coefficient is a value greater than 0 and less than 1; correct the dynamic time window according to the safety margin coefficient to obtain a corrected time window; perform a first comparison process on the predicted time consumption value and the corrected time window to obtain a first comparison result; when the first comparison result indicates that the predicted time consumption value is greater than the corrected time window, determine that the intelligent inference task has not passed the admission judgment, and postpone the intelligent inference task to the next scanning cycle.

[0282] In one possible implementation, the processing module 605 can also be used to: when the first comparison result indicates that the predicted time is less than or equal to the correction time window, determine the first inference segment to be executed by the intelligent inference task from the pre-divided multiple inference segments, and the worst execution time corresponding to the first inference segment; perform a second comparison process on the worst execution time corresponding to the first inference segment and the correction time window to obtain a second comparison result; when the second comparison result indicates that the worst execution time is greater than the correction time window, determine that the intelligent inference task has not passed the admission judgment, and postpone the intelligent inference task to the next scan cycle; when the second comparison result indicates that the worst execution time is less than or equal to the correction time window, determine that the intelligent inference task has passed the admission judgment, and allow the intelligent inference task to start execution in the current scan cycle.

[0283] In one possible implementation, the processing module 605 can also be used to: obtain the target inference segment currently to be executed in the intelligent inference task, and the worst-case execution time corresponding to the target inference segment; obtain the current remaining time of the target controller in the current scan cycle, and the remaining budget value of the fixed time budget at the current moment; perform a minimum operation on the current remaining time and the remaining budget value to obtain the current available time window; compare the worst-case execution time corresponding to the target inference segment with the current available time window to obtain the segment execution judgment result; when the segment execution judgment result indicates that the worst-case execution time is less than or equal to the current available time window, execute the target inference segment; when the segment execution judgment result indicates that the worst-case execution time is greater than the current available time window, pause the execution of the target inference segment, and save the checkpoint information of the current inference state. The checkpoint information is used to restore the execution state of the intelligent inference task in the next scan cycle.

[0284] In one possible implementation, the processing module 605 can also be used to: perform checkpoint saving processing on the current inference state of the intelligent inference task to obtain updated checkpoint information, which includes the layer index that has been calculated, the intermediate activation value tensor, and the inference time consumed in the current scan cycle; and persistently store the updated checkpoint information in the storage unit of the target controller.

[0285] In one possible implementation, the first acquisition module 601 can also be used to: acquire multiple model versions corresponding to the intelligent inference task, wherein the multiple model versions exhibit a gradient distribution in terms of inference accuracy and execution time; for each model version, acquire the worst-case execution time set of segments calibrated at each inference segment granularity, thereby obtaining the version segment time set corresponding to the model version; correspondingly, after acquiring the dynamic time window of the current scanning cycle of the target controller, the method further includes: acquiring a preset first time threshold and a second time threshold, wherein the first time threshold is less than the second time threshold; performing matching processing on the dynamic time window with the first time threshold and the second time threshold to obtain the model version selection result; and determining the target model version from the multiple model versions based on the model version selection result to execute the intelligent inference task, wherein the prediction time value and the worst-case execution time set of segments both correspond to the target model version.

[0286] In one possible implementation, the first acquisition module 601 can also be used to: when the dynamic time window is less than a first time threshold, select the lightweight model with the shortest inference execution time from multiple model versions and determine the lightweight model as the target model version; when the dynamic time window is greater than or equal to the first time threshold and less than a second time threshold, select the standard model from multiple model versions and determine the standard model as the target model version; when the dynamic time window is greater than or equal to the second time threshold, select the high-precision model with the highest inference accuracy from multiple model versions and determine the high-precision model as the target model version.

[0287] In one possible implementation, the processing module 605 can also be used to: monitor the running status of the target controller during the execution of the intelligent inference task and obtain monitoring results; when the monitoring results indicate the existence of a preset abnormal event, suspend the execution of the intelligent inference task and maintain the normal operation of the real-time control task; and perform recovery processing operations according to the abnormal type corresponding to the abnormal event. The recovery processing operations include at least one of the following: reloading the most recently saved valid checkpoint information, switching to the lightweight model with the least inference execution time to re-execute the intelligent inference task, abandoning the intelligent inference task in the current scan cycle and delaying it to the next scan cycle to re-perform the admission judgment, and switching the target controller to traditional control logic.

[0288] The intelligent reasoning and scheduling device for industrial control systems provided in this embodiment can execute the methods provided in the above-described method embodiments. Its implementation principle and technical effects are similar, and will not be described in detail here.

[0289] Figure 7 A schematic diagram of the structure of the electronic device provided in this application, such as a programmable logic controller. Figure 7As shown, the electronic device 70 provided in this embodiment includes at least one processor 701 and a memory 702. Optionally, the device 70 further includes a communication component 703. The processor 701, memory 702, and communication component 703 are connected via a bus 704.

[0290] In a specific implementation, at least one processor 701 executes computer execution instructions stored in memory 702, causing at least one processor 701 to perform the above-described method.

[0291] The specific implementation process of processor 701 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0292] In some examples, the electronic device may also include an AI acceleration unit (such as an NPU or FPGA) to accelerate the computation of AI inference tasks. The aforementioned task segmentation and checkpoint management module dynamically adjusts the granularity of computational segmentation based on the computing power of the AI ​​acceleration unit and the current load. Furthermore, the electronic device is a programmable logic controller (PLC), which is a soft PLC based on ARM or x86 architecture, or a hard PLC based on FPGA.

[0293] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.

[0294] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0295] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0296] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0297] In one example, the computer program may include: (1) program instructions for offline preprocessing and inference time prediction model construction (model training, segmentation, WCET calibration); (2) program instructions for bandwidth reservation and time budget management (T_budget calculation, T_avail calculation); (3) program instructions for real-time adaptation selection of multi-level model versions; (4) program instructions for two-stage admission control with scanning cycle awareness (coarse screening based on T_pred + fine screening based on T_WCET_1); and (5) program instructions for cross-cycle segmentation execution and dynamic segment scheduling based on checkpoints (segment sequence acquisition, dynamic security check before execution, checkpoint saving and restoration).

[0298] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.

[0299] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.

[0300] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.

[0301] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0302] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0303] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0304] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0305] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0306] It should be understood that the terms “comprising” and “having” and any variations thereof used in this application are intended to cover but not exclude inclusion. For example, a product or device that includes a series of components is not necessarily limited to those components that are explicitly listed, but may include other components that are not explicitly listed or that are inherent to such product or device.

[0307] As used in this application, the term "module" means any known or subsequently developed hardware, software, firmware, artificial intelligence, fuzzy logic, or combination of hardware and / or software code capable of performing the functions associated with that element.

[0308] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope.

Claims

1. An intelligent reasoning scheduling method for an industrial control system, characterized in that, include: Acquire the input data characteristics, model structure parameters, and system state information of the target controller during the current scanning cycle of the intelligent inference task; Based on the input data characteristics, the model structure parameters, and the system state information, the predicted time consumption value of the intelligent reasoning task is determined using a preset time prediction model. The dynamic time window of the current scan cycle of the target controller is obtained. The dynamic time window is the time quota for executing the intelligent inference task, which is determined based on a preset fixed time budget and the remaining time of the scan cycle after the periodic real-time control task in the target controller is completed within the current scan cycle. Based on the comparison between the predicted time consumption value and the dynamic time window, an admission judgment is made on the intelligent inference task to determine whether the intelligent inference task is allowed to start execution in the current scanning cycle. In response to the intelligent inference task passing the admission judgment, the intelligent inference task is executed in segments within the current scanning cycle, wherein the intelligent inference task includes multiple inference segments pre-divided according to the computation graph structure, and the segmented execution includes: dynamically selecting whether to execute each inference segment based on the dynamic time window.

2. The method of claim 1, wherein, The step of obtaining the dynamic time window of the current scan cycle of the target controller includes: Obtain a preset fixed time budget, which is determined by the preset total duration of the scanning cycle, the sum of the worst-case execution time of the real-time control task, and the system safety margin time. Obtain the remaining scan cycle time after the target controller executes the real-time control task within the current scan cycle; The dynamic time window is obtained by taking the smaller of the fixed time budget and the remaining time of the scanning cycle.

3. The method of claim 1, wherein, The multiple reasoning segments are pre-divided in the following way: The initial computation graph of the intelligent reasoning task is parsed to obtain a computation graph structure containing multiple neural networks; Based on the preset scan cycle duration and preset scaling factor of the target controller, the reference time limit for the inference segment is determined; Based on the reference time limit, the computational amount is accumulated layer by layer in the computation graph structure to determine the estimated time accumulation value. When the estimated time accumulation value reaches the reference time limit, a split point is set at the current accumulation position to pre-divide the intelligent reasoning task into the multiple reasoning segments. The worst-case execution time is assigned to each inference segment to obtain a set of worst-case execution times for each segment. This set of worst-case execution times is used for judgment during the segmented execution process.

4. The method of claim 3, wherein, The step of performing an admission judgment on the intelligent inference task based on the comparison result between the predicted time consumption value and the dynamic time window, and determining whether to allow the intelligent inference task to start execution within the current scanning cycle, includes: Obtain a preset safety margin coefficient, wherein the safety margin coefficient is a value greater than 0 and less than 1; The dynamic time window is corrected based on the safety margin coefficient to obtain the corrected time window; The predicted time consumption value and the corrected time window are compared in a first comparison process to obtain a first comparison result; When the first comparison result indicates that the prediction time is greater than the correction time window, it is determined that the intelligent inference task has not passed the admission judgment, and the intelligent inference task is postponed to the next scan cycle.

5. The method of claim 4, wherein, The method further includes: When the first comparison result indicates that the predicted time consumption value is less than or equal to the corrected time window, the first inference segment to be executed by the intelligent inference task and the worst execution time corresponding to the first inference segment are determined from the pre-divided plurality of inference segments. A second comparison process is performed between the worst-case execution time corresponding to the first inference segment and the corrected time window to obtain a second comparison result; When the second comparison result indicates that the worst execution time is greater than the corrected time window, it is determined that the intelligent inference task has not passed the admission judgment, and the intelligent inference task is postponed to the next scan cycle; When the second comparison result indicates that the worst execution time is less than or equal to the corrected time window, the intelligent inference task is determined to have passed the admission judgment, and the intelligent inference task is allowed to start execution within the current scan cycle.

6. The method of claim 1, wherein, The dynamic selection of whether to execute each inference segment based on the dynamic time window includes: Obtain the target inference segment currently to be executed in the intelligent inference task, and the worst execution time corresponding to the target inference segment; Obtain the current remaining time of the target controller in the current scan cycle, and the remaining budget value of the fixed time budget at the current moment; The current available time window is obtained by taking the smaller of the current remaining time and the remaining budget value. The worst-case execution time corresponding to the target inference segment is compared with the currently available time window to obtain the segment execution judgment result; When the execution result of the segment indicates that the worst execution time is less than or equal to the current available time window, the target inference segment is executed; When the execution result of the segment indicates that the worst execution time is greater than the current available time window, the execution of the target inference segment is paused, and the checkpoint information of the current inference state is saved. The checkpoint information is used to restore the execution state of the intelligent inference task in the next scan cycle.

7. The method of claim 6, wherein, After executing the target inference segment, the method further includes: The current inference state of the intelligent inference task is saved by checkpoint processing to obtain updated checkpoint information. The updated checkpoint information includes the layer index that has been calculated, the intermediate activation value tensor, and the inference time consumed in the current scan cycle. The updated checkpoint information is persistently stored in the storage unit of the target controller.

8. The method according to any one of claims 1 to 7, characterized in that, Before acquiring the input data features, model structure parameters, and system state information of the target controller during the current scanning cycle of the intelligent inference task, the method further includes: Obtain multiple model versions corresponding to the intelligent inference task, wherein the multiple model versions exhibit a gradient distribution in terms of inference accuracy and execution time; For each model version, obtain the worst execution time set of the segments labeled at each inference segment granularity for that model version, and obtain the version segment time set corresponding to that model version; Accordingly, after obtaining the dynamic time window of the current scan cycle of the target controller, the method further includes: Obtain a preset first time threshold and a second time threshold, wherein the first time threshold is less than the second time threshold; The dynamic time window is matched with the first time threshold and the second time threshold to obtain the model version selection result. Based on the model version selection result, a target model version is determined from the plurality of model versions to execute the intelligent inference task, wherein the prediction time value and the worst execution time set of the segment both correspond to the target model version.

9. The method of claim 8, wherein, The process of matching the dynamic time window with the first time threshold and the second time threshold to obtain the model version selection result includes: When the dynamic time window is less than the first time threshold, the lightweight model with the shortest inference execution time is selected from the multiple model versions, and the lightweight model is determined as the target model version. When the dynamic time window is greater than or equal to the first time threshold and less than the second time threshold, a standard model is selected from the plurality of model versions, and the standard model is determined as the target model version. When the dynamic time window is greater than or equal to the second time threshold, the high-precision model with the highest inference accuracy is selected from the multiple model versions, and the high-precision model is determined as the target model version.

10. The method according to any one of claims 1-7, characterized in that, The method further includes: During the execution of the intelligent reasoning task, the operating status of the target controller is monitored, and monitoring results are obtained; When the monitoring results indicate the presence of a preset abnormal event, the execution of the intelligent reasoning task is paused, while the normal operation of the real-time control task is maintained; Based on the anomaly type corresponding to the abnormal event, a recovery processing operation is performed, which includes at least one of the following: reloading the most recently saved valid checkpoint information, switching to the lightweight model with the least inference execution time to re-execute the intelligent inference task, abandoning the intelligent inference task in the current scan cycle and delaying it to the next scan cycle to re-perform the admission judgment, and switching the target controller to the traditional control logic.