Skip to content

Commit

Permalink
Fix Bandwidth Calculations in JSON
Browse files Browse the repository at this point in the history
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
  • Loading branch information
sraikund16 authored and facebook-github-bot committed Sep 25, 2024
1 parent 0aacc09 commit ba4a84a
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions libkineto/src/CuptiActivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@
#include "Demangle.h"
#include "DeviceProperties.h"
#include "output_base.h"
#include "Logger.h"

#define SECONDS_TO_MS 1000
#define MS_TO_US 1000
#define US_TO_NS 1000
#define SECONDS_TO_US (SECONDS_TO_MS * MS_TO_US)
#define SECONDS_TO_NS (SECONDS_TO_US * US_TO_NS)

#define KB_TO_B 1024
#define MB_TO_KB 1024
#define GB_TO_MB 1024
#define MB_TO_B (MB_TO_KB * KB_TO_B)
#define GB_TO_B (GB_TO_MB * MB_TO_B)


namespace KINETO_NAMESPACE {

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

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

template<>
Expand All @@ -167,7 +181,7 @@ inline const std::string GpuActivity<CUpti_ActivityMemcpy>::metadataJson() const
"bytes": {}, "memory bandwidth (GB/s)": {})JSON",
memcpy.deviceId, memcpy.contextId,
memcpy.streamId, memcpy.correlationId,
memcpy.bytes, bandwidth(memcpy.bytes, memcpy.end - memcpy.start));
memcpy.bytes, bandwidth(memcpy.bytes, duration()));
// clang-format on
}

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

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

Expand Down

0 comments on commit ba4a84a

Please sign in to comment.