Skip to content

Commit

Permalink
Update integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
brenhinkeller committed Oct 20, 2022
1 parent af5d9f2 commit 5bd9159
Show file tree
Hide file tree
Showing 9 changed files with 402 additions and 88 deletions.
16 changes: 16 additions & 0 deletions test/scripts/interop.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using StaticCompiler
using StaticTools

function interop(argc, argv)
lib = StaticTools.dlopen(c"libm")
printf(lib)
sin = StaticTools.dlsym(lib, c"sin")
printf(sin)
x = @ptrcall sin(5.0::Float64)::Float64
printf(x)
newline()
StaticTools.dlclose(lib)
end

# Attempt to compile
path = compile_executable(interop, (Int64, Ptr{Ptr{UInt8}}), "./", cflags=`-ldl -lm`)
9 changes: 4 additions & 5 deletions test/scripts/loopvec_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ end

function loopvec_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
rows = parse(Int64, argv, 2) # First command-line argument
cols = parse(Int64, argv, 3) # Second command-line argument
rows = argparse(Int64, argv, 2) # First command-line argument
cols = argparse(Int64, argv, 3) # Second command-line argument

# LHS
A = MallocArray{Float64}(undef, rows, cols)
Expand All @@ -41,9 +41,8 @@ function loopvec_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
# Print to stdout
printf(C)
# Also print to file
fp = fopen(c"table.tsv",c"w")
printf(fp, C)
fclose(fp)
printdlm(c"table.tsv", C, '\t')
fwrite(c"table.b", C)
# Clean up matrices
free(A)
free(B)
Expand Down
49 changes: 49 additions & 0 deletions test/scripts/loopvec_matrix_stack.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using StaticCompiler
using StaticTools
using LoopVectorization

@inline function mul!(C::StackArray, A::StackArray, B::StackArray)
@turbo for n indices((C,B), 2), m indices((C,A), 1)
Cmn = zero(eltype(C))
for k indices((A,B), (2,1))
Cmn += A[m,k] * B[k,n]
end
C[m,n] = Cmn
end
return C
end

function loopvec_matrix_stack()
rows = 10
cols = 5

# LHS
A = StackArray{Float64}(undef, rows, cols)
@turbo for i axes(A, 1)
for j axes(A, 2)
A[i,j] = i*j
end
end

# RHS
B = StackArray{Float64}(undef, cols, rows)
@turbo for i axes(B, 1)
for j axes(B, 2)
B[i,j] = i*j
end
end

# # Matrix multiplication
C = StackArray{Float64}(undef, cols, cols)
mul!(C, B, A)

# Print to stdout
printf(C)
# Also print to file
fp = fopen(c"table.tsv",c"w")
printf(fp, C)
fclose(fp)
end

# Attempt to compile
path = compile_executable(loopvec_matrix_stack, (), "./")
4 changes: 2 additions & 2 deletions test/scripts/loopvec_product.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ using LoopVectorization

function loopvec_product(argc::Int, argv::Ptr{Ptr{UInt8}})
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
rows = parse(Int64, argv, 2) # First command-line argument
cols = parse(Int64, argv, 3) # Second command-line argument
rows = argparse(Int64, argv, 2) # First command-line argument
cols = argparse(Int64, argv, 3) # Second command-line argument

s = 0
@turbo for i=1:rows
Expand Down
8 changes: 5 additions & 3 deletions test/scripts/rand_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ using StaticTools

function rand_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
rows = parse(Int64, argv, 2) # First command-line argument
cols = parse(Int64, argv, 3) # Second command-line argument
rows = argparse(Int64, argv, 2) # First command-line argument
cols = argparse(Int64, argv, 3) # Second command-line argument

# Manually fil matrix
M = MallocArray{Float64}(undef, rows, cols)
rng = static_rng()
@inbounds for i=1:rows
Expand All @@ -18,4 +19,5 @@ function rand_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
end

# Attempt to compile
path = compile_executable(rand_matrix, (Int64, Ptr{Ptr{UInt8}}), "./")
# cflags=`-lm`: need to explicitly include libm math library on linux
path = compile_executable(rand_matrix, (Int64, Ptr{Ptr{UInt8}}), "./", cflags=`-lm`)
22 changes: 22 additions & 0 deletions test/scripts/randn_matrix.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using StaticCompiler
using StaticTools

function randn_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
rows = argparse(Int64, argv, 2) # First command-line argument
cols = argparse(Int64, argv, 3) # Second command-line argument

M = MallocArray{Float64}(undef, rows, cols)
rng = MarsagliaPolar(static_rng())
@inbounds for i=1:rows
for j=1:cols
M[i,j] = randn(rng)
end
end
printf(M)
free(M)
end

# Attempt to compile
# cflags=`-lm`: need to explicitly include libm math library on linux
path = compile_executable(randn_matrix, (Int64, Ptr{Ptr{UInt8}}), "./", cflags=`-lm`)
9 changes: 4 additions & 5 deletions test/scripts/times_table.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ using StaticTools

function times_table(argc::Int, argv::Ptr{Ptr{UInt8}})
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
rows = parse(Int64, argv, 2) # First command-line argument
cols = parse(Int64, argv, 3) # Second command-line argument
rows = argparse(Int64, argv, 2) # First command-line argument
cols = argparse(Int64, argv, 3) # Second command-line argument

M = MallocArray{Int64}(undef, rows, cols)
@inbounds for i=1:rows
Expand All @@ -15,9 +15,8 @@ function times_table(argc::Int, argv::Ptr{Ptr{UInt8}})
# Print to stdout
printf(M)
# Also print to file
fp = fopen(c"table.tsv",c"w")
printf(fp, M)
fclose(fp)
fwrite(c"table.b", M)
printdlm(c"table.tsv", M)
# Clean up matrix
free(M)
end
Expand Down
31 changes: 31 additions & 0 deletions test/scripts/withmallocarray.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using StaticCompiler
using StaticTools

function withmallocarray(argc::Int, argv::Ptr{Ptr{UInt8}})
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
rows = argparse(Int64, argv, 2) # First command-line argument
cols = argparse(Int64, argv, 3) # Second command-line argument

mzeros(rows, cols) do A
printf(A)
end
mones(Int, rows, cols) do A
printf(A)
end
mfill(3.141592, rows, cols) do A
printf(A)
end

# Random number generation
rng = MarsagliaPolar()
mrand(rng, rows, cols) do A
printf(A)
end
mrandn(rng, rows, cols) do A
printf(A)
end
end

# Attempt to compile
# cflags=`-lm`: need to explicitly include libm math library on linux
path = compile_executable(withmallocarray, (Int64, Ptr{Ptr{UInt8}}), "./", cflags=`-lm`)
Loading

0 comments on commit 5bd9159

Please sign in to comment.