amd_common.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //go:build linux || windows
  2. package gpu
  3. import (
  4. "fmt"
  5. "log/slog"
  6. "os"
  7. "path/filepath"
  8. "strconv"
  9. "strings"
  10. )
  11. // Determine if the given ROCm lib directory is usable by checking for existence of some glob patterns
  12. func rocmLibUsable(libDir string) bool {
  13. slog.Debug("evaluating potential rocm lib dir " + libDir)
  14. for _, g := range ROCmLibGlobs {
  15. res, _ := filepath.Glob(filepath.Join(libDir, g))
  16. if len(res) == 0 {
  17. return false
  18. }
  19. }
  20. return true
  21. }
  22. func GetSupportedGFX(libDir string) ([]string, error) {
  23. var ret []string
  24. files, err := filepath.Glob(filepath.Join(libDir, "rocblas", "library", "TensileLibrary_lazy_gfx*.dat"))
  25. if err != nil {
  26. return nil, err
  27. }
  28. for _, file := range files {
  29. ret = append(ret, strings.TrimSuffix(strings.TrimPrefix(filepath.Base(file), "TensileLibrary_lazy_"), ".dat"))
  30. }
  31. return ret, nil
  32. }
  33. func amdSetVisibleDevices(ids []int, skip map[int]interface{}) {
  34. // Set the visible devices if not already set
  35. // TODO - does sort order matter?
  36. devices := []string{}
  37. for i := range ids {
  38. slog.Debug(fmt.Sprintf("i=%d", i))
  39. if _, skipped := skip[i]; skipped {
  40. slog.Debug("skipped")
  41. continue
  42. }
  43. devices = append(devices, strconv.Itoa(i))
  44. }
  45. slog.Debug(fmt.Sprintf("devices=%v", devices))
  46. val := strings.Join(devices, ",")
  47. err := os.Setenv("HIP_VISIBLE_DEVICES", val)
  48. if err != nil {
  49. slog.Warn(fmt.Sprintf("failed to set env: %s", err))
  50. }
  51. slog.Debug("HIP_VISIBLE_DEVICES=" + val)
  52. }