e3c8979e8d
- 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>
71 lines
2.4 KiB
Markdown
71 lines
2.4 KiB
Markdown
---
|
|
name: get_gpu_info
|
|
kind: function
|
|
lang: go
|
|
domain: infra
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "func GetGpuInfo() ([]GpuInfo, error)"
|
|
description: "Consulta GPUs NVIDIA via nvidia-smi y retorna un slice de GpuInfo con index, nombre, VRAM total/libre, driver y version CUDA. Si nvidia-smi no esta instalado o no hay GPU NVIDIA, retorna slice vacio y nil (ausencia de hardware no es error)."
|
|
tags: [gpu, nvidia, cuda, hardware, infra, probe]
|
|
uses_functions: []
|
|
uses_types: ["gpu_info_go_infra"]
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [encoding/csv, errors, fmt, os/exec, strconv, strings]
|
|
params:
|
|
- name: (ninguno)
|
|
desc: "No toma parametros. Lee el estado del sistema via nvidia-smi."
|
|
output: "Slice de GpuInfo con una entrada por GPU detectada. Slice vacio si no hay GPUs NVIDIA o nvidia-smi no esta instalado. Error solo si nvidia-smi existe pero falla inesperadamente al parsear la salida CSV."
|
|
tested: true
|
|
tests:
|
|
- "retorna slice vacio y nil cuando no hay GPU NVIDIA"
|
|
- "linea GPU RTX 3080 tipica"
|
|
- "dos GPUs en el CSV"
|
|
- "CSV vacio retorna slice vacio"
|
|
- "linea con menos de 6 campos se ignora"
|
|
- "espacios extra en los valores se eliminan"
|
|
- "campos del struct GpuInfo correctos"
|
|
test_file_path: "functions/infra/get_gpu_info_test.go"
|
|
file_path: "functions/infra/get_gpu_info.go"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```go
|
|
gpus, err := GetGpuInfo()
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
if len(gpus) == 0 {
|
|
fmt.Println("No NVIDIA GPUs detected")
|
|
} else {
|
|
for _, g := range gpus {
|
|
fmt.Printf("[%d] %s VRAM: %d/%d MiB Driver: %s CUDA: %s\n",
|
|
g.Index, g.Name, g.VramFreeMb, g.VramTotalMb,
|
|
g.DriverVersion, g.CudaVersion)
|
|
}
|
|
}
|
|
```
|
|
|
|
## Salida nvidia-smi
|
|
|
|
Ejecuta:
|
|
```
|
|
nvidia-smi --query-gpu=index,name,memory.total,memory.free,driver_version,cuda_version --format=csv,noheader,nounits
|
|
```
|
|
|
|
Ejemplo de salida con una GPU:
|
|
```
|
|
0, NVIDIA GeForce RTX 3080, 10240, 8192, 550.54.15, 12.4
|
|
```
|
|
|
|
## Notas
|
|
|
|
- Requiere `nvidia-smi` en PATH (parte del driver NVIDIA).
|
|
- La columna `cuda_version` en nvidia-smi refleja la version maxima de CUDA soportada por el driver, no la del toolkit instalado.
|
|
- Para comprobar el toolkit CUDA instalado, usar `cuda_toolkit_check_bash_infra`.
|
|
- En maquinas sin GPU NVIDIA retorna `([]GpuInfo{}, nil)` — el caller puede tratar esto como "sin GPU disponible".
|
|
- No ejecutar tests automatizados para esta funcion en CI sin GPU; verificar manualmente o con mock.
|