Skip to content

Commit

Permalink
Merge pull request #86 from brenhinkeller/master
Browse files Browse the repository at this point in the history
Linux fixes, update integration tests
  • Loading branch information
brenhinkeller authored Oct 20, 2022
2 parents d33e25c + 5bd9159 commit 38dbdbe
Show file tree
Hide file tree
Showing 13 changed files with 410 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
fail-fast: false
matrix:
version:
- '1.8.0-rc1'
- '1.8.0-beta3'
os:
- ubuntu-latest
- macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
matrix:
version:
- '1.7'
- '1.8.0-rc1'
- '1.8.0-beta3'
os:
- ubuntu-latest
- macOS-latest
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "StaticCompiler"
uuid = "81625895-6c0f-48fc-b932-11a18313743c"
authors = ["Tom Short"]
version = "0.4.5"
authors = ["Tom Short and contributors"]
version = "0.4.6"

[deps]
Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"
Expand Down
5 changes: 4 additions & 1 deletion src/StaticCompiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,10 @@ function generate_executable(f, tt, path=tempname(), name=GPUCompiler.safe_name(
# Write a minimal wrapper to avoid having to specify a custom entry
wrapper_path = joinpath(path, "wrapper.c")
f = open(wrapper_path, "w")
print(f, """int main(int argc, char** argv)
print(f, """int julia_$name(int argc, char** argv);
void* __stack_chk_guard = (void*) $(rand(UInt) >> 1);
int main(int argc, char** argv)
{
julia_$name(argc, argv);
return 0;
Expand Down
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

2 comments on commit 38dbdbe

@brenhinkeller
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register:

Release notes:

  • Avoids the implicit function declaration warning on non-macOS systems
  • Fixes the __stack_chk_guard error (Linking error #83 )

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/70704

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.6 -m "<description of version>" 38dbdbef14ca2f484661221ad238af4b5b75c0dc
git push origin v0.4.6

Please sign in to comment.