You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
VSL (V Scientific Library) is the low-level linear algebra foundation for VTL. VSL provides vsl.la.Matrix (column-major, f64), BLAS/LAPACK wrappers, and VCL (OpenCL) for data transport. For GPU acceleration to work end-to-end, VSL must provide GPU-accelerated gemm, matmul, and element-wise operations that VTL's la/ module calls.
This issue is the VSL counterpart of VTL issue #58 (Phase 1: Vulkan Compute Foundation).
VTL's compute/gemm_vulkan is used directly for Tensor[T]
VSL's la.vulkan must also support vsl.la.Matrix for:
VSL's own operations (la.gemm, la.matmul)
VTL's la/ module when it uses VSL as the backend
Why Vulkan for VSL
VSL uses Vulkan Compute as the primary GPU backend (same as VTL). Benefits:
Cross-vendor: Works on NVIDIA, AMD, Intel, ARM Mali/Adreno
No proprietary SDK: Unlike CUDA which only works on NVIDIA
Same code path: VTL and VSL share the same Vulkan compute kernels
SPIR-V: Unified GPU IR across all vendors
Reference Repositories
The V ecosystem has existing GPU/compute infrastructure used as reference:
antono2/vulkan — Full raw Vulkan 1.0–1.4 bindings (~1.3 MB). Use as the pattern for VSL's own Vulkan bindings: C→V type mapping, struct layout, handle definitions, API function signatures. MIT licensed.
antono2/v_vulkan_bindings — Python generator: Khronos XML → V code. Fork to generate a vsl-specific Vulkan bindings subset. MIT licensed.
antono2/vulkan_memory_allocator — Pool-based GPU memory allocator. Use as architectural reference for VSL's memory allocator. MIT licensed.
vsl.vcl — Mature OpenCL wrapper. Use as pattern for VSL's compute abstraction.
Implementation Pattern: Self-Contained Wrappers
Decision: VSL maintains its own Vulkan bindings within vsl/vulkan/, following the same pattern as BLAS, LAPACK, and VCL. Use antono2/vulkan, antono2/v_vulkan_bindings, and antono2/vulkan_memory_allocator as reference implementations.
Motivation
VSL (V Scientific Library) is the low-level linear algebra foundation for VTL. VSL provides
vsl.la.Matrix(column-major, f64), BLAS/LAPACK wrappers, and VCL (OpenCL) for data transport. For GPU acceleration to work end-to-end, VSL must provide GPU-acceleratedgemm,matmul, and element-wise operations that VTL'sla/module calls.This issue is the VSL counterpart of VTL issue #58 (Phase 1: Vulkan Compute Foundation).
VSL's Role in the GPU Architecture
VTL's
la/la.vconvertsTensor[T]->[]f64->vsl.la.Matrix-> calls VSL -> converts back. When VTL calls GPU-accelerated operations:compute/gemm_vulkanis used directly forTensor[T]la.vulkanmust also supportvsl.la.Matrixfor:la.gemm,la.matmul)la/module when it uses VSL as the backendWhy Vulkan for VSL
VSL uses Vulkan Compute as the primary GPU backend (same as VTL). Benefits:
Reference Repositories
The V ecosystem has existing GPU/compute infrastructure used as reference:
antono2/vulkan— Full raw Vulkan 1.0–1.4 bindings (~1.3 MB). Use as the pattern for VSL's own Vulkan bindings: C→V type mapping, struct layout, handle definitions, API function signatures. MIT licensed.antono2/v_vulkan_bindings— Python generator: Khronos XML → V code. Fork to generate avsl-specific Vulkan bindings subset. MIT licensed.antono2/vulkan_memory_allocator— Pool-based GPU memory allocator. Use as architectural reference for VSL's memory allocator. MIT licensed.vsl.vcl— Mature OpenCL wrapper. Use as pattern for VSL's compute abstraction.Implementation Pattern: Self-Contained Wrappers
Decision: VSL maintains its own Vulkan bindings within
vsl/vulkan/, following the same pattern as BLAS, LAPACK, and VCL. Useantono2/vulkan,antono2/v_vulkan_bindings, andantono2/vulkan_memory_allocatoras reference implementations.This keeps VSL self-contained and gives full control over the Vulkan API surface.
Scope
Files to create
vsl/vulkan/— VSL's own Vulkan bindings directoryvsl/vulkan/vk.c.v— C function declarations (fn C.vkCreateInstance(...),fn C.vkCmdDispatch(...), etc.)vsl/vulkan/vk.ctypes.v— C type definitions (VkInstance,VkDevice,VkBuffer,VkDeviceMemory, etc.)vsl/vulkan/vk.device.v— Device discovery, instance, physical device, logical device, queuevsl/vulkan/vk.buffer.v— Buffer creation, memory bindingvsl/vulkan/vk.memory.v— Memory allocation, host<->device mappingvsl/vulkan/vk.shader.v— Shader module creation from SPIR-Vvsl/vulkan/vk.pipeline.v— Compute pipeline, pipeline layoutvsl/vulkan/vk.descriptor.v— Descriptor set layout, pool, allocationvsl/vulkan/vk.command.v— Command buffer, submit, waitvsl/vulkan/vk.kernels.v— GLSL compute shader sources as V string constantsvsl/compute/— VSL compute abstraction directoryvsl/compute/gemm.v— GPU GEMM dispatcher (routes to Vulkan/CUDA/VCL/BLAS)vsl/compute/elementwise.v— GPU element-wise ops dispatchervsl/compute/broadcast.v— GPU broadcast ops dispatchervsl/la/vulkan.v— Vulkan GEMM forvsl.la.MatrixFiles to modify
vsl/la/la.v— Updategemm,matmulto dispatch to GPU via$if defined(vulkan)vsl/vcl/vector.c.v— Add methods to extractvcl.Vector[f64]fromvsl.la.MatrixAPI Contracts
Integration with VTL
VTL's
la/la.vneeds a path that calls VSL GPU compute:SPIR-V Compilation
Same strategy as VTL Phase 1:
vsl/vulkan/vk.kernels.vglslangValidator -V -x -o out.spvvkCreateShaderModuleVSL-specific Considerations
vsl.la.Matrixis column-major (Fortran style). Vulkan kernels must account for this:LDA = num_rows(column stride = number of rows)A[i + j * lda]whereiis row,jis columnf64only (no genericT). Simplifies kernel variants.Tensor[T], VSL'sMatrixdoes not have views — all operations allocate new matrices. GPU storage model is simpler.vsl.vclmodule. The Vulkan backend (vk) should coexist with VCL — they are separate backends, not competing.Testing Plan
gemm_vulkanproduces same output asla.gemm(within FP64 tolerance)la.matmulproduces same output with Vulkan backendMatrix.vulkan()/.cpu()round-trip preserves dataDependencies
vsl/vulkan/module (new — needs to be written first)glslangValidatorin PATH for SPIR-V compilationla/module (existing)Checklist
vsl/vulkan/directory and Vulkan bindings (vk.c.v, vk.ctypes.v)vsl/vulkan/vk.device.v: device discovery, instance, physical device, queuevsl/vulkan/vk.buffer.v: buffer creation, memory bindingvsl/vulkan/vk.memory.v: memory allocation, host<->device mappingvsl/vulkan/vk.shader.v: shader module creation from SPIR-Vvsl/vulkan/vk.pipeline.v: compute pipeline, pipeline layoutvsl/vulkan/vk.descriptor.v: descriptor set layout, pool, allocationvsl/vulkan/vk.command.v: command buffer, submit, waitvsl/vulkan/vk.kernels.v: GLSL compute shader sourcesvsl/compute/directory and dispatcher modulesvsl/compute/gemm.v: GPU dispatch for GEMMvsl/compute/elementwise.v: GPU dispatch for element-wisevsl/compute/broadcast.v: GPU dispatch for broadcastvsl/la/vulkan.v: Vulkan GEMM for vsl.la.Matrixvsl/la/la.v: update gemm/matmul to dispatch to Vulkanvsl/vcl/vector.c.v: add methods for vcl.Vector extractionRelated: VTL #58 (Phase 1: Vulkan Compute Foundation)
Parent: #236
Labels: enhancement, gpu, phase-a, vulkan