Aicraft
Skip to main content

Vulkan GPU Guide

Accelerate Aicraft with Vulkan compute shaders.

Prerequisites

  • Vulkan SDK installed (or system Vulkan drivers)
  • A GPU that supports Vulkan 1.0+ compute

Enabling Vulkan

gcc -O3 demo.c -I./include -lvulkan -o demo

At runtime, Aicraft automatically detects available GPU devices and selects the best one.

Device Selection

ac_init();
ac_vulkan_init(); // Auto-select best GPU

// Or manually select a device
ac_vulkan_select_device(0); // First GPU

// Query device info
AcVkDeviceInfo info = ac_vulkan_device_info();
printf("GPU: %s (%d MB VRAM)\n", info.name, info.vram_mb);

Compute Shaders

Aicraft includes 14 GLSL compute shaders:

ShaderOperation
gemm.compGeneral matrix multiply
relu.compReLU activation
sigmoid.compSigmoid activation
softmax.compSoftmax activation
add.compElement-wise add
mul.compElement-wise multiply
reduce_sum.compSum reduction
reduce_max.compMax reduction
transpose.compMatrix transpose
cross_entropy.compCross-entropy loss
mse.compMSE loss
adam_step.compAdam optimiser step
quantize.compINT8 quantisation
broadcast.compBroadcasting

CPU ↔ GPU Transfer

// Move tensor to GPU
ac_vulkan_upload(tensor);

// Run operations on GPU (automatic)
AcTensor *y = ac_forward_seq(net, 2, x);

// Download result back to CPU
ac_vulkan_download(y);

Performance Tips

  • Batch operations to minimise CPU↔GPU transfers
  • Use ac_vulkan_sync() explicitly only when needed
  • Larger batch sizes benefit more from GPU acceleration