Repository navigation
Cache the launch limits queried by KernelAbstractions - #1196
Conversation
Each KernelAbstractions launch queried HIP for the device's maximum workgroup size (`hipDeviceGetAttribute`, which formats a string), twice for the kernel's maximum workgroup size, and for its occupancy. These queries took about 330 of the 390 ns KernelAbstractions adds to a launch. Store the device limit in `HIPDevice`, alongside its other limits, and cache the kernel limit and occupancy without dynamic shared memory in `HIPFunction`. Both are fixed when the function is loaded. HIP picks the largest workgroup size occupancy allows, or the limit rounded up to the wavefront size if smaller. Reuse the cached result for limits that admit it.
|
cscs-ci run MI250,MI300 |
|
Documentation preview: https://amdgpu.juliagpu.org/previews/PR1196/ |
Benchmark resultsCompared with 3e7016582, the merge base. Times are the minimum time of every benchmark. A change is unusual when it exceeds both three times the benchmark's typical change between consecutive runs on the default branch and a minimum per category (performance 3%, latency 5%, applications 3%, other 3%). A benchmark that starts or stops allocating is listed however few the allocations. A single run can still be a fluke, so rerun before drawing conclusions.
All benchmarks
|
Each KernelAbstractions launch queried HIP for the device's maximum workgroup size (
hipDeviceGetAttribute, which formats a string), twice for the kernel's maximum workgroup size, and for the kernel's occupancy. In a profiled launch loop, these queries took about 330 of the 390 ns that KernelAbstractions adds to a launch.Store the device limit in
HIPDevice(HIP.max_workgroup_size), alongsidemax_workgroup_dims, and cache the kernel limit and occupancy without dynamic shared memory inHIPFunction, as CUDA.jl does inCuFunction. Both are fixed when the function is loaded and need no invalidation: HIP's cache-configuration and attribute setters do not change the inputs to the occupancy calculation.HIP picks the largest workgroup size occupancy allows, or the limit rounded up to the wavefront size if smaller (
ihipOccupancyMaxActiveBlocksPerMultiprocessorin clr), so limits that admit the cached result reuse it. Smaller limits, e.g. anndrangebelow the cached workgroup size, still query HIP. The test compares cached and queried configurations across a range of limits.Host time per launch, 64 launches per batch without synchronization, median over 6 interleaved runs (9950X iGPU, gfx1036; Julia 1.12.7, KernelAbstractions 0.10.3, KernelInterface 0.4.3; base 3e70165):
@roc, for referencendrange=1000ndrange=10_000ndrange=(30, 30, 30)The "after" runs also include #1197, which only changes compile-time latency.
Tests: the full suite on gfx1036 (30553 passed, 14 broken), including
kernelabstractions_testsandkernelinterface_tests.