amd_common.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. if _, skipped := skip[i]; skipped {
  39. continue
  40. }
  41. devices = append(devices, strconv.Itoa(i))
  42. }
  43. val := strings.Join(devices, ",")
  44. err := os.Setenv("HIP_VISIBLE_DEVICES", val)
  45. if err != nil {
  46. slog.Warn(fmt.Sprintf("failed to set env: %s", err))
  47. } else {
  48. slog.Info("Setting HIP_VISIBLE_DEVICES=" + val)
  49. }
  50. }