From d215ba03d0d5748861829f437336bb2ca06e8484 Mon Sep 17 00:00:00 2001 From: ZheWang Date: Mon, 22 Jul 2024 09:56:24 +0800 Subject: [PATCH] fix old lze driver crash --- gpu/gpu.go | 76 ++++++++++++++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/gpu/gpu.go b/gpu/gpu.go index d34193fa3b8..59b64d240d9 100644 --- a/gpu/gpu.go +++ b/gpu/gpu.go @@ -312,45 +312,47 @@ func GetGPUInfo() GpuInfoList { // Intel if envconfig.IntelGpu { oHandles = initOneAPIHandles() - // On windows we bundle the oneapi library one level above the runner dir - depPath = "" - if runtime.GOOS == "windows" && envconfig.RunnersDir != "" { - depPath = filepath.Join(filepath.Dir(envconfig.RunnersDir), "oneapi") - } - - for d := range oHandles.oneapi.num_drivers { - if oHandles.oneapi == nil { - // shouldn't happen - slog.Warn("nil oneapi handle with driver count", "count", int(oHandles.oneapi.num_drivers)) - continue + if oHandles.oneapi != nil { + // On windows we bundle the oneapi library one level above the runner dir + depPath = "" + if runtime.GOOS == "windows" && envconfig.RunnersDir != "" { + depPath = filepath.Join(filepath.Dir(envconfig.RunnersDir), "oneapi") } - devCount := C.oneapi_get_device_count(*oHandles.oneapi, C.int(d)) - for i := range devCount { - gpuInfo := OneapiGPUInfo{ - GpuInfo: GpuInfo{ - Library: "oneapi", - }, - driverIndex: int(d), - gpuIndex: int(i), - } - // TODO - split bootstrapping from updating free memory - C.oneapi_check_vram(*oHandles.oneapi, C.int(d), i, &memInfo) - // TODO - convert this to MinimumMemory based on testing... - var totalFreeMem float64 = float64(memInfo.free) * 0.95 // work-around: leave some reserve vram for mkl lib used in ggml-sycl backend. - memInfo.free = C.uint64_t(totalFreeMem) - gpuInfo.TotalMemory = uint64(memInfo.total) - gpuInfo.FreeMemory = uint64(memInfo.free) - gpuInfo.ID = C.GoString(&memInfo.gpu_id[0]) - gpuInfo.Name = C.GoString(&memInfo.gpu_name[0]) - // now level-zero dosen't support iGPU mem status detection, 0 byte vram is a sign of iGPU - gpuInfo.isiGPU = gpuInfo.TotalMemory == 0 - // enable Core Ultra Xe igpus. - if envconfig.ForceEnableIntelIGPU || (IsIntelCoreUltraCpus() && gpuInfo.isiGPU) { - DetectInteliGpuMemStatus(&gpuInfo) + + for d := range oHandles.oneapi.num_drivers { + if oHandles.oneapi == nil { + // shouldn't happen + slog.Warn("nil oneapi handle with driver count", "count", int(oHandles.oneapi.num_drivers)) + continue } - gpuInfo.DependencyPath = depPath - if gpuInfo.TotalMemory > 0 { - oneapiGPUs = append(oneapiGPUs, gpuInfo) + devCount := C.oneapi_get_device_count(*oHandles.oneapi, C.int(d)) + for i := range devCount { + gpuInfo := OneapiGPUInfo{ + GpuInfo: GpuInfo{ + Library: "oneapi", + }, + driverIndex: int(d), + gpuIndex: int(i), + } + // TODO - split bootstrapping from updating free memory + C.oneapi_check_vram(*oHandles.oneapi, C.int(d), i, &memInfo) + // TODO - convert this to MinimumMemory based on testing... + var totalFreeMem float64 = float64(memInfo.free) * 0.95 // work-around: leave some reserve vram for mkl lib used in ggml-sycl backend. + memInfo.free = C.uint64_t(totalFreeMem) + gpuInfo.TotalMemory = uint64(memInfo.total) + gpuInfo.FreeMemory = uint64(memInfo.free) + gpuInfo.ID = C.GoString(&memInfo.gpu_id[0]) + gpuInfo.Name = C.GoString(&memInfo.gpu_name[0]) + // now level-zero dosen't support iGPU mem status detection, 0 byte vram is a sign of iGPU + gpuInfo.isiGPU = gpuInfo.TotalMemory == 0 + // enable Core Ultra Xe igpus. + if envconfig.ForceEnableIntelIGPU || (IsIntelCoreUltraCpus() && gpuInfo.isiGPU) { + DetectInteliGpuMemStatus(&gpuInfo) + } + gpuInfo.DependencyPath = depPath + if gpuInfo.TotalMemory > 0 { + oneapiGPUs = append(oneapiGPUs, gpuInfo) + } } } }