diff --git a/GPU/GPUTracking/Base/GPUReconstruction.h b/GPU/GPUTracking/Base/GPUReconstruction.h index 7be1413650119..33dd5b9e6bb89 100644 --- a/GPU/GPUTracking/Base/GPUReconstruction.h +++ b/GPU/GPUTracking/Base/GPUReconstruction.h @@ -428,6 +428,7 @@ class GPUReconstruction debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents); void header(); void row(char type, uint32_t count, std::string name, double gpu_time, double cpu_time, double total_time, std::size_t memSize, std::string nEventReport = ""); + private: std::ofstream streamCSV; bool mMarkdown; diff --git a/GPU/GPUTracking/Base/GPUReconstructionDebug.cxx b/GPU/GPUTracking/Base/GPUReconstructionDebug.cxx index abc65d333ea09..3ae30dfe50f91 100644 --- a/GPU/GPUTracking/Base/GPUReconstructionDebug.cxx +++ b/GPU/GPUTracking/Base/GPUReconstructionDebug.cxx @@ -189,84 +189,106 @@ bool GPUReconstruction::triggerDebugDump() return false; } -GPUReconstruction::debugWriter::debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents) : mMarkdown{markdown}, mStatNEvents{statNEvents} { +GPUReconstruction::debugWriter::debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents) : mMarkdown{markdown}, mStatNEvents{statNEvents} +{ if (!filenameCSV.empty()) { streamCSV.open(filenameCSV, std::ios::out | std::ios::app); } } -void GPUReconstruction::debugWriter::header() { +void GPUReconstruction::debugWriter::header() +{ if (streamCSV.is_open() && !streamCSV.tellp()) { - streamCSV << "type,count,name,gpu (us),cpu (us),cpu/total,total (us),GB/s,bytes,bytes/call\n"; + streamCSV << "type,count,name,gpu (us),cpu (us),cpu/total,total (us),GB/s,bytes,bytes/call\n"; } if (mMarkdown) { - std::cout << "| | count | name | gpu (us) | cpu (us) | cpu/tot | tot (us) | GB/s | bytes | bytes/call |\n"; - std::cout << "|---|--------|-------------------------------------------|-----------|-----------|---------|-----------|-----------|---------------|---------------|\n"; + std::cout << "| | count | name | gpu (us) | cpu (us) | cpu/tot | tot (us) | GB/s | bytes | bytes/call |\n"; + std::cout << "|---|--------|-------------------------------------------|-----------|-----------|---------|-----------|-----------|---------------|---------------|\n"; } } -void GPUReconstruction::debugWriter::row(char type, uint32_t count, std::string name, double gpu_time, double cpu_time, double total_time, std::size_t memSize, std::string nEventReport) { - double scale = 1000000.0 / mStatNEvents; +void GPUReconstruction::debugWriter::row(char type, uint32_t count, std::string name, double gpu_time, double cpu_time, double total_time, std::size_t memSize, std::string nEventReport) +{ + double scale = 1000000.0 / mStatNEvents; - if (streamCSV.is_open()) { - streamCSV << type << ","; - if (count != 0) streamCSV << count; - streamCSV << "," << name << ","; - if (gpu_time != -1.0) streamCSV << std::format("{:.0f}", gpu_time * scale); - streamCSV << ","; - if (cpu_time != -1.0) streamCSV << std::format("{:.0f}", cpu_time * scale); - streamCSV << ","; - if (cpu_time != -1.0 && total_time != -1.0) streamCSV << std::format("{:.2f}", cpu_time / total_time); - streamCSV << ","; - if (total_time != -1.0) streamCSV << std::format("{:.0f}", total_time * scale); - streamCSV << ","; - if (memSize != 0 && count != 0) streamCSV << std::format("{:.3f},{},{}", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count); - else streamCSV << ",,"; - streamCSV << std::endl; - } + if (streamCSV.is_open()) { + streamCSV << type << ","; + if (count != 0) + streamCSV << count; + streamCSV << "," << name << ","; + if (gpu_time != -1.0) + streamCSV << std::format("{:.0f}", gpu_time * scale); + streamCSV << ","; + if (cpu_time != -1.0) + streamCSV << std::format("{:.0f}", cpu_time * scale); + streamCSV << ","; + if (cpu_time != -1.0 && total_time != -1.0) + streamCSV << std::format("{:.2f}", cpu_time / total_time); + streamCSV << ","; + if (total_time != -1.0) + streamCSV << std::format("{:.0f}", total_time * scale); + streamCSV << ","; + if (memSize != 0 && count != 0) + streamCSV << std::format("{:.3f},{},{}", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count); + else + streamCSV << ",,"; + streamCSV << std::endl; + } - if (mMarkdown) { - std::cout << "| " << type << " | "; - if (count != 0) std::cout << std::format("{:6} |", count); - else std::cout << " |"; - std::cout << std::format(" {:42}|", name); - if (gpu_time != -1.0) std::cout << std::format("{:10.0f} |", gpu_time * scale); - else std::cout << " |"; - if (cpu_time != -1.0) std::cout << std::format("{:10.0f} |", cpu_time * scale); - else std::cout << " |"; - if (cpu_time != -1.0 && total_time != -1.0) std::cout << std::format("{:8.2f} |", cpu_time / total_time); - else std::cout << " |"; - if (total_time != -1.0) std::cout << std::format("{:10.0f} |", total_time * scale); - else std::cout << " |"; - if (memSize != 0 && count != 0) std::cout << std::format("{:10.3f} |{:14} |{:14} |", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count); - else std::cout << " | | |"; - std::cout << std::endl; - } else { - if (name.substr(0, 3) == "GPU") { - char bandwidth[256] = ""; - if (memSize && mStatNEvents && gpu_time != 0.0) { - snprintf(bandwidth, 256, " (%8.3f GB/s - %'14zu bytes - %'14zu per call)", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count); - } - printf("Execution Time: Task (%c %8ux): %50s Time: %'10.0f us%s\n", type, count, name.c_str(), gpu_time * scale, bandwidth); - } else if (name.substr(0, 3) == "TPC") { - std::size_t n = name.find('('); - std::string basename = name.substr(0, n - 1); - std::string postfix = name.substr(n + 1, name.size() - n - 2); - if (total_time != -1.0) { - printf("Execution Time: Step : %11s %38s Time: %'10.0f us %64s ( Total Time : %'14.0f us, CPU Time : %'14.0f us, %'7.2fx )\n", postfix.c_str(), - basename.c_str(), gpu_time * scale, "", total_time * scale, cpu_time * scale, cpu_time / total_time); - } else { - printf("Execution Time: Step (D %8ux): %11s %38s Time: %'10.0f us (%8.3f GB/s - %'14zu bytes - %'14zu per call)\n", count, postfix.c_str(), basename.c_str(), gpu_time * scale, - memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count); - } - } else if (name == "Prepare") { - printf("Execution Time: General Step : %50s Time: %'10.0f us\n", name.c_str(), gpu_time * scale); - } else if (name == "Wall") { - if (gpu_time != -1.0) { - printf("Execution Time: Total : %50s Time: %'10.0f us%s\n", "Total Kernel", gpu_time * scale, nEventReport.c_str()); - } - printf("Execution Time: Total : %50s Time: %'10.0f us ( CPU Time : %'10.0f us, %7.2fx ) %s\n", "Total Wall", total_time * scale, cpu_time * scale, cpu_time / total_time, nEventReport.c_str()); + if (mMarkdown) { + std::cout << "| " << type << " | "; + if (count != 0) + std::cout << std::format("{:6} |", count); + else + std::cout << " |"; + std::cout << std::format(" {:42}|", name); + if (gpu_time != -1.0) + std::cout << std::format("{:10.0f} |", gpu_time * scale); + else + std::cout << " |"; + if (cpu_time != -1.0) + std::cout << std::format("{:10.0f} |", cpu_time * scale); + else + std::cout << " |"; + if (cpu_time != -1.0 && total_time != -1.0) + std::cout << std::format("{:8.2f} |", cpu_time / total_time); + else + std::cout << " |"; + if (total_time != -1.0) + std::cout << std::format("{:10.0f} |", total_time * scale); + else + std::cout << " |"; + if (memSize != 0 && count != 0) + std::cout << std::format("{:10.3f} |{:14} |{:14} |", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count); + else + std::cout << " | | |"; + std::cout << std::endl; + } else { + if (name.substr(0, 3) == "GPU") { + char bandwidth[256] = ""; + if (memSize && mStatNEvents && gpu_time != 0.0) { + snprintf(bandwidth, 256, " (%8.3f GB/s - %'14zu bytes - %'14zu per call)", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count); } + printf("Execution Time: Task (%c %8ux): %50s Time: %'10.0f us%s\n", type, count, name.c_str(), gpu_time * scale, bandwidth); + } else if (name.substr(0, 3) == "TPC") { + std::size_t n = name.find('('); + std::string basename = name.substr(0, n - 1); + std::string postfix = name.substr(n + 1, name.size() - n - 2); + if (total_time != -1.0) { + printf("Execution Time: Step : %11s %38s Time: %'10.0f us %64s ( Total Time : %'14.0f us, CPU Time : %'14.0f us, %'7.2fx )\n", postfix.c_str(), + basename.c_str(), gpu_time * scale, "", total_time * scale, cpu_time * scale, cpu_time / total_time); + } else { + printf("Execution Time: Step (D %8ux): %11s %38s Time: %'10.0f us (%8.3f GB/s - %'14zu bytes - %'14zu per call)\n", count, postfix.c_str(), basename.c_str(), gpu_time * scale, + memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count); + } + } else if (name == "Prepare") { + printf("Execution Time: General Step : %50s Time: %'10.0f us\n", name.c_str(), gpu_time * scale); + } else if (name == "Wall") { + if (gpu_time != -1.0) { + printf("Execution Time: Total : %50s Time: %'10.0f us%s\n", "Total Kernel", gpu_time * scale, nEventReport.c_str()); + } + printf("Execution Time: Total : %50s Time: %'10.0f us ( CPU Time : %'10.0f us, %7.2fx ) %s\n", "Total Wall", total_time * scale, cpu_time * scale, cpu_time / total_time, nEventReport.c_str()); } + } }