Nx.Vulkan.PipelineCache (nx_vulkan v0.1.0)

Copy Markdown View Source

Phase 2 W5 — disk persistence for spirit's VkPipelineCache.

The vkPipelineCache holds compiled SPIR-V → device ISA. Without persistence, every BEAM restart pays the full backend-compile cost on first dispatch (~30-200 ms per shader on NVIDIA Linux). With persistence, the second-and-later restarts of a process that has the cache file get cache hits — vkCreateComputePipelines skips the compile entirely.

File layout

~/.exmc/gpu_node/pipeline_cache/{device_uuid_hex}.bin

The device_uuid_hex is the lowercased hex of VkPhysicalDevice pipelineCacheUUID (16 bytes → 32 hex chars). Different GPUs and different drivers produce different UUIDs, so the file is inherently device-specific. The driver itself silently rejects blobs whose embedded header doesn't match the running device, so even if the wrong file lands in the directory it just produces a fresh empty cache (with a stderr warning).

Usage

# At application start, before any pipelines are built:
Nx.Vulkan.PipelineCache.load()

# At application shutdown, or periodically:
Nx.Vulkan.PipelineCache.persist()

Summary

Functions

Convenience for benchmarks / tests — clear the cache directory.

Path the cache file would land at for the current device.

Lowercased hex of the device's 16-byte pipelineCacheUUID.

Load the disk cache (if present) into spirit's pipeline cache. Returns :ok on success, including the "no file yet" case.

Persist spirit's current pipeline cache to disk via atomic write-temp-rename. Returns :ok.

Functions

clear()

Convenience for benchmarks / tests — clear the cache directory.

default_path()

Path the cache file would land at for the current device.

device_uuid_hex()

Lowercased hex of the device's 16-byte pipelineCacheUUID.

load()

Load the disk cache (if present) into spirit's pipeline cache. Returns :ok on success, including the "no file yet" case.

persist()

Persist spirit's current pipeline cache to disk via atomic write-temp-rename. Returns :ok.