diff --git a/.github/workflows/benchmark_pr.yml b/.github/workflows/benchmark_pr.yml index e7c68410e..3ce87582c 100644 --- a/.github/workflows/benchmark_pr.yml +++ b/.github/workflows/benchmark_pr.yml @@ -49,7 +49,7 @@ jobs: path: plots - name: Create markdown table from benchmarks run: | - benchpkgtable ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --input-dir=results/ --ratio > table.md + benchpkgtable ${{ steps.extract-package-name.outputs.package_name }} --rev="${{github.event.repository.default_branch}},${{github.event.pull_request.head.sha}}" --input-dir=results/ --ratio --mode=time,memory > table.md echo '### Benchmark Results' > body.md echo '' >> body.md echo '
' >> body.md diff --git a/benchmark/benchmarks.jl b/benchmark/benchmarks.jl index b153f60ee..2ab88641d 100644 --- a/benchmark/benchmarks.jl +++ b/benchmark/benchmarks.jl @@ -65,3 +65,72 @@ let default = BenchmarkGroup() end SUITE["saxpy"]["default"] = default end + +# Launch overhead: a problem of a single workgroup, so that the time is dominated by the +# host-side work of a launch. The kernel is constructed in the setup and the backend +# synchronized in the teardown, so only the launch itself is measured. +@kernel function scale_kernel!(A, @Const(B)) + I = @index(Global) + @inbounds A[I] = 2 * B[I] +end + +@kernel function scale_kernel_3d!(A, @Const(B)) + i, j, k = @index(Global, NTuple) + @inbounds A[i, j, k] = 2 * B[i, j, k] +end + +SUITE["launch"] = BenchmarkGroup() + +let launch = BenchmarkGroup(), n = 16, dims = (4, 4, 4) + launch["dynamic workgroup, dynamic ndrange"] = @benchmarkable kernel(A, B, ndrange = $n) setup = ( + kernel = scale_kernel!($BACKEND); + A = KernelAbstractions.zeros($BACKEND, Float64, $n); + B = rand!(KernelAbstractions.zeros($BACKEND, Float64, $n)) + ) teardown = KernelAbstractions.synchronize($BACKEND) + + launch["dynamic workgroup, dynamic ndrange, workgroupsize given"] = @benchmarkable kernel(A, B, ndrange = $n, workgroupsize = $n) setup = ( + kernel = scale_kernel!($BACKEND); + A = KernelAbstractions.zeros($BACKEND, Float64, $n); + B = rand!(KernelAbstractions.zeros($BACKEND, Float64, $n)) + ) teardown = KernelAbstractions.synchronize($BACKEND) + + launch["static workgroup, dynamic ndrange"] = @benchmarkable kernel(A, B, ndrange = $n) setup = ( + kernel = scale_kernel!($BACKEND, $n); + A = KernelAbstractions.zeros($BACKEND, Float64, $n); + B = rand!(KernelAbstractions.zeros($BACKEND, Float64, $n)) + ) teardown = KernelAbstractions.synchronize($BACKEND) + + launch["static workgroup, static ndrange"] = @benchmarkable kernel(A, B) setup = ( + kernel = scale_kernel!($BACKEND, $n, $n); + A = KernelAbstractions.zeros($BACKEND, Float64, $n); + B = rand!(KernelAbstractions.zeros($BACKEND, Float64, $n)) + ) teardown = KernelAbstractions.synchronize($BACKEND) + + launch["3D static workgroup, dynamic ndrange"] = @benchmarkable kernel(A, B, ndrange = $dims) setup = ( + kernel = scale_kernel_3d!($BACKEND, $dims); + A = KernelAbstractions.zeros($BACKEND, Float64, $dims...); + B = rand!(KernelAbstractions.zeros($BACKEND, Float64, $dims...)) + ) teardown = KernelAbstractions.synchronize($BACKEND) + + launch["3D static workgroup, static ndrange"] = @benchmarkable kernel(A, B) setup = ( + kernel = scale_kernel_3d!($BACKEND, $dims, $dims); + A = KernelAbstractions.zeros($BACKEND, Float64, $dims...); + B = rand!(KernelAbstractions.zeros($BACKEND, Float64, $dims...)) + ) teardown = KernelAbstractions.synchronize($BACKEND) + + SUITE["launch"] = launch +end + +# Host-side partitioning of the iteration space, independent of the backend. +let partition = BenchmarkGroup(), ndrange = Ref((1024,)), workgroupsize = Ref((16,)) + partition["dynamic workgroup, dynamic ndrange"] = @benchmarkable KernelAbstractions.partition(kernel, $ndrange[], $workgroupsize[]) setup = ( + kernel = scale_kernel!($BACKEND) + ) + partition["static workgroup, dynamic ndrange"] = @benchmarkable KernelAbstractions.partition(kernel, $ndrange[], nothing) setup = ( + kernel = scale_kernel!($BACKEND, 16) + ) + partition["static workgroup, static ndrange"] = @benchmarkable KernelAbstractions.partition(kernel, nothing, nothing) setup = ( + kernel = scale_kernel!($BACKEND, 16, 1024) + ) + SUITE["partition"] = partition +end