Skip to content

Commit ba6d8c8

Browse files
bmass02tensorflower-gardener
authored andcommitted
Add CoreId-to-CoreDetails map to OpStats.
PiperOrigin-RevId: 711909143
1 parent 2b39f2c commit ba6d8c8

File tree

6 files changed

+27
-7
lines changed

6 files changed

+27
-7
lines changed

tensorflow/core/profiler/convert/xplane_to_op_stats.cc

+15-1
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,25 @@ OpStats ConvertXSpaceToOpStats(const XSpace& space,
357357
}
358358
}
359359

360-
// TODO(bvandermoon): Add the TPU equivalent for setting core details hostname
361360
if (!is_tpu) {
362361
CoreDetails& details =
363362
(*op_stats.mutable_core_id_to_details())[kDefaultGpuLocalCoreId];
364363
details.set_hostname(Hostname(space));
364+
} else {
365+
std::string hostname = Hostname(space);
366+
auto& core_id_to_details = *op_stats.mutable_core_id_to_details();
367+
for (const XPlane* device_plane : device_planes) {
368+
XPlaneVisitor visitor =
369+
tsl::profiler::CreateTfXPlaneVisitor(device_plane);
370+
auto stat = visitor.GetStat(StatType::kCoreDetails);
371+
if (stat.has_value()) {
372+
CoreDetails core_details;
373+
// TODO: Switch to StrOrRefValue once protobuf version is updated.
374+
core_details.ParseFromString(stat->ToString());
375+
core_details.set_hostname(hostname);
376+
core_id_to_details[device_plane->id()] = core_details;
377+
}
378+
}
365379
}
366380

367381
// Set program_id_to_name map in OpStats from Xspace

tensorflow/core/profiler/convert/xplane_to_step_events.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -301,11 +301,11 @@ StepEvents ConvertDeviceTraceXPlaneToStepEvents(const XPlane& device_trace) {
301301
// one more step than the "Step" line. We need to intersect them to get
302302
// the common step numbers.
303303
stream_step_events =
304-
ConvertTpuDeviceTraceXLineToStepEvents(*tpu_core_id, line);
304+
ConvertTpuDeviceTraceXLineToStepEvents(plane.Id(), line);
305305
IntersectCombineStepEvents(stream_step_events, &device_step_events);
306306
} else if (sc_core_id.has_value()) {
307-
stream_step_events = ConvertTpuDeviceTraceXLineToStepEvents(
308-
kSparseCoreIndexStart + *sc_core_id, line);
307+
stream_step_events =
308+
ConvertTpuDeviceTraceXLineToStepEvents(plane.Id(), line);
309309
IntersectCombineStepEvents(stream_step_events, &device_step_events);
310310
} else {
311311
stream_step_events =

third_party/xla/xla/tsl/profiler/utils/xplane_schema.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@ const StatTypeMap& GetStatTypeMap() {
360360
{"source_stack", kSourceStack},
361361
{"device_offset_ps", kDeviceOffsetPs},
362362
{"device_duration_ps", kDeviceDurationPs},
363-
{"scope_range_id", kScopeRangeId}});
363+
{"scope_range_id", kScopeRangeId},
364+
{"core_details", kCoreDetails}});
364365
DCHECK_EQ(stat_type_map->size(), kNumStatTypes);
365366
return *stat_type_map;
366367
}

third_party/xla/xla/tsl/profiler/utils/xplane_schema.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ enum StatType {
346346
kDeviceOffsetPs,
347347
kDeviceDurationPs,
348348
kScopeRangeId,
349-
kLastStatType = kScopeRangeId,
349+
kCoreDetails,
350+
kLastStatType = kCoreDetails,
350351
};
351352

352353
enum MegaScaleStatType : uint8_t {

third_party/xla/xla/tsl/profiler/utils/xplane_utils.cc

+1
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,7 @@ void AggregateXPlane(const XPlane& full_trace, XPlane& aggregated_trace) {
556556
const XPlaneVisitor& plane = CreateTfXPlaneVisitor(&full_trace);
557557
XPlaneBuilder aggregated_plane(&aggregated_trace);
558558
aggregated_plane.SetName(plane.Name());
559+
aggregated_plane.SetId(plane.Id());
559560

560561
uint64_t first_op_start_ps = kint64max;
561562
uint64_t last_op_end_ps = 0;

third_party/xla/xla/tsl/profiler/utils/xplane_utils_test.cc

+4-1
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ TEST(XplaneUtilsTest, FindMutablePlanesWithPredicate) {
397397
TEST(XplaneUtilsTest, TestAggregateXPlanes) {
398398
XPlane xplane;
399399
XPlaneBuilder builder(&xplane);
400+
builder.SetId(123);
400401
auto& event_metadata1 = *builder.GetOrCreateEventMetadata("EventMetadata1");
401402
auto& event_metadata2 = *builder.GetOrCreateEventMetadata("EventMetadata2");
402403
auto& event_metadata3 = *builder.GetOrCreateEventMetadata("EventMetadata3");
@@ -442,14 +443,16 @@ TEST(XplaneUtilsTest, TestAggregateXPlanes) {
442443
XPlane aggregated_xplane;
443444
AggregateXPlane(xplane, aggregated_xplane);
444445

446+
EXPECT_EQ(aggregated_xplane.id(), 123);
445447
// Protobuf matchers are unavailable in OSS (b/169705709)
446448
#if defined(PLATFORM_GOOGLE)
447449
// TODO(b/238349654): Proto matcher are ineffective for XPlanes.
448450
ASSERT_THAT(
449451
aggregated_xplane,
450452
IgnoringFields(
451453
{"tensorflow.profiler.XEvent.metadata_id",
452-
"tensorflow.profiler.XPlane.event_metadata"},
454+
"tensorflow.profiler.XPlane.event_metadata",
455+
"tensorflow.profiler.XPlane.id"},
453456
IgnoringRepeatedFieldOrdering(EqualsProto(
454457
R"pb(lines {
455458
id: 1

0 commit comments

Comments
 (0)