@@ -29,7 +29,6 @@ class PluginTraceBuilder {
2929
3030 if (pProfileEvent == nullptr ) {
3131 LOG (ERROR) << " Failed to add event of nullptr" ;
32-
3332 return -1 ;
3433 }
3534
@@ -38,7 +37,6 @@ class PluginTraceBuilder {
3837 if (pProfileEvent->unpaddedStructSize <
3938 KINETO_PLUGIN_PROFILER_PROCESS_EVENTS_PARAMS_UNPADDED_STRUCT_SIZE) {
4039 LOG (ERROR) << " Profile event has an incompatible version" ;
41-
4240 return -1 ;
4341 }
4442
@@ -66,18 +64,15 @@ class PluginTraceBuilder {
6664
6765 if (pName == nullptr ) {
6866 LOG (ERROR) << " Failed to set last event name of nullptr" ;
69-
7067 return -1 ;
7168 }
7269
7370 if (buffer_->activities .empty ()) {
7471 LOG (ERROR) << " Failed to set last event flow as there is no last event" ;
75-
7672 return -1 ;
7773 }
7874
7975 buffer_->activities .back ()->activityName .assign (pName);
80-
8176 return 0 ;
8277 }
8378
@@ -97,13 +92,11 @@ class PluginTraceBuilder {
9792 if (pProfileEventFlow->unpaddedStructSize <
9893 KINETO_PLUGIN_PROFILE_EVENT_FLOW_UNPADDED_STRUCT_SIZE) {
9994 LOG (ERROR) << " Profile event flow has an incompatible version" ;
100-
10195 return -1 ;
10296 }
10397
10498 if (buffer_->activities .empty ()) {
10599 LOG (ERROR) << " Failed to set last event flow as there is no last event" ;
106-
107100 return -1 ;
108101 }
109102
@@ -123,19 +116,43 @@ class PluginTraceBuilder {
123116
124117 if (pKey == nullptr || pValue == nullptr ) {
125118 LOG (ERROR) << " Failed to set last event metadata of nullptr" ;
126-
127119 return -1 ;
128120 }
129121
130122 if (buffer_->activities .empty ()) {
131123 LOG (ERROR)
132124 << " Failed to set last event metadata as there is no last event" ;
133-
134125 return -1 ;
135126 }
136127
137128 buffer_->activities .back ()->addMetadata (std::string{pKey},
138129 std::string{pValue});
130+ return 0 ;
131+ }
132+
133+ int addDeviceInfo (const KinetoPlugin_ProfileDeviceInfo *pProfileDeviceInfo) {
134+ if (pProfileDeviceInfo == nullptr ) {
135+ LOG (ERROR) << " Failed to add device info of nullptr" ;
136+ return -1 ;
137+ }
138+
139+ // Handle versioning
140+ // Currently expect the exact same version
141+ if (pProfileDeviceInfo->unpaddedStructSize <
142+ KINETO_PLUGIN_PROFILE_DEVICE_INFO_UNPADDED_STRUCT_SIZE) {
143+ LOG (ERROR) << " Profile device info has an incompatible version" ;
144+ return -1 ;
145+ }
146+
147+ DeviceInfo deviceInfo (
148+ pProfileDeviceInfo->deviceId , pProfileDeviceInfo->sortIndex ,
149+ pProfileDeviceInfo->pName
150+ ? std::string (pProfileDeviceInfo->pName )
151+ : std::to_string (pProfileDeviceInfo->deviceId ),
152+ pProfileDeviceInfo->pLabel ? std::string (pProfileDeviceInfo->pLabel )
153+ : " " );
154+
155+ deviceInfos_.push_back (deviceInfo);
139156
140157 return 0 ;
141158 }
@@ -144,7 +161,6 @@ class PluginTraceBuilder {
144161 const KinetoPlugin_ProfileResourceInfo *pProfileResourceInfo) {
145162 if (pProfileResourceInfo == nullptr ) {
146163 LOG (ERROR) << " Failed to add resource info of nullptr" ;
147-
148164 return -1 ;
149165 }
150166
@@ -153,7 +169,6 @@ class PluginTraceBuilder {
153169 if (pProfileResourceInfo->unpaddedStructSize <
154170 KINETO_PLUGIN_PROFILE_RESOURCE_INFO_UNPADDED_STRUCT_SIZE) {
155171 LOG (ERROR) << " Profile resource info has an incompatible version" ;
156-
157172 return -1 ;
158173 }
159174
@@ -178,6 +193,7 @@ class PluginTraceBuilder {
178193 .setLastEventName = cSetLastEventName,
179194 .setLastEventFlow = cSetLastEventFlow,
180195 .addLastEventMetadata = cAddLastEventMetadata,
196+ .addDeviceInfo = cAddDeviceInfo,
181197 .addResourceInfo = cAddResourceInfo};
182198 }
183199
@@ -186,6 +202,8 @@ class PluginTraceBuilder {
186202 return std::move (buffer_);
187203 }
188204
205+ std::vector<DeviceInfo> getDeviceInfos () { return deviceInfos_; }
206+
189207 std::vector<ResourceInfo> getResourceInfos () { return resourceInfos_; }
190208
191209private:
@@ -220,6 +238,14 @@ class PluginTraceBuilder {
220238 return pPluginTraceBuilder->addLastEventMetadata (pKey, pValue);
221239 }
222240
241+ static int
242+ cAddDeviceInfo (KinetoPlugin_TraceBuilderHandle *pTraceBuilderHandle,
243+ const KinetoPlugin_ProfileDeviceInfo *pProfileDeviceInfo) {
244+ auto pPluginTraceBuilder =
245+ reinterpret_cast <PluginTraceBuilder *>(pTraceBuilderHandle);
246+ return pPluginTraceBuilder->addDeviceInfo (pProfileDeviceInfo);
247+ }
248+
223249 static int cAddResourceInfo (
224250 KinetoPlugin_TraceBuilderHandle *pTraceBuilderHandle,
225251 const KinetoPlugin_ProfileResourceInfo *pProfileResourceInfo) {
@@ -229,6 +255,7 @@ class PluginTraceBuilder {
229255 }
230256
231257 std::unique_ptr<CpuTraceBuffer> buffer_;
258+ std::vector<DeviceInfo> deviceInfos_;
232259 std::vector<ResourceInfo> resourceInfos_;
233260};
234261
0 commit comments