Skip to content

Default to post conversion to dynamic update slice #1496

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
23 changes: 15 additions & 8 deletions src/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ const SUM_TO_CONV = Ref(false)
const AGGRESSIVE_SUM_TO_CONV = Ref(false)
const AGGRESSIVE_PROPAGATION = Ref(false)
const DUS_SLICE_SIMPLIFY = Ref(true)
const CONCATS_TO_DUS = Ref(false)
const CONCATS_TO_DUS = Ref(true)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

benefit is x/ref #1462

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[assuming we ofc nicely fix dus comm and other things, so can revert/change/etc things]


# Optimization passes via transform dialect
function optimization_passes(
Expand Down Expand Up @@ -768,7 +768,6 @@ function optimization_passes(
"iota_simplify<16>($max_constant_threshold)",
"broadcast_in_dim_simplify<16>($max_constant_threshold)",
"convert_concat<1>",
"dynamic_update_to_concat<1>",
"slice_of_dynamic_update<1>",
"slice_elementwise<1>",
"dot_reshape_dot<1>",
Expand Down Expand Up @@ -1177,8 +1176,16 @@ function optimization_passes(
)
end

if !CONCATS_TO_DUS[]
push!(transform_passes_list, "dynamic_update_to_concat<1>")
end

lower_transform_passes = copy(transform_passes_list)

if CONCATS_TO_DUS[]
push!(transform_passes_list, "dynamic_update_to_concat<1>")
end

if recognize_comms
append!(
transform_passes_list,
Expand All @@ -1198,6 +1205,12 @@ function optimization_passes(
],
",",
)
if CONCATS_TO_DUS[]
transform_passes = transform_passes * ",enzyme-hlo-generate-td{patterns=concat_to_onedim_dus},transform-interpreter,enzyme-hlo-remove-transform"
if lower_comms
push!(lower_transform_passes, "concat_to_onedim_dus")
end
end
func_passes = join(["canonicalize", "cse", "canonicalize", transform_passes], ",")
if lower_comms
func_passes =
Expand All @@ -1206,12 +1219,6 @@ function optimization_passes(
join(lower_transform_passes, ';') *
"},transform-interpreter,enzyme-hlo-remove-transform"
end
if CONCATS_TO_DUS[]
push!(
transform_passes_list,
"enzyme-hlo-generate-td{patterns=concat_to_onedim_dus},transform-interpreter,enzyme-hlo-remove-transform",
)
end
passes = String[]
if compile_options.inline
push!(passes, "inline{default-pipeline=canonicalize max-iterations=4}")
Expand Down
4 changes: 2 additions & 2 deletions src/ConcreteRArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ end

Base.similar(a::ConcretePJRTArray, dims::Dims) = similar(a, eltype(a), dims)

@inline function Base.similar(AT::Type{<:ConcretePJRTArray{T}}, dims; kwargs...) where {T}
@inline function Base.similar(AT::Type{<:ConcretePJRTArray{T}}, dims::Dims; kwargs...) where {T}
return Base.similar(AT, T, dims; kwargs...)
end

Expand All @@ -416,7 +416,7 @@ function Base.similar(a::ConcreteIFRTArray{T}, ::Type{S}=T, dims::Dims=size(a))
)
end
Base.similar(a::ConcreteIFRTArray, dims::Dims) = similar(a, eltype(a), dims)
function Base.similar(::Type{ConcreteIFRTArray{T}}, dims) where {T}
function Base.similar(::Type{ConcreteIFRTArray{T}}, dims::Dims) where {T}
return ConcreteIFRTArray(similar(Array{T}, dims))
end

Expand Down
13 changes: 13 additions & 0 deletions test/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@ end
@test y ≈ Array(y_ra)
end

function write_row_simple!(xs_mut, i, v)
xs_mut[:, i] = v
nothing
end

@testset "setindex: DUS" begin
x_ra = similar(ConcreteRArray{Float64}, (76, 100))
y_ra = similar(ConcreteRArray{Float64}, 76)
hlo = @code_hlo write_row_simple!(x_ra, 1, y_ra)
@test contains(repr(hlo), "dynamic_update_slice")
@test !contains(repr(hlo), "concatenate")
end

function maskset!(y, x)
y[:] = x
return nothing
Expand Down
Loading