transpiler: invalid memory access error finally fixed
Some checks are pending
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Waiting to run
Some checks are pending
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.10) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, 1.6) (push) Waiting to run
CI / Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} (x64, ubuntu-latest, pre) (push) Waiting to run
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using LinearAlgebra
|
||||
using BenchmarkTools
|
||||
|
||||
function test_cpu_interpreter(nrows; parallel = false)
|
||||
exprs = [
|
||||
@ -18,16 +19,27 @@ function test_cpu_interpreter(nrows; parallel = false)
|
||||
reps= 100
|
||||
|
||||
if parallel
|
||||
t_sec = @elapsed fetch.([Threads.@spawn interpret_cpu(exprs, X, p; repetitions=expr_reps) for i in 1:reps])
|
||||
println("~ $(round(30 * reps * expr_reps * nrows / 1e9 / t_sec, digits=2)) GFLOPS ($(Threads.nthreads()) threads) ($(round(peakflops(1000, eltype=Float32, ntrials=1) / 1e9, digits=2)) GFLOPS (peak, single-core))")
|
||||
# t_sec = @elapsed fetch.([Threads.@spawn interpret_cpu(exprs, X, p; repetitions=expr_reps) for i in 1:reps])
|
||||
@btime parallel(exprs, X, p, expr_reps, reps)
|
||||
println("~ $(round(30 * reps * expr_reps * nrows / 1e9 / t_sec, digits=2)) GFLOPS ($(Threads.nthreads()) threads) ($(round(LinearAlgebra.peakflops(1000, eltype=Float32, ntrials=1) / 1e9, digits=2)) GFLOPS (peak, single-core))")
|
||||
else
|
||||
t_sec = @elapsed for i in 1:reps interpret_cpu(exprs, X, p; repetitions=expr_reps) end
|
||||
println("~ $(round(30 * reps * expr_reps * nrows / 1e9 / t_sec, digits=2)) GFLOPS (single-core) ($(round(peakflops(1000, eltype=Float32, ntrials=1) / 1e9, digits=2)) GFLOPS (peak, single-core))")
|
||||
# t_sec = @elapsed for i in 1:reps interpret_cpu(exprs, X, p; repetitions=expr_reps) end
|
||||
@btime single(exprs, X, p, expr_reps, reps)
|
||||
println("~ $(round(30 * reps * expr_reps * nrows / 1e9 / t_sec, digits=2)) GFLOPS (single-core) ($(round(LinearAlgebra.peakflops(1000, eltype=Float32, ntrials=1) / 1e9, digits=2)) GFLOPS (peak, single-core))")
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
LinearAlgebra.BLAS.set_num_threads(1) # only use a single thread for peakflops
|
||||
function parallel(exprs, X, p, expr_reps, reps)
|
||||
fetch.([Threads.@spawn interpret_cpu(exprs, X, p; repetitions=expr_reps) for i in 1:reps])
|
||||
end
|
||||
|
||||
function single(exprs, X, p, expr_reps, reps)
|
||||
for i in 1:reps interpret_cpu(exprs, X, p; repetitions=expr_reps) end
|
||||
end
|
||||
|
||||
|
||||
# LinearAlgebra.BLAS.set_num_threads(1) # only use a single thread for peakflops
|
||||
|
||||
@test test_cpu_interpreter(1000)
|
||||
@test test_cpu_interpreter(1000, parallel=true) # start julia -t 6 for six threads
|
||||
|
47
package/test/PerformanceTests.jl
Normal file
47
package/test/PerformanceTests.jl
Normal file
@ -0,0 +1,47 @@
|
||||
using .Transpiler
|
||||
using .Interpreter
|
||||
|
||||
@testset "CPU performance" begin
|
||||
function test_cpu_interpreter(nrows; parallel = false)
|
||||
exprs = [
|
||||
# CPU interpreter requires an anonymous function and array ref s
|
||||
:(p[1] * x[1] + p[2]), # 5 op
|
||||
:((((x[1] + x[2]) + x[3]) + x[4]) + x[5]), # 9 op
|
||||
:(log(abs(x[1]))), # 3 op
|
||||
:(powabs(p[2] - powabs(p[1] + x[1], 1/x[1]),p[3])) # 13 op
|
||||
] # 30 op
|
||||
exprs = map(e -> Expr(:->, :(x,p), e), exprs)
|
||||
X = randn(Float32, nrows, 10)
|
||||
p = [randn(Float32, 10) for _ in 1:length(exprs)] # generate 10 random parameter values for each expr
|
||||
|
||||
# warmup
|
||||
interpret_cpu(exprs, X, p)
|
||||
expr_reps = 100 # for each expr
|
||||
reps= 100
|
||||
|
||||
if parallel
|
||||
t_sec = @elapsed fetch.([Threads.@spawn interpret_cpu(exprs, X, p; repetitions=expr_reps) for i in 1:reps])
|
||||
println("~ $(round(30 * reps * expr_reps * nrows / 1e9 / t_sec, digits=2)) GFLOPS ($(Threads.nthreads()) threads) ($(round(peakflops(1000, eltype=Float32, ntrials=1) / 1e9, digits=2)) GFLOPS (peak, single-core))")
|
||||
else
|
||||
t_sec = @elapsed for i in 1:reps interpret_cpu(exprs, X, p; repetitions=expr_reps) end
|
||||
println("~ $(round(30 * reps * expr_reps * nrows / 1e9 / t_sec, digits=2)) GFLOPS (single-core) ($(round(peakflops(1000, eltype=Float32, ntrials=1) / 1e9, digits=2)) GFLOPS (peak, single-core))")
|
||||
end
|
||||
true
|
||||
end
|
||||
|
||||
LinearAlgebra.BLAS.set_num_threads(1) # only use a single thread for peakflops
|
||||
|
||||
@test test_cpu_interpreter(1000)
|
||||
@test test_cpu_interpreter(1000, parallel=true) # start julia -t 6 for six threads
|
||||
@test test_cpu_interpreter(10000)
|
||||
@test test_cpu_interpreter(10000, parallel=true)
|
||||
|
||||
end
|
||||
|
||||
@testset "Interpreter Performance" begin
|
||||
|
||||
end
|
||||
|
||||
@testset "Transpiler Performance" begin
|
||||
|
||||
end
|
@ -1,4 +1,6 @@
|
||||
[deps]
|
||||
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
|
||||
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
|
||||
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
|
||||
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
|
||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||
|
@ -48,30 +48,70 @@ end
|
||||
|
||||
expr = Vector{Expr}()
|
||||
push!(expr, expressions[1])
|
||||
# @time Transpiler.evaluate(expr, variables, parameters)
|
||||
@time Transpiler.evaluate(expr, variables, parameters)
|
||||
end
|
||||
|
||||
#TODO: test performance of transpiler PTX generation when doing "return String(take!(buffer))" vs "return take!(buffer)"
|
||||
|
||||
function test_kernel(results)
|
||||
@inbounds results[1] = 10f0
|
||||
|
||||
return nothing
|
||||
end
|
||||
|
||||
@testset "TEMP" begin
|
||||
return
|
||||
results = CuArray{Float32}(undef, 2)
|
||||
# @device_code_ptx @cuda test_kernel(results)
|
||||
|
||||
|
||||
# println(CUDA.code_ptx(kernel.fun, ))
|
||||
# return
|
||||
|
||||
ptx = "
|
||||
.version 7.1
|
||||
.version 8.5
|
||||
.target sm_61
|
||||
.address_size 64
|
||||
|
||||
.visible .entry ExpressionProcessing(
|
||||
.param .u32 param_1)
|
||||
.param .u64 param_1)
|
||||
{
|
||||
.reg .u32 %parameter<1>;
|
||||
.reg .u32 %i<1>;
|
||||
.reg .b64 %parameter<1>;
|
||||
.reg .b64 %i<1>;
|
||||
//.reg .b64 %rd<6>;
|
||||
|
||||
ld.param.u32 %i0, [param_1];
|
||||
cvta.to.global.u32 %parameter0, %i0;
|
||||
ld.param.u64 %i0, [param_1];
|
||||
cvta.to.global.u64 %parameter0, %i0;
|
||||
|
||||
st.global.f32 [%parameter0], 10.0;
|
||||
ret;
|
||||
}"
|
||||
|
||||
ptx = ".version 8.5
|
||||
.target sm_61
|
||||
.address_size 64
|
||||
|
||||
.visible .entry ExpressionProcessing(
|
||||
.param .u64 param_1)
|
||||
{
|
||||
.reg .b64 %parameter<1>;
|
||||
.reg .b32 %r<4>;
|
||||
.reg .pred %p<1>;
|
||||
.reg .b64 %i<1>;
|
||||
|
||||
ld.param.u64 %i0, [param_1];
|
||||
cvta.to.global.u64 %parameter0, %i0;
|
||||
|
||||
mov.u32 %r0, %ntid.x;
|
||||
mov.u32 %r1, %ctaid.x;
|
||||
mov.u32 %r2, %tid.x;
|
||||
mad.lo.s32 %r3, %r0, %r1, %r2;
|
||||
setp.gt.s32 %p0, %r3, 2;
|
||||
@%p0 bra \$L__BB0_2;
|
||||
st.global.f32 [%parameter0], 10.0;
|
||||
\$L__BB0_2: ret;
|
||||
}"
|
||||
|
||||
linker = CuLink()
|
||||
add_data!(linker, "ExpressionProcessing", ptx)
|
||||
|
||||
@ -90,11 +130,10 @@ end
|
||||
threads = min(variableCols, config.threads)
|
||||
blocks = cld(variableCols, threads)
|
||||
|
||||
cudacall(func, Tuple{CuPtr{Float32}}, cudaResults; threads=1, blocks=1)
|
||||
cudacall(func, Tuple{CuPtr{Float32}}, cudaResults; threads=4, blocks=1)
|
||||
# launch(func, cudaResults; threads=threads, blocks=blocks)
|
||||
|
||||
println(Array(cudaResults))
|
||||
end
|
||||
|
||||
|
||||
# TODO: University setup at 10.20.1.7
|
@ -14,9 +14,9 @@ include(joinpath(baseFolder, "src", "Transpiler.jl"))
|
||||
end
|
||||
|
||||
|
||||
#@testset "CPU Interpreter" begin
|
||||
# include("CpuInterpreterTests.jl")
|
||||
#end
|
||||
# @testset "CPU Interpreter" begin
|
||||
# include("CpuInterpreterTests.jl")
|
||||
# end
|
||||
|
||||
@testset "Performance tests" begin
|
||||
# TODO: make performance tests
|
||||
|
Reference in New Issue
Block a user