Skip to content

Commit 6eb7f94

Browse files
cvinson830chihuahua
authored andcommitted
Make list of devices display correctly when coloring by "Device", "Compute", or "Memory" (#901)
Fixes two polymer bugs/misuses: dom-repeat items can't be intialized from a function call that takes a property dom-repeat can't be used with table rows. Additionally, the device checkboxes: now display the trimmed item suffix is aligned with item suffix * Syntax/convention update 1) Made devices-checkbox a class, and included this class in the DIV containing the device checkboxes 2) Removed the inline style (style="text-align:left;vertical-align:middle") for the device checkbox, and used the CSS class "devices-checkbox" in its place.
1 parent c500b28 commit 6eb7f94

File tree

1 file changed

+109
-46
lines changed

1 file changed

+109
-46
lines changed

tensorboard/plugins/graph/tf_graph_controls/tf-graph-controls.html

+109-46
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@
200200
stroke: var(--tb-graph-faded);
201201
}
202202

203+
#unfilled-rect {
204+
stroke: #a6a6a6;
205+
}
206+
207+
.devices-checkbox input {
208+
text-align: left;
209+
vertical-align: middle
210+
}
211+
203212
.button-text {
204213
text-transform: none;
205214
padding: 8px 18px 0 18px;
@@ -285,6 +294,10 @@
285294
<use xmlns:xlink="http://www.w3.org/1999/xlink"
286295
xlink:href="#legend-rect"/>
287296
</g>
297+
<g id="unfilled-rect">
298+
<use xmlns:xlink="http://www.w3.org/1999/xlink"
299+
xlink:href="#legend-rect"/>
300+
</g>
288301
</defs>
289302
</svg>
290303
<div class="allcontrols">
@@ -412,24 +425,16 @@
412425
<br style="clear: both">
413426
<div>Devices included in stats:</div>
414427
<div class="deviceList">
415-
<table>
416-
<template is="dom-repeat" items="[[_getDevices(devicesForStats)]]">
417-
<tr>
418-
<td>
419-
<input type="checkbox" value$="[[item.device]]" checked$="[[item.used]]" on-click="_deviceCheckboxClicked"/>
420-
</td>
421-
<td>
422-
<div>
423-
<span>[[item.suffix]]</span>
424-
<template is="dom-if" if="[[item.ignoredMsg]]">
425-
<paper-icon-button icon="help" class="help-icon"></paper-icon-button>
426-
<paper-tooltip position="right" animation-delay="0">[[item.ignoredMsg]]</paper-tooltip>
427-
</template>
428-
</div>
429-
</td>
430-
</tr>
428+
<template is="dom-repeat" items="[[_currentDevices]]">
429+
<div class="color-legend-row devices-checkbox">
430+
<span><input type="checkbox" value$="[[item.device]]" checked$="[[item.used]]" on-click="_deviceCheckboxClicked"/></span>
431+
<span>[[item.suffix]]</span>
432+
<template is="dom-if" if="[[item.ignoredMsg]]">
433+
<paper-icon-button icon="help" class="help-icon"></paper-icon-button>
434+
<paper-tooltip position="right" animation-delay="0">[[item.ignoredMsg]]</paper-tooltip>
435+
</template>
436+
</div>
431437
</template>
432-
</table>
433438
</div>
434439
</template>
435440
<template is="dom-if" if="[[_equals(colorBy, 'structure')]]">
@@ -450,22 +455,16 @@
450455
</div>
451456
</template>
452457
<template is="dom-if" if="[[_equals(colorBy, 'device')]]">
453-
<div class="color-text">
454-
<div class="deviceList">
455-
<table>
456-
<template is="dom-repeat" items="[[colorByParams.device]]">
457-
<tr>
458-
<td style$="[[_getBackgroundColor(item.color)]]">
459-
<div class="colorBox"></div>
460-
</td>
461-
<td>
462-
<div>[[item.device]]</div>
463-
</td>
464-
</tr>
465-
</template>
466-
</table>
467-
</div>
468-
<br/>
458+
<div>
459+
<template is="dom-repeat" items="[[_currentDeviceParams]]">
460+
<div class="color-legend-row">
461+
<svg>
462+
<use xmlns:xlink="http://www.w3.org/1999/xlink"
463+
xlink:href="#unfilled-rect" x="0" y="0" style="fill:[[item.color]]"/>
464+
</svg>
465+
<span class="color-legend-value">[[item.device]]</span>
466+
</div>
467+
</template>
469468
<div class="color-legend-row">
470469
<svg>
471470
<use xmlns:xlink="http://www.w3.org/1999/xlink"
@@ -479,7 +478,7 @@
479478
<div class="color-text">
480479
<div class="xlaClusterList">
481480
<table>
482-
<template is="dom-repeat" items="[[colorByParams.xla_cluster]]">
481+
<template is="dom-repeat" items="[[_currentXlaClusterParams]]">
483482
<tr>
484483
<td style$="[[_getBackgroundColor(item.color)]]">
485484
<div class="colorBox"></div>
@@ -730,16 +729,26 @@
730729
<script>
731730
(function() { // Private scope.
732731
/**
733-
* Stats from device names that match these regexes will be excluded by default.
734-
* The user can still turn on a device by selecting the checkbox in the device list.
732+
* Display only devices matching one of the following regex.
735733
*/
736-
var DEVICE_NAMES_EXCLUDE = [
734+
var DEVICE_NAMES_INCLUDE = [
737735
{
738-
regex: /gpu:[0-9]+$/,
739-
msg: 'Excluded by default since this is a CPU thread setting up GPU kernels.'
736+
// Don't include GPU stream, memcpy, etc. devices
737+
regex: /device:[^:]+:[0-9]+$/,
740738
}
741739
];
742740

741+
/**
742+
* Stats from device names that match these regexes will be disabled by default.
743+
* The user can still turn on a device by selecting the checkbox in the device list.
744+
*/
745+
var DEVICE_STATS_DEFAULT_OFF = [
746+
// {
747+
// regex: //,
748+
// msg: 'Excluded by default since...'
749+
// }
750+
];
751+
743752
Polymer({
744753
is: 'tf-graph-controls',
745754
properties: {
@@ -761,7 +770,11 @@
761770
notify: true,
762771
readonly: true
763772
},
764-
colorByParams: Object,
773+
colorByParams: {
774+
type: Object,
775+
notify: true,
776+
readonly: true,
777+
},
765778
datasets: {
766779
type: Array,
767780
observer: '_datasetsChanged'
@@ -789,6 +802,18 @@
789802
notify: true,
790803
value: -1
791804
},
805+
_currentDevices: {
806+
type: Array,
807+
computed: '_getCurrentDevices(devicesForStats)'
808+
},
809+
_currentDeviceParams: {
810+
type: Array,
811+
computed: '_getCurrentDeviceParams(colorByParams)'
812+
},
813+
_currentXlaClusterParams: {
814+
type: Array,
815+
computed: '_getCurrentXlaClusterParams(colorByParams)'
816+
},
792817
_currentGradientParams: {
793818
type: Object,
794819
computed: '_getCurrentGradientParams(colorByParams, colorBy)'
@@ -833,26 +858,41 @@
833858
}
834859
var devicesForStats = {};
835860
var devices = _.each(stats.dev_stats, function(d) {
836-
// Avoid device names that are ignored by default.
837-
var exclude = _.some(DEVICE_NAMES_EXCLUDE, function(rule) {
861+
// Only considered included devices.
862+
var include = _.some(DEVICE_NAMES_INCLUDE, function(rule) {
863+
return rule.regex.test(d.device);
864+
});
865+
// Exclude device names that are ignored by default.
866+
var exclude = _.some(DEVICE_STATS_DEFAULT_OFF, function(rule) {
838867
return rule.regex.test(d.device);
839868
});
840-
if (!exclude) {
869+
if (include && !exclude) {
841870
devicesForStats[d.device] = true;
842871
}
843872
});
844873
this.set('devicesForStats', devicesForStats);
845874
},
846-
_getDevices: function(devicesForStats) {
847-
var devices = _.map(this.stats.dev_stats, function(d) {
875+
_getCurrentDevices: function(devicesForStats) {
876+
var all_devices = _.map(this.stats && this.stats.dev_stats, function(d) {
848877
return d.device;
849878
});
879+
var devices = _.filter(all_devices, function(d) {
880+
return _.some(DEVICE_NAMES_INCLUDE, function(rule) {
881+
return rule.regex.test(d);
882+
});
883+
});
850884
// Devices names can be long so we remove the longest common prefix
851885
// before showing the devices in a list.
852886
var suffixes = tf.graph.util.removeCommonPrefix(devices);
887+
if (suffixes.length == 1) {
888+
var found = suffixes[0].match(/device:([^:]+:[0-9]+)$/);
889+
if (found) {
890+
suffixes[0] = found[1];
891+
}
892+
}
853893
return _.map(devices, function(device, i) {
854894
var ignoredMsg = null;
855-
_.each(DEVICE_NAMES_EXCLUDE, function(rule) {
895+
_.each(DEVICE_STATS_DEFAULT_OFF, function(rule) {
856896
if (rule.regex.test(device)) {
857897
ignoredMsg = rule.msg;
858898
}
@@ -892,6 +932,29 @@
892932
_equals: function(a, b) {
893933
return a === b;
894934
},
935+
_getCurrentDeviceParams: function(colorByParams) {
936+
var deviceParams = _.filter(colorByParams.device, function(param) {
937+
return _.some(DEVICE_NAMES_INCLUDE, function(rule) {
938+
return rule.regex.test(param.device);
939+
});
940+
});
941+
// Remove common prefix and merge back corresponding color. If
942+
// there is only one device then remove everything up to "/device:".
943+
var suffixes = tf.graph.util.removeCommonPrefix(
944+
_.map(deviceParams, function(d) { return d.device; }));
945+
if (suffixes.length == 1) {
946+
var found = suffixes[0].match(/device:([^:]+:[0-9]+)$/);
947+
if (found) {
948+
suffixes[0] = found[1];
949+
}
950+
}
951+
return _.map(deviceParams, function(d, i) {
952+
return { device : suffixes[i], color : d.color };
953+
});
954+
},
955+
_getCurrentXlaClusterParams: function(colorByParams) {
956+
return colorByParams.xla_cluster;
957+
},
895958
_getCurrentGradientParams: function(colorByParams, colorBy) {
896959
if (!this._isGradientColoring(this.stats, colorBy)) {
897960
return;

0 commit comments

Comments
 (0)