Skip to content

Commit

Permalink
[Profiler] Add optimization advice for reducing the host-to-TPU data …
Browse files Browse the repository at this point in the history
…transfer time.

PiperOrigin-RevId: 312388184
Change-Id: I2fc8a60af6724467e447026dde7a8d6925ed1357
  • Loading branch information
tensorflower-gardener committed May 20, 2020
1 parent 692bb1d commit 7f3ef3e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -752,5 +752,17 @@ std::string GetSummaryNextStep(absl::string_view input_classification,
return summary_next_step;
}

double HostToDeviceTransferAsPercentOfInputTime(
const InputTimeBreakdown& breakdown) {
// Thanks to the scaling trick we did in GenerateHostResult(), we can
// estimate the percentage of input-time spent on host-to-device transfer in
// the following way.
double total_input_time_us =
breakdown.demanded_file_read_us() + breakdown.advanced_file_read_us() +
breakdown.preprocessing_us() + breakdown.enqueue_us() +
breakdown.unclassified_non_enqueue_us();
return 100.0 * SafeDivide(breakdown.enqueue_us(), total_input_time_us);
}

} // namespace profiler
} // namespace tensorflow
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ limitations under the License.
namespace tensorflow {
namespace profiler {

// If the percent of input-time spent on host-to-device transfer is greater than
// kHostToDeviceTimePercentAsSignificant, we should advise the
// user to optimize this transfer.
constexpr double kHostToDeviceTimePercentAsSignificant = 10.0;

// If the percent of input-time spent on host-to-device transfer is greater than
// kHostToDeviceTimePercentAsDominant, we should ONLY advise the
// user to optimize this transfer; we won't bother to suggest optimization for
// tf.data.
constexpr double kHostToDeviceTimePercentAsDominant = 90.0;

// Computes the summary of step time in milliseconds.
StepSummary ComputeStepTimeSummaryInMs(
const ::tensorflow::protobuf::RepeatedPtrField<PerCoreStepInfo>&
Expand Down Expand Up @@ -62,6 +73,11 @@ void OutputAnalysis(double output_percent, std::string* output_classification,
string GetSummaryNextStep(absl::string_view input_classification,
const InputTimeBreakdown& breakdown);

// Returns the percentage of the input time that is spent on transferring the
// data from host to device.
double HostToDeviceTransferAsPercentOfInputTime(
const InputTimeBreakdown& breakdown);

void AddErrorMessages(const OpStats& op_stats,
InputPipelineAnalysisResult* result);

Expand Down
2 changes: 2 additions & 0 deletions tensorflow/core/profiler/protobuf/overview_page.proto
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ message OverviewPageRecommendation {
// A statement for input that recommends the next steps for investigating the
// bottleneck.
string statement = 2;
// A list of tips for tackling input bottleneck.
repeated OverviewPageTip input_tips = 11;
// A statement for output that recommends the next steps for investigating the
// bottleneck.
string output_statement = 9;
Expand Down

0 comments on commit 7f3ef3e

Please sign in to comment.