mirror of
https://github.com/ollama/ollama.git
synced 2026-04-18 08:13:29 +02:00
* prefer rocm v6 on windows Avoid building with v7 - more changes are needed * MLX: add header vendoring and remove go build tag This switches to using a vendoring approach for the mlx-c headers so that Go can build without requiring a cmake first. This enables building the new MLX based code by default. Every time cmake runs, the headers are refreshed, so we can easily keep them in sync when we bump mlx versions. Basic Windows and Linux support are verified. * ci: harden for flaky choco repo servers CI sometimes fails due to choco not actually installing cache. Since it just speeds up the build, we can proceed without. * review comments
60 lines
1.2 KiB
Go
60 lines
1.2 KiB
Go
package mlx
|
|
|
|
// #include "generated.h"
|
|
import "C"
|
|
|
|
import (
|
|
"log/slog"
|
|
"sync"
|
|
)
|
|
|
|
type Device struct {
|
|
ctx C.mlx_device
|
|
}
|
|
|
|
func (d Device) LogValue() slog.Value {
|
|
str := C.mlx_string_new()
|
|
defer C.mlx_string_free(str)
|
|
C.mlx_device_tostring(&str, d.ctx)
|
|
return slog.StringValue(C.GoString(C.mlx_string_data(str)))
|
|
}
|
|
|
|
var DefaultDevice = sync.OnceValue(func() Device {
|
|
d := C.mlx_device_new()
|
|
C.mlx_get_default_device(&d)
|
|
return Device{d}
|
|
})
|
|
|
|
// GPUIsAvailable returns true if a GPU device is available.
|
|
func GPUIsAvailable() bool {
|
|
dev := C.mlx_device_new_type(C.MLX_GPU, 0)
|
|
defer C.mlx_device_free(dev)
|
|
var avail C.bool
|
|
C.mlx_device_is_available(&avail, dev)
|
|
return bool(avail)
|
|
}
|
|
|
|
// SetDefaultDeviceGPU sets the default MLX device to GPU.
|
|
func SetDefaultDeviceGPU() {
|
|
dev := C.mlx_device_new_type(C.MLX_GPU, 0)
|
|
C.mlx_set_default_device(dev)
|
|
C.mlx_device_free(dev)
|
|
}
|
|
|
|
type Stream struct {
|
|
ctx C.mlx_stream
|
|
}
|
|
|
|
func (s Stream) LogValue() slog.Value {
|
|
str := C.mlx_string_new()
|
|
defer C.mlx_string_free(str)
|
|
C.mlx_stream_tostring(&str, s.ctx)
|
|
return slog.StringValue(C.GoString(C.mlx_string_data(str)))
|
|
}
|
|
|
|
var DefaultStream = sync.OnceValue(func() Stream {
|
|
s := C.mlx_stream_new()
|
|
C.mlx_get_default_stream(&s, DefaultDevice().ctx)
|
|
return Stream{s}
|
|
})
|