diff --git a/gpu/README.md b/gpu/README.md index fae96005a9..38d5479934 100644 --- a/gpu/README.md +++ b/gpu/README.md @@ -30,8 +30,8 @@ $ go run cogentcore.org/core/gpu/cmd/webgpuinfo@latest The following environment variables can be set to specifically select a particular device by device number or name (`deviceName`): -* `GPU_DEVICE_SELECT`, for GUI and compute usage. -* `GPU_COMPUTE_DEVICE_SELECT`, only used for compute, if present, will override above, so you can use different GPUs for graphics vs compute. +* `GPU_DEVICE`, for GUI and compute usage. +* `GPU_COMPUTE_DEVICE`, only used for compute, if present, will override above, so you can use different GPUs for graphics vs compute. * `GPU` represents the hardware `Adapter` and maintains global settings, info about the hardware. diff --git a/gpu/cmd/webgpuinfo/main.go b/gpu/cmd/webgpuinfo/main.go index 0348dc7e47..a59356be03 100644 --- a/gpu/cmd/webgpuinfo/main.go +++ b/gpu/cmd/webgpuinfo/main.go @@ -9,6 +9,7 @@ import ( "fmt" "cogentcore.org/core/base/reflectx" + "cogentcore.org/core/gpu" "github.com/cogentcore/webgpu/wgpu" ) @@ -16,6 +17,12 @@ func main() { instance := wgpu.CreateInstance(nil) gpus := instance.EnumerateAdapters(nil) + gp := gpu.NewGPU(nil) + gpIndex := gp.SelectGPU(gpus) + props := gpus[gpIndex].GetInfo() + fmt.Println("Default WebGPU Adapter number:", gpIndex, " Type:", props.AdapterType.String(), " Backend:", props.BackendType.String()) + fmt.Println("Set the GPU_DEVICE environment variable to an adapter number to select a different GPU") + for i, a := range gpus { props := a.GetInfo() fmt.Println("\n#####################################################################") diff --git a/gpu/gpu.go b/gpu/gpu.go index c6ba084b55..58d0f301e9 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -14,7 +14,6 @@ import ( "strconv" "strings" - "cogentcore.org/core/base/errors" "cogentcore.org/core/base/reflectx" "github.com/cogentcore/webgpu/wgpu" ) @@ -86,7 +85,7 @@ type GPU struct { Limits wgpu.SupportedLimits // ComputeOnly indicates if this GPU is only used for compute, - // which determines if it listens to GPU_COMPUTE_DEVICE_SELECT + // which determines if it listens to GPU_COMPUTE_DEVICE // environment variable, allowing different compute devices to be // selected vs. graphics devices. ComputeOnly bool @@ -115,7 +114,7 @@ func NewGPU(sf *wgpu.Surface) *GPU { // NewComputeGPU returns a new GPU, configured and ready to use, // for purely compute use, which causes it to listen to -// use the GPU_COMPUTE_DEVICE_SELECT variable for which GPU device to use. +// use the GPU_COMPUTE_DEVICE variable for which GPU device to use. func NewComputeGPU() *GPU { gp := &GPU{} gp.ComputeOnly = true @@ -132,15 +131,21 @@ func (gp *GPU) init(sf *wgpu.Surface) error { gpIndex = gp.SelectGPU(gpus) gp.GPU = gpus[gpIndex] } else { - opts := &wgpu.RequestAdapterOptions{ - CompatibleSurface: sf, - PowerPreference: wgpu.PowerPreferenceHighPerformance, - } - ad, err := inst.RequestAdapter(opts) - if errors.Log(err) != nil { - return err - } - gp.GPU = ad + gpus := inst.EnumerateAdapters(nil) + gpIndex = gp.SelectGPU(gpus) + gp.GPU = gpus[gpIndex] + // note: below is a more standard way of doing it, but until we fix the issues + // with NVIDIA adapters on linux (#1247), we are using our custom logic. + // + // opts := &wgpu.RequestAdapterOptions{ + // CompatibleSurface: sf, + // PowerPreference: wgpu.PowerPreferenceHighPerformance, + // } + // ad, err := inst.RequestAdapter(opts) + // if errors.Log(err) != nil { + // return err + // } + // gp.GPU = ad } gp.Properties = gp.GPU.GetInfo() gp.DeviceName = adapterName(&gp.Properties) @@ -213,11 +218,11 @@ func (gp *GPU) SelectGPU(gpus []*wgpu.Adapter) int { return 0 } trgDevNm := "" - if ev := os.Getenv("GPU_DEVICE_SELECT"); ev != "" { + if ev := os.Getenv("GPU_DEVICE"); ev != "" { trgDevNm = ev } if gp.ComputeOnly { - if ev := os.Getenv("GPU_COMPUTE_DEVICE_SELECT"); ev != "" { + if ev := os.Getenv("GPU_COMPUTE_DEVICE"); ev != "" { trgDevNm = ev } } @@ -236,13 +241,13 @@ func (gp *GPU) SelectGPU(gpus []*wgpu.Adapter) int { if strings.Contains(pnm, trgDevNm) { devNm := props.Name if Debug { - log.Printf("wgpu: selected device named: %s, specified in *_DEVICE_SELECT environment variable, index: %d\n", devNm, gi) + log.Printf("gpu: selected device named: %s, specified in GPU_DEVICE or GPU_COMPUTE_DEVICE environment variable, index: %d\n", devNm, gi) } return gi } } if Debug { - log.Printf("vgpu: unable to find device named: %s, specified in *_DEVICE_SELECT environment variable\n", trgDevNm) + log.Printf("gpu: unable to find device named: %s, specified in GPU_DEVICE or GPU_COMPUTE_DEVICE environment variable\n", trgDevNm) } }