Home | History | Annotate | Download | only in service
      1 /* Copyright 2017 The TensorFlow Authors. All Rights Reserved.
      2 
      3 Licensed under the Apache License, Version 2.0 (the "License");
      4 you may not use this file except in compliance with the License.
      5 You may obtain a copy of the License at
      6 
      7     http://www.apache.org/licenses/LICENSE-2.0
      8 
      9 Unless required by applicable law or agreed to in writing, software
     10 distributed under the License is distributed on an "AS IS" BASIS,
     11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     12 See the License for the specific language governing permissions and
     13 limitations under the License.
     14 ==============================================================================*/
     15 
     16 #include "tensorflow/compiler/xla/service/hlo_profile_printer.h"
     17 
     18 #include "tensorflow/compiler/xla/service/human_readable_profile_builder.h"
     19 
     20 namespace xla {
     21 string PrintHloProfile(const HloProfilePrinterData& hlo_profile_printer_data,
     22                        const int64* counters, double clock_rate_ghz) {
     23   using HloComputationInfo = HloProfilePrinterData::HloComputationInfo;
     24   using HloInstructionInfo = HloProfilePrinterData::HloInstructionInfo;
     25 
     26   string result;
     27 
     28   for (const HloComputationInfo& computation_info :
     29        hlo_profile_printer_data.computation_infos()) {
     30     const auto& instruction_infos = computation_info.instruction_infos();
     31     bool any_instruction_profiled =
     32         std::any_of(instruction_infos.begin(), instruction_infos.end(),
     33                     [&](const HloInstructionInfo& instruction_info) {
     34                       return counters[instruction_info.profile_index()] != 0;
     35                     });
     36 
     37     if (!any_instruction_profiled) {
     38       continue;
     39     }
     40 
     41     // Once we start using this in AOT for real, we will probably need a more
     42     // minimal version of HumanReadableProfileBuilder.
     43     HumanReadableProfileBuilder builder(
     44         computation_info.name(), counters[computation_info.profile_index()],
     45         clock_rate_ghz);
     46 
     47     for (const auto& instruction_info : instruction_infos) {
     48       builder.AddOp(
     49           /*op_name=*/instruction_info.long_name(),
     50           /*short_name=*/instruction_info.short_name(),
     51           instruction_info.category(),
     52           counters[instruction_info.profile_index()],
     53           instruction_info.flop_count(),
     54           instruction_info.transcendental_count(),
     55           instruction_info.bytes_accessed(),
     56           instruction_info.optimal_seconds());
     57     }
     58 
     59     result += builder.ToString();
     60   }
     61 
     62   return result;
     63 }
     64 }  // namespace xla
     65