Lesson 3: Environment Variables & LD_LIBRARY_PATH
Environment variables are the way Linux passes configuration settings to running programs. CUDA will not find libcuda.so without the correct LD_LIBRARY_PATH, and CUDA_VISIBLE_DEVICES determines which GPUs each program sees — a critical multi-GPU scheduling tool at NVIDIA. (The concept of a 'process'
Environment variables are like a message board outside every room: the kernel posts instructions there like 'search for libraries in /usr/local/cuda/lib64' and 'only use GPUs 0 and 1'. Every process reads the board before it starts running.
- Environment Variable
- A key-value pair the kernel passes to every process. A process can read, set, and pass environment variables to its child processes.
- PATH
- An environment variable containing a colon-separated list of directories. When you type a command, the shell searches for the binary in each directory in order.
- LD_LIBRARY_PATH
- A variable defining directories to search for shared libraries (.so) at runtime. The dynamic linker (ld.so) searches these directories before /usr/lib.
- CUDA_VISIBLE_DEVICES
- A variable defining which GPU cards are visible to a CUDA process. CUDA_VISIBLE_DEVICES=0,1 hides GPUs 2,3 from the process — essential for scheduling in multi-GPU environments.
- export
- A bash command that marks a variable as an environment variable so it is passed to child processes. Without export, the variable is visible only to the current shell process.