Skip to content

Commit 8ea6ad2

Browse files
committed
define basic intrinsics
1 parent 9741962 commit 8ea6ad2

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
@@ -194,6 +194,10 @@ function unsafe_free! end
194194

195195
unsafe_free!(::AbstractArray) = return
196196

197+
include("intrinsics.jl")
198+
import .KernelIntrinsics
199+
export KernelIntrinsics
200+
197201
###
198202
# Kernel language
199203
# - @localmem
@@ -460,13 +464,27 @@ end
460464
# Internal kernel functions
461465
###
462466

463-
function __index_Local_Linear end
464-
function __index_Group_Linear end
465-
function __index_Global_Linear end
467+
function __index_Local_Linear(ctx)
468+
return KernelIntrinsics.get_local_id().x
469+
end
466470

467-
function __index_Local_Cartesian end
468-
function __index_Group_Cartesian end
469-
function __index_Global_Cartesian end
471+
function __index_Group_Linear(ctx)
472+
return KernelIntrinsics.get_group_id().x
473+
end
474+
475+
function __index_Global_Linear(ctx)
476+
return KernelIntrinsics.get_global_id().x
477+
end
478+
479+
function __index_Local_Cartesian(ctx)
480+
return @inbounds workitems(__iterspace(ctx))[KernelIntrinsics.get_local_id().x]
481+
end
482+
function __index_Group_Cartesian(ctx)
483+
return @inbounds blocks(__iterspace(ctx))[KernelIntrinsics.get_group_id().x]
484+
end
485+
function __index_Global_Cartesian(ctx)
486+
return @inbounds expand(__iterspace(ctx), KernelIntrinsics.get_group_id().x, KernelIntrinsics.get_local_id().x)
487+
end
470488

471489
@inline __index_Local_NTuple(ctx, I...) = Tuple(__index_Local_Cartesian(ctx, I...))
472490
@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)