Description
Funlib originally contains only one basic GEMM implementation. This is enough for validating matrix multiplication, but it does not provide the memory reuse, device-resident execution, or hardware-specific optimization required for practical AI workloads.
One of Funlib's goals is to support AI training and inference using a portable SYCL implementation that can execute on both Intel and NVIDIA GPUs. Transformer workloads require GEMM for operations such as:
Input projections: Q = XWq, K = XWk, V = XWv
Attention scores: QK^T
Attention output: softmax(QK^T)V
Output projection: attention_output * Wo
Feed-forward: XW1 -> GELU -> XW2
These operations execute repeatedly and often use large matrices. GEMM performance will therefore have a major effect on the training and inference performance of Funlib.
Currently
- Funlib has a basic GEMM implementation.
- Tensor operations can execute through a user-selected SYCL queue.
- The same library is intended to support Intel and NVIDIA GPU backends.
- There is no set of specialized GEMM kernels for different devices and matrix shapes.
- There is no dedicated correctness and performance infrastructure for comparing GEMM implementations.
- Host/device transfers and tensor allocation can hide the actual kernel performance when they are included in measurements.
Plan
1. Add correctness and timing infrastructure
2. Support device-resident tensors
The intended user-facing flow is:
flib::sycl_handler::register_queue(
"cuda",
flib::device::GPU,
flib::vendor::NVIDIA,
flib::backend::CUDA,
true);
sycl::queue queue = flib::sycl_handler::get_queue("cuda");
flib::ftensor A(M, K, queue);
flib::ftensor B(K, N, queue);
A.copy_from(hostA.data(), queue).wait();
B.copy_from(hostB.data(), queue).wait();
flib::ftensor C = flib::tensor_operations::gemmTiled(A, B, queue);
std::vector<float> hostC = C.to_host(queue);
3. Add a local-memory tiled GEMM
4. Add a 2x2 register-blocked GEMM
5. Combine local-memory tiling with 2x2 register blocking
6. Benchmark all GEMM implementations
Initial benchmark shapes should include:
128x128x128
256x256x256
512x512x512
127x512x512
512x64x512
512x512x2048
7. Add device- and shape-aware dispatch
8. Investigate later optimizations
Acceptance criteria
Description
Funlib originally contains only one basic GEMM implementation. This is enough for validating matrix multiplication, but it does not provide the memory reuse, device-resident execution, or hardware-specific optimization required for practical AI workloads.
One of Funlib's goals is to support AI training and inference using a portable SYCL implementation that can execute on both Intel and NVIDIA GPUs. Transformer workloads require GEMM for operations such as:
These operations execute repeatedly and often use large matrices. GEMM performance will therefore have a major effect on the training and inference performance of Funlib.
Currently
Plan
1. Add correctness and timing infrastructure
float,double, andintwhere supported.2 * M * K * Noperations.2. Support device-resident tensors
The intended user-facing flow is:
3. Add a local-memory tiled GEMM
4. Add a 2x2 register-blocked GEMM
5. Combine local-memory tiling with 2x2 register blocking
6. Benchmark all GEMM implementations
Compare the following implementations under identical conditions:
gemmgemmTiledgemm_blocked2x2gemm_tiled_blocked2x2Use the same device-resident inputs for every implementation.
Measure total operation time and kernel-only time separately.
Include representative transformer shapes in addition to small square matrices.
Run the benchmark through Intel OpenCL, Intel Level Zero, and NVIDIA CUDA SYCL backends where available.
Record the device name, backend, driver, tile size, work-group size, and data type with every result.
Initial benchmark shapes should include:
7. Add device- and shape-aware dispatch
8. Investigate later optimizations
Acceptance criteria