通用大语言模型用于基础线性代数子程序代码生成的性能评估
Performance Evaluation of General Purpose Large Language Models for Basic Linear Algebra Subprograms Code Generation
AI总结:
本文评估了GPT-4.1和o4-mini两个通用大语言模型生成BLAS代码的能力,发现仅凭例程名称即可在多数情况下生成正确代码,并能实现线程并行化、SIMD向量化和缓存分块等优化,且生成代码性能优于参考实现。
摘要:
基于大语言模型(LLM)的生成式人工智能技术已被开发并应用于辅助或自动生成程序代码。本文评估了现有通用大语言模型在面向CPU的基础线性代数子程序(BLAS)代码生成方面的能力。我们使用OpenAI提供的两个大语言模型:GPT-4.1,一种生成式预训练Transformer(GPT)模型,以及o4-mini,o系列推理模型之一。两者均于2025年4月发布。针对从第1级到第3级的BLAS例程,我们尝试生成:(1)仅根据例程名称生成未经优化的C代码;(2)仅根据例程名称生成具有基本性能优化(线程并行化、SIMD向量化和缓存分块)的C代码;(3)基于Fortran参考代码生成具有基本性能优化的C代码。结果表明,在许多情况下,即使仅给出例程名称,也能生成正确的代码。我们还确认,基于OpenMP的线程并行化、SIMD向量化和缓存分块可以在一定程度上实现,并且生成的代码比参考代码更快。
英文摘要:
Generative AI technology based on Large Language Models (LLM) has been developed and applied to assist or automatically generate program codes. In this paper, we evaluate the capability of existing general LLMs for Basic Linear Algebra Subprograms (BLAS) code generation for CPUs. We use two LLMs provided by OpenAI: GPT-4.1, a Generative Pre-trained Transformer (GPT) model, and o4-mini, one of the o-series of Reasoning models. Both have been released in April 2025. For the routines from level-1 to 3 BLAS, we tried to generate (1) C code without optimization from routine name only, (2) C code with basic performance optimizations (thread parallelization, SIMD vectorization, and cache blocking) from routine name only, and (3) C code with basic performance optimizations based on Fortran reference code. As a result, we found that correct code can be generated in many cases even when only routine name are given. We also confirmed that thread parallelization with OpenMP, SIMD vectorization, and cache blocking can be implemented to some extent, and that the code is faster than the reference code.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。