{"id":24309,"library":"pycuda","title":"PyCUDA","description":"PyCUDA is a Python wrapper for Nvidia CUDA. It provides access to Nvidia's CUDA parallel computation API from Python. The latest version is 2026.1 (requires Python ~=3.8). Release cadence is roughly semi-annual.","status":"active","version":"2026.1","language":"python","source_language":"en","source_url":"https://github.com/inducer/pycuda","tags":["cuda","gpgpu","gpu-computing","nvidia"],"install":[{"cmd":"pip install pycuda","lang":"bash","label":"PyPI"}],"dependencies":[{"reason":"Required for array operations and data transfer.","package":"numpy","optional":false},{"reason":"Used for metaprogramming and caching.","package":"pytools","optional":false},{"reason":"CUDA drivers and runtime (system-level).","package":"cuda-toolkit","optional":true}],"imports":[{"note":"Standard import to automatically initialize CUDA context.","symbol":"AutoInit","correct":"import pycuda.autoinit"},{"note":"Common mistake: use `import pycuda.driver as cuda` to avoid shadowing built-in `driver`.","wrong":"from pycuda import driver","symbol":"driver","correct":"import pycuda.driver as cuda"},{"note":"SourceModule is not in the top-level pycuda package.","wrong":"from pycuda import SourceModule","symbol":"compiler.SourceModule","correct":"from pycuda.compiler import SourceModule"}],"quickstart":{"code":"import pycuda.autoinit\nimport pycuda.driver as cuda\nimport numpy as np\nfrom pycuda.compiler import SourceModule\n\nmod = SourceModule(\"\"\"\n__global__ void add_one(float *a)\n{\n    int idx = threadIdx.x;\n    a[idx] += 1.0f;\n}\n\"\"\")\n\nadd_one = mod.get_function(\"add_one\")\na = np.float32([1.0, 2.0, 3.0])\nadd_one(cuda.InOut(a), block=(32,1,1), grid=(1,1))\nprint(a)","lang":"python","description":"Kernel that adds 1 to each element of a float array."},"warnings":[{"fix":"Upgrade to pycuda>=2025.1.2 or use CUDA 12.x.","message":"CUDA 13.x compatibility: PyCUDA v2025.1.2 added a fix for cuCtxCreate API change. Earlier versions may crash with CUDA 13.","severity":"breaking","affected_versions":"<2025.1.2"},{"fix":"Use `platformdirs` instead of `appdirs`.","message":"appdirs replaced by platformdirs in v2024.1.1; if you depend on appdirs directly, update your imports.","severity":"deprecated","affected_versions":">=2024.1.1"},{"fix":"Always wrap arrays with the appropriate flag: `cuda.InOut(a)` for read-write.","message":"Memory transfers require explicit use of `cuda.In`, `cuda.Out`, `cuda.InOut`, or `cuda.mem_alloc`/`cuda.memcpy_htod`. Simply passing numpy arrays will not work.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Check `nvidia-smi` for GPU presence; install CUDA toolkit and driver.","cause":"No compatible GPU or CUDA drivers not installed.","error":"pycuda.driver.Error: CUDA_ERROR_NO_DEVICE"},{"fix":"Run `pip install pycuda`.","cause":"PyCUDA not installed in current Python environment.","error":"ModuleNotFoundError: No module named 'pycuda'"},{"fix":"Ensure CUDA toolkit is installed and `LD_LIBRARY_PATH` includes CUDA's `lib64` directory.","cause":"CUDA driver library not found in library path.","error":"ImportError: libcuda.so.1: cannot open shared object file"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}