Skip to content

Commit 38dbdbe

Browse files
Merge pull request #86 from brenhinkeller/master
Linux fixes, update integration tests
2 parents d33e25c + 5bd9159 commit 38dbdbe

13 files changed

Lines changed: 410 additions & 93 deletions

.github/workflows/ci-integration.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
version:
21-
- '1.8.0-rc1'
21+
- '1.8.0-beta3'
2222
os:
2323
- ubuntu-latest
2424
- macOS-latest

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
matrix:
2020
version:
2121
- '1.7'
22-
- '1.8.0-rc1'
22+
- '1.8.0-beta3'
2323
os:
2424
- ubuntu-latest
2525
- macOS-latest

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StaticCompiler"
22
uuid = "81625895-6c0f-48fc-b932-11a18313743c"
3-
authors = ["Tom Short"]
4-
version = "0.4.5"
3+
authors = ["Tom Short and contributors"]
4+
version = "0.4.6"
55

66
[deps]
77
Clang_jll = "0ee61d77-7f21-5576-8119-9fcc46b10100"

src/StaticCompiler.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,10 @@ function generate_executable(f, tt, path=tempname(), name=GPUCompiler.safe_name(
377377
# Write a minimal wrapper to avoid having to specify a custom entry
378378
wrapper_path = joinpath(path, "wrapper.c")
379379
f = open(wrapper_path, "w")
380-
print(f, """int main(int argc, char** argv)
380+
print(f, """int julia_$name(int argc, char** argv);
381+
void* __stack_chk_guard = (void*) $(rand(UInt) >> 1);
382+
383+
int main(int argc, char** argv)
381384
{
382385
julia_$name(argc, argv);
383386
return 0;

test/scripts/interop.jl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using StaticCompiler
2+
using StaticTools
3+
4+
function interop(argc, argv)
5+
lib = StaticTools.dlopen(c"libm")
6+
printf(lib)
7+
sin = StaticTools.dlsym(lib, c"sin")
8+
printf(sin)
9+
x = @ptrcall sin(5.0::Float64)::Float64
10+
printf(x)
11+
newline()
12+
StaticTools.dlclose(lib)
13+
end
14+
15+
# Attempt to compile
16+
path = compile_executable(interop, (Int64, Ptr{Ptr{UInt8}}), "./", cflags=`-ldl -lm`)

test/scripts/loopvec_matrix.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ end
1515

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

2121
# LHS
2222
A = MallocArray{Float64}(undef, rows, cols)
@@ -41,9 +41,8 @@ function loopvec_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
4141
# Print to stdout
4242
printf(C)
4343
# Also print to file
44-
fp = fopen(c"table.tsv",c"w")
45-
printf(fp, C)
46-
fclose(fp)
44+
printdlm(c"table.tsv", C, '\t')
45+
fwrite(c"table.b", C)
4746
# Clean up matrices
4847
free(A)
4948
free(B)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
using StaticCompiler
2+
using StaticTools
3+
using LoopVectorization
4+
5+
@inline function mul!(C::StackArray, A::StackArray, B::StackArray)
6+
@turbo for n indices((C,B), 2), m indices((C,A), 1)
7+
Cmn = zero(eltype(C))
8+
for k indices((A,B), (2,1))
9+
Cmn += A[m,k] * B[k,n]
10+
end
11+
C[m,n] = Cmn
12+
end
13+
return C
14+
end
15+
16+
function loopvec_matrix_stack()
17+
rows = 10
18+
cols = 5
19+
20+
# LHS
21+
A = StackArray{Float64}(undef, rows, cols)
22+
@turbo for i axes(A, 1)
23+
for j axes(A, 2)
24+
A[i,j] = i*j
25+
end
26+
end
27+
28+
# RHS
29+
B = StackArray{Float64}(undef, cols, rows)
30+
@turbo for i axes(B, 1)
31+
for j axes(B, 2)
32+
B[i,j] = i*j
33+
end
34+
end
35+
36+
# # Matrix multiplication
37+
C = StackArray{Float64}(undef, cols, cols)
38+
mul!(C, B, A)
39+
40+
# Print to stdout
41+
printf(C)
42+
# Also print to file
43+
fp = fopen(c"table.tsv",c"w")
44+
printf(fp, C)
45+
fclose(fp)
46+
end
47+
48+
# Attempt to compile
49+
path = compile_executable(loopvec_matrix_stack, (), "./")

test/scripts/loopvec_product.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ using LoopVectorization
44

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

1010
s = 0
1111
@turbo for i=1:rows

test/scripts/rand_matrix.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ using StaticTools
33

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

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

2021
# Attempt to compile
21-
path = compile_executable(rand_matrix, (Int64, Ptr{Ptr{UInt8}}), "./")
22+
# cflags=`-lm`: need to explicitly include libm math library on linux
23+
path = compile_executable(rand_matrix, (Int64, Ptr{Ptr{UInt8}}), "./", cflags=`-lm`)

test/scripts/randn_matrix.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using StaticCompiler
2+
using StaticTools
3+
4+
function randn_matrix(argc::Int, argv::Ptr{Ptr{UInt8}})
5+
argc == 3 || return printf(stderrp(), c"Incorrect number of command-line arguments\n")
6+
rows = argparse(Int64, argv, 2) # First command-line argument
7+
cols = argparse(Int64, argv, 3) # Second command-line argument
8+
9+
M = MallocArray{Float64}(undef, rows, cols)
10+
rng = MarsagliaPolar(static_rng())
11+
@inbounds for i=1:rows
12+
for j=1:cols
13+
M[i,j] = randn(rng)
14+
end
15+
end
16+
printf(M)
17+
free(M)
18+
end
19+
20+
# Attempt to compile
21+
# cflags=`-lm`: need to explicitly include libm math library on linux
22+
path = compile_executable(randn_matrix, (Int64, Ptr{Ptr{UInt8}}), "./", cflags=`-lm`)

0 commit comments

Comments
 (0)