# CUDA error: invalid sync object (cudaErrorInvalidSyncObject)

- **ID:** `cuda/cuda-error-invalid-sync-object`
- **Domain:** cuda
- **Category:** runtime_error
- **Error Code:** `cudaErrorInvalidSyncObject (806)`
- **Verification:** ai_generated
- **Fix Rate:** 80%

## Root Cause

A CUDA synchronization object (e.g., cudaExternalSemaphore or cudaEvent) was passed to an API that expects a valid, initialized object, but the object was destroyed, never created, or created on a different device context.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| CUDA 12.5 | active | — | — |
| CUDA 12.7 | active | — | — |
| NVIDIA Driver 560.35.03 | active | — | — |
| NVIDIA Driver 565.57.01 | active | — | — |
| PyTorch 2.6.0 | active | — | — |

## Workarounds

1. **Verify that the sync object is created on the correct device context. For example, in CUDA C++: `cudaSetDevice(deviceId); cudaEvent_t event; cudaEventCreate(&event);` Ensure all subsequent uses of `event` are on the same device.** (85% success)
   ```
   Verify that the sync object is created on the correct device context. For example, in CUDA C++: `cudaSetDevice(deviceId); cudaEvent_t event; cudaEventCreate(&event);` Ensure all subsequent uses of `event` are on the same device.
   ```
2. **Check if the sync object has been destroyed before reuse. Implement a wrapper that tracks the object's lifetime: `if (event) { cudaEventDestroy(event); event = nullptr; }`** (80% success)
   ```
   Check if the sync object has been destroyed before reuse. Implement a wrapper that tracks the object's lifetime: `if (event) { cudaEventDestroy(event); event = nullptr; }`
   ```
3. **For external semaphores, ensure the import handle is valid and the driver supports the semaphore type. Use `cudaImportExternalSemaphore` with a properly initialized `cudaExternalSemaphoreHandleDesc`.** (75% success)
   ```
   For external semaphores, ensure the import handle is valid and the driver supports the semaphore type. Use `cudaImportExternalSemaphore` with a properly initialized `cudaExternalSemaphoreHandleDesc`.
   ```

## Dead Ends

- **** — Synchronizing the device does not recreate or validate the sync object; it only waits for pending operations to complete. (70% fail)
- **** — The error is about an invalid object handle, not resource exhaustion; more streams do not fix a null or cross-context object. (85% fail)
