Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ uuid = "b58c8408-13c4-4787-8733-7038ae624acf"
version = "0.2.1"
authors = ["Anton Oresten <antonoresten@proton.me> and contributors"]

[workspace]
projects = ["test", "docs"]

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Republic = "27243419-9dde-4721-b67c-fd63626fea7f"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[weakdeps]
cuTile = "0dea8319-8c4a-4662-a73d-20234d115b9a"

[extensions]
cuTileExt = "cuTile"

[compat]
Adapt = "4.6.1"
Republic = "2.2.0"
Expand Down
41 changes: 41 additions & 0 deletions ext/cuTileExt.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module cuTileExt

using BitPacking: NarrowArray, bitwidth

import Adapt
import cuTile as ct

struct ReinterpretTileArray{T,N,A<:ct.TileArray{UInt8,N}} <: ct.AbstractTileArray{T,N}
parent::A
end

Base.parent(arr::ReinterpretTileArray) = arr.parent
Base.eltype(::ReinterpretTileArray{T}) where T = T
Base.ndims(::ReinterpretTileArray{T,N}) where {T,N} = N

function Base.size(arr::ReinterpretTileArray, i::Integer)
ratio = 8 ÷ bitwidth(eltype(arr))
return i == 1 ? size(parent(arr), i) * ratio : size(parent(arr), i)
end
Base.size(arr::ReinterpretTileArray) = ntuple(i -> size(arr, i), Val(ndims(arr)))

function Adapt.adapt_structure(to::ct.KernelAdaptor, arr::NarrowArray)
parent = Adapt.adapt(to, reinterpret(UInt8, arr))
return ReinterpretTileArray{eltype(arr),ndims(parent),typeof(parent)}(parent)
end

function ct.store(arr::ReinterpretTileArray, index, tile; kws...)
return ct.store(parent(arr), index, reinterpret(UInt8, tile); kws...)
end

function ct.load(arr::ReinterpretTileArray, index, shape; kws...)
ratio = 8 ÷ bitwidth(eltype(arr))
shape′ = ntuple(Val(ndims(arr))) do i
i == 1 ? shape[i] ÷ ratio : shape[i]
end
byte_tile = ct.load(parent(arr), index, shape′; kws...)
tile = reinterpret(eltype(arr), byte_tile)
return tile
end

end
Loading