Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support swapped offset-encoded 4+4-bit integers #7

Merged
merged 3 commits into from
Sep 10, 2024
Merged
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
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name = "IndexSpaces"
uuid = "3ceaaf38-e7b4-4193-a23a-303dd231a83a"
authors = ["Erik Schnetter <[email protected]>"]
version = "1.6.0"
version = "1.7.0"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CUDASIMDTypes = "ba1ee33b-8807-41fd-9812-6d5f2ce04139"

[compat]
CUDA = "3.12.0, 4, 5"
CUDASIMDTypes = "1.6.0"
CUDASIMDTypes = "1.9.0"
julia = "1.6"
31 changes: 21 additions & 10 deletions src/IndexSpaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1038,14 +1038,7 @@ function load!(
reg1_name = register_name(reg_var, state1)
vals = physics_values(state0, reg_layout)
addr = memory_index(reg_layout, mem_layout, vals)
push!(
emitter.statements,
:(
($reg0_name, $reg1_name) = IndexSpaces.unsafe_load2(
$mem_var, $(postprocess(addr)) + 0x1
)
),
)
push!(emitter.statements, :(($reg0_name, $reg1_name) = IndexSpaces.unsafe_load2($mem_var, $(postprocess(addr)) + 0x1)))
end
elseif align == 16
# Find registers with strides 1 and 2
Expand Down Expand Up @@ -1422,6 +1415,7 @@ function widen!(
var::Symbol,
simd_register::Pair{SIMD,Register};
newtype::Union{Nothing,Type}=nothing,
swapped_withoffset::Bool=false,
unshifted_withoffset::Bool=false,
)
simd, register = simd_register
Expand Down Expand Up @@ -1471,8 +1465,11 @@ function widen!(
end
if indextag(var_value) == indextag(res_value) == IntValueTag
if var_value.length == 4 && res_value.length == 8
@assert !(swapped_withoffset && unshifted_withoffset)
if unshifted_withoffset
stmt = :(($(res_names...),) = IndexSpaces.int4x8_to_2int8x4_unshifted_withoffset($var_name))
elseif swapped_withoffset
stmt = :(($(res_names...),) = convert_swapped_withoffset(NTuple{2,Int8x4}, $var_name))
else
stmt = :(($(res_names...),) = convert(NTuple{2,Int8x4}, $var_name))
end
Expand Down Expand Up @@ -1509,6 +1506,7 @@ function widen2!(
simd_register1::Pair{SIMD,Register},
simd_register2::Pair{SIMD,Register};
newtype::Union{Nothing,Type}=nothing,
swapped_withoffset::Bool=false,
unshifted_withoffset::Bool=false,
)
simd1, register1 = simd_register1
Expand Down Expand Up @@ -1567,6 +1565,7 @@ function widen2!(
end
if indextag(var_value) == indextag(res_value) == IntValueTag
if var_value.length == 4 && res_value.length == 16
@assert !swapped_withoffset
stmt = :(($(res_names...),) = convert(NTuple{4,Int16x2}, $var_name))
elseif var_value.length == 8 && res_value.length == 32
stmt = :(($(res_names...),) = convert(NTuple{4,Int32}, $var_name))
Expand All @@ -1575,7 +1574,11 @@ function widen2!(
end
elseif indextag(var_value) == IntValueTag && indextag(res_value) == FloatValueTag
if var_value.length == 4 && res_value.length == 16
stmt = :(($(res_names...),) = convert(NTuple{4,Float16x2}, $var_name))
if swapped_withoffset
stmt = :(($(res_names...),) = convert_swapped_withoffset(NTuple{4,Float16x2}, $var_name))
else
stmt = :(($(res_names...),) = convert(NTuple{4,Float16x2}, $var_name))
end
elseif var_value.length == 8 && res_value.length == 32
stmt = :(($(res_names...),) = convert(NTuple{4,Float32}, $var_name))
else
Expand Down Expand Up @@ -1661,6 +1664,7 @@ function narrow2!(
register_simd1::Pair{Register,SIMD},
register_simd2::Pair{Register,SIMD};
newtype::Union{Nothing,Type}=nothing,
swapped_withoffset::Bool=false,
)
register1, simd1 = register_simd1
register2, simd2 = register_simd2
Expand Down Expand Up @@ -1741,7 +1745,14 @@ function narrow2!(
var1_name = register_name(var, state1)
var2_name = register_name(var, state2)
var3_name = register_name(var, state3)
push!(emitter.statements, :($res_name = Int4x8(($var0_name, $var1_name, $var2_name, $var3_name))))
if swapped_withoffset
push!(
emitter.statements,
:($res_name = convert_swapped_withoffset(Int4x8, ($var0_name, $var1_name, $var2_name, $var3_name))),
)
else
push!(emitter.statements, :($res_name = convert(Int4x8, ($var0_name, $var1_name, $var2_name, $var3_name))))
end
end

return nothing
Expand Down
Loading