Skip to content

Commit 63244eb

Browse files
committed
fixup! define basic intrinsics
1 parent ee7dd48 commit 63244eb

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
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

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ module KernelIntrinsics
44
get_global_size()::@NamedTuple{x::Int32, y::Int32, z::Int32}
55
66
Return the number of global work-items specified.
7+
8+
!!! note
9+
1-based.
710
"""
811
function get_global_size end
912

@@ -12,7 +15,7 @@ function get_global_size end
1215
1316
Returns the unique global work-item ID.
1417
"""
15-
function get_global_id end
18+
function get_global_id end
1619

1720
"""
1821
get_local_size()::@NamedTuple{x::Int32, y::Int32, z::Int32}
@@ -40,10 +43,10 @@ function get_num_groups end
4043
4144
Returns the unique group ID.
4245
"""
43-
function get_group_id end
46+
function get_group_id end
4447

4548
function localmemory end
4649
function barrier end
4750
function print end
4851

49-
end
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)