Implementation:Ollama Ollama Discover CPU Windows
| Knowledge Sources | |
|---|---|
| Domains | HardwareDiscovery, Windows |
| Last Updated | 2025-02-15 00:00 GMT |
Overview
Windows-specific CPU memory and topology discovery module that calls Win32 APIs via syscall to determine available system resources including efficiency core detection.
Description
GetCPUMem calls GlobalMemoryStatusEx from kernel32.dll using unsafe pointer casting to populate a MEMORYSTATUSEX struct with total physical memory, available memory, and available page file. GetCPUDetails calls GetLogicalProcessorInformationEx to retrieve a raw byte buffer of processor relationship data, then processSystemLogicalProcessorInforationList parses it in three passes: first identifying CPU packages (sockets) with their group affinities, then determining the maximum efficiency class across all cores (to detect Intel hybrid P-core/E-core architectures), and finally matching cores to packages while counting total cores, threads, and efficiency cores based on EfficiencyClass and Flags fields. IsNUMA always returns false since NUMA support in ggml is Linux-only.
Usage
Called during Ollama startup on Windows to determine available system resources for optimal model loading and inference thread allocation.
Code Reference
Source Location
- Repository: Ollama
- File: discover/cpu_windows.go
- Lines: 1-221
Signature
func GetCPUMem() (memInfo, error)
func GetCPUDetails() []CPU
func IsNUMA() bool
type MEMORYSTATUSEX struct {
length uint32
MemoryLoad uint32
TotalPhys uint64
AvailPhys uint64
TotalPageFile uint64
AvailPageFile uint64
TotalVirtual uint64
AvailVirtual uint64
AvailExtendedVirtual uint64
}
type winPackage struct {
groups []*GROUP_AFFINITY
coreCount int
efficiencyCoreCount int
threadCount int
}
Import
import "github.com/ollama/ollama/discover"
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| kernel32.dll | Win32 DLL | Yes | Windows kernel library for memory and processor APIs |
| GlobalMemoryStatusEx | Win32 API | Yes | System memory status |
| GetLogicalProcessorInformationEx | Win32 API | Yes | Processor topology information |
Outputs
| Name | Type | Description |
|---|---|---|
| memInfo | struct | TotalMemory, FreeMemory, FreeSwap in bytes |
| []CPU | slice | List of CPU packages with core/thread/efficiency counts |
| isNUMA | bool | Always false on Windows |
Usage Examples
mem, err := discover.GetCPUMem()
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total: %d bytes, Available: %d bytes\n",
mem.TotalMemory, mem.FreeMemory)
cpus := discover.GetCPUDetails()
for _, cpu := range cpus {
fmt.Printf("Package: %d cores (%d efficiency), %d threads\n",
cpu.CoreCount, cpu.EfficiencyCoreCount, cpu.ThreadCount)
}