Skip to content

Emulated complex#2942

Open
wsmoses wants to merge 9 commits into
mainfrom
ecomplex
Open

Emulated complex#2942
wsmoses wants to merge 9 commits into
mainfrom
ecomplex

Conversation

@wsmoses

@wsmoses wsmoses commented Jun 3, 2026

Copy link
Copy Markdown
Member

No description provided.

Comment thread src/CompileOptions.jl
@assert shardy_passes in [:none, :to_mhlo_shardings, :post_sdy_propagation]
end

emulate_complex_val = emulate_complex === nothing ? (client === nothing ? false : !XLA.supports_complex(client)) : emulate_complex

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
emulate_complex_val = emulate_complex === nothing ? (client === nothing ? false : !XLA.supports_complex(client)) : emulate_complex
emulate_complex_val = if emulate_complex === nothing
(client === nothing ? false : !XLA.supports_complex(client))
else
emulate_complex
end

Comment thread src/compiler/Compiler.jl
mod = MLIR.IR.Module(MLIR.IR.Location())

compile_options, kwargs_inner = __get_compile_options_and_kwargs(; kwargs...)
compile_options, kwargs_inner = __get_compile_options_and_kwargs(; client, kwargs...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
compile_options, kwargs_inner = __get_compile_options_and_kwargs(; client, kwargs...)
compile_options, kwargs_inner = __get_compile_options_and_kwargs(;
client, kwargs...
)

Comment thread test/core/complex.jl
@test c == ones(ComplexF32, 2) + ones(ComplexF32, 2)
end
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

Comment thread src/xla/IFRT/Array.jl
client::Client, array::Base.StridedArray{T,N}, sharding
) where {T<:Reactant.ReactantPrimitive,N}
if T <: Complex && !XLA.supports_complex(client)
@assert sharding isa Reactant.Sharding.NoSharding || sharding isa Reactant.Sharding.Replicated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
@assert sharding isa Reactant.Sharding.NoSharding || sharding isa Reactant.Sharding.Replicated
@assert sharding isa Reactant.Sharding.NoSharding ||
sharding isa Reactant.Sharding.Replicated

Comment thread src/xla/PJRT/Buffer.jl
Comment on lines 107 to 113
MLIR.API.UninitPJRTBuffer(
client.client,
device.device,
XLA.primitive_type(S),
length(dims),
collect(Int64, reverse(dims)),
ptype,
ndims,
sizear,
),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
MLIR.API.UninitPJRTBuffer(
client.client,
device.device,
XLA.primitive_type(S),
length(dims),
collect(Int64, reverse(dims)),
ptype,
ndims,
sizear,
),
MLIR.API.UninitPJRTBuffer(client.client, device.device, ptype, ndims, sizear)

Comment thread src/TracedUtils.jl

result = try
process_linear_args!(linear_args, fnbody, do_transpose, optimize_then_pad, inv_map)
process_linear_args!(linear_args, fnbody, do_transpose, optimize_then_pad, inv_map, emulate_complex)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
process_linear_args!(linear_args, fnbody, do_transpose, optimize_then_pad, inv_map, emulate_complex)
process_linear_args!(
linear_args,
fnbody,
do_transpose,
optimize_then_pad,
inv_map,
emulate_complex,
)

Comment thread src/TracedUtils.jl
end

function process_linear_args!(linear_args, fnbody, do_transpose, optimize_then_pad, inv_map)
function process_linear_args!(linear_args, fnbody, do_transpose, optimize_then_pad, inv_map, emulate_complex)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
function process_linear_args!(linear_args, fnbody, do_transpose, optimize_then_pad, inv_map, emulate_complex)
function process_linear_args!(
linear_args, fnbody, do_transpose, optimize_then_pad, inv_map, emulate_complex
)

Comment thread src/TracedUtils.jl
end
end
set_mlir_data!(arg, row_maj_arg)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

Comment thread src/TracedUtils.jl
Comment on lines +641 to +642

start_real = ones(Int, N+1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
start_real = ones(Int, N+1)
start_real = ones(Int, N + 1)

Comment thread src/TracedUtils.jl
start_real = ones(Int, N+1)
limit_real = collect(Int, sz)
pushfirst!(limit_real, 1)
start_imag = ones(Int, N+1)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
start_imag = ones(Int, N+1)
start_imag = ones(Int, N + 1)

Comment thread src/TracedUtils.jl
Comment on lines +649 to +651

traced_raw = TracedRArray{T2, N+1}((), row_maj_arg, (2, sz...))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
traced_raw = TracedRArray{T2, N+1}((), row_maj_arg, (2, sz...))
traced_raw = TracedRArray{T2,N + 1}((), row_maj_arg, (2, sz...))

Comment thread src/TracedUtils.jl

real_slice = Ops.slice(traced_raw, start_real, limit_real)
imag_slice = Ops.slice(traced_raw, start_imag, limit_imag)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

Comment thread src/TracedUtils.jl

real_part = Ops.reshape(real_slice, sz...)
imag_part = Ops.reshape(imag_slice, sz...)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

Comment thread src/TracedUtils.jl
(; sym_name, mesh_attr) = mesh_cache[key]
T = Reactant.unwrapped_eltype(arg)
if T <: Complex && emulate_complex
sharding = Reactant.adapt_sharding_for_emulated_complex(sharding, ndims(arg))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
sharding = Reactant.adapt_sharding_for_emulated_complex(sharding, ndims(arg))
sharding = Reactant.adapt_sharding_for_emulated_complex(
sharding, ndims(arg)
)

Comment thread src/xla/Client.jl
end
return true
end

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change

@wsmoses wsmoses marked this pull request as ready for review June 3, 2026 22:31
@wsmoses wsmoses requested review from Pangoraw, avik-pal and mofeing June 3, 2026 22:31
Comment thread src/compiler/Compiler.jl
finalize(mod)

return exec, hlo_modules, mlir_fn_res, device, client, module_string
return exec, hlo_modules, mlir_fn_res, device, client, module_string, compile_options

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
return exec, hlo_modules, mlir_fn_res, device, client, module_string, compile_options
return exec,
hlo_modules, mlir_fn_res, device, client, module_string,
compile_options

@mofeing mofeing left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm, but don't we take the size for some TracedRArray from MLIR's type inference for some op in Ops? in such case, it would we wrong for emulated complex

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants