# scope_profiler.gpu_timing

*module*

Optional CUDA-event timing backends for asynchronous GPU work.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L1-L1)

## scope_profiler.gpu_timing.CuPyCUDATimingBackend

*class*

```python
class CuPyCUDATimingBackend
```

CUDA-event timing through CuPy's current CUDA stream.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L52-L90)

### scope_profiler.gpu_timing.CuPyCUDATimingBackend.name

*attribute* · *class attribute* · *instance attribute*

```python
name = 'cupy'
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L55-L55)

### scope_profiler.gpu_timing.CuPyCUDATimingBackend.elapsed_time_ns

*method*

```python
def elapsed_time_ns(start_event, end_event) -> int
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L83-L90)

### scope_profiler.gpu_timing.CuPyCUDATimingBackend.record_event

*method*

```python
def record_event()
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L74-L77)

### scope_profiler.gpu_timing.CuPyCUDATimingBackend.synchronize

*method*

```python
def synchronize() -> None
```

Wait for all work on the current CUDA device.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L79-L81)

## scope_profiler.gpu_timing.GPUTimingBackend

*class*

```python
class GPUTimingBackend(Protocol)
```

Bases: `Protocol`

Minimal backend contract used by GPU-timed regions.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L8-L17)

### scope_profiler.gpu_timing.GPUTimingBackend.name

*attribute* · *instance attribute*

```python
name: str
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L11-L11)

### scope_profiler.gpu_timing.GPUTimingBackend.elapsed_time_ns

*method*

```python
def elapsed_time_ns(start_event, end_event) -> int
```

Return elapsed device time between two events in nanoseconds.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L16-L17)

### scope_profiler.gpu_timing.GPUTimingBackend.record_event

*method*

```python
def record_event()
```

Record and return an event on the backend's current CUDA stream.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L13-L14)

## scope_profiler.gpu_timing.TorchCUDATimingBackend

*class*

```python
class TorchCUDATimingBackend
```

CUDA-event timing through PyTorch's current CUDA stream.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L20-L49)

### scope_profiler.gpu_timing.TorchCUDATimingBackend.name

*attribute* · *class attribute* · *instance attribute*

```python
name = 'torch'
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L23-L23)

### scope_profiler.gpu_timing.TorchCUDATimingBackend.elapsed_time_ns

*method*

```python
def elapsed_time_ns(start_event, end_event) -> int
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L47-L49)

### scope_profiler.gpu_timing.TorchCUDATimingBackend.record_event

*method*

```python
def record_event()
```

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L38-L41)

### scope_profiler.gpu_timing.TorchCUDATimingBackend.synchronize

*method*

```python
def synchronize() -> None
```

Wait for all work on the current CUDA device.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L43-L45)

## scope_profiler.gpu_timing.resolve_gpu_timing_backend

*function*

```python
def resolve_gpu_timing_backend(backend='auto') -> GPUTimingBackend
```

Resolve a CUDA timing backend name or validate a backend-like object.

[View source](https://github.com/max-models/scope-profiler/blob/devel/src/scope_profiler/gpu_timing.py#L93-L130)
