mirror of
https://github.com/ollama/ollama.git
synced 2026-04-18 09:54:18 +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
90 lines
1.5 KiB
Go
90 lines
1.5 KiB
Go
package mlx
|
|
|
|
// #include "generated.h"
|
|
import "C"
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"strconv"
|
|
)
|
|
|
|
func (b Byte) String() string {
|
|
return strconv.FormatInt(int64(b), 10) + " B"
|
|
}
|
|
|
|
func (b KibiByte) String() string {
|
|
return strconv.FormatFloat(float64(b)/(1<<10), 'f', 2, 64) + " KiB"
|
|
}
|
|
|
|
func (b MebiByte) String() string {
|
|
return strconv.FormatFloat(float64(b)/(1<<(2*10)), 'f', 2, 64) + " MiB"
|
|
}
|
|
|
|
func (b GibiByte) String() string {
|
|
return strconv.FormatFloat(float64(b)/(1<<(3*10)), 'f', 2, 64) + " GiB"
|
|
}
|
|
|
|
func (b TebiByte) String() string {
|
|
return strconv.FormatFloat(float64(b)/(1<<(4*10)), 'f', 2, 64) + " TiB"
|
|
}
|
|
|
|
func PrettyBytes(n int) fmt.Stringer {
|
|
switch {
|
|
case n < 1<<10:
|
|
return Byte(n)
|
|
case n < 1<<(2*10):
|
|
return KibiByte(n)
|
|
case n < 1<<(3*10):
|
|
return MebiByte(n)
|
|
case n < 1<<(4*10):
|
|
return GibiByte(n)
|
|
default:
|
|
return TebiByte(n)
|
|
}
|
|
}
|
|
|
|
func ActiveMemory() int {
|
|
var active C.size_t
|
|
C.mlx_get_active_memory(&active)
|
|
return int(active)
|
|
}
|
|
|
|
func CacheMemory() int {
|
|
var cache C.size_t
|
|
C.mlx_get_cache_memory(&cache)
|
|
return int(cache)
|
|
}
|
|
|
|
func PeakMemory() int {
|
|
var peak C.size_t
|
|
C.mlx_get_peak_memory(&peak)
|
|
return int(peak)
|
|
}
|
|
|
|
func ResetPeakMemory() {
|
|
C.mlx_reset_peak_memory()
|
|
}
|
|
|
|
type Memory struct{}
|
|
|
|
func (Memory) LogValue() slog.Value {
|
|
return slog.GroupValue(
|
|
slog.Any("active", PrettyBytes(ActiveMemory())),
|
|
slog.Any("cache", PrettyBytes(CacheMemory())),
|
|
slog.Any("peak", PrettyBytes(PeakMemory())),
|
|
)
|
|
}
|
|
|
|
type (
|
|
Byte int
|
|
KibiByte int
|
|
MebiByte int
|
|
GibiByte int
|
|
TebiByte int
|
|
)
|
|
|
|
func ClearCache() {
|
|
C.mlx_clear_cache()
|
|
}
|