Skip to content

feat(acceleration): Kernel Block-Dimension Occupancy Tuning (v1.9.0) - #4618

Merged
makr-code merged 2 commits into
developfrom
copilot/kernel-block-dimension-occupancy-tuning
Apr 13, 2026
Merged

makr-code merged 2 commits into
developfrom
copilot/kernel-block-dimension-occupancy-tuning

Conversation

Copilot AI commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Replaces all hard-coded 256-thread block sizes in CUDA/HIP kernel launchers with runtime-tuned values queried via cudaOccupancyMaxPotentialBlockSize / hipOccupancyMaxPotentialBlockSize at initialize() time. Adds AMD GCN wavefront-64 awareness and Vulkan specialization-constant injection for the L2 compute pipeline.

Description

Pattern applied across all affected kernel TUs

Each .cu/.hip file now exposes a module-level mutable block-size variable, a direct setter, and an internal tuner that calls the occupancy API on its own kernel pointer — avoiding the need to expose __global__ symbols across TU boundaries:

// cuda/geo_kernels.cu (representative)
static int g_cuda_geo_block_size = 256;          // safe default

extern "C" void setGeoKernelBlockSize(int bs) { g_cuda_geo_block_size = bs; }

extern "C" int tuneGeoKernelBlockSize() {
    int minGrid = 0, tuned = 256;
    if (cudaOccupancyMaxPotentialBlockSize(&minGrid, &tuned, haversineDistanceKernel, 0, 0)
            == cudaSuccess && tuned > 0) {
        tuned = (tuned / 32) * 32;
        g_cuda_geo_block_size = std::max(tuned, 32);
    }
    return g_cuda_geo_block_size;
}
// CUDAGeoBackend::initialize() calls tuneGeoKernelBlockSize(); launchers read g_cuda_geo_block_size.

Files changed

CUDA kernel files

  • cuda/geo_kernels.cu — g_cuda_geo_block_size; tuneGeoKernelBlockSize() queries haversineDistanceKernel
  • cuda/graph_kernels.cu — kBFSBlockDim (now mutable); tuneGraphBFSBlockDim() queries graphBFSInitKernel
  • cuda/vector_kernels.cu — g_cuda_vec_block_dim replaces dim3(16,16); tuneVecKernelBlockSize() queries computeL2DistanceKernel, computes integer-sqrt 2-D block

HIP kernel files

  • hip/ann_kernels.hip — g_hip_topk_block_size; hipSetTopKBlockSize(int)
  • hip/geo_kernels.hip — g_hip_geo_block_size; hipSetGeoKernelBlockSize(int)

Backend initialization

  • hip_backend.cpp — HIPBackendImpl::occupancyTunedBlockSize; starts baseline at 64 when warpSize == 64 (AMD GCN), then queries topKSelectionKernel; propagates to all HIP launcher setters; batchKnnSearchWithMetric reads the stored value
  • cuda_backend.cpp — CUDAVectorBackend, CUDAGraphBackend, CUDAGeoBackend each call their respective tune*() in initialize()

Vulkan backend

  • vulkan_backend_full.cpp — createComputePipelines() builds a VkSpecializationInfo (constant_id 0 → LOCAL_SIZE_X, 1 → LOCAL_SIZE_Y) injected into the L2 pipeline stage; 32×16 when maxComputeWorkGroupInvocations ≥ 512, otherwise 16×16

Benchmark

  • benchmarks/kernel_block_size_bench.cpp — Google Benchmark sweeping 64/128/256/512 for CUDA geo Haversine, HIP geo Haversine, and HIP top-K; reports pairs_per_sec / queries_per_sec rate counters
  • cmake/CMakeLists.txt — registers kernel_block_size_bench target

Documentation

  • src/acceleration/FUTURE_ENHANCEMENTS.md — all implementation items marked [x]

Linked Issues

Closes #234

Type of Change

  • Bug fix (non-breaking)
  • New feature (non-breaking)
  • Refactoring (non-breaking)
  • Documentation
  • Breaking change (requires MAJOR version bump — see VERSIONING.md)
  • Security fix
  • Other:

Breaking Change Checklist

N/A

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • Benchmarks run (if performance-sensitive change)

📚 Research & Knowledge (wenn applicable)

  • Diese PR basiert auf wissenschaftlichen Paper(s) oder Best Practices?

Relevante Quellen:

  • Paper:
  • Best Practice:
  • Architecture Decision:

Checklist

  • Code follows project style guidelines (clang-format / clang-tidy)
  • Self-review completed
  • Documentation updated (if needed)
  • CHANGELOG.md updated under [Unreleased]
  • No new warnings introduced
  • Security-sensitive paths reviewed by security maintainer (if applicable)

Copilot AI linked an issue Apr 13, 2026 that may be closed by this pull request
14 tasks
Copilot AI changed the title [WIP] Implement kernel block-dimension occupancy tuning for v1.9.0 feat(acceleration): Kernel Block-Dimension Occupancy Tuning (v1.9.0) Apr 13, 2026
Copilot AI requested a review from makr-code April 13, 2026 11:49
@makr-code
makr-code marked this pull request as ready for review April 13, 2026 11:50
@makr-code
makr-code merged commit 8c426c9 into develop Apr 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Kernel Block-Dimension Occupancy Tuning 03-implement-llm-prefix-cache.md

2 participants