Skip to content

Commit 0e4f087

Browse files
author
xly
committed
feat(proto): add server-measured fields to DeviceProfileData (#45 step 1)
Append 5 optional fields to proto.DeviceProfileData (tags 8-12): measured_flops, measured_flops_verified, measured_lat_ns, measured_ul_bw_bps, measured_dl_bw_bps. Mirror in the C++ struct with zero defaults, extend SerializeProto/DeserializeProto with has_* guards, and have DebugString surface the new fields only when set. Wire-compat: legacy clients/servers continue to round-trip the 7 required fields unchanged because the new fields are protobuf optional. Locked in by test_device_profile_roundtrip (LegacyFieldsOnly, LegacyPlusMeasured, DebugStringMentionsMeasuredWhenSet). This is step 1 of the #45 plan. Steps 2-8 (DeviceMeasurementService, probe opcodes, server wiring, env-var config, docs, integration tests) follow.
1 parent d2c5693 commit 0e4f087

5 files changed

Lines changed: 139 additions & 7 deletions

File tree

‎csrc/backend/matrix_partition.cpp‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,15 @@ std::string DeviceProfileData::DebugString() const {
697697
oss << "uuid: " << uuid << ", flops: " << flops << ", memory: " << memory
698698
<< ", ul_bw: " << ul_bw << ", dl_bw: " << dl_bw << ", ul_lat: " << ul_lat
699699
<< ", dl_lat: " << dl_lat;
700+
if (measured_flops != 0 || measured_lat_ns != 0 || measured_ul_bw_bps != 0 ||
701+
measured_dl_bw_bps != 0) {
702+
oss << ", measured_flops: " << measured_flops
703+
<< ", measured_flops_verified: "
704+
<< (measured_flops_verified ? "true" : "false")
705+
<< ", measured_lat_ns: " << measured_lat_ns
706+
<< ", measured_ul_bw_bps: " << measured_ul_bw_bps
707+
<< ", measured_dl_bw_bps: " << measured_dl_bw_bps;
708+
}
700709
return oss.str();
701710
}
702711

@@ -733,6 +742,14 @@ SerializationBufferPtr DeviceProfileData::SerializeProto() const {
733742
profile_msg->set_ul_lat(ul_lat);
734743
profile_msg->set_dl_lat(dl_lat);
735744

745+
if (measured_flops != 0) profile_msg->set_measured_flops(measured_flops);
746+
if (measured_flops_verified) profile_msg->set_measured_flops_verified(true);
747+
if (measured_lat_ns != 0) profile_msg->set_measured_lat_ns(measured_lat_ns);
748+
if (measured_ul_bw_bps != 0)
749+
profile_msg->set_measured_ul_bw_bps(measured_ul_bw_bps);
750+
if (measured_dl_bw_bps != 0)
751+
profile_msg->set_measured_dl_bw_bps(measured_dl_bw_bps);
752+
736753
// Serialize (no tensor data for DeviceProfileData)
737754
std::string proto_str = umsg.SerializeAsString();
738755
uint32_t proto_size = proto_str.size();
@@ -788,6 +805,20 @@ void DeviceProfileData::DeserializeProto(const void* data, size_t size) {
788805
dl_bw = profile_msg.dl_bw();
789806
ul_lat = profile_msg.ul_lat();
790807
dl_lat = profile_msg.dl_lat();
808+
809+
measured_flops =
810+
profile_msg.has_measured_flops() ? profile_msg.measured_flops() : 0ULL;
811+
measured_flops_verified = profile_msg.has_measured_flops_verified()
812+
? profile_msg.measured_flops_verified()
813+
: false;
814+
measured_lat_ns =
815+
profile_msg.has_measured_lat_ns() ? profile_msg.measured_lat_ns() : 0ULL;
816+
measured_ul_bw_bps = profile_msg.has_measured_ul_bw_bps()
817+
? profile_msg.measured_ul_bw_bps()
818+
: 0ULL;
819+
measured_dl_bw_bps = profile_msg.has_measured_dl_bw_bps()
820+
? profile_msg.measured_dl_bw_bps()
821+
: 0ULL;
791822
}
792823

793824
// ============================================================================

‎csrc/backend/server_base.h‎

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,20 @@ typedef std::shared_ptr<DeviceRegisterRequest> DeviceRegisterRequestPtr;
202202
// Device profile data (client -> server)
203203
// Contains device performance characteristics and capabilities
204204
struct DeviceProfileData : public ISerializable {
205-
uint64_t uuid;
206-
uint64_t flops;
207-
uint64_t memory;
208-
uint64_t ul_bw; // upload bandwidth
209-
uint64_t dl_bw; // download bandwidth
210-
uint64_t ul_lat; // upload latency
211-
uint64_t dl_lat; // download latency
205+
uint64_t uuid = 0;
206+
uint64_t flops = 0;
207+
uint64_t memory = 0;
208+
uint64_t ul_bw = 0; // upload bandwidth
209+
uint64_t dl_bw = 0; // download bandwidth
210+
uint64_t ul_lat = 0; // upload latency
211+
uint64_t dl_lat = 0; // download latency
212+
213+
// Server-measured fields (#45). Zero means "not measured".
214+
uint64_t measured_flops = 0;
215+
bool measured_flops_verified = false;
216+
uint64_t measured_lat_ns = 0;
217+
uint64_t measured_ul_bw_bps = 0;
218+
uint64_t measured_dl_bw_bps = 0;
212219

213220
// ISerializable interface
214221
SerializationBufferPtr Serialize(

‎proto/global_api.proto‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ message DeviceProfileData {
4444
required uint64 dl_bw = 5;
4545
required uint64 ul_lat = 6;
4646
required uint64 dl_lat = 7;
47+
48+
// Server-measured fields (#45). Optional so legacy clients/servers
49+
// round-trip without breakage; unset == "not measured".
50+
optional uint64 measured_flops = 8;
51+
optional bool measured_flops_verified = 9;
52+
optional uint64 measured_lat_ns = 10;
53+
optional uint64 measured_ul_bw_bps = 11;
54+
optional uint64 measured_dl_bw_bps = 12;
4755
}
4856

4957
message ComputeGemmData {

‎tests/cpp/unit/zerocopy/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ add_zerocopy_test(test_aligned_buffer_pool)
6262
add_zerocopy_test(test_serialization_buffer)
6363
add_zerocopy_test(test_scatter_gather_buffer)
6464
add_zerocopy_test(test_matrix_partition)
65+
add_zerocopy_test(test_device_profile_roundtrip)
6566

6667
# ============================================================================
6768
# CUDA Pinned Pool Test (uses CUDAToolkit from parent project)
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
// Issue #45 Step 1: DeviceProfileData carries server-measured fields.
2+
//
3+
// Locks in two contracts:
4+
// - Legacy payloads (without measured_* fields) deserialize cleanly,
5+
// leaving the new optional fields at their default value 0.
6+
// - Round-tripping a struct with measured_* set preserves all 12 fields.
7+
8+
#include <gtest/gtest.h>
9+
10+
#include <memory>
11+
12+
#include "backend/serialization_buffer.h"
13+
#include "backend/server_base.h"
14+
15+
namespace {
16+
17+
DeviceProfileData LegacyProfile() {
18+
DeviceProfileData p{};
19+
p.uuid = 0x1122334455667788ULL;
20+
p.flops = 100000000000ULL;
21+
p.memory = 16ULL * 1024 * 1024 * 1024;
22+
p.ul_bw = 10ULL * 1024 * 1024 * 1024;
23+
p.dl_bw = 10ULL * 1024 * 1024 * 1024;
24+
p.ul_lat = 1000;
25+
p.dl_lat = 1000;
26+
return p;
27+
}
28+
29+
TEST(DeviceProfileDataRoundtrip, LegacyFieldsOnly) {
30+
DeviceProfileData src = LegacyProfile();
31+
auto buf = src.Serialize();
32+
ASSERT_TRUE(buf != nullptr);
33+
34+
DeviceProfileData dst{};
35+
dst.Deserialize(buf->GetBuffer(), buf->GetSize());
36+
37+
EXPECT_EQ(dst.uuid, src.uuid);
38+
EXPECT_EQ(dst.flops, src.flops);
39+
EXPECT_EQ(dst.memory, src.memory);
40+
EXPECT_EQ(dst.ul_bw, src.ul_bw);
41+
EXPECT_EQ(dst.dl_bw, src.dl_bw);
42+
EXPECT_EQ(dst.ul_lat, src.ul_lat);
43+
EXPECT_EQ(dst.dl_lat, src.dl_lat);
44+
45+
// New optional fields default to 0 when sender omits them.
46+
EXPECT_EQ(dst.measured_flops, 0ULL);
47+
EXPECT_EQ(dst.measured_lat_ns, 0ULL);
48+
EXPECT_EQ(dst.measured_ul_bw_bps, 0ULL);
49+
EXPECT_EQ(dst.measured_dl_bw_bps, 0ULL);
50+
EXPECT_FALSE(dst.measured_flops_verified);
51+
}
52+
53+
TEST(DeviceProfileDataRoundtrip, LegacyPlusMeasured) {
54+
DeviceProfileData src = LegacyProfile();
55+
src.measured_flops = 95000000000ULL;
56+
src.measured_flops_verified = true;
57+
src.measured_lat_ns = 250000ULL;
58+
src.measured_ul_bw_bps = 9ULL * 1024 * 1024 * 1024;
59+
src.measured_dl_bw_bps = 8ULL * 1024 * 1024 * 1024;
60+
61+
auto buf = src.Serialize();
62+
ASSERT_TRUE(buf != nullptr);
63+
64+
DeviceProfileData dst{};
65+
dst.Deserialize(buf->GetBuffer(), buf->GetSize());
66+
67+
EXPECT_EQ(dst.uuid, src.uuid);
68+
EXPECT_EQ(dst.measured_flops, src.measured_flops);
69+
EXPECT_TRUE(dst.measured_flops_verified);
70+
EXPECT_EQ(dst.measured_lat_ns, src.measured_lat_ns);
71+
EXPECT_EQ(dst.measured_ul_bw_bps, src.measured_ul_bw_bps);
72+
EXPECT_EQ(dst.measured_dl_bw_bps, src.measured_dl_bw_bps);
73+
}
74+
75+
TEST(DeviceProfileDataRoundtrip, DebugStringMentionsMeasuredWhenSet) {
76+
DeviceProfileData src = LegacyProfile();
77+
src.measured_flops = 95000000000ULL;
78+
src.measured_flops_verified = true;
79+
80+
const auto s = src.DebugString();
81+
EXPECT_NE(s.find("measured_flops"), std::string::npos);
82+
EXPECT_NE(s.find("95000000000"), std::string::npos);
83+
}
84+
85+
} // namespace

0 commit comments

Comments
 (0)