# CUDA error: invalid program counter (cudaErrorInvalidPc)

- **ID:** `cuda/cuda-error-invalid-pc`
- **Domain:** cuda
- **Category:** runtime_error
- **Error Code:** `cudaErrorInvalidPc (805)`
- **Verification:** ai_generated
- **Fix Rate:** 75%

## Root Cause

The GPU attempted to execute a kernel with an invalid program counter, typically due to a corrupted device function pointer, a miscompiled kernel, or an out-of-bounds jump in device code (e.g., from a misused function pointer or indirect call).

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CUDA 12.4 | active | — | — |
| CUDA 12.6 | active | — | — |
| NVIDIA Driver 550.54.10 | active | — | — |
| NVIDIA Driver 560.35.03 | active | — | — |
| PyTorch 2.5.0 | active | — | — |

## Workarounds

1. **Compile the kernel with `-lineinfo` and run with `cuda-memcheck` or `compute-sanitizer` to identify the exact source line causing the invalid jump: `compute-sanitizer --tool memcheck ./my_app`** (85% success)
   ```
   Compile the kernel with `-lineinfo` and run with `cuda-memcheck` or `compute-sanitizer` to identify the exact source line causing the invalid jump: `compute-sanitizer --tool memcheck ./my_app`
   ```
2. **Avoid using function pointers in device code if possible; replace them with switch statements or templates to eliminate indirect jumps.** (80% success)
   ```
   Avoid using function pointers in device code if possible; replace them with switch statements or templates to eliminate indirect jumps.
   ```
3. **Ensure all device function pointers are initialized correctly and not left as null or garbage. For example, in CUDA C++: `typedef void (*func_t)(); func_t f = &my_device_func;`** (75% success)
   ```
   Ensure all device function pointers are initialized correctly and not left as null or garbage. For example, in CUDA C++: `typedef void (*func_t)(); func_t f = &my_device_func;`
   ```

## Dead Ends

- **** — The error occurs during kernel execution, not during API calls; post-hoc checks do not prevent the invalid program counter from being reached. (80% fail)
- **** — Scheduling policy does not affect kernel correctness; the invalid PC is a code bug, not a synchronization issue. (90% fail)
