vulkan_support#
Shared Vulkan compute-pipeline helpers for kernelfoundry tasks.
A Vulkan task only differs from another in its compiled shader, buffer count, and
push-constant layout; everything else (instance/device setup, descriptor sets, command
buffer recording, submission) is identical boilerplate. This module builds that boilerplate
once via create_vulkan_compute_context(), returning a VulkanCtx that a task’s
vulkan_ctx fixture can expose directly.
Functions
|
Builds a VkInstance/VkDevice/compute pipeline for a compiled SPIR-V module. |
Classes
|
A storage buffer plus its backing device memory and byte size. |
|
Holds the Vulkan objects (device, pipeline, descriptor set, command buffer) needed to dispatch a compute shader. |
- class kernelfoundry.eval_pipeline.utils.vulkan_support.VulkanBuffer(buffer: Any, memory: Any, size: int)[source]#
A storage buffer plus its backing device memory and byte size.
- class kernelfoundry.eval_pipeline.utils.vulkan_support.VulkanCtx(device: Any, queue: Any, command_buffer: Any, descriptor_set: Any, pipeline: Any, pipeline_layout: Any, mem_properties: Any)[source]#
Holds the Vulkan objects (device, pipeline, descriptor set, command buffer) needed to dispatch a compute shader. Built once per test session via create_vulkan_compute_context().
- find_memory_type(type_bits: int, flags: int) int[source]#
Finds a device memory type index matching type_bits and property flags.
- make_buffer(size_bytes: int) VulkanBuffer[source]#
Allocates a host-visible/coherent storage buffer of the given byte size.
- upload(vbuf: VulkanBuffer, data: ndarray) None[source]#
Copies a numpy array into a storage buffer’s host-visible memory.
- download(vbuf: ~kernelfoundry.eval_pipeline.utils.vulkan_support.VulkanBuffer, dtype=<class 'numpy.float32'>) ndarray[source]#
Waits for all submitted work to complete, then reads a storage buffer’s host-visible memory back into a numpy array.
- submit(buffers: Sequence[VulkanBuffer], n: int, push_constants: bytes = b'', local_size_x: int = 256) None[source]#
Records (if needed) and submits ceil(n / local_size_x) workgroups to the queue, without waiting for completion. Call wait() (or download(), which waits internally) once submissions are batched, to synchronize.
- dispatch(buffers: Sequence[VulkanBuffer], n: int, push_constants: bytes = b'', local_size_x: int = 256) None[source]#
Binds buffers to the pipeline’s descriptor set (in order, starting at binding 0), pushes push_constants if any, and dispatches ceil(n / local_size_x) workgroups, blocking until the GPU is done. Convenience for one-off calls; for tight loops, use submit() repeatedly and wait() once to avoid a full CPU-GPU sync on every call.
- kernelfoundry.eval_pipeline.utils.vulkan_support.create_vulkan_compute_context(spv_path: str | Path, num_storage_buffers: int, push_constant_size: int = 0, app_name: str = 'kernelfoundry') VulkanCtx[source]#
Builds a VkInstance/VkDevice/compute pipeline for a compiled SPIR-V module.
Picks the first integrated/discrete GPU with a compute-capable queue family, exactly as other kernelfoundry backends pick their first available device.
- Parameters:
spv_path – Path to the compiled .spv shader module (see
kernelfoundry.compiler.compile_glsl_to_spirv()).num_storage_buffers – Number of SSBO bindings (0, 1, 2, …) the shader declares.
push_constant_size – Byte size of the shader’s push_constant block, 0 if none.
app_name – VkApplicationInfo application name (cosmetic).
- Returns:
A VulkanCtx ready to receive make_buffer()/upload()/dispatch()/download() calls.