Skip to content

Commit 1b9eed8

Browse files
committed
native: add Adreno device constraints for OpenCL backend
Signed-off-by: Jacob Howard <jacob.howard@docker.com>
1 parent 183b92b commit 1b9eed8

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

pkg/inference/backends/llamacpp/gpuinfo_windows.go

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,53 @@ func hasCUDA11CapableGPU(ctx context.Context, nvGPUInfoBin string) (bool, error)
5858
return false, nil
5959
}
6060

61+
// supportedAdrenoGPUVersions are the Adreno versions supported by llama.cpp.
62+
// See (and keep in sync with):
63+
// https://github.com/ggml-org/llama.cpp/blob/43ddab6eeeaab5a04fe5a364af0bafb0e4d35065/ggml/src/ggml-opencl/ggml-opencl.cpp#L180-L196
64+
var supportedAdrenoGPUVersions = []string{
65+
"730",
66+
"740",
67+
"750",
68+
"830",
69+
"X1",
70+
}
71+
72+
func hasSupportedAdrenoGPU() (bool, error) {
73+
gpus, err := ghw.GPU()
74+
if err != nil {
75+
return false, err
76+
}
77+
for _, gpu := range gpus.GraphicsCards {
78+
isAdrenoFamily := strings.Contains(gpu.DeviceInfo.Product.Name, "Adreno") ||
79+
strings.Contains(gpu.DeviceInfo.Product.Name, "Qualcomm")
80+
if !isAdrenoFamily {
81+
continue
82+
}
83+
for _, version := range supportedAdrenoGPUVersions {
84+
if strings.Contains(gpu.DeviceInfo.Product.Name, version) {
85+
return true, nil
86+
}
87+
}
88+
}
89+
return false, nil
90+
}
91+
6192
func hasOpenCL() (bool, error) {
93+
// We compile our llama.cpp backend with Adreno-specific kernels, so for now
94+
// we don't support OpenCL on other GPUs.
95+
adrenoGPU, err := hasSupportedAdrenoGPU()
96+
if !adrenoGPU || err != nil {
97+
return false, err
98+
}
99+
100+
// Check for an OpenCL implementation.
62101
opencl, err := syscall.LoadLibrary("OpenCL.dll")
63102
if err != nil {
64103
if errors.Is(err, syscall.ERROR_MOD_NOT_FOUND) {
65104
return false, nil
66105
}
67106
return false, fmt.Errorf("unable to load OpenCL DLL: %w", err)
68107
}
69-
// We could perform additional platform and device version checks here (if
70-
// we scaffold out the relevant OpenCL API datatypes in Go), but since users
71-
// can opt-out of GPU support, we can probably skip that and just let users
72-
// disable it if things don't work. Alternatively, we could inspect the GPUs
73-
// found by the ghw package, if it supports (e.g.) Adreno GPUs.
74108
syscall.FreeLibrary(opencl)
75109
return true, nil
76110
}

0 commit comments

Comments
 (0)