Skripsi
OPTIMASI KERNEL CUDA BERBASIS MEMORY-AWARE UNTUK SELF-ATTENTION PADA INFERENSI LLM
The self-attention mechanism in Large Language Models (LLMs) is computationally intensive and memory-bound, posing significant challenges for inference on consumer-grade hardware. This research proposes a memory-aware optimization of CUDA kernels for the self-attention mechanism within the GPT-2 architecture, integrating Shared Memory Tiling, Streaming Softmax, and Kernel Fusion to minimize global memory traffic and reduce kernel launch overhead. The implementation was developed using CUDA C++ and Python, validated against a PyTorch baseline on an NVIDIA RTX 3050 GPU. Experimental results on matrices of varying sizes show consistent optimization gains, with the 4096 × 4096 configuration yielding the most pronounced improvements: the fully fused kernel achieves a 3.44× speedup over the naive baseline (mean execution time reduced from 24.86 ms to 7.22 ms, averaged over 100 runs) and reduces peak memory usage by 89.3% (from 141.12 MB to 15.12 MB) by eliminating intermediate attention matrices. Numerical stability was confirmed with a negligible Mean Absolute Error (MAE) of approximately 10⁻⁸. These findings demonstrate that low-level kernel fusion significantly enhances memory efficiency and inference speed on consumer-grade GPUs.