Skip to content

Commit 7062556

Browse files
committed
do tests with a binary loaded on another process. This will catch
reloactability problems
1 parent 310ffea commit 7062556

2 files changed

Lines changed: 43 additions & 21 deletions

File tree

test/Project.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
66
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
77
LoopVectorization = "bdcacae8-1622-11e9-2a5c-532679323890"
88
ManualMemory = "d125e4d3-2237-4719-b19c-fa641b8a4667"
9-
StrideArraysCore = "7792a7ef-975c-4747-a70f-980b88e8d1da"
9+
StrideArraysCore = "7792a7ef-975c-4747-a70f-980b88e8d1da"
10+
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"

test/runtests.jl

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,38 @@ using LinearAlgebra
55
using LoopVectorization
66
using ManualMemory
77
using StrideArraysCore
8+
using Distributed
9+
10+
addprocs(1)
11+
@everywhere using StaticCompiler
12+
13+
remote_load_call(path, args...) = fetch(@spawnat 2 load_function(path)(args...))
814

915
@testset "Basics" begin
1016

1117
simple_sum(x) = x + one(typeof(x))
1218

1319
# This probably needs a macro
1420
for T (Int, Float64, Int32, Float32, Int16, Float16)
15-
@test compile(simple_sum, (T,))[1]( T(1) ) == T(2)
21+
_, path, = compile(simple_sum, (T,))
22+
@test remote_load_call(path, T(1)) == T(2)
1623
end
1724
end
1825

1926

2027
fib(n) = n <= 1 ? n : fib(n - 1) + fib(n - 2) # This needs to be defined globally due to https://github.com/JuliaLang/julia/issues/40990
2128

2229
@testset "Recursion" begin
23-
@test compile(fib, (Int,))[1](10) == fib(10)
30+
_, path = compile(fib, (Int,))
31+
@test remote_load_call(path, 10) == fib(10)
2432

2533
# Trick to work around #40990
2634
_fib2(_fib2, n) = n <= 1 ? n : _fib2(_fib2, n-1) + _fib2(_fib2, n-2)
2735
fib2(n) = _fib2(_fib2, n)
28-
29-
@test compile(fib2, (Int,))[1](20) == fib(20)
36+
37+
_, path = compile(fib2, (Int,))
38+
@test remote_load_call(path, 20) == fib(20)
39+
#@test compile(fib2, (Int,))[1](20) == fib(20)
3040
end
3141

3242
# Call binaries for testing
@@ -50,7 +60,8 @@ end
5060
end
5161
s
5262
end
53-
@test compile(sum_first_N_int, (Int,))[1](10) == 55
63+
_, path = compile(sum_first_N_int, (Int,))
64+
@test remote_load_call(path, 10) == 55
5465

5566
function sum_first_N_float64(N)
5667
s = Float64(0)
@@ -59,7 +70,8 @@ end
5970
end
6071
s
6172
end
62-
@test compile(sum_first_N_float64, (Int,))[1](10) == 55.
73+
_, path = compile(sum_first_N_float64, (Int,))
74+
@test remote_load_call(path, 10) == 55.
6375

6476
function sum_first_N_int_inbounds(N)
6577
s = 0
@@ -68,7 +80,8 @@ end
6880
end
6981
s
7082
end
71-
@test compile(sum_first_N_int_inbounds, (Int,))[1](10) == 55
83+
_, path = compile(sum_first_N_int_inbounds, (Int,))
84+
@test remote_load_call(path, 10) == 55
7285

7386
function sum_first_N_float64_inbounds(N)
7487
s = Float64(0)
@@ -77,8 +90,8 @@ end
7790
end
7891
s
7992
end
80-
@test compile(sum_first_N_float64_inbounds, (Int,))[1](10) == 55.
81-
93+
_, path = compile(sum_first_N_float64_inbounds, (Int,))
94+
@test remote_load_call(path, 10) == 55.
8295
end
8396

8497
# Arrays with different input types Int32, Int64, Float32, Float64, Complex?
@@ -90,20 +103,25 @@ end
90103
end
91104
s
92105
end
106+
for T (Int, Complex{Float32}, Complex{Float64})
107+
_, path = compile(array_sum, (Int, Vector{T}))
108+
@test remote_load_call(path, 10, T.(1:10)) == T(55)
109+
end
93110

94-
@test compile(array_sum, (Int, Vector{Int}))[1](10, Int.(1:10)) == 55
95-
@test compile(array_sum, (Int, Vector{Complex{Float32}}))[1](10, Complex{Float32}.(1:10)) == 55f0 + 0f0im
96-
@test compile(array_sum, (Int, Vector{Complex{Float64}}))[1](10, Complex{Float64}.(1:10)) == 55f0 + 0f0im
111+
# @test (10, Int.(1:10)) == 55
112+
# @test compile(array_sum, (Int, Vector{Complex{Float32}}))[1](10, Complex{Float32}.(1:10)) == 55f0 + 0f0im
113+
# @test compile(array_sum, (Int, Vector{Complex{Float64}}))[1](10, Complex{Float64}.(1:10)) == 55f0 + 0f0im
97114
end
98115

99116

100117
# Julia wants to treat Tuple (and other things like it) as plain bits, but LLVM wants to treat it as something with a pointer.
101118
# We need to be careful to not send, nor receive an unwrapped Tuple to a compiled function.
102119
# The interface made in `compile` should handle this fine.
103120
@testset "Send and receive Tuple" begin
104-
foo(u::Tuple) = 2 .* reverse(u) .- 1 # we can't just compile this as is.
105-
106-
@test compile(foo, (NTuple{3, Int},))[1]((1, 2, 3)) == (5, 3, 1)
121+
foo(u::Tuple) = 2 .* reverse(u) .- 1
122+
123+
_, path = compile(foo, (NTuple{3, Int},))
124+
@test remote_load_call(path, (1, 2, 3)) == (5, 3, 1)
107125
end
108126

109127

@@ -114,8 +132,9 @@ end
114132
BLAS.dot(N, a, 1, a, 1)
115133
end
116134
a = [1.0, 2.0]
117-
118-
@test compile(mydot, (Vector{Float64},))[1](a) == 5.0
135+
mydot_compiled, path = compile(mydot, (Vector{Float64},))
136+
@test_skip remote_load_call(path, a) == 5.0 # this needs a relocatable pointer to work
137+
@test mydot_compiled(a) == 5.0
119138
end
120139

121140

@@ -146,7 +165,9 @@ end
146165
A = rand(10, 11)
147166
B = rand(11, 12)
148167

149-
compile(mul!, (Matrix{Float64}, Matrix{Float64}, Matrix{Float64},))[1](C, A, B)
168+
_, path = compile(mul!, (Matrix{Float64}, Matrix{Float64}, Matrix{Float64},))
169+
# remote_load_call(path, C, A, B) This won't work because @spawnat copies C
170+
C .= fetch(@spawnat 2 (load_function(path)(C, A, B); C))
150171
@test C A*B
151172
end
152173

@@ -163,8 +184,8 @@ end
163184
sum(arr) # compute the sum. It is very imporatant that no references to arr escape the function body
164185
end
165186
end
166-
167-
@test compile(f, (Int,))[1](20) == 20
187+
_, path = compile(f, (Int,))
188+
@test remote_load_call(path, 20) == 20
168189
end
169190

170191

0 commit comments

Comments
 (0)