Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bandwidth Calculations to RoCM Traces #1010

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions libkineto/src/RoctracerActivity_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "RoctracerActivity.h"

#include <fmt/format.h>
#include <stddef.h>
#include <cstdint>

#include "Demangle.h"
Expand All @@ -20,8 +21,11 @@ namespace KINETO_NAMESPACE {

using namespace libkineto;

static std::unordered_map<int, std::string> correlationToGrid;
static std::unordered_map<int, std::string> correlationToBlock;
namespace {
thread_local std::unordered_map<int, std::string> correlationToGrid;
thread_local std::unordered_map<int, std::string> correlationToBlock;
thread_local std::unordered_map<int, size_t> correlationToSize;
} // namespace

const char* getGpuActivityKindString(uint32_t kind) {
switch (kind) {
Expand Down Expand Up @@ -94,11 +98,29 @@ inline void GpuActivity::log(ActivityLogger& logger) const {
logger.handleActivity(*this);
}

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

inline const std::string GpuActivity::metadataJson() const {
const auto& gpuActivity = raw();
// clang-format off

// if memcpy or memset, add size
if (correlationToSize.count(gpuActivity.id) > 0) {
size_t size = correlationToSize[gpuActivity.id];
std::string bandwidth_gib = (bandwidth(size, gpuActivity.end - gpuActivity.begin));
return fmt::format(R"JSON(
"device": {}, "stream": {},
"correlation": {}, "kind": "{}",
"bytes": {}, "memory bandwidth (GB/s)": {})JSON",
gpuActivity.device, gpuActivity.queue,
gpuActivity.id, getGpuActivityKindString(gpuActivity.kind),
size, bandwidth_gib);
}

if (correlationToGrid.count(gpuActivity.id) > 0) {
// if compute kernel, add grid and block
else if (correlationToGrid.count(gpuActivity.id) > 0) {
return fmt::format(R"JSON(
"device": {}, "stream": {},
"correlation": {}, "kind": "{}",
Expand Down Expand Up @@ -189,9 +211,10 @@ inline const std::string RuntimeActivity<roctracerKernelRow>::metadataJson()
template <>
inline const std::string RuntimeActivity<roctracerCopyRow>::metadataJson()
const {
correlationToSize[raw().id] = raw().size;
return fmt::format(
R"JSON(
"cid": {}, "correlation": {}, "src": "{}", "dst": "{}", "size": "{}", "kind": "{}")JSON",
"cid": {}, "correlation": {}, "src": "{}", "dst": "{}", "bytes": "{}", "kind": "{}")JSON",
raw().cid,
raw().id,
raw().src,
Expand All @@ -203,11 +226,12 @@ inline const std::string RuntimeActivity<roctracerCopyRow>::metadataJson()
template <>
inline const std::string RuntimeActivity<roctracerMallocRow>::metadataJson()
const {
correlationToSize[raw().id] = raw().size;
std::string size = "";
if (raw().cid == HIP_API_ID_hipMalloc) {
size = fmt::format(
R"JSON(
"size": {}, )JSON",
"bytes": {}, )JSON",
raw().size);
}
return fmt::format(
Expand Down
Loading