Files
fn_registry/python/functions/ml/cuda_available.md
T
egutierrez a802f59f55 chore: auto-commit (95 archivos)
- cmd/fn/doctor.go
- cmd/fn/main.go
- cpp/apps/primitives_gallery/playground/tables/CMakeLists.txt
- cpp/apps/primitives_gallery/playground/tables/data_table.cpp
- cpp/apps/primitives_gallery/playground/tables/data_table_logic.cpp
- cpp/apps/primitives_gallery/playground/tables/data_table_logic.h
- cpp/apps/primitives_gallery/playground/tables/self_test.cpp
- cpp/apps/primitives_gallery/playground/tables/tql.cpp
- cpp/apps/primitives_gallery/playground/tables/viz.cpp
- cpp/apps/primitives_gallery/playground/tables/viz.h
- ...

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-13 00:50:34 +02:00

68 lines
1.9 KiB
Markdown

---
name: cuda_available
kind: function
lang: py
domain: ml
version: "1.0.0"
purity: impure
signature: "def cuda_available() -> dict"
description: "Detecta si CUDA esta disponible via torch. Devuelve device_count, nombres de GPU y version de CUDA. Si torch no esta instalado, retorna available=False sin lanzar excepcion."
tags: [cuda, gpu, torch, pytorch, hardware, probe, ml, device]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: "error_go_core"
imports: []
params: []
output: "dict con claves: available (bool), device_count (int), devices (list[str] con nombres de GPU), torch_version (str o 'not_installed'), cuda_version (str | None)"
tested: true
tests:
- "sin torch retorna available=False y torch_version=not_installed"
- "con torch sin cuda retorna available=False y device_count=0"
- "claves del dict siempre presentes"
test_file_path: "python/functions/ml/tests/test_cuda_available.py"
file_path: "python/functions/ml/cuda_available.py"
---
## Ejemplo
```python
from ml.cuda_available import cuda_available
info = cuda_available()
# Sin GPU:
# {
# "available": False,
# "device_count": 0,
# "devices": [],
# "torch_version": "2.3.0",
# "cuda_version": None
# }
# Con GPU:
# {
# "available": True,
# "device_count": 1,
# "devices": ["NVIDIA RTX 4090"],
# "torch_version": "2.3.0",
# "cuda_version": "12.1"
# }
# Sin torch instalado:
# {
# "available": False,
# "device_count": 0,
# "devices": [],
# "torch_version": "not_installed",
# "cuda_version": None
# }
```
## Notas
- Nunca lanza ImportError aunque torch no este instalado.
- `cuda_version` es la version de CUDA con la que fue compilado torch, no necesariamente la del sistema.
- Usar junto a `torch_device_select` para elegir device y `gpu_info` para estadisticas de VRAM.
- impure: depende del estado del hardware y de librerias del sistema en tiempo de ejecucion.