Skip to content

Commit 23dcbfd

Browse files
bmass02copybara-github
authored andcommitted
Project import generated by Copybara
PiperOrigin-RevId: 929430465
1 parent 18e5780 commit 23dcbfd

6 files changed

Lines changed: 77 additions & 7 deletions

File tree

xprof/convert/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,7 @@ cc_test(
15181518
"@com_google_googletest//:gtest",
15191519
"@com_google_googletest//:gtest_main",
15201520
"@org_xprof//plugin/xprof/protobuf:hardware_types_proto_cc",
1521+
"@org_xprof//plugin/xprof/protobuf:op_metrics_proto_cc",
15211522
"@org_xprof//plugin/xprof/protobuf:op_stats_proto_cc",
15221523
"@org_xprof//plugin/xprof/protobuf:power_metrics_proto_cc",
15231524
"@org_xprof//plugin/xprof/protobuf:steps_db_proto_cc",

xprof/convert/op_metrics_db_combiner.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,6 @@ void CopyOpMetricsMetadata(const OpMetrics& src, OpMetrics* dst) {
6161
if (!dst->has_layout() && src.has_layout()) {
6262
*dst->mutable_layout() = src.layout();
6363
}
64-
if (!dst->has_children() && src.has_children()) {
65-
*dst->mutable_children() = src.children();
66-
}
6764
if (!dst->has_source_info() && src.has_source_info()) {
6865
*dst->mutable_source_info() = src.source_info();
6966
}
@@ -101,6 +98,10 @@ void CombineOpMetrics(const OpMetrics& src, OpMetrics* dst,
10198
if (src.has_vdd_energy_j() || dst->has_vdd_energy_j()) {
10299
dst->set_vdd_energy_j(src.vdd_energy_j() + dst->vdd_energy_j());
103100
}
101+
if (src.has_children()) {
102+
OpMetricsDbCombiner combiner(dst->mutable_children());
103+
combiner.Combine(src.children(), update_num_cores);
104+
}
104105
}
105106

106107
void CombineMemoryAccessedBreakdown(

xprof/convert/op_stats_combiner_test.cc

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ limitations under the License.
2323
#include "google/protobuf/util/message_differencer.h"
2424
#include "xla/tsl/platform/types.h"
2525
#include "plugin/xprof/protobuf/hardware_types.pb.h"
26+
#include "plugin/xprof/protobuf/op_metrics.pb.h"
2627
#include "plugin/xprof/protobuf/op_stats.pb.h"
2728
#include "plugin/xprof/protobuf/power_metrics.pb.h"
2829
#include "plugin/xprof/protobuf/steps_db.pb.h"
@@ -234,6 +235,74 @@ TEST(CombineAllOpStatsTest, CombineDisaggregatedServingStats) {
234235
1e-6);
235236
}
236237

238+
TEST(CombineAllOpStatsTest, CombineDeviceOpMetricsDbWithChildren) {
239+
OpStats dst_op_stats, op_stats_1, op_stats_2;
240+
241+
// Set up op_stats_1 with one device op that has children.
242+
{
243+
auto* db = op_stats_1.mutable_device_op_metrics_db();
244+
auto* op = db->add_metrics_db();
245+
op->set_name("parent_op");
246+
op->set_hlo_module_id(123);
247+
op->set_occurrences(1);
248+
op->set_time_ps(100);
249+
250+
auto* child_db = op->mutable_children();
251+
auto* child_op = child_db->add_metrics_db();
252+
child_op->set_name("Add_1");
253+
child_op->set_hlo_module_id(123);
254+
child_op->set_occurrences(5);
255+
child_op->set_time_ps(400);
256+
}
257+
258+
// Set up op_stats_2 with the same device op that has other children.
259+
{
260+
auto* db = op_stats_2.mutable_device_op_metrics_db();
261+
auto* op = db->add_metrics_db();
262+
op->set_name("parent_op");
263+
op->set_hlo_module_id(123);
264+
op->set_occurrences(2);
265+
op->set_time_ps(200);
266+
267+
auto* child_db = op->mutable_children();
268+
auto* child_op = child_db->add_metrics_db();
269+
child_op->set_name("Add_1");
270+
child_op->set_hlo_module_id(123);
271+
child_op->set_occurrences(10);
272+
child_op->set_time_ps(800);
273+
}
274+
275+
OpStatsInfo op_stats_info_1(&op_stats_1, TPU, 0);
276+
OpStatsInfo op_stats_info_2(&op_stats_2, TPU, 1);
277+
278+
std::vector<OpStatsInfo> all_op_stats_info = {op_stats_info_1,
279+
op_stats_info_2};
280+
281+
StepDatabaseResult dummy_step_db_result;
282+
absl::flat_hash_map<uint32_t /*host_id*/, const StepDatabaseResult*> result;
283+
result.insert({0, &dummy_step_db_result});
284+
StepIntersection dummy_step_intersection = StepIntersection(1, result);
285+
286+
CombineAllOpStats(all_op_stats_info, dummy_step_intersection, &dst_op_stats);
287+
288+
// Verify that the combined op metrics has the parent_op.
289+
const auto& combined_db = dst_op_stats.device_op_metrics_db();
290+
ASSERT_EQ(combined_db.metrics_db_size(), 1);
291+
const auto& combined_op = combined_db.metrics_db(0);
292+
EXPECT_EQ(combined_op.name(), "parent_op");
293+
EXPECT_EQ(combined_op.occurrences(), 3);
294+
EXPECT_EQ(combined_op.time_ps(), 300);
295+
296+
// Verify that the children are merged without duplication.
297+
const auto& combined_children_db = combined_op.children();
298+
ASSERT_EQ(combined_children_db.metrics_db_size(), 1);
299+
300+
const auto& child_op = combined_children_db.metrics_db(0);
301+
EXPECT_EQ(child_op.name(), "Add_1");
302+
EXPECT_EQ(child_op.occurrences(), 15);
303+
EXPECT_EQ(child_op.time_ps(), 1200);
304+
}
305+
237306
} // namespace
238307
} // namespace profiler
239308
} // namespace tensorflow

xprof/convert/smart_suggestion/BUILD

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ cc_library(
1919
":tool_data_provider",
2020
"@com_google_absl//absl/container:flat_hash_map",
2121
"@com_google_absl//absl/container:flat_hash_set",
22-
"@com_google_absl//absl/log",
2322
"@com_google_absl//absl/status",
2423
"@com_google_absl//absl/status:statusor",
2524
"@com_google_absl//absl/strings",
@@ -205,7 +204,6 @@ cc_test(
205204
":mock_tool_data_provider",
206205
":signal_provider",
207206
":sparse_core_offload_rule",
208-
"@com_google_absl//absl/status",
209207
"@com_google_absl//absl/status:statusor",
210208
"@com_google_googletest//:gtest_main",
211209
"@org_xprof//plugin/xprof/protobuf:memory_profile_proto_cc",

xprof/utils/op_metrics_db_utils.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,9 @@ void AdjustFlopsAndBytesAccessed(OpMetrics& op_metrics) {
336336

337337
OpMetricsDbBuilder::OpMetricsDbBuilder(OpMetricsDb* db) : db_(db) {
338338
DCHECK_NE(db_, nullptr);
339-
DCHECK_EQ(db_->metrics_db_size(), db->metrics_db_size());
339+
for (OpMetrics& metrics : *db_->mutable_metrics_db()) {
340+
op_metrics_map_[metrics.hlo_module_id()][metrics.name()] = &metrics;
341+
}
340342
}
341343

342344
OpMetrics* OpMetricsDbBuilder::LookupOrInsertNewOpMetrics(

xprof/utils/op_metrics_db_utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ TF_CONST_INIT extern const uint32_t kSparseCoreIndexStart;
4545
class OpMetricsDbBuilder {
4646
public:
4747
// Create with a borrowed op database.
48-
// REQUIRED: The op database must be empty.
4948
explicit OpMetricsDbBuilder(OpMetricsDb* db);
5049

5150
protected:

0 commit comments

Comments
 (0)