-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdata_layouts_fill.jl
45 lines (43 loc) · 1.35 KB
/
data_layouts_fill.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function knl_fill!(dest, val, us)
I = universal_index(dest)
if is_valid_index(dest, I, us)
@inbounds dest[I] = val
end
return nothing
end
function knl_fill_linear!(dest, val, us)
i = threadIdx().x + (blockIdx().x - Int32(1)) * blockDim().x
if linear_is_valid_index(i, us)
@inbounds dest[i] = val
end
return nothing
end
function Base.fill!(dest::AbstractData, bc, ::ToCUDA)
(_, _, Nv, _, Nh) = DataLayouts.universal_size(dest)
us = DataLayouts.UniversalSize(dest)
args = (dest, bc, us)
if Nv > 0 && Nh > 0
if !(VERSION ≥ v"1.11.0-beta") && dest isa DataLayouts.EndsWithField
threads = threads_via_occupancy(knl_fill_linear!, args)
n_max_threads = min(threads, get_N(us))
p = linear_partition(prod(size(dest)), n_max_threads)
auto_launch!(
knl_fill_linear!,
args;
threads_s = p.threads,
blocks_s = p.blocks,
)
else
threads = threads_via_occupancy(knl_fill!, args)
n_max_threads = min(threads, get_N(us))
p = partition(dest, n_max_threads)
auto_launch!(
knl_fill!,
args;
threads_s = p.threads,
blocks_s = p.blocks,
)
end
end
return dest
end