Skip to content

Commit 8315915

Browse files
Move debugWriter to GPUReconstructionCPU.h
1 parent 7005e1b commit 8315915

File tree

4 files changed

+119
-117
lines changed

4 files changed

+119
-117
lines changed

GPU/GPUTracking/Base/GPUReconstruction.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,17 +424,6 @@ class GPUReconstruction
424424
void debugInit();
425425
void debugExit();
426426

427-
struct debugWriter {
428-
debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents);
429-
void header();
430-
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 = "");
431-
432-
private:
433-
std::ofstream streamCSV;
434-
bool mMarkdown;
435-
uint32_t mStatNEvents;
436-
};
437-
438427
static GPUReconstruction* GPUReconstruction_Create_CPU(const GPUSettingsDeviceBackend& cfg);
439428
};
440429

GPU/GPUTracking/Base/GPUReconstructionCPU.cxx

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
#include <atomic>
3737
#include <ctime>
38+
#include <format>
39+
#include <iostream>
3840
#include <string>
3941

4042
#ifndef _WIN32
@@ -373,3 +375,107 @@ void GPUReconstructionCPU::UpdateParamOccupancyMap(const uint32_t* mapHost, cons
373375
WriteToConstantMemory((char*)&processors()->param.occupancyMap - (char*)processors(), &tmp, sizeof(tmp), stream, ev);
374376
}
375377
}
378+
379+
GPUReconstructionCPU::debugWriter::debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents) : mMarkdown{markdown}, mStatNEvents{statNEvents}
380+
{
381+
if (!filenameCSV.empty()) {
382+
streamCSV.open(filenameCSV, std::ios::out | std::ios::app);
383+
}
384+
}
385+
386+
void GPUReconstructionCPU::debugWriter::header()
387+
{
388+
if (streamCSV.is_open() && !streamCSV.tellp()) {
389+
streamCSV << "type,count,name,gpu (us),cpu (us),cpu/total,total (us),GB/s,bytes,bytes/call\n";
390+
}
391+
392+
if (mMarkdown) {
393+
std::cout << "| | count | name | gpu (us) | cpu (us) | cpu/tot | tot (us) | GB/s | bytes | bytes/call |\n";
394+
std::cout << "|---|--------|-------------------------------------------|-----------|-----------|---------|-----------|-----------|---------------|---------------|\n";
395+
}
396+
}
397+
398+
void GPUReconstructionCPU::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)
399+
{
400+
double scale = 1000000.0 / mStatNEvents;
401+
402+
if (streamCSV.is_open()) {
403+
streamCSV << type << ",";
404+
if (count != 0)
405+
streamCSV << count;
406+
streamCSV << "," << name << ",";
407+
if (gpu_time != -1.0)
408+
streamCSV << std::format("{:.0f}", gpu_time * scale);
409+
streamCSV << ",";
410+
if (cpu_time != -1.0)
411+
streamCSV << std::format("{:.0f}", cpu_time * scale);
412+
streamCSV << ",";
413+
if (cpu_time != -1.0 && total_time != -1.0)
414+
streamCSV << std::format("{:.2f}", cpu_time / total_time);
415+
streamCSV << ",";
416+
if (total_time != -1.0)
417+
streamCSV << std::format("{:.0f}", total_time * scale);
418+
streamCSV << ",";
419+
if (memSize != 0 && count != 0)
420+
streamCSV << std::format("{:.3f},{},{}", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count);
421+
else
422+
streamCSV << ",,";
423+
streamCSV << std::endl;
424+
}
425+
426+
if (mMarkdown) {
427+
std::cout << "| " << type << " | ";
428+
if (count != 0)
429+
std::cout << std::format("{:6} |", count);
430+
else
431+
std::cout << " |";
432+
std::cout << std::format(" {:42}|", name);
433+
if (gpu_time != -1.0)
434+
std::cout << std::format("{:10.0f} |", gpu_time * scale);
435+
else
436+
std::cout << " |";
437+
if (cpu_time != -1.0)
438+
std::cout << std::format("{:10.0f} |", cpu_time * scale);
439+
else
440+
std::cout << " |";
441+
if (cpu_time != -1.0 && total_time != -1.0)
442+
std::cout << std::format("{:8.2f} |", cpu_time / total_time);
443+
else
444+
std::cout << " |";
445+
if (total_time != -1.0)
446+
std::cout << std::format("{:10.0f} |", total_time * scale);
447+
else
448+
std::cout << " |";
449+
if (memSize != 0 && count != 0)
450+
std::cout << std::format("{:10.3f} |{:14} |{:14} |", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count);
451+
else
452+
std::cout << " | | |";
453+
std::cout << std::endl;
454+
} else {
455+
if (name.substr(0, 3) == "GPU") {
456+
char bandwidth[256] = "";
457+
if (memSize && mStatNEvents && gpu_time != 0.0) {
458+
snprintf(bandwidth, 256, " (%8.3f GB/s - %'14zu bytes - %'14zu per call)", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count);
459+
}
460+
printf("Execution Time: Task (%c %8ux): %50s Time: %'10.0f us%s\n", type, count, name.c_str(), gpu_time * scale, bandwidth);
461+
} else if (name.substr(0, 3) == "TPC") {
462+
std::size_t n = name.find('(');
463+
std::string basename = name.substr(0, n - 1);
464+
std::string postfix = name.substr(n + 1, name.size() - n - 2);
465+
if (total_time != -1.0) {
466+
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(),
467+
basename.c_str(), gpu_time * scale, "", total_time * scale, cpu_time * scale, cpu_time / total_time);
468+
} else {
469+
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,
470+
memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count);
471+
}
472+
} else if (name == "Prepare") {
473+
printf("Execution Time: General Step : %50s Time: %'10.0f us\n", name.c_str(), gpu_time * scale);
474+
} else if (name == "Wall") {
475+
if (gpu_time != -1.0) {
476+
printf("Execution Time: Total : %50s Time: %'10.0f us%s\n", "Total Kernel", gpu_time * scale, nEventReport.c_str());
477+
}
478+
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());
479+
}
480+
}
481+
}

GPU/GPUTracking/Base/GPUReconstructionCPU.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
#define GPURECONSTRUCTIONICPU_H
1717

1818
#include "GPUReconstructionProcessing.h"
19+
#include <fstream>
1920
#include <stdexcept>
21+
#include <string>
2022
#include <vector>
2123

2224
namespace Ort
@@ -100,6 +102,17 @@ class GPUReconstructionCPU : public GPUReconstructionProcessing::KernelInterface
100102
size_t TransferMemoryResourcesHelper(GPUProcessor* proc, int32_t stream, bool all, bool toGPU);
101103
template <class S, int32_t I = 0, typename... Args>
102104
void runKernelInterface(krnlSetup&& setup, Args const&... args);
105+
106+
struct debugWriter {
107+
debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents);
108+
void header();
109+
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 = "");
110+
111+
private:
112+
std::ofstream streamCSV;
113+
bool mMarkdown;
114+
uint32_t mStatNEvents;
115+
};
103116
};
104117

105118
} // namespace o2::gpu

GPU/GPUTracking/Base/GPUReconstructionDebug.cxx

Lines changed: 0 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#include <mutex>
2323
#include <filesystem>
2424
#include <chrono>
25-
#include <format>
26-
#include <iostream>
2725
#include <string>
2826

2927
using namespace o2::gpu;
@@ -188,107 +186,3 @@ bool GPUReconstruction::triggerDebugDump()
188186
}
189187
return false;
190188
}
191-
192-
GPUReconstruction::debugWriter::debugWriter(std::string filenameCSV, bool markdown, uint32_t statNEvents) : mMarkdown{markdown}, mStatNEvents{statNEvents}
193-
{
194-
if (!filenameCSV.empty()) {
195-
streamCSV.open(filenameCSV, std::ios::out | std::ios::app);
196-
}
197-
}
198-
199-
void GPUReconstruction::debugWriter::header()
200-
{
201-
if (streamCSV.is_open() && !streamCSV.tellp()) {
202-
streamCSV << "type,count,name,gpu (us),cpu (us),cpu/total,total (us),GB/s,bytes,bytes/call\n";
203-
}
204-
205-
if (mMarkdown) {
206-
std::cout << "| | count | name | gpu (us) | cpu (us) | cpu/tot | tot (us) | GB/s | bytes | bytes/call |\n";
207-
std::cout << "|---|--------|-------------------------------------------|-----------|-----------|---------|-----------|-----------|---------------|---------------|\n";
208-
}
209-
}
210-
211-
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)
212-
{
213-
double scale = 1000000.0 / mStatNEvents;
214-
215-
if (streamCSV.is_open()) {
216-
streamCSV << type << ",";
217-
if (count != 0)
218-
streamCSV << count;
219-
streamCSV << "," << name << ",";
220-
if (gpu_time != -1.0)
221-
streamCSV << std::format("{:.0f}", gpu_time * scale);
222-
streamCSV << ",";
223-
if (cpu_time != -1.0)
224-
streamCSV << std::format("{:.0f}", cpu_time * scale);
225-
streamCSV << ",";
226-
if (cpu_time != -1.0 && total_time != -1.0)
227-
streamCSV << std::format("{:.2f}", cpu_time / total_time);
228-
streamCSV << ",";
229-
if (total_time != -1.0)
230-
streamCSV << std::format("{:.0f}", total_time * scale);
231-
streamCSV << ",";
232-
if (memSize != 0 && count != 0)
233-
streamCSV << std::format("{:.3f},{},{}", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count);
234-
else
235-
streamCSV << ",,";
236-
streamCSV << std::endl;
237-
}
238-
239-
if (mMarkdown) {
240-
std::cout << "| " << type << " | ";
241-
if (count != 0)
242-
std::cout << std::format("{:6} |", count);
243-
else
244-
std::cout << " |";
245-
std::cout << std::format(" {:42}|", name);
246-
if (gpu_time != -1.0)
247-
std::cout << std::format("{:10.0f} |", gpu_time * scale);
248-
else
249-
std::cout << " |";
250-
if (cpu_time != -1.0)
251-
std::cout << std::format("{:10.0f} |", cpu_time * scale);
252-
else
253-
std::cout << " |";
254-
if (cpu_time != -1.0 && total_time != -1.0)
255-
std::cout << std::format("{:8.2f} |", cpu_time / total_time);
256-
else
257-
std::cout << " |";
258-
if (total_time != -1.0)
259-
std::cout << std::format("{:10.0f} |", total_time * scale);
260-
else
261-
std::cout << " |";
262-
if (memSize != 0 && count != 0)
263-
std::cout << std::format("{:10.3f} |{:14} |{:14} |", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count);
264-
else
265-
std::cout << " | | |";
266-
std::cout << std::endl;
267-
} else {
268-
if (name.substr(0, 3) == "GPU") {
269-
char bandwidth[256] = "";
270-
if (memSize && mStatNEvents && gpu_time != 0.0) {
271-
snprintf(bandwidth, 256, " (%8.3f GB/s - %'14zu bytes - %'14zu per call)", memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count);
272-
}
273-
printf("Execution Time: Task (%c %8ux): %50s Time: %'10.0f us%s\n", type, count, name.c_str(), gpu_time * scale, bandwidth);
274-
} else if (name.substr(0, 3) == "TPC") {
275-
std::size_t n = name.find('(');
276-
std::string basename = name.substr(0, n - 1);
277-
std::string postfix = name.substr(n + 1, name.size() - n - 2);
278-
if (total_time != -1.0) {
279-
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(),
280-
basename.c_str(), gpu_time * scale, "", total_time * scale, cpu_time * scale, cpu_time / total_time);
281-
} else {
282-
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,
283-
memSize / gpu_time * 1e-9, memSize / mStatNEvents, memSize / mStatNEvents / count);
284-
}
285-
} else if (name == "Prepare") {
286-
printf("Execution Time: General Step : %50s Time: %'10.0f us\n", name.c_str(), gpu_time * scale);
287-
} else if (name == "Wall") {
288-
if (gpu_time != -1.0) {
289-
printf("Execution Time: Total : %50s Time: %'10.0f us%s\n", "Total Kernel", gpu_time * scale, nEventReport.c_str());
290-
}
291-
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());
292-
}
293-
}
294-
}

0 commit comments

Comments
 (0)