This paper presents a templated approach for automatic generation of optimized library functions using Halide as a replacement for the functions generated by Simulink. Although Simulink is widely used for the development of embedded systems, the automatically generated code may have limitations in compute-intensive models. Therefore, we propose library function generation using Halide from prewritten templates, extracting the Simulink model parameters using a model-based parallelizer. Experiments were conducted on central processing units (CPUs) and graphical processing units (GPUs) to evaluate performance. On CPUs, compared with compiler vectorization and the basic linear algebra subprograms (BLAS) library, Halide achieved up to 65.77 times speedup in multi-core and up to 36.20 times speedup in single-core scenarios. Although Halide did not always outperform BLAS for larger matrix sizes, it still showed considerable improvements. On GPUs, experiments on MX450 and Jetson platforms demonstrated that Halide’s performance was comparable to that of cuBLAS and even surpassed it for larger matrices.