Skip to content

Commit e3aa7fc

Browse files
sam-mccalljart
authored andcommitted
Show layout analysis for convolution ops (tensorflow#484)
1 parent 22ca45d commit e3aa7fc

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

tensorboard/plugins/profile/tf_op_profile/tf-op-details.html

+52
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,31 @@
8484
font-style: italic;
8585
color: #666;
8686
}
87+
88+
.layout {
89+
display: table;
90+
width: 50%;
91+
border-spacing: 1em 0.3em;
92+
}
93+
.layout > * { display: table-row; }
94+
.layout > * > * { display: table-cell; }
95+
.layout .size, .layout .size-x { text-align: center; }
96+
.layout .size-x { font-weight: bold; color: #888; }
97+
.layout .semantics {
98+
font-size: smaller;
99+
font-weight: bold;
100+
color: #48c;
101+
text-transform: uppercase;
102+
vertical-align: middle;
103+
}
104+
.layout .alignment {
105+
/* Make the background extend outside the box */
106+
position: absolute;
107+
padding: 0.5em;
108+
margin-top: -0.5em;
109+
width: 50%;
110+
box-sizing: border-box;
111+
}
87112
</style>
88113
<template>
89114
<paper-card id="card" heading="[[node.name]]" elevation="2">
@@ -103,6 +128,19 @@
103128
<div class="unavailable" hidden="[[!node.category]]">
104129
Select items within this category for performace details.
105130
</div>
131+
<div hidden="[[!node.xla.layout]]">
132+
<b>Layout: </b>
133+
<div class="layout" hidden="[[!node.xla.layout]]">
134+
<template is="dom-repeat" items="[[node.xla.layout.dimensions]]">
135+
<div hidden="[[!index]]"><span class="size-x">×</span></div>
136+
<div>
137+
<span class="size">[[item.size]]</span>
138+
<span class="semantics">[[item.semantics]]</span>
139+
<span class="alignment" style$="background-color:[[_dimensionColor(item)]]">[[_dimensionHint(item)]]</span>
140+
</div>
141+
</template>
142+
</div>
143+
</div>
106144
</div>
107145
</paper-card>
108146
</template>
@@ -133,6 +171,20 @@
133171
return "Unknown";
134172
},
135173
_fused: function(node){ return node && node.xla && !node.metrics; },
174+
_dimensionColor: function(dim) {
175+
if (!dim || !dim.alignment) return null;
176+
var ratio = dim.size / dim.alignment;
177+
// Colors should grade harshly: 50% in a dimension is already very bad.
178+
var harshCurve = (x) => 1 - Math.sqrt(1 - x);
179+
return flameColor(ratio / Math.ceil(ratio), 1, 0.25, harshCurve);
180+
},
181+
_dimensionHint: function(dim) {
182+
if (!dim || !dim.alignment) return null;
183+
var mul = Math.ceil(dim.size / dim.alignment);
184+
var mulSuffix = (mul == 1) ? "" : ": " + mul + " × " + dim.alignment;
185+
if (dim.size % dim.alignment == 0) return "Exact fit" + mulSuffix;
186+
return "Pad to " + (mul * dim.alignment) + mulSuffix;
187+
},
136188
});
137189
</script>
138190
</dom-module>

tensorboard/plugins/profile/tf_op_profile/utils.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ function rgba(red: number, green: number, blue: number, alpha: number) {
2323
* @param {number} fraction
2424
* @param {number=} brightness
2525
* @param {number=} opacity
26+
* @param {Function=} curve mapping [0-1] to [0-1]
2627
* @return {string} An RGBA color.
2728
*/
28-
export function flameColor(fraction: number, brightness = 1, opacity = 1) {
29+
export function flameColor(
30+
fraction: number, brightness = 1, opacity = 1, curve = Math.sqrt) {
2931
if (isNaN(fraction)) return rgba(brightness, brightness, brightness, opacity);
30-
fraction = Math.sqrt(fraction); // Or everything is depressing and red.
32+
fraction = curve(fraction); // Or everything is depressing and red.
3133
return (fraction < 0.5) ?
3234
rgba(brightness, 2 * fraction * brightness, 0, opacity) :
3335
rgba(2 * (1 - fraction) * brightness, brightness, 0, opacity);

0 commit comments

Comments
 (0)