1 Commits

Author SHA1 Message Date
6bcc9000b1 benchmarking: added initial results for transpiler 2025-05-19 09:12:59 +02:00
12 changed files with 148 additions and 589 deletions

View File

@ -9,7 +9,6 @@ include("Code.jl")
include("CpuInterpreter.jl") include("CpuInterpreter.jl")
end end
using CUDA
using ..ExpressionProcessing using ..ExpressionProcessing
export interpret_gpu,interpret_cpu export interpret_gpu,interpret_cpu
@ -23,51 +22,36 @@ export evaluate_gpu
# #
# Evaluate Expressions on the GPU # Evaluate Expressions on the GPU
function interpret_gpu(expressions::Vector{Expr}, X::Matrix{Float32}, p::Vector{Vector{Float32}}; repetitions=1)::Matrix{Float32} function interpret_gpu(exprs::Vector{Expr}, X::Matrix{Float32}, p::Vector{Vector{Float32}}; repetitions=1)::Matrix{Float32}
@assert axes(expressions) == axes(p) @assert axes(exprs) == axes(p)
variableCols = size(X, 2) ncols = size(X, 2)
variableRows = size(X, 1)
variables = CuArray(X) results = Matrix{Float32}(undef, ncols, length(exprs))
# TODO: create CuArray for variables here already, as they never change
# could/should be done even before calling this, but I guess it would be diminishing returns
# TODO: test how this would impact performance, if it gets faster, adapt implementation section
# TODO: create CuArray for expressions here already. They also do not change over the course of parameter optimisation and therefore a lot of unnecessary calls to expr_to_postfix can be save (even though a cache is used, this should still be faster)
exprs = Vector{ExpressionProcessing.PostfixType}(undef, length(expressions))
@inbounds Threads.@threads for i in eachindex(expressions)
exprs[i] = ExpressionProcessing.expr_to_postfix(expressions[i])
end
cudaExprs = Utils.create_cuda_array(exprs, ExpressionProcessing.ExpressionElement(EMPTY, 0)) # column corresponds to data for one expression;
exprsLength = length(exprs)
exprsInnerLength = Utils.get_max_inner_length(exprs)
results = Matrix{Float32}(undef, variableCols, length(exprs))
for i in 1:repetitions # Simulate parameter tuning -> local search (X remains the same, p gets changed in small steps and must be performed sequentially, which it is with this impl) for i in 1:repetitions # Simulate parameter tuning -> local search (X remains the same, p gets changed in small steps and must be performed sequentially, which it is with this impl)
results = Interpreter.interpret(cudaExprs, exprsLength, exprsInnerLength, variables, variableCols, variableRows, p) results = Interpreter.interpret(exprs, X, p)
end end
return results return results
end end
# Convert Expressions to PTX Code and execute that instead # Convert Expressions to PTX Code and execute that instead
function evaluate_gpu(expressions::Vector{Expr}, X::Matrix{Float32}, p::Vector{Vector{Float32}}; repetitions=1)::Matrix{Float32} function evaluate_gpu(exprs::Vector{Expr}, X::Matrix{Float32}, p::Vector{Vector{Float32}}; repetitions=1)::Matrix{Float32}
@assert axes(expressions) == axes(p) @assert axes(exprs) == axes(p)
numVariableSets = size(X, 2) # nr. of columns of X ncols = size(X, 2)
variableSetSize = size(X, 1) # nr. of rows of X
variables = CuArray(X) results = Matrix{Float32}(undef, ncols, length(exprs))
# TODO: create CuArray for variables here already, as they never change
# could/should be done even before calling this, but I guess it would be diminishing returns
# TODO: test how this would impact performance, if it gets faster, adapt implementation section
# TODO: create CuArray for expressions here already. They also do not change over the course of parameter optimisation and therefore a lot of unnecessary calls to expr_to_postfix can be save (even though a cache is used, this should still be faster)
largestParameterSetSize = Utils.get_max_inner_length(p) # parameters get transformed into matrix. Will be nr. of rows in parameter matrix
ptxKernels = Vector{String}(undef, length(expressions))
kernelName = "evaluate_gpu"
@inbounds Threads.@threads for i in eachindex(expressions)
ex = ExpressionProcessing.expr_to_postfix(expressions[i])
ptxKernels[i] = Transpiler.transpile(ex, variableSetSize, largestParameterSetSize, numVariableSets, i-1, kernelName) # i-1 because julia is 1-based but PTX needs 0-based indexing
end
results = Matrix{Float32}(undef, numVariableSets, length(expressions))
for i in 1:repetitions # Simulate parameter tuning -> local search (X remains the same, p gets changed in small steps and must be performed sequentially, which it is with this impl) for i in 1:repetitions # Simulate parameter tuning -> local search (X remains the same, p gets changed in small steps and must be performed sequentially, which it is with this impl)
# evaluate results = Transpiler.evaluate(exprs, X, p)
# results = Transpiler.evaluate(exprs, variables, numVariableSets, variableSetSize, p)
results = Transpiler.evaluate(ptxKernels, variables, numVariableSets, p, kernelName)
end end
return results return results
@ -109,6 +93,7 @@ function interpret_cpu(exprs::Vector{Expr}, X::Matrix{Float32}, p::Vector{Vector
res res
end end
# Flow # Flow
# input: Vector expr == expressions contains eg. 4 expressions # input: Vector expr == expressions contains eg. 4 expressions
# Matrix X == |expr| columns, n rows. n == number of variabls x1..xn; n is the same for all expressions --- WRONG # Matrix X == |expr| columns, n rows. n == number of variabls x1..xn; n is the same for all expressions --- WRONG

View File

@ -22,6 +22,7 @@ const PostfixType = Vector{ExpressionElement}
" "
Converts a julia expression to its postfix notation. Converts a julia expression to its postfix notation.
NOTE: All 64-Bit values will be converted to 32-Bit. Be aware of the lost precision. NOTE: All 64-Bit values will be converted to 32-Bit. Be aware of the lost precision.
NOTE: This function is not thread save, especially cache access is not thread save
" "
function expr_to_postfix(expression::Expr)::PostfixType function expr_to_postfix(expression::Expr)::PostfixType
expr = expression expr = expression

View File

@ -8,25 +8,31 @@ export interpret
"Interprets the given expressions with the values provided. "Interprets the given expressions with the values provided.
# Arguments # Arguments
- cudaExprs::CuArray{ExpressionProcessing.PostfixType} : The expressions to execute in postfix form and already sent to the GPU. The type information in the signature is missing, because creating a CuArray{ExpressionProcessing.PostfixType} results in a mor everbose type definition - expressions::Vector{ExpressionProcessing.PostfixType} : The expressions to execute in postfix form
- cudaVars::CuArray{Float32} : The variables to use. Each column is mapped to the variables x1..xn. The type information is missing due to the same reasons as cudaExprs - variables::Matrix{Float32} : The variables to use. Each column is mapped to the variables x1..xn
- parameters::Vector{Vector{Float32}} : The parameters to use. Each Vector contains the values for the parameters p1..pn. The number of parameters can be different for every expression - parameters::Vector{Vector{Float32}} : The parameters to use. Each Vector contains the values for the parameters p1..pn. The number of parameters can be different for every expression
- kwparam ```frontendCache```: The cache that stores the (partial) results of the frontend - kwparam ```frontendCache```: The cache that stores the (partial) results of the frontend
" "
function interpret(cudaExprs, numExprs::Integer, exprsInnerLength::Integer, function interpret(expressions::Vector{Expr}, variables::Matrix{Float32}, parameters::Vector{Vector{Float32}})::Matrix{Float32}
cudaVars, variableColumns::Integer, variableRows::Integer, parameters::Vector{Vector{Float32}})::Matrix{Float32} exprs = Vector{ExpressionProcessing.PostfixType}(undef, length(expressions))
@inbounds for i in eachindex(expressions)
exprs[i] = ExpressionProcessing.expr_to_postfix(expressions[i])
end
variableCols = size(variables, 2) # number of variable sets to use for each expression
cudaVars = CuArray(variables)
cudaParams = Utils.create_cuda_array(parameters, NaN32) # column corresponds to data for one expression cudaParams = Utils.create_cuda_array(parameters, NaN32) # column corresponds to data for one expression
cudaExprs = Utils.create_cuda_array(exprs, ExpressionElement(EMPTY, 0)) # column corresponds to data for one expression;
# put into seperate cuArray, as this is static and would be inefficient to send seperatly to each kernel # put into seperate cuArray, as this is static and would be inefficient to send seperatly to each kernel
cudaStepsize = CuArray([exprsInnerLength, Utils.get_max_inner_length(parameters), variableRows]) # max num of values per expression; max nam of parameters per expression; number of variables per expression cudaStepsize = CuArray([Utils.get_max_inner_length(exprs), Utils.get_max_inner_length(parameters), size(variables, 1)]) # max num of values per expression; max nam of parameters per expression; number of variables per expression
# each expression has nr. of variable sets (nr. of columns of the variables) results and there are n expressions # each expression has nr. of variable sets (nr. of columns of the variables) results and there are n expressions
cudaResults = CuArray{Float32}(undef, variableColumns, numExprs) cudaResults = CuArray{Float32}(undef, variableCols, length(exprs))
# Start kernel for each expression to ensure that no warp is working on different expressions # Start kernel for each expression to ensure that no warp is working on different expressions
@inbounds Threads.@threads for i in 1:numExprs # multithreaded to speedup dispatching (seems to have improved performance) @inbounds Threads.@threads for i in eachindex(exprs)
numThreads = min(variableColumns, 121) numThreads = min(variableCols, 256)
numBlocks = cld(variableColumns, numThreads) numBlocks = cld(variableCols, numThreads)
@cuda threads=numThreads blocks=numBlocks fastmath=true interpret_expression(cudaExprs, cudaVars, cudaParams, cudaResults, cudaStepsize, i) @cuda threads=numThreads blocks=numBlocks fastmath=true interpret_expression(cudaExprs, cudaVars, cudaParams, cudaResults, cudaStepsize, i)
end end

View File

@ -12,56 +12,79 @@ const Operand = Union{Float32, String} # Operand is either fixed value or regist
- kwparam ```frontendCache```: The cache that stores the (partial) results of the frontend, to speedup the pre-processing - kwparam ```frontendCache```: The cache that stores the (partial) results of the frontend, to speedup the pre-processing
- kwparam ```frontendCache```: The cache that stores the result of the transpilation. Useful for parameter optimisation, as the same expression gets executed multiple times - kwparam ```frontendCache```: The cache that stores the result of the transpilation. Useful for parameter optimisation, as the same expression gets executed multiple times
" "
function evaluate(expressions::Vector{ExpressionProcessing.PostfixType}, cudaVars::CuArray{Float32}, variableColumns::Integer, variableRows::Integer, parameters::Vector{Vector{Float32}})::Matrix{Float32} function evaluate(expressions::Vector{Expr}, variables::Matrix{Float32}, parameters::Vector{Vector{Float32}})::Matrix{Float32}
varRows = size(variables, 1)
variableCols = size(variables, 2)
# kernels = Vector{CuFunction}(undef, length(expressions))
# TODO: test this again with multiple threads. The first time I tried, I was using only one thread
# Test this parallel version again when doing performance tests. With the simple "functionality" tests this took 0.03 seconds while sequential took "0.00009" seconds
# Threads.@threads for i in eachindex(expressions)
# cacheLock = ReentrantLock()
# cacheHit = false
# lock(cacheLock) do
# if haskey(transpilerCache, expressions[i])
# kernels[i] = transpilerCache[expressions[i]]
# cacheHit = true
# end
# end
# if cacheHit
# continue
# end
# formattedExpr = ExpressionProcessing.expr_to_postfix(expressions[i])
# kernel = transpile(formattedExpr, varRows, Utils.get_max_inner_length(parameters), variableCols, i-1) # i-1 because julia is 1-based but PTX needs 0-based indexing
# linker = CuLink()
# add_data!(linker, "ExpressionProcessing", kernel)
# image = complete(linker)
# mod = CuModule(image)
# kernels[i] = CuFunction(mod, "ExpressionProcessing")
# @lock cacheLock transpilerCache[expressions[i]] = kernels[i]
# end
cudaVars = CuArray(variables) # maybe put in shared memory (see PerformanceTests.jl for more info)
cudaParams = Utils.create_cuda_array(parameters, NaN32) # maybe make constant (see PerformanceTests.jl for more info) cudaParams = Utils.create_cuda_array(parameters, NaN32) # maybe make constant (see PerformanceTests.jl for more info)
# each expression has nr. of variable sets (nr. of columns of the variables) results and there are n expressions # each expression has nr. of variable sets (nr. of columns of the variables) results and there are n expressions
cudaResults = CuArray{Float32}(undef, variableColumns, length(expressions)) cudaResults = CuArray{Float32}(undef, variableCols, length(expressions))
threads = min(variableColumns, 256) threads = min(variableCols, 256)
blocks = cld(variableColumns, threads) blocks = cld(variableCols, threads)
kernelName = "evaluate_gpu" kernelName = "evaluate_gpu"
# TODO: Implement batching as a middleground between "transpile everything and then run" and "tranpile one run one" even though cudacall is async
@inbounds Threads.@threads for i in eachindex(expressions) @inbounds Threads.@threads for i in eachindex(expressions)
kernel = transpile(expressions[i], variableRows, Utils.get_max_inner_length(parameters), variableColumns, i-1, kernelName) # i-1 because julia is 1-based but PTX needs 0-based indexing # if haskey(resultCache, expressions[i])
compiledKernel = CompileKernel(kernel, kernelName) # kernels[i] = resultCache[expressions[i]]
# continue
# end
formattedExpr = ExpressionProcessing.expr_to_postfix(expressions[i])
kernel = transpile(formattedExpr, varRows, Utils.get_max_inner_length(parameters), variableCols, i-1, kernelName) # i-1 because julia is 1-based but PTX needs 0-based indexing
linker = CuLink()
add_data!(linker, kernelName, kernel)
image = complete(linker)
mod = CuModule(image)
compiledKernel = CuFunction(mod, kernelName)
cudacall(compiledKernel, (CuPtr{Float32},CuPtr{Float32},CuPtr{Float32}), cudaVars, cudaParams, cudaResults; threads=threads, blocks=blocks) cudacall(compiledKernel, (CuPtr{Float32},CuPtr{Float32},CuPtr{Float32}), cudaVars, cudaParams, cudaResults; threads=threads, blocks=blocks)
end end
return cudaResults # for kernel in kernels
end # cudacall(kernel, (CuPtr{Float32},CuPtr{Float32},CuPtr{Float32}), cudaVars, cudaParams, cudaResults; threads=threads, blocks=blocks)
# end
"
A simplified version of the evaluate function. It takes a list of already transpiled kernels to be executed. This should yield better performance, where the same expressions should be evaluated multiple times i.e. for parameter optimisation.
"
function evaluate(kernels::Vector{String}, cudaVars::CuArray{Float32}, nrOfVariableSets::Integer, parameters::Vector{Vector{Float32}}, kernelName::String)::Matrix{Float32}
cudaParams = Utils.create_cuda_array(parameters, NaN32) # maybe make constant (see PerformanceTests.jl for more info)
# each expression has nr. of variable sets (nr. of columns of the variables) results and there are n expressions
cudaResults = CuArray{Float32}(undef, nrOfVariableSets, length(kernels))
threads = min(nrOfVariableSets, 256)
blocks = cld(nrOfVariableSets, threads)
@inbounds Threads.@threads for i in eachindex(kernels)
compiledKernel = CompileKernel(kernels[i], kernelName)
cudacall(compiledKernel, (CuPtr{Float32},CuPtr{Float32},CuPtr{Float32}), cudaVars, cudaParams, cudaResults; threads=threads, blocks=blocks)
end
return cudaResults return cudaResults
end end
function CompileKernel(ptxKernel::String, kernelName::String)::CuFunction
linker = CuLink()
add_data!(linker, kernelName, ptxKernel)
image = complete(linker)
mod = CuModule(image)
return CuFunction(mod, kernelName)
end
# To increase performance, it would probably be best for all helper functions to return their IO Buffer and not a string # To increase performance, it would probably be best for all helper functions to return their IO Buffer and not a string
# seekstart(buf1); write(buf2, buf1) # seekstart(buf1); write(buf2, buf1)
" "

View File

@ -21,16 +21,8 @@ parameters[2][1] = 5.0
parameters[2][2] = 0.0 parameters[2][2] = 0.0
function testHelper(expression::Expr, variables::Matrix{Float32}, parameters::Vector{Vector{Float32}}, expectedResult) function testHelper(expression::Expr, variables::Matrix{Float32}, parameters::Vector{Vector{Float32}}, expectedResult)
exprs = [ExpressionProcessing.expr_to_postfix(expression)] exprs = Vector([expression])
cudaExprs = Utils.create_cuda_array(exprs, ExpressionProcessing.ExpressionElement(EMPTY, 0)) result = Interpreter.interpret(exprs, variables, parameters)
exprsLength = length(exprs)
exprsInnerLength = Utils.get_max_inner_length(exprs)
X = CuArray(variables)
variableCols = size(variables, 2)
variableRows = size(variables, 1)
result = Interpreter.interpret(cudaExprs, exprsLength, exprsInnerLength, X, variableCols, variableRows, parameters)
expectedResult32 = convert(Float32, expectedResult) expectedResult32 = convert(Float32, expectedResult)
@test isequal(result[1,1], expectedResult32) @test isequal(result[1,1], expectedResult32)
@ -135,16 +127,8 @@ end
expr1 = :((x1 + 5) * p1 - 3 / abs(x2) + (2^4) - log(8)) expr1 = :((x1 + 5) * p1 - 3 / abs(x2) + (2^4) - log(8))
expr2 = :(1 + 5 * x1 - 10^2 + (p1 - p2) / 9 + exp(x2)) expr2 = :(1 + 5 * x1 - 10^2 + (p1 - p2) / 9 + exp(x2))
exprs = [ExpressionProcessing.expr_to_postfix(expr1), ExpressionProcessing.expr_to_postfix(expr2)] exprs = Vector([expr1, expr2])
cudaExprs = Utils.create_cuda_array(exprs, ExpressionProcessing.ExpressionElement(EMPTY, 0)) result = Interpreter.interpret(exprs, var, param)
exprsLength = length(exprs)
exprsInnerLength = Utils.get_max_inner_length(exprs)
X = CuArray(var)
variableCols = size(var, 2)
variableRows = size(var, 1)
result = Interpreter.interpret(cudaExprs, exprsLength, exprsInnerLength, X, variableCols, variableRows, param)
# var set 1 # var set 1
@test isapprox(result[1,1], 37.32, atol=0.01) # expr1 @test isapprox(result[1,1], 37.32, atol=0.01) # expr1

View File

@ -10,7 +10,6 @@ using .ExpressionProcessing
include("parser.jl") # to parse expressions from a file include("parser.jl") # to parse expressions from a file
# ATTENTAION: Evaluation information at the very bottom
const BENCHMARKS_RESULTS_PATH = "./results-fh-new" const BENCHMARKS_RESULTS_PATH = "./results-fh-new"
# Number of expressions can get really big (into millions) # Number of expressions can get really big (into millions)
@ -69,7 +68,7 @@ suite["GPUT"]["nikuradse_1"] = @benchmarkable evaluate_gpu(exprs, X_t, parameter
loadparams!(suite, BenchmarkTools.load("params.json")[1], :samples, :evals, :gctrial, :time_tolerance, :evals_set, :gcsample, :seconds, :overhead, :memory_tolerance) loadparams!(suite, BenchmarkTools.load("params.json")[1], :samples, :evals, :gctrial, :time_tolerance, :evals_set, :gcsample, :seconds, :overhead, :memory_tolerance)
results = run(suite, verbose=true, seconds=43200) # 12 hour timeout results = run(suite, verbose=true, seconds=28800) # 8 hour timeout
resultsCPU = BenchmarkTools.load("$BENCHMARKS_RESULTS_PATH/cpu.json")[1] resultsCPU = BenchmarkTools.load("$BENCHMARKS_RESULTS_PATH/cpu.json")[1]
if compareWithCPU if compareWithCPU
@ -105,7 +104,7 @@ if compareWithCPU
println(gpuiVsGPUT_median) println(gpuiVsGPUT_median)
println(gpuiVsGPUT_std) println(gpuiVsGPUT_std)
BenchmarkTools.save("$BENCHMARKS_RESULTS_PATH/1-fronted-and-data-transfer-to-ExpressionExecutor.json", results) BenchmarkTools.save("$BENCHMARKS_RESULTS_PATH/0-initial.json", results)
else else
resultsOld = BenchmarkTools.load("$BENCHMARKS_RESULTS_PATH/3-tuned-blocksize_I128_T96.json")[1] resultsOld = BenchmarkTools.load("$BENCHMARKS_RESULTS_PATH/3-tuned-blocksize_I128_T96.json")[1]
# resultsOld = BenchmarkTools.load("$BENCHMARKS_RESULTS_PATH/3-tuned-blocksize_I128_T96.json")[1] # resultsOld = BenchmarkTools.load("$BENCHMARKS_RESULTS_PATH/3-tuned-blocksize_I128_T96.json")[1]
@ -140,8 +139,3 @@ else
println(oldVsGPUT_std) println(oldVsGPUT_std)
end end
# Initial implementation:
# - Interpreter: no cache; 256 blocksize; exprs pre-processed and sent to GPU on every call; vars sent on every call; frontend + dispatch are multithreaded
# - Transpiler: no cahce; 256 blocksize; exprs pre-processed and transpiled on every call; vars sent on every call; frontend + transpilation + dispatch are multithreaded

View File

@ -1,38 +1,30 @@
using CUDA using CUDA
using DelimitedFiles
using GZip
using .Transpiler using .Transpiler
using .Interpreter using .Interpreter
include("parser.jl") # to parse expressions from a file varsets_medium = 10000
X = randn(Float32, 5, varsets_medium)
exprsGPU = [
# CPU interpreter requires an anonymous function and array ref s
:(p1 * x1 + p2), # 5 op
:((((x1 + x2) + x3) + x4) + x5), # 9 op
:(log(abs(x1))), # 3 op
:(powabs(p2 - powabs(p1 + x1, 1/x1),p3)) # 13 op
] # 30 op
data,varnames = readdlm("data/nikuradse_1.csv", ',', header=true); # p is the same for CPU and GPU
X = permutedims(convert(Matrix{Float32}, data)) p = [randn(Float32, 10) for _ in 1:length(exprsGPU)] # generate 10 random parameter values for each expr
exprs = Expr[]
parameters = Vector{Vector{Float32}}()
varnames = ["x$i" for i in 1:10]
paramnames = ["p$i" for i in 1:20]
# data/esr_nvar2_len10.txt.gz_9.txt.gz has ~250_000 exprs
# data/esr_nvar2_len10.txt.gz_10.txt.gz has ~800_000 exrps
GZip.open("data/esr_nvar2_len10.txt.gz_3.txt.gz") do io
for line in eachline(io)
expr, p = parse_infix(line, varnames, paramnames)
push!(exprs, expr)
push!(parameters, randn(Float32, length(p)))
end
end
expr_reps = 1 expr_reps = 1
@testset "Interpreter Tuning" begin @testset "Interpreter Tuning" begin
# CUDA.@profile interpret_gpu(exprs, X, parameters; repetitions=expr_reps) CUDA.@profile interpret_gpu(exprsGPU, X, p; repetitions=expr_reps)
end end
@testset "Transpiler Tuning" begin @testset "Transpiler Tuning" begin
CUDA.@profile evaluate_gpu(exprs, X, parameters; repetitions=expr_reps) CUDA.@profile evaluate_gpu(exprsGPU, X, p; repetitions=expr_reps)
end end

View File

@ -41,15 +41,19 @@ parameters[2][1] = 5.0
parameters[2][2] = 0.0 parameters[2][2] = 0.0
parameters[3][1] = 16.0 parameters[3][1] = 16.0
@testset "TEMP" begin
return
exprs = [:(x1 + p1)]
vars = Matrix{Float32}(undef, 1, 1)
params = Vector{Vector{Float32}}(undef, 1)
vars[1, 1] = 1
params[1] = [1]
Transpiler.evaluate(exprs, vars, params)
end
@testset "Test transpiler evaluation" begin @testset "Test transpiler evaluation" begin
variableCols = size(variables, 2) results = Transpiler.evaluate(expressions, variables, parameters)
variableRows = size(variables, 1)
X = CuArray(variables)
exprs = [ExpressionProcessing.expr_to_postfix(expressions[1]), ExpressionProcessing.expr_to_postfix(expressions[2]), ExpressionProcessing.expr_to_postfix(expressions[3])]
results = Transpiler.evaluate(exprs, X, variableCols, variableRows, parameters)
# dump(expressions[3]; maxdepth=10) # dump(expressions[3]; maxdepth=10)
# Expr 1: # Expr 1:

View File

@ -1,194 +0,0 @@
[
{
"Julia": "1.11.5",
"BenchmarkTools": {
"major": 1,
"minor": 6,
"patch": 0,
"prerelease": [],
"build": []
}
},
[
[
"BenchmarkGroup",
{
"data": {
"GPUT": [
"BenchmarkGroup",
{
"data": {
"nikuradse_1": [
"Trial",
{
"allocs": 9578295211,
"gctimes": [
5.773640884485e12
],
"memory": 99694581250168,
"params": [
"Parameters",
{
"gctrial": true,
"time_tolerance": 0.05,
"evals_set": false,
"samples": 50,
"evals": 1,
"gcsample": false,
"seconds": 43200.0,
"overhead": 0.0,
"memory_tolerance": 0.01
}
],
"times": [
5.1630263257036e13
]
}
]
},
"tags": [
"GPUTranspiler"
]
}
],
"GPUI": [
"BenchmarkGroup",
{
"data": {
"nikuradse_1": [
"Trial",
{
"allocs": 768768117,
"gctimes": [
1.1975019005e10,
7.985238732e9,
1.4256539541e10,
8.877686056e9,
1.4680883881e10,
7.692335492e9,
9.536354709e9,
1.3536376614e10,
1.4238839111e10,
1.9925752838e10,
9.025028453e9,
1.5572506957e10,
1.952938358e10,
1.1815896105e10,
1.3613672963e10,
1.155423324e10,
1.4004956257e10,
8.806173097e9,
8.174429914e9,
1.3263383027e10,
1.0794204698e10,
1.5559450665e10,
1.1655933294e10,
1.0337481053e10,
1.736781041e10,
1.7557373752e10,
1.0408159512e10,
1.9575876788e10,
1.1552463317e10,
1.226612493e10,
1.39046431e10,
1.4741246638e10,
1.3349550404e10,
1.1029748223e10,
1.2336413042e10,
1.8974104972e10,
1.62980404e10,
1.7060266354e10,
1.4275735627e10,
1.1090002413e10,
9.354486934e9,
1.0120009791e10,
1.2904978229e10,
1.9392024576e10,
1.4288312066e10,
9.172039439e9,
1.1963691856e10,
1.7642492412e10,
1.4929130699e10,
1.5905152758e10
],
"memory": 54082719144,
"params": [
"Parameters",
{
"gctrial": true,
"time_tolerance": 0.05,
"evals_set": false,
"samples": 50,
"evals": 1,
"gcsample": false,
"seconds": 43200.0,
"overhead": 0.0,
"memory_tolerance": 0.01
}
],
"times": [
5.14174363969e11,
5.18689077274e11,
5.1025535864e11,
5.10803229124e11,
5.23299818383e11,
5.16455770592e11,
5.02350694438e11,
5.0439224751e11,
5.04269366358e11,
5.06595858959e11,
5.11724089224e11,
5.1262595436e11,
5.03168612131e11,
5.21219083737e11,
5.00099394667e11,
5.11001185335e11,
5.08254610458e11,
5.15228010681e11,
5.1538764885e11,
5.00595179658e11,
5.09523742228e11,
5.09818545112e11,
5.14655215639e11,
5.14933349609e11,
5.0169600001e11,
5.12605187963e11,
5.08668518972e11,
4.99756633692e11,
5.04657100071e11,
4.96300433311e11,
5.02859857609e11,
5.00544153225e11,
5.01888246474e11,
5.10711561485e11,
5.1255887708e11,
5.03690773615e11,
4.98071106526e11,
5.14512763271e11,
5.06840174712e11,
5.18008421655e11,
5.1741870342e11,
5.01369775936e11,
5.08726698998e11,
5.04550273414e11,
5.06774233833e11,
5.16671635611e11,
5.09574401096e11,
5.03123609086e11,
5.11987873937e11,
5.03337347704e11
]
}
]
},
"tags": [
"GPUInterpreter"
]
}
]
},
"tags": []
}
]
]
]

View File

@ -1,196 +0,0 @@
[
{
"Julia": "1.11.5",
"BenchmarkTools": {
"major": 1,
"minor": 6,
"patch": 0,
"prerelease": [],
"build": []
}
},
[
[
"BenchmarkGroup",
{
"data": {
"GPUT": [
"BenchmarkGroup",
{
"data": {
"nikuradse_1": [
"Trial",
{
"allocs": 1534044518,
"gctimes": [
3.162096218033e12,
2.514920522839e12
],
"memory": 51380856414712,
"params": [
"Parameters",
{
"gctrial": true,
"time_tolerance": 0.05,
"evals_set": false,
"samples": 50,
"evals": 1,
"gcsample": false,
"seconds": 43200.0,
"overhead": 0.0,
"memory_tolerance": 0.01
}
],
"times": [
3.579290341907e13,
3.6476991686227e13
]
}
]
},
"tags": [
"GPUTranspiler"
]
}
],
"GPUI": [
"BenchmarkGroup",
{
"data": {
"nikuradse_1": [
"Trial",
{
"allocs": 768767740,
"gctimes": [
1.4209871071e10,
8.529233725e9,
8.165943693e9,
8.180014668e9,
8.231263428e9,
1.1110946388e10,
1.3136749872e10,
1.0515143897e10,
1.2978886885e10,
1.0709110363e10,
1.2408937103e10,
1.4486745203e10,
1.3229416582e10,
1.8353010658e10,
1.32173253e10,
1.1621004633e10,
1.1136122325e10,
9.614762707e9,
1.4564265563e10,
9.399404156e9,
1.063983064e10,
1.2513746965e10,
9.039906393e9,
1.2382209752e10,
1.3127092115e10,
1.2713843793e10,
1.1111974511e10,
1.5837882785e10,
1.5005237417e10,
1.2439743996e10,
9.607861366e9,
1.0680724758e10,
1.4012997282e10,
1.258804731e10,
1.020862355e10,
9.630750655e9,
1.5428270551e10,
1.746317266e10,
1.3141055589e10,
1.5009128259e10,
8.453648604e9,
1.6874341516e10,
1.1411307067e10,
1.2542892313e10,
1.1232296452e10,
1.3458245148e10,
1.0818032806e10,
9.239119183e9,
1.7897566617e10,
1.565065385e10
],
"memory": 54082712568,
"params": [
"Parameters",
{
"gctrial": true,
"time_tolerance": 0.05,
"evals_set": false,
"samples": 50,
"evals": 1,
"gcsample": false,
"seconds": 43200.0,
"overhead": 0.0,
"memory_tolerance": 0.01
}
],
"times": [
4.72169572882e11,
5.0409909815e11,
5.07815085942e11,
5.10453558146e11,
5.10478958938e11,
4.97262381193e11,
5.0260603513e11,
4.99542972531e11,
4.87993778737e11,
4.89021704445e11,
5.03746768492e11,
4.89869107858e11,
4.73146154356e11,
4.8171801387e11,
5.08579879922e11,
4.949573335e11,
4.72187897068e11,
4.99229768599e11,
4.60419913288e11,
4.69019613895e11,
4.50583091837e11,
4.72792727311e11,
4.72333754492e11,
4.65152305777e11,
4.82234976786e11,
4.72238483765e11,
4.73826923338e11,
4.76267120461e11,
4.87120033427e11,
5.04120244741e11,
4.69559064737e11,
4.72201757593e11,
4.69914031792e11,
4.93629873162e11,
4.71968584791e11,
5.01452793581e11,
4.80458931455e11,
4.83065538379e11,
4.99070229147e11,
4.71609869279e11,
4.71492369998e11,
4.58522950715e11,
4.80960881323e11,
4.91960762476e11,
4.73412762655e11,
4.69283546561e11,
4.66574358844e11,
4.67318993209e11,
4.5724723899e11,
4.7334516285e11
]
}
]
},
"tags": [
"GPUInterpreter"
]
}
]
},
"tags": []
}
]
]
]

View File

@ -1,82 +1,42 @@
\chapter{Evaluation} \chapter{Evaluation}
\label{cha:evaluation} \label{cha:evaluation}
This thesis aims to determine whether one of the two GPU evaluators is faster than the current CPU evaluator. This chapter describes the performance evaluation process. First, the environment in which the performance benchmarks are conducted is explained. Next the individual results for the GPU interpreter and transpiler are presented individually. This section also includes the performance tuning steps taken to achieve these results. Finally, the results of the GPU evaluators are compared to those of the CPU evaluator to answer the research questions of this thesis. The aim of this thesis is to determine whether at least one of the GPU evaluators is faster than the current CPU evaluator. This chapter describes the performance evaluation. First, the environment in which the performance tests are performed is explained. Then the individual results for the GPU interpreter and the transpiler are presented. In addition, this part also includes the performance tuning steps taken to achieve these results. Finally, the results of the GPU evaluators are compared to the CPU evaluator in order to answer the research questions of this thesis.
\section{Benchmark Environment} \section{Test environment}
In this section, the benchmark environment used to evaluate the performance is outlined. To ensure the validity and reliability of the results, it is necessary to specify the details of the environment. This includes a description of the hardware and software configuration as well as the performance evaluation process. With this, the variance between the results is minimised, which allows for better reproducibility and comparability between the implementations. Explain the hardware used, as well as the actual data (how many expressions, variables etc.)
\subsection{Hardware Configuration}
The hardware configuration is the most important aspect of the benchmark environment. The capabilities of both the CPU and GPU can have a significant impact on the resulting performance. The following sections outline the importance of the individual components as well as the hardware used for the benchmarks.
\subsubsection{GPU}
Especially the GPU is important, as different microarchitectures typically require different optimisations. While the evaluators can generally run on any Nvidia GPU with a compute capability of at least 6.1, they are tuned for the Ampere microarchitecture with a compute capability of 8.6. Despite the evaluators being tuned for this microarchitecture, more modern ones can be used as well. However, additional tuning is required to ensure the evaluators can utilise the hardware to its fullest potential.
\subsubsection{CPU}
Although the GPU plays a crucial role, work is also carried out on the CPU. The interpreter mainly uses the CPU for data transfer and the pre-processing step and is therefore more GPU-bound. However, the transpiler additionally needs the CPU to perform the transpilation step. This step produces a kernel for each expression and also involves sending these kernels to the driver for compilation, a process which is also performed by the CPU. By contrast, the interpreter only has one kernel that needs to be converted into PTX and compiled by the driver only once. Consequently, the transpiler is much more CPU-bound and variations in the used CPU have a much greater impact. Therefore, using a more powerful CPU benefits the transpiler more than the interpreter.
\subsubsection{System Memory}
In addition to the hardware configuration of the GPU and CPU, system memory (RAM) also plays a crucial role. While RAM does not directly contribute to the overall performance, it can have a noticeable indirect impact due to its role in caching. Insufficient RAM forces the operating system to use the page file, which is stored on a much slower SSD. This results in slower cache access, thereby reducing the overall performance of the application.
As seen in the list below, only 16 GB of RAM were available during the benchmarking process. This amount is insufficient to utilise caching to the extent outlined in Chapter \ref{cha:implementation}. More RAM was not available, which means some caching had to be disabled, which will be further explained in Section \ref{sec:results}.
\subsubsection{Hardware}
With the requirements explained above in mind, the following hardware is used to perform the benchmarks for the CPU-based evaluator, which was used as the baseline, as well as for the GPU-based evaluators:
\begin{itemize}
\item Intel i5 12500
\item Nvidia RTX 3060 Ti
\item 16 GB 4400 MT/s DDR5 RAM
\end{itemize}
\subsection{Software Configuration}
Apart from the hardware, the performance of the evaluators can also be significantly affected by the software. Primarily these three software components are involved in the performance:
\begin{itemize}
\item GPU Driver
\item Julia
\item CUDA.jl
\end{itemize}
Typically, newer versions of these components include performance improvements, among other things. This is why it is important to specify the version which is used for benchmarking. The GPU driver uses version \emph{561.17}, Julia uses version \emph{1.11.5}, and CUDA.jl uses version \emph{5.8.1}. As with the hardware configuration, this ensures that the results are reproducible and comparable to each other.
\subsection{Performance evaluation process}
% explain the actual data
% Nikuradse dataset (flowrate through rough pipes (fact check that again))
% 250k expressions; ~300 variable sets; 100 parameter optimisation steps (simulated)
% using Benchmarktools.jl as a tried and tested benchmark suite
% 50 samples to eliminate any run-to-run variance
three scenarios -> few, normal and many variable sets;; expr repetitions to simulate parameter optimisation
Benchmarktools.jl -> 1000 samples per scenario
\section{Results} \section{Results}
\label{sec:results} talk about what we will see now (results only for interpreter, then transpiler and then compared with each other and a CPU interpreter)
talk about what we will see now (results only for interpreter, then transpiler and then compared with each other and the CPU interpreter)
BECAUSE OF RAM CONSTRAINTS, CACHING IS NOT USED TO THE FULL EXTEND AS IN CONTRAST TO HOW IT IS EXPLAINED IN THE IMPLEMENTATION CHAPTER. I hope I can cache the frontend. If only the finished kernels can not be cached, move this explanation to the transpiler section below and update the reference in subsubsection "System Memory"
\subsection{Interpreter} \subsection{Interpreter}
Results only for Interpreter (also contains final kernel configuration and probably quick overview/recap of the implementation used and described in Implementation section) Results only for Interpreter (also contains final kernel configuration and probably quick overview/recap of the implementation used and described in Implementation section)
\subsection{Performance Tuning} \subsection{Performance tuning}
Document the process of performance tuning Document the process of performance tuning
Initial: no cache; 256 blocksize; exprs pre-processed and sent to GPU on every call; vars sent on every call; frontend + dispatch are multithreaded Initial: CPU-Side single-threaded; up to 1024 threads per block; bounds-checking enabled (especially in kernel)
1.) Done before parameter optimisation loop: Frontend, transmitting Exprs and Variables (improved runtime)
2.) tuned blocksize to have as little wasted threads as possible (new blocksize 121 -> 3-blocks -> 363 threads but 362 threads needed per expression)
1.) Blocksize reduced to a maximum of 256 -> moderate improvement in medium and large
2.) Using @inbounds -> noticeable improvement in 2 out of 3
3.) Tuned blocksize with NSight compute -> slight improvement
4.) used int32 everywhere to reduce register usage -> significant performance drop (probably because a lot more waiting time "latency hiding not working basically", or more type conversions happening on GPU? look at generated PTX code and use that as an argument to describe why it is slower)
5.) reverted previous; used fastmath instead -> imporvement (large var set is now faster than on transpiler)
\subsection{Transpiler} \subsection{Transpiler}
Results only for Transpiler (also contains final kernel configuration and probably quick overview/recap of the implementation used and described in Implementation section Results only for Transpiler (also contains final kernel configuration and probably quick overview/recap of the implementation used and described in Implementation section
\subsection{Performance tuning}
\subsection{Performance Tuning}
Document the process of performance tuning Document the process of performance tuning
Initial: no cache; 256 blocksize; exprs pre-processed and transpiled on every call; vars sent on every call; frontend + transpilation + dispatch are multithreaded Initial: CPU-Side single-threaded; up to 1024 threads per block; bounds-checking enabled
1.) Done before parameter optimisation loop: Frontend, transmitting Exprs and Variables (improved runtime) 1.) Blocksize reduced to a maximum of 256 -> moderate improvement in medium and large
2.) All expressions to execute are transpiled first (before they were transpiled for every execution, even in parameter optimisation scenarios). Compilation is still done every time, because too little RAM was available (compilation takes the most time, so this is only a minor boost) 2.) Using @inbounds -> small improvement only on CPU side code
3.) Tuned blocksize with NSight compute -> slight improvement
4.) Only changed things on interpreter side
5.) Only changed things on interpreter side
\subsection{Comparison} \subsection{Comparison}
Comparison of Interpreter and Transpiler as well as Comparing the two with CPU interpreter Comparison of Interpreter and Transpiler as well as Comparing the two with CPU interpreter

Binary file not shown.