Skip to content

Detect Vulkan via the loader before falling back to vulkaninfo - #1446

Merged
martindevans merged 1 commit into
SciSharp:masterfrom
ipevo-brooks:vulkan-detect-in-process
Oct 1, 2026
Merged

martindevans merged 1 commit into
SciSharp:masterfrom
ipevo-brooks:vulkan-detect-in-process

Conversation

@ipevo-brooks

Copy link
Copy Markdown
Contributor

Problem

SystemInfo.GetVulkanVersion() detects Vulkan only by spawning vulkaninfo --summary and parsing its output.

vulkaninfo is a developer tool that comes with the Vulkan SDK (and is bundled by some driver installers, e.g. NVIDIA), but it is not part of the Vulkan loader or of every driver. On a Windows machine with only an Intel GPU (tested on an Intel N100 box) the driver installs a fully working vulkan-1.dll but no vulkaninfo.exe. LLamaSharp then concludes there is no Vulkan, skips LLamaSharp.Backend.Vulkan, and ggml only ever lists the CPU device. The user gets CPU inference with no error.

Spawning an external process also has the latency / timeout problems already discussed in #884, #885 and #930.

Fix

Ask the loader directly first:

  • P/Invoke vkEnumerateInstanceVersion (Vulkan 1.1+) from vulkan-1.dll on Windows or libvulkan.so.1 on Linux.
  • Decode the packed version into major.minor.patch (same shape as the string parsed from vulkaninfo on Windows).
  • If the loader is missing, predates 1.1, returns an error, or the platform is neither Windows nor Linux, fall back to the existing vulkaninfo --summary path unchanged.

VulkanVersion is only tested for != null by NativeLibraryWithVulkan, so the string format change on Linux (previously 4206847 (1.3.255) from vulkaninfo) has no functional effect.

Testing

  • Built LLama/LLamaSharp.csproj (netstandard2.0 + net8.0), no new warnings.
  • Windows 11, Intel Arc 140T + NVIDIA RTX 4050: in-process call returns 1.4.350, matching the installed loader's file version.
  • Same patch has been running in a vendored copy of LLamaSharp 0.29.0 on an Intel N100 (no vulkaninfo) since 2026-09; Vulkan backend is now selected and the iGPU is listed.
  • Machines without Vulkan: DllNotFoundException is caught and the old path runs, so behaviour is unchanged.

SystemInfo.GetVulkanVersion relied solely on spawning `vulkaninfo --summary`.
That tool ships with the Vulkan SDK / some driver bundles, not with every
Vulkan-capable driver (e.g. Windows machines with only an Intel GPU), and the
external process can be slow or time out (SciSharp#930). When it is missing the Vulkan
backend is silently skipped and only the CPU backend is offered.

Query the loader in-process with vkEnumerateInstanceVersion first
(vulkan-1.dll on Windows, libvulkan.so.1 on Linux) and only fall back to
vulkaninfo when the loader is absent or the call fails. Behaviour on machines
without Vulkan is unchanged.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@martindevans martindevans left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together, it looks good to me. I'll merge it once the tests complete.

@martindevans
martindevans merged commit bf6520e into SciSharp:master Oct 1, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants