Files
AetherForge/agent/miner/pyopencl_linux.go

49 lines
1.3 KiB
Go

//go:build linux
package miner
import (
"fmt"
"os/exec"
"strings"
)
// DetectCUDA reports NVIDIA CUDA via nvidia-smi.
func DetectCUDA() bool {
out, err := exec.Command("nvidia-smi", "-L").CombinedOutput()
return err == nil && strings.TrimSpace(string(out)) != ""
}
// DetectPyOpenCL reports python3 + PyOpenCL import success.
func DetectPyOpenCL() bool {
err := exec.Command("python3", "-c", "import pyopencl").Run()
return err == nil
}
// StartPyOpenCLTier attempts a one-shot OpenCL probe via python3 -c (no external miner exe).
// Returns error when PyOpenCL is absent or the probe fails — chain advances to stratum_direct.
func StartPyOpenCLTier(cfg config.RuntimeConfig) error {
if !DetectPyOpenCL() {
return fmt.Errorf("python3 pyopencl not available")
}
script := `
import pyopencl as cl
platforms = cl.get_platforms()
if not platforms:
raise SystemExit('no opencl platforms')
devices = platforms[0].get_devices()
if not devices:
raise SystemExit('no opencl devices')
print('pyopencl_ok')
`
out, err := exec.Command("python3", "-c", script).CombinedOutput()
if err != nil {
return fmt.Errorf("pyopencl probe: %v (%s)", err, strings.TrimSpace(string(out)))
}
if !strings.Contains(string(out), "pyopencl_ok") {
return fmt.Errorf("pyopencl probe unexpected output")
}
_ = cfg
return nil
}