Skip to content

Commit 7a5e159

Browse files
committed
define basic intrinsics
1 parent e565304 commit 7a5e159

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

193193
unsafe_free!(::AbstractArray) = return
194194

195+
include("intrinsics.jl")
196+
import .KernelIntrinsics
197+
export KernelIntrinsics
198+
195199
###
196200
# Kernel language
197201
# - @localmem
@@ -450,13 +454,27 @@ end
450454
# Internal kernel functions
451455
###
452456

453-
function __index_Local_Linear end
454-
function __index_Group_Linear end
455-
function __index_Global_Linear end
457+
function __index_Local_Linear(ctx)
458+
return KernelIntrinsics.get_local_id().x
459+
end
456460

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

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