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>
87 lines
3.5 KiB
Markdown
87 lines
3.5 KiB
Markdown
---
|
|
name: gpu_check
|
|
kind: function
|
|
lang: cpp
|
|
domain: gfx
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "bool fn_gfx::gpu_check_caps(GpuCaps& out)"
|
|
description: "Rellena GpuCaps con las capacidades del contexto OpenGL activo: vendor, renderer, version, limites de compute workgroup, flags has_compute_shader/has_storage_buffer, y version CUDA runtime (deteccion en compile-time via CUDART_VERSION). Requiere contexto GL activo. Retorna false si el contexto no esta disponible."
|
|
tags: [gpu, opengl, cuda, caps, hardware, probe, gfx, compute, infra]
|
|
uses_functions: ["gl_loader_cpp_gfx"]
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: [gfx/gpu_check.h, gfx/gl_loader.h, cuda_runtime.h, cstring, string]
|
|
tested: false
|
|
tests: []
|
|
test_file_path: ""
|
|
file_path: "cpp/functions/gfx/gpu_check.cpp"
|
|
framework: opengl
|
|
params:
|
|
- name: out
|
|
desc: "Referencia a GpuCaps que se rellena con las capacidades detectadas. Se resetea al inicio de la llamada."
|
|
output: "true si el contexto GL esta activo y gl_vendor no esta vacio; false si no hay contexto GL activo o el driver devuelve nullptr para GL_VENDOR."
|
|
---
|
|
|
|
# gpu_check
|
|
|
|
Probing de capacidades GPU en runtime: OpenGL strings, compute shader support y CUDA.
|
|
|
|
## Uso tipico
|
|
|
|
```cpp
|
|
#include "gfx/gpu_check.h"
|
|
#include "gfx/gl_loader.h"
|
|
|
|
// Dentro de render(), despues del primer frame (contexto GL activo):
|
|
fn::gfx::GpuCaps caps;
|
|
if (fn::gfx::gpu_check_caps(caps)) {
|
|
printf("GPU: %s\n", caps.gl_renderer.c_str());
|
|
printf("Compute shaders: %s\n", caps.has_compute_shader ? "yes" : "no");
|
|
if (!caps.cuda_runtime_version.empty())
|
|
printf("CUDA runtime: %s\n", caps.cuda_runtime_version.c_str());
|
|
} else {
|
|
printf("No GL context active\n");
|
|
}
|
|
```
|
|
|
|
## Estructura GpuCaps
|
|
|
|
```cpp
|
|
struct GpuCaps {
|
|
std::string gl_vendor; // "NVIDIA Corporation"
|
|
std::string gl_renderer; // "NVIDIA GeForce RTX 3080/PCIe/SSE2"
|
|
std::string gl_version; // "4.6.0 NVIDIA 550.54.15"
|
|
int max_compute_workgroup_count[3]; // [65535, 65535, 65535] tipico NVIDIA
|
|
int max_compute_workgroup_size[3]; // [1024, 1024, 64] tipico
|
|
bool has_compute_shader; // GL 4.3+ o ARB_compute_shader
|
|
bool has_storage_buffer; // GL 4.3+ o ARB_shader_storage_buffer_object
|
|
std::string cuda_runtime_version; // "12.4" o "" si no compilado con CUDA
|
|
};
|
|
```
|
|
|
|
## CUDA detection
|
|
|
|
La version CUDA se detecta en **compile time** via el macro `CUDART_VERSION` de `<cuda_runtime.h>`. Si la app no esta compilada con el CUDA toolkit, `cuda_runtime_version` sera `""`. Para detection en runtime del toolkit del sistema, usar `cuda_toolkit_check_bash_infra`.
|
|
|
|
## Requisito de contexto GL
|
|
|
|
Llamar siempre despues de crear el contexto GL. En apps que usan `fn::run_app`, el contexto esta activo desde el primer frame del `render()` callback. En Windows, `fn::gfx::gl_loader_init()` debe haberse llamado antes para que los punteros de funcion esten resueltos.
|
|
|
|
## Uso previsto (fn doctor cpp-apps)
|
|
|
|
Esta funcion sera invocada por el audit de `fn doctor cpp-apps` para verificar que las apps C++ del registry tienen acceso a compute shaders cuando declaran dependencias de `gpu_compute_program`, `gpu_dispatch`, etc.
|
|
|
|
## CMakeLists.txt
|
|
|
|
```cmake
|
|
add_imgui_app(mi_app
|
|
main.cpp
|
|
${CMAKE_SOURCE_DIR}/cpp/functions/gfx/gpu_check.cpp
|
|
)
|
|
# CUDA opcional: si la app compila con CUDA toolkit el header cuda_runtime.h
|
|
# estara disponible y FN_HAS_CUDA_RUNTIME se activara automaticamente.
|
|
```
|