Skip to content

Commit 1d33a4f

Browse files
committed
rtyh
1 parent 1679169 commit 1d33a4f

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

examples/histogram.jl

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ end
2828
# possible to get a value of 312, then we will have 2 separate shmem blocks,
2929
# one from 1->256, and another from 256->512
3030
@uniform max_element = 1
31+
# @print("tid=$tid, lid=$lid, gs=$gs, N=$N, max_element=$max_element\n")
32+
3133
for min_element in 1:gs:N
3234

3335
# Setting shared_histogram to 0
@@ -41,8 +43,12 @@ end
4143

4244
# Defining bin on shared memory and writing to it if possible
4345
bin = input[tid]
46+
win = bin
47+
# if lid == 5
48+
# end
4449
if bin >= min_element && bin < max_element
4550
bin -= min_element - 1
51+
@print("tid=$tid, lid=$lid, bin=$win, gs=$gs, N=$N, max_element=$max_element, min_element=$min_element, bin=$(bin)\n")
4652
@atomic shared_histogram[bin] += 1
4753
end
4854

@@ -53,13 +59,16 @@ end
5359
end
5460

5561
end
62+
# @print("tid=$tid, lid=$lid, gs=$gs, N=$N, max_element=$max_element\n")
5663

5764
end
5865

59-
function histogram!(histogram_output, input)
66+
function histogram!(histogram_output, input, groupsize=256)
6067
backend = get_backend(histogram_output)
6168
# Need static block size
62-
kernel! = histogram_kernel!(backend, (256,))
69+
kernel! = histogram_kernel!(backend, (groupsize,))
70+
@show kernel!
71+
@show size(input)
6372
kernel!(histogram_output, input, ndrange = size(input))
6473
return
6574
end
@@ -73,28 +82,33 @@ end
7382

7483
@testset "histogram tests" begin
7584
# Use Int32 as some backends don't support 64-bit atomics
76-
rand_input = Int32.(rand(1:128, 1000))
77-
linear_input = Int32.(rand(1:128, 1024))
78-
all_two = fill(Int32(2), 512)
85+
# rand_input = Int32.(rand(1:128, 1000))
86+
rand_input = Int32.(rand(1:20, 20))
87+
# linear_input = Int32.(rand(1:128, 1024))
88+
# all_two = fill(Int32(2), 512)
7989

8090
histogram_rand_baseline = create_histogram(rand_input)
81-
histogram_linear_baseline = create_histogram(linear_input)
82-
histogram_two_baseline = create_histogram(all_two)
91+
# histogram_linear_baseline = create_histogram(linear_input)
92+
# histogram_two_baseline = create_histogram(all_two)
8393

8494
rand_input = move(backend, rand_input)
85-
linear_input = move(backend, linear_input)
86-
all_two = move(backend, all_two)
95+
# linear_input = move(backend, linear_input)
96+
# all_two = move(backend, all_two)
8797

8898
rand_histogram = KernelAbstractions.zeros(backend, eltype(rand_input), maximum(rand_input))
89-
linear_histogram = KernelAbstractions.zeros(backend, eltype(linear_input), maximum(linear_input))
90-
two_histogram = KernelAbstractions.zeros(backend, eltype(all_two), maximum(all_two))
99+
# linear_histogram = KernelAbstractions.zeros(backend, eltype(linear_input), maximum(linear_input))
100+
# two_histogram = KernelAbstractions.zeros(backend, eltype(all_two), maximum(all_two))
91101

92-
histogram!(rand_histogram, rand_input)
93-
histogram!(linear_histogram, linear_input)
94-
histogram!(two_histogram, all_two)
102+
histogram!(rand_histogram, rand_input, 9)
103+
# histogram!(linear_histogram, linear_input)
104+
# histogram!(two_histogram, all_two)
95105
KernelAbstractions.synchronize(backend)
96106

107+
@show sum(Array(rand_histogram))
108+
@show sum(histogram_rand_baseline)
109+
@show findall(Array(rand_histogram) .!= histogram_rand_baseline)
110+
97111
@test isapprox(Array(rand_histogram), histogram_rand_baseline)
98-
@test isapprox(Array(linear_histogram), histogram_linear_baseline)
99-
@test isapprox(Array(two_histogram), histogram_two_baseline)
112+
# @test isapprox(Array(linear_histogram), histogram_linear_baseline)
113+
# @test isapprox(Array(two_histogram), histogram_two_baseline)
100114
end

0 commit comments

Comments
 (0)