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

#sdy Add extra export_test.py tests for using different meshes.. #405

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
19 changes: 16 additions & 3 deletions shardy/dialect/sdy/ir/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,20 @@ int64_t isScalar(Value value) {
return false;
}

MeshOp getMeshOp(Operation* op, SymbolRefAttr meshSymName) {
return SymbolTable::lookupNearestSymbolFrom<sdy::MeshOp>(
op, meshSymName);
}

MeshOp getMeshOp(Operation* op, StringRef meshName) {
return getMeshOp(op, SymbolRefAttr::get(op->getContext(), meshName));
}

MeshOp getMeshOp(const SymbolTable& symbolTable, StringRef meshName) {
return symbolTable.lookup<MeshOp>(meshName);
}


MeshAttr getMeshOrLookup(const SymbolTable& symbolTable, Attribute meshOrRef) {
if (auto mesh = dyn_cast<MeshAttr>(meshOrRef)) {
return mesh;
Expand All @@ -143,7 +157,7 @@ MeshAttr getMeshOrLookup(Operation* op, Attribute meshOrRef) {
}

MeshAttr getMeshAttr(const SymbolTable& symbolTable, StringRef meshName) {
if (auto meshOp = symbolTable.lookup<MeshOp>(meshName)) {
if (MeshOp meshOp = getMeshOp(symbolTable, meshName)) {
return meshOp.getMesh();
}

Expand All @@ -160,8 +174,7 @@ MeshAttr getMeshAttr(Operation* op, StringRef meshName) {
}

MeshAttr getMeshAttr(Operation* op, SymbolRefAttr meshSymName) {
if (auto meshOp =
SymbolTable::lookupNearestSymbolFrom<MeshOp>(op, meshSymName)) {
if (MeshOp meshOp = getMeshOp(op, meshSymName)) {
return meshOp.getMesh();
}

Expand Down
14 changes: 14 additions & 0 deletions shardy/dialect/sdy/ir/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,20 @@ int64_t getTensorRank(Value value);
// Returns true if the value is a tensor with rank 0.
int64_t isScalar(Value value);

// Looks up the mesh symbol with the given `meshName` in `symbolTable`, and
// returns it if it exists in the table, or nullptr otherwise.
MeshOp getMeshOp(const SymbolTable& symbolTable, StringRef meshName);

// Looks up the mesh symbol with the given `meshSymName` in the symbol table of
// the enclosing module of `op`, and returns it if it exists in the table, or
// nullptr otherwise.
MeshOp getMeshOp(Operation* op, SymbolRefAttr meshSymName);

// Looks up the mesh symbol with the given `meshName` in the symbol table of
// the enclosing module of `op`, and returns it if it exists in the table, or
// nullptr otherwise.
MeshOp getMeshOp(Operation* op, StringRef meshName);

// If `meshOrRef` is a `MeshAttr`, returns it, otherwise, looks up the
// referenced mesh symbol in `symbolTable`, and returns its `MeshAttr`
// if it exists in the table, or nullptr otherwise.
Expand Down