Skip to content

Commit

Permalink
define basic intrinsics
Browse files Browse the repository at this point in the history
  • Loading branch information
vchuravy committed Feb 6, 2025
1 parent 77f1ee0 commit 87af609
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 24 deletions.
30 changes: 24 additions & 6 deletions src/KernelAbstractions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ function unsafe_free! end

unsafe_free!(::AbstractArray) = return

include("intrinsics.jl")
import .KernelIntrinsics
export KernelIntrinsics

###
# Kernel language
# - @localmem
Expand Down Expand Up @@ -447,13 +451,27 @@ end
# Internal kernel functions
###

function __index_Local_Linear end
function __index_Group_Linear end
function __index_Global_Linear end
function __index_Local_Linear(ctx)
return KernelIntrinsics.get_local_id().x

Check warning on line 455 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L454-L455

Added lines #L454 - L455 were not covered by tests
end

function __index_Local_Cartesian end
function __index_Group_Cartesian end
function __index_Global_Cartesian end
function __index_Group_Linear(ctx)
return KernelIntrinsics.get_group_id().x

Check warning on line 459 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L458-L459

Added lines #L458 - L459 were not covered by tests
end

function __index_Global_Linear(ctx)
return KernelIntrinsics.get_global_id().x

Check warning on line 463 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L462-L463

Added lines #L462 - L463 were not covered by tests
end

function __index_Local_Cartesian(ctx)
return @inbounds workitems(__iterspace(ctx))[KernelIntrinsics.get_local_id().x]

Check warning on line 467 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L466-L467

Added lines #L466 - L467 were not covered by tests
end
function __index_Group_Cartesian(ctx)
return @inbounds blocks(__iterspace(ctx))[KernelIntrinsics.get_group_id().x]

Check warning on line 470 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L469-L470

Added lines #L469 - L470 were not covered by tests
end
function __index_Global_Cartesian(ctx)
return @inbounds expand(__iterspace(ctx), KernelIntrinsics.get_group_id().x, KernelIntrinsics.get_local_id().x)

Check warning on line 473 in src/KernelAbstractions.jl

View check run for this annotation

Codecov / codecov/patch

src/KernelAbstractions.jl#L472-L473

Added lines #L472 - L473 were not covered by tests
end

@inline __index_Local_NTuple(ctx, I...) = Tuple(__index_Local_Cartesian(ctx, I...))
@inline __index_Group_NTuple(ctx, I...) = Tuple(__index_Group_Cartesian(ctx, I...))
Expand Down
52 changes: 52 additions & 0 deletions src/intrinsics.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module KernelIntrinsics

"""
get_global_size()::@NamedTuple{x::Int32, y::Int32, z::Int32}
Return the number of global work-items specified.
!!! note
1-based.
"""
function get_global_size end

"""
get_global_id()::@NamedTuple{x::Int32, y::Int32, z::Int32}
Returns the unique global work-item ID.
"""
function get_global_id end

"""
get_local_size()::@NamedTuple{x::Int32, y::Int32, z::Int32}
Return the number of local work-items specified.
"""
function get_local_size end

"""
get_local_id()::@NamedTuple{x::Int32, y::Int32, z::Int32}
Returns the unique local work-item ID.
"""
function get_local_id end

"""
get_num_groups()::@NamedTuple{x::Int32, y::Int32, z::Int32}
Returns the number of groups.
"""
function get_num_groups end

"""
get_group_id()::@NamedTuple{x::Int32, y::Int32, z::Int32}
Returns the unique group ID.
"""
function get_group_id end

function localmemory end
function barrier end
function print end

end
25 changes: 7 additions & 18 deletions src/pocl/backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,29 +139,18 @@ end


## Indexing Functions
const KI = KA.KernelIntrinsics

@device_override @inline function KA.__index_Local_Linear(ctx)
return get_local_id(1)
@device_override @inline function KI.get_local_id()
return (; x = get_local_id(1), y = get_local_id(2), z = get_local_id(3))

Check warning on line 145 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L144-L145

Added lines #L144 - L145 were not covered by tests
end

@device_override @inline function KA.__index_Group_Linear(ctx)
return get_group_id(1)
@device_override @inline function KI.get_group_id()
return (; x = get_group_id(1), y = get_group_id(2), z = get_group_id(3))

Check warning on line 149 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L148-L149

Added lines #L148 - L149 were not covered by tests
end

@device_override @inline function KA.__index_Global_Linear(ctx)
return get_global_id(1)
end

@device_override @inline function KA.__index_Local_Cartesian(ctx)
@inbounds KA.workitems(KA.__iterspace(ctx))[get_local_id(1)]
end

@device_override @inline function KA.__index_Group_Cartesian(ctx)
@inbounds KA.blocks(KA.__iterspace(ctx))[get_group_id(1)]
end

@device_override @inline function KA.__index_Global_Cartesian(ctx)
return @inbounds KA.expand(KA.__iterspace(ctx), get_group_id(1), get_local_id(1))
@device_override @inline function KI.get_global_id()
return (; x = get_global_id(1), y = get_global_id(2), z = get_global_id(3))

Check warning on line 153 in src/pocl/backend.jl

View check run for this annotation

Codecov / codecov/patch

src/pocl/backend.jl#L152-L153

Added lines #L152 - L153 were not covered by tests
end

@device_override @inline function KA.__validindex(ctx)
Expand Down

0 comments on commit 87af609

Please sign in to comment.