The CUDA Toolkit allows developers to write parallel programs that run directly on NVIDIA GPUs. When writing the core execution code (known as kernels) that runs on the GPU's streaming multiprocessors, which programming language is natively used?
Select an answer to reveal the explanation.
Short Explanation and Infographic
Okay, let's clear up a common misconception here. You'll see Python used all the time in machine learning libraries like PyTorch or TensorFlow. But under the hood, when you write the actual GPU kernel—the code that runs directly on the hardware—it's written in C/C++. NVIDIA built CUDA as an extension of C/C++. You compile it with nvcc (the NVIDIA compiler) to generate code the GPU can run. Python and Java might call these functions, but C/C++ is the native language of the CUDA kernel. Keep this straight for the exam: PyTorch is Python, but CUDA kernels are C/C++!
Full explanation below image
Full Explanation
NVIDIA's Compute Unified Device Architecture (CUDA) is a parallel computing platform and programming model. It extends standard programming languages to allow developers to write kernels—functions that are executed in parallel by thousands of GPU threads.
The primary and native programming language used for writing CUDA kernels is C/C++. Developers write code containing special CUDA keywords, which is then compiled using the NVIDIA CUDA Compiler (nvcc) into PTX (Parallel Thread Execution) assembly code that runs on the GPU.
Let's look at the other languages: - Python is widely used in high-level machine learning frameworks (like PyTorch and TensorFlow), but these libraries act as wrappers. The underlying performance-critical kernels they call are written in C/C++ and compiled via CUDA. - Java is a managed, bytecode-compiled language that runs inside a Virtual Machine (JVM). It cannot natively compile into GPU instruction sets, although wrappers (like JCuda) exist to interface with compiled C/C++ CUDA binaries. - Fortran has a variant called CUDA Fortran (developed by PGI/NVIDIA), but it is a niche language primarily used in legacy scientific computing, not the primary or standard language for the general CUDA Toolkit.