# Using Graphics Processing Units and Compute Shaders in Real Time Multimodel Adaptive Robust Control

^{*}

## Abstract

**:**

## 1. Introduction

## 2. Materials and Methods

#### 2.1. GPU Hardware Overview

#### 2.2. Computations of System Outputs

#### 2.3. Using the Compute Shader

- gl_NumWorkGroups, contains the number of work groups requested by the dispatch call.
- gl_WorkGroupID represents the current work group.
- gl_LocalInvocationID represents the thread index inside the current work group.
- gl_GlobalInvocationID uniquely identifies the current thread among all threads in all work groups.
- gl_LocalInvocationIndex is the 1D normalization of the position of the thread within the work group.

- Create an openGL Program. Programs are objects that are used to apply shaders in the graphics pipeline.
- Create a pointer to the compute shader.
- Set the source of the shader. The shader can be precompiled before the application is run or it can be compiled at runtime. In this case, it was chosen to compile the shader at runtime.
- Compile the shader (not necessary if it was precompiled).
- Attach the shader to the Program object.
- Link the Program object.
- Install the Program in the graphics pipeline.
- Generate the buffers that will be used for passing data to and from the GPU, with the appropriate target type (like ShadderStorageBuffer) and usage mask (e.g., the write bit and invalidate buffer bit). For efficiency, the same input buffer can also be used for output.
- Fill the buffers with the appropriate input data.
- Call the glDispatchCompute method with the desire parameters.
- Read the results from the output buffers.

## 3. Results

## 4. Discussion

## 5. Conclusions

## Author Contributions

## Funding

## Acknowledgments

## Conflicts of Interest

## References

- Popescu, D.; Gharbi, A.; Stefanoiu, D.; Borne, P. Process Control Design for Industrial Applications; John Wiley & Sons: Hoboken, NJ, USA, 2017. [Google Scholar]
- Afshar, S.; Paunonen, L. Adaptive robust output regulation control design. In Proceedings of the 2019 American Control Conference (ACC), Philadelphia, PA, USA, 10–12 July 2019. [Google Scholar]
- Liu, K.Z.; Yao, Y. Robust Control: Theory and Applications; John Wiley & Sons: Hoboken, NJ, USA, 2016. [Google Scholar]
- Lupu, C.; Borne, P.; Popescu, D. Multi-model adaptive control for nonlinear system. J. Control Eng. Appl. Inform.
**2007**, 40, 108–112. [Google Scholar] [CrossRef] - Narendra, K.S.; Driollet, O.A.; Feiler, M.; George, K. Adaptive control using multiple models, switching, and tuning. Int. J. Adapt. Control Signal Process.
**2003**, 17, 87–102. [Google Scholar] [CrossRef] - Lupu, C.; Mihai, C.C.; Secuianu, F.D.; Petrescu, C. Fast Disturbance Rejection in MIMO Process Based on Algorithms Switching. In Proceedings of the 2018 22nd International Conference on System Theory, Control and Computing (ICSTCC), Sinaia, Romania, 10–12 October 2018. [Google Scholar]
- Li, W.; Ke, H. Adaptive control using multiple models without switching. J. Theor. Appl. Inf. Technol.
**2013**, 53, 229–235. [Google Scholar] - Mihai, C.C.; Lupu, C.; Secuianu, D.; Vulpe, A. Implementing high performance system simulators using modern graphics rendering devices: Implementing system control algorithms on graphics hardware. In Proceedings of the 14th International Conference on Engineering of Modern Electric Systems (EMES), Oradea, Romania, 1–2 June 2017. [Google Scholar]
- Narendra, K.S.; Han, Z. Adaptive Control Using Collective Information Obtained from Multiple Model. IFAC Proc. Vol.
**2011**, 44, 362–367. [Google Scholar] [CrossRef] [Green Version] - Narendra, K.S.; Balakrishnan, J. Adaptive Control Using Multiple Models. IEEE Trans. Autom. Control
**1997**, 42, 171–187. [Google Scholar] [CrossRef] - Khronos Group. Rendering Pipeline Overview. Available online: https://www.khronos.org/opengl/wiki/Rendering_Pipeline_Overview (accessed on 15 July 2021).
- Khronos Group. Compute Shader. 2019. Available online: www.khronos.org/opengl/wiki/Compute_Shader (accessed on 16 July 2021).
- nVidia. Nvidia Turing Gpu Architecture Whitepaper. 2019. Available online: https://images.nvidia.com/aem-dam/en-zz/Solutions/design-visualization/technologies/turing-architecture/NVIDIA-Turing-Architecture-Whitepaper.pdf (accessed on 15 May 2021).
- Microsoft Corporation. Compute Shader Overview. 31 May 2018. Available online: https://docs.microsoft.com/en-us/windows/win32/direct3d11/direct3d-11-advanced-stages-compute-shader (accessed on 15 July 2021).
- Microsoft Corporation. Pipeline Stages (Direct3D 10). 31 May 2018. Available online: https://docs.microsoft.com/en-us/windows/win32/direct3d10/d3d10-graphics-programming-guide-pipeline-stages (accessed on 15 July 2021).
- Microsoft Corporation. Accessing Resources. Available online: https://docs.microsoft.com/en-us/windows/win32/direct3d11/direct3d-11-advanced-stages-cs-access (accessed on 17 July 2021).
- Mihai, C.C.; Lupu, C.; Vulpe, A.A. Using graphics processing units and openGL in adaptive-robust real time control. In Proceedings of the 2020 12th International Conference on Electronics, Computers and Artificial Intelligence (ECAI), Bucharest, Romania, 25–27 June 2020. [Google Scholar]
- MathWorks. PID Tuning Algorithm for Linear Plant Model. Available online: https://www.mathworks.com/help/control/ref/lti.pidtune.html (accessed on 10 August 2021).
- MathWorks. Calling MATLAB as COM Automation Server. Available online: https://www.mathworks.com/help/matlab/call-matlab-com-automation-server.html (accessed on 10 August 2021).
- Microsoft Corporation. Visual Studio Community. Available online: https://visualstudio.microsoft.com/vs/community/ (accessed on 3 February 2021).
- Gliga, L.I.; Mihai, C.C.; Lupu, C.; Popescu, D. Adaptive—Robust control a computational efficient real time simulation. In Proceedings of the 2015 13th International Conference on Engineering of Modern Electric Systems (EMES), Oradea, Romania, 11–12 June 2015. [Google Scholar]
- Khronos Group. Shader Compilation. Available online: www.khronos.org/opengl/wiki/Shader_Compilation (accessed on 16 July 2021).
- Lupu, C.; Petrescu, C.; Popescu, D. Practical Solution for Software Implementation of Algorithms Switching in Multiple Models Control Systems. In Proceedings of the CSCS15—Control Systems and Computer Science, Bucharest, 25–27 May 2005. [Google Scholar]

**Figure 1.**Example of working regimes a plane may encounter during its trip. Depending on weather conditions and drive path, several different controllers might be needed for its direction system.

**Figure 2.**Overview of multimodel control scheme. The blue blocks on the left represents the algorithm selector block; the yellow and green blocks on the top right represents the model selection block. A model is chosen using inputs from the real process. Based on the chosen model, a control algorithm is chosen to issue new commands to the process.

**Figure 3.**Detailed view of a work group of an nVidia Turing GPU. The group consists of arithmetic cores split into two subgroups and several support units that perform advanced mathematical operations (such as trigonometric operations) [13].

**Figure 4.**Overview of a compute shader dispatch. The top figure shows the layout of working groups with a glDispachCompute(4, 3, 2) invocation. There are 24 total work groups. The bottom figure shows the zoomed in layout of a work group, with local_size_x = 3, local_size_y = 2, local_size_z = 2. Each work group therefore contains 12 threads. The glDispatchCompute invocation resulted in a total of 288 threads running in parallel.

**Figure 5.**Overview of the work group layout of the compute shader used to calculate the switching criterion, with local_size_x = 1024, local_size_y = local_size_z = 1. Each box represents an instance of the data structure associated with a nominal model used to pass information to and from the GPU.

**Figure 7.**Evolution of the real plant and the nominal models after exposing the real plant to perturbations.

**Figure 8.**Evolution of the real plant and the nominal models after exposing the real plant to perturbations, switching from model 3 to model 2.

**Figure 9.**Evolution of the real plant and the nominal models after exposing the real plant to perturbations, with output measurement noise.

**Figure 10.**Evolution of the real plant and the nominal models after exposing the real plant to perturbations, switching from model 3 to model 2, with measurement noise.

**Figure 12.**Switching from the initial model to cached model 1 and then to cached model 2, a poorly dumped second order transfer function.

**Figure 13.**A series of switches between various models, mixed structural and parametric perturbances with noisy output measurements.

**Table 1.**Performance figures for compute shaders with various number of elements. Performance is subject to variations based on hardware specifications, its power state, operating system, and driver version. All values are averages over 600 samples. Memory copy from GPU to CPU also involves converting raw bytes to the data structures describing model state, which is why it is slightly slower and consumes the better part of the GPU operation.

No. of Models | Input Buffer Create | Compute Dispatch | Memory Copy from GPU to CPU |
---|---|---|---|

100 | ~0.0202 ms | ~0.3998 ms | ~1.2346 ms |

1000 | ~0.0365 ms | ~0.5479 ms | ~2.8668 ms |

10,000 | ~0.1506 ms | ~1.3838 ms | ~18.5257 ms |

Publisher’s Note: MDPI stays neutral with regard to jurisdictional claims in published maps and institutional affiliations. |

© 2021 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).

## Share and Cite

**MDPI and ACS Style**

Mihai, C.-C.; Lupu, C.
Using Graphics Processing Units and Compute Shaders in Real Time Multimodel Adaptive Robust Control. *Electronics* **2021**, *10*, 2462.
https://doi.org/10.3390/electronics10202462

**AMA Style**

Mihai C-C, Lupu C.
Using Graphics Processing Units and Compute Shaders in Real Time Multimodel Adaptive Robust Control. *Electronics*. 2021; 10(20):2462.
https://doi.org/10.3390/electronics10202462

**Chicago/Turabian Style**

Mihai, Cosmin-Constantin, and Ciprian Lupu.
2021. "Using Graphics Processing Units and Compute Shaders in Real Time Multimodel Adaptive Robust Control" *Electronics* 10, no. 20: 2462.
https://doi.org/10.3390/electronics10202462