Skip to content

Commit

Permalink
Fix unloaded external NSDFGs
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad authored Nov 30, 2023
1 parent 3a7e2cf commit 2a93f04
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
11 changes: 7 additions & 4 deletions src/renderer/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,8 @@ export class SDFGRenderer extends EventEmitter {
this.sdfg_tree = {};
this.for_all_sdfg_elements(
(otype: SDFGElementGroup, odict: any, obj: any) => {
if (obj.type === SDFGElementType.NestedSDFG)
if (obj.type === SDFGElementType.NestedSDFG &&
obj.attributes.sdfg)
this.sdfg_tree[obj.attributes.sdfg.sdfg_list_id] =
odict.sdfg.sdfg_list_id;
}
Expand Down Expand Up @@ -1907,7 +1908,8 @@ export class SDFGRenderer extends EventEmitter {

// If nested SDFG, traverse recursively
if (node.data.node.type ===
SDFGElementType.NestedSDFG)
SDFGElementType.NestedSDFG &&
node.attributes().sdfg)
traverseRecursive(
node.data.graph,
node.attributes().sdfg.attributes.name,
Expand Down Expand Up @@ -2004,7 +2006,8 @@ export class SDFGRenderer extends EventEmitter {
);

// If nested SDFG, traverse recursively
if (node.type === SDFGElementType.NestedSDFG)
if (node.type === SDFGElementType.NestedSDFG &&
node.attributes.sdfg)
traverse_recursive(node.attributes.sdfg);
});

Expand Down Expand Up @@ -3739,7 +3742,7 @@ function relayoutSDFGState(
const topleft = gnode.topleft();

// Offset nested SDFG.
if (node.type === SDFGElementType.NestedSDFG) {
if (node.type === SDFGElementType.NestedSDFG && node.attributes.sdfg) {

offset_sdfg(node.attributes.sdfg, gnode.data.graph, {
x: topleft.x + SDFV.LINEHEIGHT,
Expand Down
7 changes: 5 additions & 2 deletions src/renderer/renderer_elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2087,7 +2087,9 @@ export class NestedSDFG extends SDFGNode {
ctx.fillStyle = this.getCssProperty(
renderer, '--node-foreground-color'
);
const label = this.data.node.attributes.label;
let label = this.data.node.attributes.label;
if (!this.data.node.attributes.sdfg)
label += ' (not loaded)';
const textmetrics = ctx.measureText(label);
ctx.fillText(
label, this.x - textmetrics.width / 2.0,
Expand Down Expand Up @@ -2514,7 +2516,8 @@ export function offset_state(
c.y += offset.y;
});

if (node.data.node.type === SDFGElementType.NestedSDFG)
if (node.data.node.type === SDFGElementType.NestedSDFG &&
node.data.node.attributes.sdfg)
offset_sdfg(
node.data.node.attributes.sdfg, node.data.graph, offset
);
Expand Down
2 changes: 1 addition & 1 deletion src/sdfv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export class SDFV {
}

// If nested SDFG, add SDFG information too
if (elem instanceof NestedSDFG) {
if (elem instanceof NestedSDFG && elem.attributes().sdfg) {
const sdfg_sdfg = elem.attributes().sdfg;
contents.append($('<br>'));
contents.append($('<h4>', {
Expand Down
6 changes: 3 additions & 3 deletions src/utils/sdfg/traversal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ export function memlet_tree_nested(
const name = edge.dst_connector;
const nested_sdfg = next_node.attributes.sdfg;

nested_sdfg.nodes.forEach((nstate: any) => {
nested_sdfg?.nodes.forEach((nstate: any) => {
nstate.edges.forEach((e: any) => {
const node = nstate.nodes[e.src];
if (node.type === SDFGElementType.AccessNode &&
Expand Down Expand Up @@ -328,7 +328,7 @@ export function memlet_tree_nested(
const name = edge.src_connector;
const nested_sdfg = next_node.attributes.sdfg;

nested_sdfg.nodes.forEach((nstate: JsonSDFGState) => {
nested_sdfg?.nodes.forEach((nstate: JsonSDFGState) => {
nstate.edges.forEach((e: JsonSDFGEdge) => {
const node = nstate.nodes[parseInt(e.dst)];
if (node.type === SDFGElementType.AccessNode &&
Expand Down Expand Up @@ -394,7 +394,7 @@ export function memlet_tree_recursive(root_sdfg: JsonSDFG): any[] {
});

state.nodes.forEach((n: JsonSDFGNode) => {
if (n.type == SDFGElementType.NestedSDFG) {
if (n.type == SDFGElementType.NestedSDFG && n.attributes.sdfg) {
const t = memlet_tree_recursive(n.attributes.sdfg);
trees = trees.concat(t);
}
Expand Down

0 comments on commit 2a93f04

Please sign in to comment.