Skip to content

Commit aec6c0a

Browse files
committed
define basic intrinsics
1 parent ba4eee7 commit aec6c0a

File tree

3 files changed

+83
-24
lines changed

3 files changed

+83
-24
lines changed

src/KernelAbstractions.jl

+24-6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ function unsafe_free! end
189189

190190
unsafe_free!(::AbstractArray) = return
191191

192+
include("intrinsics.jl")
193+
import .KernelIntrinsics
194+
export KernelIntrinsics
195+
192196
###
193197
# Kernel language
194198
# - @localmem
@@ -447,13 +451,27 @@ end
447451
# Internal kernel functions
448452
###
449453

450-
function __index_Local_Linear end
451-
function __index_Group_Linear end
452-
function __index_Global_Linear end
454+
function __index_Local_Linear(ctx)
455+
return KernelIntrinsics.get_local_id().x
456+
end
453457

454-
function __index_Local_Cartesian end
455-
function __index_Group_Cartesian end
456-
function __index_Global_Cartesian end
458+
function __index_Group_Linear(ctx)
459+
return KernelIntrinsics.get_group_id().x
460+
end
461+
462+
function __index_Global_Linear(ctx)
463+
return KernelIntrinsics.get_global_id().x
464+
end
465+
466+
function __index_Local_Cartesian(ctx)
467+
return @inbounds workitems(__iterspace(ctx))[KernelIntrinsics.get_local_id().x]
468+
end
469+
function __index_Group_Cartesian(ctx)
470+
return @inbounds blocks(__iterspace(ctx))[KernelIntrinsics.get_group_id().x]
471+
end
472+
function __index_Global_Cartesian(ctx)
473+
return @inbounds expand(__iterspace(ctx), KernelIntrinsics.get_group_id().x, KernelIntrinsics.get_local_id().x)
474+
end
457475

458476
@inline __index_Local_NTuple(ctx, I...) = Tuple(__index_Local_Cartesian(ctx, I...))
459477
@inline __index_Group_NTuple(ctx, I...) = Tuple(__index_Group_Cartesian(ctx, I...))

src/intrinsics.jl

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module KernelIntrinsics
2+
3+
"""
4+
get_global_size()::@NamedTuple{x::Int32, y::Int32, z::Int32}
5+
6+
Return the number of global work-items specified.
7+
8+
!!! note
9+
1-based.
10+
"""
11+
function get_global_size end
12+
13+
"""
14+
get_global_id()::@NamedTuple{x::Int32, y::Int32, z::Int32}
15+
16+
Returns the unique global work-item ID.
17+
"""
18+
function get_global_id end
19+
20+
"""
21+
get_local_size()::@NamedTuple{x::Int32, y::Int32, z::Int32}
22+
23+
Return the number of local work-items specified.
24+
"""
25+
function get_local_size end
26+
27+
"""
28+
get_local_id()::@NamedTuple{x::Int32, y::Int32, z::Int32}
29+
30+
Returns the unique local work-item ID.
31+
"""
32+
function get_local_id end
33+
34+
"""
35+
get_num_groups()::@NamedTuple{x::Int32, y::Int32, z::Int32}
36+
37+
Returns the number of groups.
38+
"""
39+
function get_num_groups end
40+
41+
"""
42+
get_group_id()::@NamedTuple{x::Int32, y::Int32, z::Int32}
43+
44+
Returns the unique group ID.
45+
"""
46+
function get_group_id end
47+
48+
function localmemory end
49+
function barrier end
50+
function print end
51+
52+
end

src/pocl/backend.jl

+7-18
Original file line numberDiff line numberDiff line change
@@ -139,29 +139,18 @@ end
139139

140140

141141
## Indexing Functions
142+
const KI = KA.KernelIntrinsics
142143

143-
@device_override @inline function KA.__index_Local_Linear(ctx)
144-
return get_local_id(1)
144+
@device_override @inline function KI.get_local_id()
145+
return (; x = get_local_id(1), y = get_local_id(2), z = get_local_id(3))
145146
end
146147

147-
@device_override @inline function KA.__index_Group_Linear(ctx)
148-
return get_group_id(1)
148+
@device_override @inline function KI.get_group_id()
149+
return (; x = get_group_id(1), y = get_group_id(2), z = get_group_id(3))
149150
end
150151

151-
@device_override @inline function KA.__index_Global_Linear(ctx)
152-
return get_global_id(1)
153-
end
154-
155-
@device_override @inline function KA.__index_Local_Cartesian(ctx)
156-
@inbounds KA.workitems(KA.__iterspace(ctx))[get_local_id(1)]
157-
end
158-
159-
@device_override @inline function KA.__index_Group_Cartesian(ctx)
160-
@inbounds KA.blocks(KA.__iterspace(ctx))[get_group_id(1)]
161-
end
162-
163-
@device_override @inline function KA.__index_Global_Cartesian(ctx)
164-
return @inbounds KA.expand(KA.__iterspace(ctx), get_group_id(1), get_local_id(1))
152+
@device_override @inline function KI.get_global_id()
153+
return (; x = get_global_id(1), y = get_global_id(2), z = get_global_id(3))
165154
end
166155

167156
@device_override @inline function KA.__validindex(ctx)

0 commit comments

Comments
 (0)