shim_ext_server_linux.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package llm
  2. import (
  3. "embed"
  4. "errors"
  5. "fmt"
  6. "io/fs"
  7. "log"
  8. "os"
  9. "strings"
  10. )
  11. //go:embed llama.cpp/gguf/build/*/*/lib/*.so
  12. var libEmbed embed.FS
  13. func updatePath(dir string) {
  14. pathComponents := strings.Split(os.Getenv("PATH"), ":")
  15. for _, comp := range pathComponents {
  16. if comp == dir {
  17. return
  18. }
  19. }
  20. newPath := strings.Join(append(pathComponents, dir), ":")
  21. log.Printf("Updating PATH to %s", newPath)
  22. os.Setenv("PATH", newPath)
  23. }
  24. func verifyDriverAccess() error {
  25. // Only check ROCm access if we have the dynamic lib loaded
  26. if _, rocmPresent := AvailableShims["rocm"]; rocmPresent {
  27. // Verify we have permissions - either running as root, or we have group access to the driver
  28. fd, err := os.OpenFile("/dev/kfd", os.O_RDWR, 0666)
  29. if err != nil {
  30. if errors.Is(err, fs.ErrPermission) {
  31. return fmt.Errorf("Radeon card detected, but permissions not set up properly. Either run ollama as root, or add you user account to the render group.")
  32. } else if errors.Is(err, fs.ErrNotExist) {
  33. // expected behavior without a radeon card
  34. return nil
  35. }
  36. return fmt.Errorf("failed to check permission on /dev/kfd: %w", err)
  37. }
  38. fd.Close()
  39. }
  40. return nil
  41. }