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 glo…