From bd042ef1c6131ce1933977a8bde13299708a32dd Mon Sep 17 00:00:00 2001 From: Teng Gao Date: Mon, 10 May 2021 14:41:11 +0800 Subject: [PATCH 1/2] dump cudaOccDeviceProp --- libkineto/src/CudaDeviceProperties.cpp | 3 -- libkineto/src/CudaDeviceProperties.h | 4 +++ libkineto/src/output_json.cpp | 42 +++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/libkineto/src/CudaDeviceProperties.cpp b/libkineto/src/CudaDeviceProperties.cpp index eda37faf0..d5e9252ab 100644 --- a/libkineto/src/CudaDeviceProperties.cpp +++ b/libkineto/src/CudaDeviceProperties.cpp @@ -7,10 +7,7 @@ #include "CudaDeviceProperties.h" -#include - #include -#include #include "Logger.h" diff --git a/libkineto/src/CudaDeviceProperties.h b/libkineto/src/CudaDeviceProperties.h index 8156c8b7d..02886b25c 100644 --- a/libkineto/src/CudaDeviceProperties.h +++ b/libkineto/src/CudaDeviceProperties.h @@ -7,10 +7,14 @@ #pragma once +#include #include +#include namespace KINETO_NAMESPACE { +const std::vector& occDeviceProps(); + float kernelOccupancy( uint32_t deviceId, uint16_t registersPerThread, diff --git a/libkineto/src/output_json.cpp b/libkineto/src/output_json.cpp index 50577329e..8902ea75f 100644 --- a/libkineto/src/output_json.cpp +++ b/libkineto/src/output_json.cpp @@ -33,12 +33,44 @@ static constexpr int kSchemaVersion = 1; void ChromeTraceLogger::handleTraceStart( const std::unordered_map& metadata) { + std::string cudaOccDeviceProps = ""; +#ifdef HAS_CUPTI + const std::vector& occProps = KINETO_NAMESPACE::occDeviceProps(); + if (occProps.size() > 0) { + std::ostringstream oss; + oss << "["; + bool first = true; + for (size_t i = 0; i < occProps.size(); i += 1) { + const cudaOccDeviceProp& occProp = occProps[i]; + if (!first) { + oss << ", "; + } + oss << "{"; + oss << "\"computeMajor\": " << occProp.computeMajor << ", "; + oss << "\"computeMinor\": " << occProp.computeMinor << ", "; + oss << "\"maxThreadsPerBlock\": " << occProp.maxThreadsPerBlock << ", "; + oss << "\"maxThreadsPerMultiprocessor\": " << occProp.maxThreadsPerMultiprocessor << ", "; + oss << "\"regsPerBlock\": " << occProp.regsPerBlock << ", "; + oss << "\"regsPerMultiprocessor\": " << occProp.regsPerMultiprocessor << ", "; + oss << "\"warpSize\": " << occProp.warpSize << ", "; + oss << "\"sharedMemPerBlock\": " << occProp.sharedMemPerBlock << ", "; + oss << "\"sharedMemPerMultiprocessor\": " << occProp.sharedMemPerMultiprocessor << ", "; + oss << "\"numSms\": " << occProp.numSms << ", "; + oss << "\"sharedMemPerBlockOptin\": " << occProp.sharedMemPerBlockOptin; + oss << "}"; + first = false; + } + oss << "]"; + cudaOccDeviceProps = oss.str(); + } +#endif // HAS_CUPTI + traceOf_ << fmt::format(R"JSON( {{ "schemaVersion": {}, )JSON", kSchemaVersion); - if (!metadata.empty()) { + if (!metadata.empty() || !cudaOccDeviceProps.empty()) { traceOf_ << R"JSON( "metadata": { )JSON"; @@ -50,6 +82,14 @@ void ChromeTraceLogger::handleTraceStart( traceOf_ << fmt::format(R"( "{}": "{}")", kv.first, kv.second); first = false; } + if (!cudaOccDeviceProps.empty()) { + if (!first) { + traceOf_ << ",\n"; + } + traceOf_ << fmt::format(R"( "{}": {})", "cudaOccDeviceProps", cudaOccDeviceProps); + first = false; + } + traceOf_ << R"JSON( }, )JSON"; From 5cee6616214ca2a57e9a10b5128da1ebf7128c92 Mon Sep 17 00:00:00 2001 From: Teng Gao Date: Tue, 11 May 2021 09:25:16 +0800 Subject: [PATCH 2/2] dump in handleTraceStart --- libkineto/src/output_json.cpp | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/libkineto/src/output_json.cpp b/libkineto/src/output_json.cpp index 8902ea75f..7e6bb391b 100644 --- a/libkineto/src/output_json.cpp +++ b/libkineto/src/output_json.cpp @@ -33,16 +33,19 @@ static constexpr int kSchemaVersion = 1; void ChromeTraceLogger::handleTraceStart( const std::unordered_map& metadata) { - std::string cudaOccDeviceProps = ""; + traceOf_ << fmt::format(R"JSON( +{{ + "schemaVersion": {}, + )JSON", kSchemaVersion); + #ifdef HAS_CUPTI const std::vector& occProps = KINETO_NAMESPACE::occDeviceProps(); if (occProps.size() > 0) { std::ostringstream oss; oss << "["; - bool first = true; for (size_t i = 0; i < occProps.size(); i += 1) { const cudaOccDeviceProp& occProp = occProps[i]; - if (!first) { + if (i > 0) { oss << ", "; } oss << "{"; @@ -58,19 +61,15 @@ void ChromeTraceLogger::handleTraceStart( oss << "\"numSms\": " << occProp.numSms << ", "; oss << "\"sharedMemPerBlockOptin\": " << occProp.sharedMemPerBlockOptin; oss << "}"; - first = false; } oss << "]"; - cudaOccDeviceProps = oss.str(); + traceOf_ << fmt::format(R"JSON( + "cudaOccDeviceProps": {}, + )JSON", oss.str()); } #endif // HAS_CUPTI - traceOf_ << fmt::format(R"JSON( -{{ - "schemaVersion": {}, - )JSON", kSchemaVersion); - - if (!metadata.empty() || !cudaOccDeviceProps.empty()) { + if (!metadata.empty()) { traceOf_ << R"JSON( "metadata": { )JSON"; @@ -82,14 +81,6 @@ void ChromeTraceLogger::handleTraceStart( traceOf_ << fmt::format(R"( "{}": "{}")", kv.first, kv.second); first = false; } - if (!cudaOccDeviceProps.empty()) { - if (!first) { - traceOf_ << ",\n"; - } - traceOf_ << fmt::format(R"( "{}": {})", "cudaOccDeviceProps", cudaOccDeviceProps); - first = false; - } - traceOf_ << R"JSON( }, )JSON";