xref: /aosp_15_r20/external/tensorflow/tensorflow/compiler/xla/service/gpu/metrics.cc (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2022 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/gpu/metrics.h"
17 
18 #include "tensorflow/core/lib/monitoring/sampler.h"
19 
20 namespace xla {
21 namespace {
22 
23 auto* compile_time_usecs_histogram = tensorflow::monitoring::Sampler<1>::New(
24     {"/xla/service/gpu/compile_time_usecs_histogram",
25      "The wall-clock time spent on compiling the graphs in microseconds.",
26      "phase"},
27     // These exponential buckets cover the following range:
28     // Minimum: 1 ms
29     // Maximum: 1 ms * 2 ^ 24 == ~4.66 hours
30     {tensorflow::monitoring::Buckets::Exponential(1000, 2, 25)});
31 
32 }  // namespace
33 
RecordHloPassesDuration(const uint64_t time_usecs)34 void RecordHloPassesDuration(const uint64_t time_usecs) {
35   static auto* cell = compile_time_usecs_histogram->GetCell("hlo_passes");
36   cell->Add(time_usecs);
37 }
38 
RecordHloToLlvmDuration(const uint64_t time_usecs)39 void RecordHloToLlvmDuration(const uint64_t time_usecs) {
40   static auto* cell = compile_time_usecs_histogram->GetCell("hlo_to_llvm");
41   cell->Add(time_usecs);
42 }
43 
RecordLlvmPassesAndLlvmToPtxDuration(const uint64_t time_usecs)44 void RecordLlvmPassesAndLlvmToPtxDuration(const uint64_t time_usecs) {
45   // When 'llvm_to_ptx' was added, it mistakenly included both llvm
46   // optimization and llvm to ptx compilation, and now changing it would
47   // invalidate historical data.
48   static auto* cell = compile_time_usecs_histogram->GetCell("llvm_to_ptx");
49   cell->Add(time_usecs);
50 }
51 
RecordLlvmPassesDuration(const uint64_t time_usecs)52 void RecordLlvmPassesDuration(const uint64_t time_usecs) {
53   static auto* cell = compile_time_usecs_histogram->GetCell("llvm_passes");
54   cell->Add(time_usecs);
55 }
56 
RecordLlvmToPtxDuration(const uint64_t time_usecs)57 void RecordLlvmToPtxDuration(const uint64_t time_usecs) {
58   // 'llvm_to_ptx' is taken and can't be changed without invalidating
59   // historical data.
60   static auto* cell = compile_time_usecs_histogram->GetCell("llvm_to_ptx_only");
61   cell->Add(time_usecs);
62 }
63 
RecordPtxToCubinDuration(const uint64_t time_usecs)64 void RecordPtxToCubinDuration(const uint64_t time_usecs) {
65   static auto* cell = compile_time_usecs_histogram->GetCell("ptx_to_cubin");
66   cell->Add(time_usecs);
67 }
68 
69 }  // namespace xla
70