Skip to content

Commit 6540a44

Browse files
committed
Simplify function name matching in tests using private modules.
1 parent a96fc50 commit 6540a44

File tree

4 files changed

+167
-108
lines changed

4 files changed

+167
-108
lines changed

test/gcn_tests.jl

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -74,44 +74,51 @@ end
7474
# bug: depending on a child function from multiple parents resulted in
7575
# the child only being present once
7676

77-
@noinline child(i) = sink_gcn(i)
78-
function parent1(i)
79-
child(i)
80-
return
77+
mod = @eval module $(gensym())
78+
export child, parent1, parent2
79+
80+
@noinline child(i) = sink_gcn(i)
81+
function parent1(i)
82+
child(i)
83+
return
84+
end
85+
function parent2(i)
86+
child(i+1)
87+
return
88+
end
8189
end
8290

83-
asm = sprint(io->GCN.code_native(io, parent1, Tuple{Int}; dump_module=true))
91+
asm = sprint(io->GCN.code_native(io, mod.parent1, Tuple{Int}; dump_module=true))
8492
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child_\d*,@function", asm)
8593

86-
function parent2(i)
87-
child(i+1)
88-
return
89-
end
90-
91-
asm = sprint(io->GCN.code_native(io, parent2, Tuple{Int}; dump_module=true))
94+
asm = sprint(io->GCN.code_native(io, mod.parent2, Tuple{Int}; dump_module=true))
9295
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child_\d*,@function", asm)
9396
end
9497

9598
@testset "child function reuse bis" begin
9699
# bug: similar, but slightly different issue as above
97100
# in the case of two child functions
98-
@noinline child1(i) = sink_gcn(i)
99-
@noinline child2(i) = sink_gcn(i+1)
100-
function parent1(i)
101-
child1(i) + child2(i)
102-
return
101+
102+
mod = @eval module $(gensym())
103+
export parent1, parent2, child1, child2
104+
105+
@noinline child1(i) = sink_gcn(i)
106+
@noinline child2(i) = sink_gcn(i+1)
107+
function parent1(i)
108+
child1(i) + child2(i)
109+
return
110+
end
111+
function parent2(i)
112+
child1(i+1) + child2(i+1)
113+
return
114+
end
103115
end
104116

105-
asm = sprint(io->GCN.code_native(io, parent1, Tuple{Int}; dump_module=true))
117+
asm = sprint(io->GCN.code_native(io, mod.parent1, Tuple{Int}; dump_module=true))
106118
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child1_\d*,@function", asm)
107119
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child2_\d*,@function", asm)
108120

109-
function parent2(i)
110-
child1(i+1) + child2(i+1)
111-
return
112-
end
113-
114-
asm = sprint(io->GCN.code_native(io, parent2, Tuple{Int}; dump_module=true))
121+
asm = sprint(io->GCN.code_native(io, mod.parent2, Tuple{Int}; dump_module=true))
115122
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child1_\d*,@function", asm)
116123
@test occursin(r"\.type.*julia_[[:alnum:]_.]*child2_\d*,@function", asm)
117124
end

test/native_tests.jl

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -388,46 +388,61 @@ Base.unsafe_trunc(::Type{Int}, x::CleverType) = unsafe_trunc(Int, x.x)
388388
end
389389

390390
@testset "invalid LLVM IR" begin
391-
foobar(i) = println(i)
391+
mod = @eval module $(gensym())
392+
export foobar
393+
foobar(i) = println(i)
394+
end
392395

393396
@test_throws_message(InvalidIRError,
394-
Native.code_execution(foobar, Tuple{Int})) do msg
397+
Native.code_execution(mod.foobar, Tuple{Int})) do msg
395398
occursin("invalid LLVM IR", msg) &&
396399
(occursin(GPUCompiler.RUNTIME_FUNCTION, msg) ||
397400
occursin(GPUCompiler.UNKNOWN_FUNCTION, msg) ||
398401
occursin(GPUCompiler.DYNAMIC_CALL, msg)) &&
399402
occursin("[1] println", msg) &&
400-
occursin(r"\[2\] .*foobar", msg)
403+
occursin("[2] foobar", msg)
401404
end
402405
end
403406

404407
@testset "invalid LLVM IR (ccall)" begin
405-
foobar(p) = (unsafe_store!(p, ccall(:time, Cint, ())); nothing)
408+
mod = @eval module $(gensym())
409+
export foobar
410+
function foobar(p)
411+
unsafe_store!(p, ccall(:time, Cint, ()))
412+
return
413+
end
414+
end
406415

407416
@test_throws_message(InvalidIRError,
408-
Native.code_execution(foobar, Tuple{Ptr{Int}})) do msg
417+
Native.code_execution(mod.foobar, Tuple{Ptr{Int}})) do msg
409418
if VERSION >= v"1.11-"
410419
occursin("invalid LLVM IR", msg) &&
411420
occursin(GPUCompiler.LAZY_FUNCTION, msg) &&
412421
occursin("call to time", msg) &&
413-
occursin(r"\[1\] .*foobar", msg)
422+
occursin("[1] foobar", msg)
414423
else
415424
occursin("invalid LLVM IR", msg) &&
416425
occursin(GPUCompiler.POINTER_FUNCTION, msg) &&
417-
occursin(r"\[1\] .*foobar", msg)
426+
occursin("[1] foobar", msg)
418427
end
419428
end
420429
end
421430

422431
@testset "delayed bindings" begin
423-
kernel() = (undefined; return)
432+
mod = @eval module $(gensym())
433+
export kernel
434+
function kernel()
435+
undefined
436+
return
437+
end
438+
end
424439

425440
@test_throws_message(InvalidIRError,
426-
Native.code_execution(kernel, Tuple{})) do msg
441+
Native.code_execution(mod.kernel, Tuple{})) do msg
427442
occursin("invalid LLVM IR", msg) &&
428443
occursin(GPUCompiler.DELAYED_BINDING, msg) &&
429-
occursin("use of 'undefined'", msg) &&
430-
occursin(r"\[1\] .*kernel", msg)
444+
occursin(r"use of '.*undefined'", msg) &&
445+
occursin("[1] kernel", msg)
431446
end
432447
end
433448

@@ -442,15 +457,18 @@ end
442457
occursin("invalid LLVM IR", msg) &&
443458
occursin(GPUCompiler.DYNAMIC_CALL, msg) &&
444459
occursin("call to nospecialize_child", msg) &&
445-
occursin(r"\[1\] kernel", msg)
460+
occursin("[1] kernel", msg)
446461
end
447462
end
448463

449464
@testset "dynamic call (apply)" begin
450-
func() = println(1)
465+
mod = @eval module $(gensym())
466+
export func
467+
func() = println(1)
468+
end
451469

452470
@test_throws_message(InvalidIRError,
453-
Native.code_execution(func, Tuple{})) do msg
471+
Native.code_execution(mod.func, Tuple{})) do msg
454472
occursin("invalid LLVM IR", msg) &&
455473
occursin(GPUCompiler.DYNAMIC_CALL, msg) &&
456474
occursin("call to println", msg) &&

test/ptx_tests.jl

Lines changed: 86 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ end
2727
end
2828

2929
ir = sprint(io->PTX.code_llvm(io, mod.kernel, Tuple{mod.Aggregate}))
30-
@test occursin(r"@\w*kernel\w*\(({ i64 }|\[1 x i64\])\* ", ir) ||
31-
occursin(r"@\w*kernel\w*\(ptr ", ir)
30+
@test occursin(r"@julia_kernel\w*\(({ i64 }|\[1 x i64\])\* ", ir) ||
31+
occursin(r"@julia_kernel\w*\(ptr ", ir)
3232

3333
ir = sprint(io->PTX.code_llvm(io, mod.kernel, Tuple{mod.Aggregate}; kernel=true))
34-
@test occursin(r"@\w*kernel\w*\(.*({ i64 }|\[1 x i64\]) ", ir)
34+
@test occursin(r"@_Z6kernel9Aggregate\(.*({ i64 }|\[1 x i64\]) ", ir)
3535
end
3636

3737
@testset "property_annotations" begin
@@ -83,13 +83,16 @@ end
8383
@testset "kernel state" begin
8484
# state should be passed by value to kernel functions
8585

86-
kernel() = return
86+
mod = @eval module $(gensym())
87+
export kernel
88+
kernel() = return
89+
end
8790

88-
ir = sprint(io->PTX.code_llvm(io, kernel, Tuple{}))
89-
@test occursin(r"@\w*kernel\w*\(\)", ir)
91+
ir = sprint(io->PTX.code_llvm(io, mod.kernel, Tuple{}))
92+
@test occursin(r"@julia_kernel\w*\(\)", ir)
9093

91-
ir = sprint(io->PTX.code_llvm(io, kernel, Tuple{}; kernel=true))
92-
@test occursin(r"@\w*kernel\w*\(\[1 x i64\] %state\)", ir)
94+
ir = sprint(io->PTX.code_llvm(io, mod.kernel, Tuple{}; kernel=true))
95+
@test occursin("@_Z6kernel([1 x i64] %state)", ir)
9396

9497
# state should only passed to device functions that use it
9598

@@ -111,13 +114,13 @@ end
111114
kernel=true, dump_module=true))
112115

113116
# kernel should take state argument before all else
114-
@test occursin(r"@\w*kernel\w*\(\[1 x i64\] %state", ir)
117+
@test occursin(r"@_Z6kernelP5Int64\(\[1 x i64\] %state", ir)
115118

116119
# child1 doesn't use the state
117-
@test occursin(r"@\w*child1\w*\((i64|i8\*|ptr)", ir)
120+
@test occursin(r"@julia_child1\w*\((i64|i8\*|ptr)", ir)
118121

119122
# child2 does
120-
@test occursin(r"@\w*child2\w*\(\[1 x i64\] %state", ir)
123+
@test occursin(r"@julia_child2\w*\(\[1 x i64\] %state", ir)
121124

122125
# can't have the unlowered intrinsic
123126
@test !occursin("julia.gpu.state_getter", ir)
@@ -133,46 +136,58 @@ end
133136
@testset "child functions" begin
134137
# we often test using @noinline child functions, so test whether these survive
135138
# (despite not having side-effects)
136-
@noinline child(i) = sink(i)
137-
function parent(i)
138-
child(i)
139-
return
139+
140+
mod = @eval module $(gensym())
141+
import ..sink
142+
export child, parent
143+
144+
@noinline child(i) = sink(i)
145+
function parent(i)
146+
child(i)
147+
return
148+
end
140149
end
141150

142-
asm = sprint(io->PTX.code_native(io, parent, Tuple{Int64}))
143-
@test occursin(r"call.uni\s+julia_.*child_"m, asm)
151+
asm = sprint(io->PTX.code_native(io, mod.parent, Tuple{Int64}))
152+
@test occursin(r"call.uni\s+julia_child_"m, asm)
144153
end
145154

146155
@testset "kernel functions" begin
147-
@noinline nonentry(i) = sink(i)
148-
function entry(i)
149-
nonentry(i)
150-
return
156+
mod = @eval module $(gensym())
157+
import ..sink
158+
export nonentry, entry
159+
160+
@noinline nonentry(i) = sink(i)
161+
function entry(i)
162+
nonentry(i)
163+
return
164+
end
151165
end
152166

153-
asm = sprint(io->PTX.code_native(io, entry, Tuple{Int64}; kernel=true))
154-
@test occursin(r"\.visible \.entry \w*entry", asm)
155-
@test !occursin(r"\.visible \.func \w*nonentry", asm)
156-
@test occursin(r"\.func \w*nonentry", asm)
167+
asm = sprint(io->PTX.code_native(io, mod.entry, Tuple{Int64};
168+
kernel=true, dump_module=true))
169+
@test occursin(".visible .entry _Z5entry5Int64", asm)
170+
@test !occursin(".visible .func julia_nonentry", asm)
171+
@test occursin(".func julia_nonentry", asm)
157172

158173
@testset "property_annotations" begin
159-
asm = sprint(io->PTX.code_native(io, entry, Tuple{Int64}; kernel=true))
174+
asm = sprint(io->PTX.code_native(io, mod.entry, Tuple{Int64}; kernel=true))
160175
@test !occursin("maxntid", asm)
161176

162-
asm = sprint(io->PTX.code_native(io, entry, Tuple{Int64};
177+
asm = sprint(io->PTX.code_native(io, mod.entry, Tuple{Int64};
163178
kernel=true, maxthreads=42))
164179
@test occursin(".maxntid 42, 1, 1", asm)
165180

166-
asm = sprint(io->PTX.code_native(io, entry, Tuple{Int64};
181+
asm = sprint(io->PTX.code_native(io, mod.entry, Tuple{Int64};
167182
kernel=true, minthreads=42))
168183
@test occursin(".reqntid 42, 1, 1", asm)
169184

170-
asm = sprint(io->PTX.code_native(io, entry, Tuple{Int64};
185+
asm = sprint(io->PTX.code_native(io, mod.entry, Tuple{Int64};
171186
kernel=true, blocks_per_sm=42))
172187
@test occursin(".minnctapersm 42", asm)
173188

174189
if LLVM.version() >= v"4.0"
175-
asm = sprint(io->PTX.code_native(io, entry, Tuple{Int64};
190+
asm = sprint(io->PTX.code_native(io, mod.entry, Tuple{Int64};
176191
kernel=true, maxregs=42))
177192
@test occursin(".maxnreg 42", asm)
178193
end
@@ -183,44 +198,55 @@ end
183198
# bug: depending on a child function from multiple parents resulted in
184199
# the child only being present once
185200

186-
@noinline child(i) = sink(i)
187-
function parent1(i)
188-
child(i)
189-
return
190-
end
191-
192-
asm = sprint(io->PTX.code_native(io, parent1, Tuple{Int}))
193-
@test occursin(r".func \w*child_", asm)
201+
mod = @eval module $(gensym())
202+
import ..sink
203+
export child, parent1, parent2
194204

195-
function parent2(i)
196-
child(i+1)
197-
return
205+
@noinline child(i) = sink(i)
206+
function parent1(i)
207+
child(i)
208+
return
209+
end
210+
function parent2(i)
211+
child(i+1)
212+
return
213+
end
198214
end
199215

200-
asm = sprint(io->PTX.code_native(io, parent2, Tuple{Int}))
201-
@test occursin(r".func \w*child_", asm)
216+
asm = sprint(io->PTX.code_native(io, mod.parent1, Tuple{Int}))
217+
@test occursin(".func julia_child_", asm)
218+
219+
asm = sprint(io->PTX.code_native(io, mod.parent2, Tuple{Int}))
220+
@test occursin(".func julia_child_", asm)
202221
end
203222

204223
@testset "child function reuse bis" begin
205224
# bug: similar, but slightly different issue as above
206225
# in the case of two child functions
207-
@noinline child1(i) = sink(i)
208-
@noinline child2(i) = sink(i+1)
209-
function parent1(i)
210-
child1(i) + child2(i)
211-
return
212-
end
213-
asm = sprint(io->PTX.code_native(io, parent1, Tuple{Int}))
214-
@test occursin(r".func \w*child1_", asm)
215-
@test occursin(r".func \w*child2_", asm)
216226

217-
function parent2(i)
218-
child1(i+1) + child2(i+1)
219-
return
227+
mod = @eval module $(gensym())
228+
import ..sink
229+
export parent1, parent2, child1, child2
230+
231+
@noinline child1(i) = sink(i)
232+
@noinline child2(i) = sink(i+1)
233+
function parent1(i)
234+
child1(i) + child2(i)
235+
return
236+
end
237+
function parent2(i)
238+
child1(i+1) + child2(i+1)
239+
return
240+
end
220241
end
221-
asm = sprint(io->PTX.code_native(io, parent2, Tuple{Int}))
222-
@test occursin(r".func \w*child1_", asm)
223-
@test occursin(r".func \w*child2_", asm)
242+
243+
asm = sprint(io->PTX.code_native(io, mod.parent1, Tuple{Int}))
244+
@test occursin(".func julia_child1_", asm)
245+
@test occursin(".func julia_child2_", asm)
246+
247+
asm = sprint(io->PTX.code_native(io, mod.parent2, Tuple{Int}))
248+
@test occursin(".func julia_child1_", asm)
249+
@test occursin(".func julia_child2_", asm)
224250
end
225251

226252
@testset "indirect sysimg function use" begin
@@ -261,6 +287,8 @@ end
261287

262288
@testset "GC and TLS lowering" begin
263289
mod = @eval module $(gensym())
290+
import ..sink
291+
264292
mutable struct PleaseAllocate
265293
y::Csize_t
266294
end

0 commit comments

Comments
 (0)