2024-01-10 04:29:58 +00:00
|
|
|
package llm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-03-26 20:04:17 +00:00
|
|
|
"github.com/ollama/ollama/gpu"
|
2024-01-10 04:29:58 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetDynLibs(t *testing.T) {
|
|
|
|
availableDynLibs = map[string]string{
|
|
|
|
"cpu": "X_cpu",
|
|
|
|
}
|
|
|
|
assert.Equal(t, false, rocmDynLibPresent())
|
|
|
|
res := getDynLibs(gpu.GpuInfo{Library: "cpu"})
|
|
|
|
assert.Len(t, res, 1)
|
|
|
|
assert.Equal(t, availableDynLibs["cpu"], res[0])
|
|
|
|
|
2024-01-11 22:43:16 +00:00
|
|
|
variant := gpu.GetCPUVariant()
|
|
|
|
if variant != "" {
|
|
|
|
variant = "_" + variant
|
|
|
|
}
|
2024-01-10 04:29:58 +00:00
|
|
|
availableDynLibs = map[string]string{
|
2024-01-11 22:43:16 +00:00
|
|
|
"rocm_v5": "X_rocm_v5",
|
|
|
|
"rocm_v6": "X_rocm_v6",
|
|
|
|
"cpu" + variant: "X_cpu",
|
2024-01-10 04:29:58 +00:00
|
|
|
}
|
|
|
|
assert.Equal(t, true, rocmDynLibPresent())
|
|
|
|
res = getDynLibs(gpu.GpuInfo{Library: "rocm"})
|
|
|
|
assert.Len(t, res, 3)
|
|
|
|
assert.Equal(t, availableDynLibs["rocm_v5"], res[0])
|
|
|
|
assert.Equal(t, availableDynLibs["rocm_v6"], res[1])
|
2024-01-11 22:43:16 +00:00
|
|
|
assert.Equal(t, availableDynLibs["cpu"+variant], res[2])
|
2024-01-10 04:29:58 +00:00
|
|
|
|
|
|
|
res = getDynLibs(gpu.GpuInfo{Library: "rocm", Variant: "v6"})
|
|
|
|
assert.Len(t, res, 3)
|
|
|
|
assert.Equal(t, availableDynLibs["rocm_v6"], res[0])
|
|
|
|
assert.Equal(t, availableDynLibs["rocm_v5"], res[1])
|
2024-01-11 22:43:16 +00:00
|
|
|
assert.Equal(t, availableDynLibs["cpu"+variant], res[2])
|
2024-01-10 04:29:58 +00:00
|
|
|
|
|
|
|
res = getDynLibs(gpu.GpuInfo{Library: "cuda"})
|
|
|
|
assert.Len(t, res, 1)
|
2024-01-11 22:43:16 +00:00
|
|
|
assert.Equal(t, availableDynLibs["cpu"+variant], res[0])
|
2024-01-10 04:29:58 +00:00
|
|
|
|
|
|
|
res = getDynLibs(gpu.GpuInfo{Library: "default"})
|
|
|
|
assert.Len(t, res, 1)
|
|
|
|
assert.Equal(t, "default", res[0])
|
|
|
|
|
|
|
|
availableDynLibs = map[string]string{
|
2024-01-11 22:43:16 +00:00
|
|
|
"rocm": "X_rocm_v5",
|
|
|
|
"cpu" + variant: "X_cpu",
|
2024-01-10 04:29:58 +00:00
|
|
|
}
|
|
|
|
assert.Equal(t, true, rocmDynLibPresent())
|
|
|
|
res = getDynLibs(gpu.GpuInfo{Library: "rocm", Variant: "v6"})
|
|
|
|
assert.Len(t, res, 2)
|
|
|
|
assert.Equal(t, availableDynLibs["rocm"], res[0])
|
2024-01-11 22:43:16 +00:00
|
|
|
assert.Equal(t, availableDynLibs["cpu"+variant], res[1])
|
2024-01-10 04:29:58 +00:00
|
|
|
}
|