Skip to content

Commit ba4a84a

Browse files
sraikund16facebook-github-bot
authored andcommitted
Fix Bandwidth Calculations in JSON
Summary: There are two issues regarding bandwidth calculations in kineto: 1. We are using TSC timestamps as durations instead of the conversion to seconds. We should never call the start/end bare, only use the duration() and timstamp() funcitons. 2. We are not correctly using KB_TO_B as 1024 but instead as 1000 which makes calculations slightly off Differential Revision: D63422014
1 parent 0aacc09 commit ba4a84a

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

libkineto/src/CuptiActivity.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313
#include "Demangle.h"
1414
#include "DeviceProperties.h"
1515
#include "output_base.h"
16+
#include "Logger.h"
17+
18+
#define SECONDS_TO_MS 1000
19+
#define MS_TO_US 1000
20+
#define US_TO_NS 1000
21+
#define SECONDS_TO_US (SECONDS_TO_MS * MS_TO_US)
22+
#define SECONDS_TO_NS (SECONDS_TO_US * US_TO_NS)
23+
24+
#define KB_TO_B 1024
25+
#define MB_TO_KB 1024
26+
#define GB_TO_MB 1024
27+
#define MB_TO_B (MB_TO_KB * KB_TO_B)
28+
#define GB_TO_B (GB_TO_MB * MB_TO_B)
29+
1630

1731
namespace KINETO_NAMESPACE {
1832

@@ -154,7 +168,7 @@ inline const std::string GpuActivity<CUpti_ActivityMemcpy>::name() const {
154168
}
155169

156170
inline std::string bandwidth(uint64_t bytes, uint64_t duration) {
157-
return duration == 0 ? "\"N/A\"" : fmt::format("{}", bytes * 1.0 / duration);
171+
return duration == 0 ? "\"N/A\"" : fmt::format("{}", bytes * ((float)SECONDS_TO_NS/GB_TO_B) / duration);
158172
}
159173

160174
template<>
@@ -167,7 +181,7 @@ inline const std::string GpuActivity<CUpti_ActivityMemcpy>::metadataJson() const
167181
"bytes": {}, "memory bandwidth (GB/s)": {})JSON",
168182
memcpy.deviceId, memcpy.contextId,
169183
memcpy.streamId, memcpy.correlationId,
170-
memcpy.bytes, bandwidth(memcpy.bytes, memcpy.end - memcpy.start));
184+
memcpy.bytes, bandwidth(memcpy.bytes, duration()));
171185
// clang-format on
172186
}
173187

@@ -194,7 +208,7 @@ inline const std::string GpuActivity<CUpti_ActivityMemcpy2>::metadataJson() cons
194208
memcpy.srcDeviceId, memcpy.deviceId, memcpy.dstDeviceId,
195209
memcpy.srcContextId, memcpy.contextId, memcpy.dstContextId,
196210
memcpy.streamId, memcpy.correlationId,
197-
memcpy.bytes, bandwidth(memcpy.bytes, memcpy.end - memcpy.start));
211+
memcpy.bytes, bandwidth(memcpy.bytes, duration()));
198212
// clang-format on
199213
}
200214

@@ -220,7 +234,7 @@ inline const std::string GpuActivity<CUpti_ActivityMemset>::metadataJson() const
220234
"bytes": {}, "memory bandwidth (GB/s)": {})JSON",
221235
memset.deviceId, memset.contextId,
222236
memset.streamId, memset.correlationId,
223-
memset.bytes, bandwidth(memset.bytes, memset.end - memset.start));
237+
memset.bytes, bandwidth(memset.bytes, duration()));
224238
// clang-format on
225239
}
226240

0 commit comments

Comments
 (0)