2024-01-10 04:29:58 +00:00
|
|
|
package gpu
|
|
|
|
|
|
|
|
import (
|
2024-08-05 19:56:20 +00:00
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
|
2024-01-10 04:29:58 +00:00
|
|
|
"golang.org/x/sys/cpu"
|
|
|
|
)
|
|
|
|
|
2024-06-05 19:07:20 +00:00
|
|
|
func GetCPUCapability() CPUCapability {
|
2024-01-10 04:29:58 +00:00
|
|
|
if cpu.X86.HasAVX2 {
|
2024-05-15 22:13:16 +00:00
|
|
|
return CPUCapabilityAVX2
|
2024-01-10 04:29:58 +00:00
|
|
|
}
|
|
|
|
if cpu.X86.HasAVX {
|
2024-05-15 22:13:16 +00:00
|
|
|
return CPUCapabilityAVX
|
2024-01-10 04:29:58 +00:00
|
|
|
}
|
|
|
|
// else LCD
|
2024-06-05 19:07:20 +00:00
|
|
|
return CPUCapabilityNone
|
2024-01-10 04:29:58 +00:00
|
|
|
}
|
2024-08-05 19:56:20 +00:00
|
|
|
|
|
|
|
func IsNUMA() bool {
|
|
|
|
if runtime.GOOS != "linux" {
|
|
|
|
// numa support in llama.cpp is linux only
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
ids := map[string]interface{}{}
|
|
|
|
packageIds, _ := filepath.Glob("/sys/devices/system/cpu/cpu*/topology/physical_package_id")
|
|
|
|
for _, packageId := range packageIds {
|
|
|
|
id, err := os.ReadFile(packageId)
|
|
|
|
if err == nil {
|
|
|
|
ids[strings.TrimSpace(string(id))] = struct{}{}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len(ids) > 1
|
|
|
|
}
|