Skip to content
Open
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: 7 additions & 2 deletions src/Tracing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1520,7 +1520,10 @@ Base.@nospecializeinfer function make_tracer(
(XLA.PJRT.AsyncEmptyBuffer,), size(prev), Sharding.NoShardInfo()
)
else
error("TODO(#2230): implement sharding")
ndev = Sharding.ndevices(sharding)
res = ConcretePJRTArray{T,N,ndev}(
ntuple(Returns(XLA.PJRT.AsyncEmptyBuffer), ndev), size(prev), Sharding.NoShardInfo()

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
ntuple(Returns(XLA.PJRT.AsyncEmptyBuffer), ndev), size(prev), Sharding.NoShardInfo()
ntuple(Returns(XLA.PJRT.AsyncEmptyBuffer), ndev),
size(prev),
Sharding.NoShardInfo(),

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.

is this really Sharding.NoShardInfo() here?

)
end
seen[prev] = res
return res
Expand All @@ -1531,7 +1534,9 @@ Base.@nospecializeinfer function make_tracer(
XLA.IFRT.AsyncEmptyArray, size(prev), Sharding.NoShardInfo()
)
else
error("TODO(#2230): implement sharding")
res = ConcreteIFRTArray{T,N}(
XLA.IFRT.AsyncEmptyArray, size(prev), Sharding.NoShardInfo()
)
end
seen[prev] = res
return res
Expand Down
8 changes: 7 additions & 1 deletion src/compiler/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1198,8 +1198,14 @@ function compile_mlir!(
end
end

sharding = if mlir_fn_res.is_sharded && !isempty(result_shardings_after_masking)
first(result_shardings_after_masking)
else
Sharding.NoSharding()
end

concrete_result = make_tracer(
OrderedIdDict(), traced_result, ("result",), TracedToConcrete; runtime
OrderedIdDict(), traced_result, ("result",), TracedToConcrete; runtime, sharding
)

return Reactant.TracedUtils.CompiledMlirFnResult(
Expand Down
21 changes: 21 additions & 0 deletions test/core/sharding/sharding.jl
Original file line number Diff line number Diff line change
Expand Up @@ -663,3 +663,24 @@ end
end
end
=#

struct WrapTest{A}
data::A
end

wrap_f(a) = WrapTest(a .* a)

@testset "Wrapped Sharded Array" begin
if length(addressable_devices) ≥ 2
ndev = length(addressable_devices)
mesh = Sharding.Mesh(reshape(addressable_devices, ndev), (:dev,))
sh = Sharding.DimsSharding(mesh, (1,), (:dev,))

x = Reactant.to_rarray(collect(Float64, 1:64); sharding = sh)

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
x = Reactant.to_rarray(collect(Float64, 1:64); sharding = sh)
x = Reactant.to_rarray(collect(Float64, 1:64); sharding=sh)

r = @jit(wrap_f(x))
@test r isa WrapTest
@test Array(r.data) ≈ collect(Float64, 1:64) .^ 2
else
@warn "Not enough addressable devices to run wrapped sharded array tests"
end
end
Loading