Skip to content
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
28 changes: 28 additions & 0 deletions deps/ReactantExtra/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
#include "shardy/integrations/c/attributes.h"
#include "xla/pjrt/mlir_to_hlo.h"
#include "xla/service/spmd/shardy/stablehlo_round_trip/export_shardings.h"
#include "xla/service/spmd/shardy/stablehlo_round_trip/stablehlo_import.h"

// IFRT
#include "xla/python/ifrt/array.h"
Expand Down Expand Up @@ -1956,4 +1957,31 @@ hloShardingFromTensorShardingAttr(mlir::sdy::TensorShardingAttr attr,
xla::sdy::convertToHloSharding(attr, get_mesh_attr, manual_axes));
}

extern "C" mlir::sdy::TensorShardingAttr
hloShardingToTensorShardingAttr(const xla::HloSharding *hloSharding,
mlir::sdy::MeshAttr meshAttr, int64_t rank,
const bool *isClosed, const int64_t *priority) {
const SmallDenseMap<int64_t, StringRef> deviceIdToMaximalMeshName =
SmallDenseMap<int64_t, StringRef>();
mlir::sdy::TensorShardingAttr tensorShardingAttr =
xla::sdy::convertToSdySharding(*hloSharding, meshAttr,
deviceIdToMaximalMeshName, rank,
/*openDims=*/true);

for (int64_t i = 0; i < rank; i++) {
auto oldDimSharding = tensorShardingAttr.getDimSharding(i);

std::optional<int64_t> dimPriority;
if (priority[i] > 0)
dimPriority = priority[i];

tensorShardingAttr = tensorShardingAttr.replaceDimSharding(
i, mlir::sdy::DimensionShardingAttr::get(oldDimSharding.getContext(),
oldDimSharding.getAxes(),
isClosed[i], dimPriority));
}

return tensorShardingAttr;
}

#pragma endregion
2 changes: 2 additions & 0 deletions deps/ReactantExtra/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ cc_library(
"-Wl,-exported_symbol,_ClientGetAddressableDevices",
"-Wl,-exported_symbol,_hloShardingFromTensorShardingAttr",
"-Wl,-exported_symbol,_op_sharding_*",
"-Wl,-exported_symbol,_hloShardingToTensorShardingAttr",
]}),
deps = [
"@enzyme//:EnzymeMLIR",
Expand Down Expand Up @@ -541,6 +542,7 @@ cc_library(
"@xla//xla/pjrt/distributed:client",
"@xla//xla/pjrt/distributed:service",
"@xla//xla/service/spmd/shardy/stablehlo_round_trip:export_shardings",
"@xla//xla/service/spmd/shardy/stablehlo_round_trip:stablehlo_import",

"@xla//xla:xla_proto_cc",
"@xla//xla:xla_proto_cc_impl",
Expand Down
Loading