|
16 | 16 | A[1] = B[1]^2
|
17 | 17 | end
|
18 | 18 |
|
| 19 | +@kernel function pow(A, B) |
| 20 | + A[1] = A[1]^B[1] |
| 21 | +end |
| 22 | + |
19 | 23 | @kernel function checked(A, a, b)
|
20 | 24 | A[1] = Base.Checked.checked_add(a, b)
|
21 | 25 | end
|
22 | 26 |
|
23 |
| -function compiler_testsuite() |
| 27 | +function check_for_overdub(stmt) |
| 28 | + if stmt isa Expr |
| 29 | + if stmt.head == :invoke |
| 30 | + mi = first(stmt.args)::Core.MethodInstance |
| 31 | + if mi.def.name === :overdub |
| 32 | + @show stmt |
| 33 | + return true |
| 34 | + end |
| 35 | + end |
| 36 | + end |
| 37 | + return false |
| 38 | +end |
| 39 | + |
| 40 | +function compiler_testsuite(backend, ArrayT) |
24 | 41 | kernel = index(CPU(), DynamicSize(), DynamicSize())
|
25 | 42 | iterspace = NDRange{1, StaticSize{(128,)}, StaticSize{(8,)}}();
|
26 | 43 | ctx = KernelAbstractions.mkcontext(kernel, 1, nothing, iterspace, Val(KernelAbstractions.NoDynamicCheck()))
|
27 | 44 | CTX = KernelAbstractions.cassette(kernel)
|
28 | 45 | @test KernelAbstractions.Cassette.overdub(CTX, KernelAbstractions.__index_Global_NTuple, ctx, CartesianIndex(1)) == (1,)
|
29 | 46 |
|
30 |
| - let (CI, rt) = @ka_code_typed literal_pow(CPU())(zeros(Int,1), ndrange=1) |
| 47 | + A = ArrayT{Int}(undef, 1) |
| 48 | + let (CI, rt) = @ka_code_typed literal_pow(backend())(A, ndrange=1) |
| 49 | + # test that there is no invoke of overdub |
| 50 | + @test !any(check_for_overdub, CI.code) |
| 51 | + end |
| 52 | + |
| 53 | + A = ArrayT{Float64}(undef, 1) |
| 54 | + let (CI, rt) = @ka_code_typed square(backend())(A, A, ndrange=1) |
| 55 | + # test that there is no invoke of overdub |
| 56 | + @test !any(check_for_overdub, CI.code) |
| 57 | + end |
| 58 | + |
| 59 | + A = ArrayT{Float64}(undef, 1) |
| 60 | + B = ArrayT{Float64}(undef, 1) |
| 61 | + let (CI, rt) = @ka_code_typed pow(backend())(A, B, ndrange=1) |
31 | 62 | # test that there is no invoke of overdub
|
32 |
| - @test !any(stmt->(stmt isa Expr) && stmt.head == :invoke, CI.code) |
| 63 | + @test !any(check_for_overdub, CI.code) |
33 | 64 | end
|
34 | 65 |
|
35 |
| - let (CI, rt) = @ka_code_typed square(CPU())(zeros(1), zeros(1), ndrange=1) |
| 66 | + A = ArrayT{Float64}(undef, 1) |
| 67 | + B = ArrayT{Int32}(undef, 1) |
| 68 | + let (CI, rt) = @ka_code_typed pow(backend())(A, B, ndrange=1) |
36 | 69 | # test that there is no invoke of overdub
|
37 |
| - @test !any(stmt->(stmt isa Expr) && stmt.head == :invoke, CI.code) |
| 70 | + @test !any(check_for_overdub, CI.code) |
38 | 71 | end
|
39 | 72 |
|
40 | 73 | if VERSION >= v"1.5"
|
41 |
| - let (CI, rt) = @ka_code_typed checked(CPU())(zeros(Int,1), 1, 2, ndrange=1) |
| 74 | + A = ArrayT{Int}(undef, 1) |
| 75 | + let (CI, rt) = @ka_code_typed checked(backend())(A, 1, 2, ndrange=1) |
42 | 76 | # test that there is no invoke of overdub
|
43 |
| - @test !any(stmt->(stmt isa Expr) && stmt.head == :invoke, CI.code) |
| 77 | + @test !any(check_for_overdub, CI.code) |
44 | 78 | end
|
45 | 79 | end
|
46 | 80 | end
|
0 commit comments