|
| 1 | +using KernelAbstractions, Test |
| 2 | + |
| 3 | +# Not passing in typelist because CuArrays will not support passing in |
| 4 | +# non-inlined types |
| 5 | +@kernel function convert_kernel!(A, B) |
| 6 | + tid = @index(Global, Linear) |
| 7 | + |
| 8 | + # Int -> Int |
| 9 | + tid = Int64(Int32(tid)) |
| 10 | + |
| 11 | + @inbounds B[tid, 1] = ceil(Int8, A[tid]) |
| 12 | + @inbounds B[tid, 2] = ceil(Int16, A[tid]) |
| 13 | + @inbounds B[tid, 3] = ceil(Int32, A[tid]) |
| 14 | + @inbounds B[tid, 4] = ceil(Int64, A[tid]) |
| 15 | + @inbounds B[tid, 5] = ceil(Int128, A[tid]) |
| 16 | + @inbounds B[tid, 6] = ceil(UInt8, A[tid]) |
| 17 | + @inbounds B[tid, 7] = ceil(UInt16, A[tid]) |
| 18 | + @inbounds B[tid, 8] = ceil(UInt32, A[tid]) |
| 19 | + @inbounds B[tid, 9] = ceil(UInt64, A[tid]) |
| 20 | + @inbounds B[tid, 10] = ceil(UInt128, A[tid]) |
| 21 | + |
| 22 | + @inbounds B[tid, 11] = floor(Int8, A[tid]) |
| 23 | + @inbounds B[tid, 12] = floor(Int16, A[tid]) |
| 24 | + @inbounds B[tid, 13] = floor(Int32, A[tid]) |
| 25 | + @inbounds B[tid, 14] = floor(Int64, A[tid]) |
| 26 | + @inbounds B[tid, 15] = floor(Int128, A[tid]) |
| 27 | + @inbounds B[tid, 16] = floor(UInt8, A[tid]) |
| 28 | + @inbounds B[tid, 17] = floor(UInt16, A[tid]) |
| 29 | + @inbounds B[tid, 18] = floor(UInt32, A[tid]) |
| 30 | + @inbounds B[tid, 19] = floor(UInt64, A[tid]) |
| 31 | + @inbounds B[tid, 20] = floor(UInt128, A[tid]) |
| 32 | + |
| 33 | + @inbounds B[tid, 21] = round(Int8, A[tid]) |
| 34 | + @inbounds B[tid, 22] = round(Int16, A[tid]) |
| 35 | + @inbounds B[tid, 23] = round(Int32, A[tid]) |
| 36 | + @inbounds B[tid, 24] = round(Int64, A[tid]) |
| 37 | + @inbounds B[tid, 25] = round(Int128, A[tid]) |
| 38 | + @inbounds B[tid, 26] = round(UInt8, A[tid]) |
| 39 | + @inbounds B[tid, 27] = round(UInt16, A[tid]) |
| 40 | + @inbounds B[tid, 28] = round(UInt32, A[tid]) |
| 41 | + @inbounds B[tid, 29] = round(UInt64, A[tid]) |
| 42 | + @inbounds B[tid, 30] = round(UInt128, A[tid]) |
| 43 | + |
| 44 | +end |
| 45 | + |
| 46 | +function convert_testsuite(backend, ArrayT) |
| 47 | + |
| 48 | + N = 32 |
| 49 | + d_A = ArrayT([rand()*3 for i = 1:N]) |
| 50 | + |
| 51 | + # 30 because we have 10 integer types and we have 3 operations |
| 52 | + d_B = ArrayT(zeros(N, 30)) |
| 53 | + |
| 54 | + @testset "convert test" begin |
| 55 | + kernel = convert_kernel!(backend(), 4) |
| 56 | + wait(kernel(d_A, d_B, ndrange=(N),)) |
| 57 | + |
| 58 | + for i = 1:10 |
| 59 | + @test d_B[:,i] == ceil.(d_A) |
| 60 | + @test d_B[:,i+10] == floor.(d_A) |
| 61 | + @test d_B[:,i+20] == round.(d_A) |
| 62 | + end |
| 63 | + end |
| 64 | +end |
0 commit comments