@@ -5,28 +5,38 @@ using LinearAlgebra
55using LoopVectorization
66using ManualMemory
77using 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
1724end
1825
1926
2027fib (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)
3040end
3141
3242# Call binaries for testing
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 )
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
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 )
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.
8295end
8396
8497# Arrays with different input types Int32, Int64, Float32, Float64, Complex?
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
97114end
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 )
107125end
108126
109127
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
119138end
120139
121140
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
151172end
152173
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
168189end
169190
170191
0 commit comments