-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamically split kernels based on parameter memory
Remove depot Refactor, move parameter mem to separate file More improvements
- Loading branch information
1 parent
041fdee
commit 3b50d16
Showing
8 changed files
with
205 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
function get_param_lim() | ||
config = CUDA.compiler_config(CUDA.device()) | ||
(; ptx, cap) = config.params | ||
return cap >= v"7.0" && ptx >= v"8.1" ? 32764 : 4096 | ||
end | ||
param_usage(arg) = sizeof(typeof(CUDA.cudaconvert(arg))) | ||
param_usage_args(args) = | ||
sum(x -> param_usage(x), args) + param_usage(CUDA.KernelState) | ||
|
||
function fused_multibroadcast_args(fmb::MBF.FusedMultiBroadcast) | ||
dest = first(fmb.pairs).first | ||
CI = CartesianIndices(axes(dest)) | ||
return (fmb, CI) | ||
end | ||
|
||
# TODO: Add recursive version of this (maybe similar to `StructuredPrinting` pattern?) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#= | ||
using TestEnv | ||
TestEnv.activate() | ||
using CUDA # (optional) | ||
using Revise; include(joinpath("test", "execution", "measure_parameter_memory.jl")) | ||
=# | ||
|
||
include("utils_test.jl") | ||
include("utils_setup.jl") | ||
include("utils_benchmark.jl") | ||
|
||
import MultiBroadcastFusion as MBF | ||
|
||
#! format: off | ||
function perf_kernel_shared_reads_fused!(X, Y) | ||
(; x1, x2, x3, x4) = X | ||
(; y1, y2, y3, y4) = Y | ||
# TODO: can we write this more compactly with `@fused_assemble`? | ||
|
||
# Let's make sure that every broadcasted object is different, | ||
# so that we use up a lot of parameter memory: | ||
fmb = MBF.@get_fused_direct begin | ||
@. y1 = x1 | ||
@. y2 = x1 + x2 | ||
@. y3 = x1 + x2 + x3 | ||
@. y4 = x1 * x2 + x3 + x4 | ||
@. y1 = x1 * x2 + x3 + x4 + x1 | ||
@. y2 = x1 * x2 + x3 + x4 + x1 + x2 | ||
@. y3 = x1 * x2 + x3 + x4 + x1 + x2 + x3 | ||
@. y4 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 | ||
@. y1 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 | ||
@. y2 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 | ||
@. y3 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 + x3 | ||
@. y4 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 | ||
@. y1 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 | ||
@. y2 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 | ||
@. y3 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 + x3 | ||
@. y4 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 | ||
@. y1 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 | ||
@. y2 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 | ||
@. y3 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 + x3 | ||
@. y4 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 | ||
@. y1 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 | ||
@. y2 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 | ||
@. y3 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 + x3 | ||
@. y4 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 | ||
@. y1 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 | ||
@. y2 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 | ||
@. y3 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 + x3 | ||
@. y4 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 | ||
@. y1 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 | ||
@. y2 = x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 * x2 + x3 + x4 + x1 + x2 # breaks on A100 due to too much parameter memory | ||
end | ||
MBFExt = Base.get_extension(MBF, :MultiBroadcastFusionCUDAExt) | ||
@show MBFExt.param_usage_args(MBFExt.fused_multibroadcast_args(fmb)) | ||
end | ||
#! format: on | ||
|
||
@static get(ENV, "USE_CUDA", nothing) == "true" && using CUDA | ||
use_cuda = @isdefined(CUDA) && CUDA.has_cuda() # will be true if you first run `using CUDA` | ||
AType = use_cuda ? CUDA.CuArray : Array | ||
device_name = use_cuda ? CUDA.name(CUDA.device()) : "CPU" | ||
bm = Benchmark(; device_name, float_type = Float32) | ||
problem_size = (50, 5, 5, 6, 5400) | ||
|
||
array_size = problem_size # array | ||
X = get_arrays(:x, AType, bm.float_type, array_size) | ||
Y = get_arrays(:y, AType, bm.float_type, array_size) | ||
@testset "Test measuring parameter memory" begin | ||
use_cuda && perf_kernel_shared_reads_fused!(X, Y) | ||
end | ||
|
||
nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters