From a3ab0aa6a874510fce4c76c3fe81ecd75d9058f2 Mon Sep 17 00:00:00 2001 From: Fangjia Shen Date: Mon, 7 Oct 2024 22:55:45 -0400 Subject: [PATCH 1/3] disable copy semantics, and implement move semantics for the PipeReader --- gpu-simulator/trace-parser/trace_parser.cc | 19 +++++++++++++++++++ gpu-simulator/trace-parser/trace_parser.h | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/gpu-simulator/trace-parser/trace_parser.cc b/gpu-simulator/trace-parser/trace_parser.cc index f39af205d..e1b6819bb 100644 --- a/gpu-simulator/trace-parser/trace_parser.cc +++ b/gpu-simulator/trace-parser/trace_parser.cc @@ -473,4 +473,23 @@ bool PipeReader::hasEnding(const std::string &fullString, ending.length(), ending)); } return false; +} + +PipeReader::PipeReader(PipeReader &&other) noexcept: + pipe(other.pipe), + command(other.command) +{ + other.pipe = NULL; + other.command = {}; +} + +PipeReader& PipeReader::operator=(PipeReader&&other) noexcept{ + if(this != &other){ + pipe = other.pipe; + command = other.command; + + other.pipe= NULL; + other.command = {}; + } + return *this; } \ No newline at end of file diff --git a/gpu-simulator/trace-parser/trace_parser.h b/gpu-simulator/trace-parser/trace_parser.h index c129f75c3..2b2118fbb 100644 --- a/gpu-simulator/trace-parser/trace_parser.h +++ b/gpu-simulator/trace-parser/trace_parser.h @@ -78,6 +78,16 @@ struct inst_trace_t { class PipeReader { public: PipeReader(const std::string &filePath); + + // It does not make sense to implement copy semantics for PipeReader, + // because each instance should hold a unique Linux pipe handle + PipeReader(const PipeReader&) = delete; + PipeReader& operator=(const PipeReader&) = delete; + + // Move semantics can be supported + PipeReader(PipeReader &&) noexcept; + PipeReader& operator=(PipeReader&&) noexcept; + void OpenFile(const std::string &filePath); // Destructor to close the pipe From 0929b87fb90c5ecb311bf230df80fc13368e83ea Mon Sep 17 00:00:00 2001 From: Fangjia Shen Date: Mon, 7 Oct 2024 23:06:42 -0400 Subject: [PATCH 2/3] reorganize code --- gpu-simulator/trace-parser/trace_parser.h | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/gpu-simulator/trace-parser/trace_parser.h b/gpu-simulator/trace-parser/trace_parser.h index 2b2118fbb..bab5a0a1d 100644 --- a/gpu-simulator/trace-parser/trace_parser.h +++ b/gpu-simulator/trace-parser/trace_parser.h @@ -79,6 +79,13 @@ class PipeReader { public: PipeReader(const std::string &filePath); + // Destructor to close the pipe + ~PipeReader() { + if (pipe) { + pclose(pipe); // Close the pipe when done + } + } + // It does not make sense to implement copy semantics for PipeReader, // because each instance should hold a unique Linux pipe handle PipeReader(const PipeReader&) = delete; @@ -88,15 +95,6 @@ class PipeReader { PipeReader(PipeReader &&) noexcept; PipeReader& operator=(PipeReader&&) noexcept; - void OpenFile(const std::string &filePath); - - // Destructor to close the pipe - ~PipeReader() { - if (pipe) { - pclose(pipe); // Close the pipe when done - } - } - // Read one line bool readLine(std::string &line); @@ -107,6 +105,8 @@ class PipeReader { // Helper function to check if a string ends with a specific suffix (file // extension) bool hasEnding(const std::string &fullString, const std::string &ending); + + void OpenFile(const std::string &filePath); }; struct kernel_trace_t { From 75e80993989b01208cec63b63bf3ed1b043dc3ff Mon Sep 17 00:00:00 2001 From: purdue-jenkins Date: Mon, 7 Oct 2024 23:30:37 -0400 Subject: [PATCH 3/3] Automated Format --- gpu-simulator/trace-parser/trace_parser.cc | 12 +++++------- gpu-simulator/trace-parser/trace_parser.h | 6 +++--- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/gpu-simulator/trace-parser/trace_parser.cc b/gpu-simulator/trace-parser/trace_parser.cc index e1b6819bb..36b2d5ee4 100644 --- a/gpu-simulator/trace-parser/trace_parser.cc +++ b/gpu-simulator/trace-parser/trace_parser.cc @@ -475,20 +475,18 @@ bool PipeReader::hasEnding(const std::string &fullString, return false; } -PipeReader::PipeReader(PipeReader &&other) noexcept: - pipe(other.pipe), - command(other.command) -{ +PipeReader::PipeReader(PipeReader &&other) noexcept + : pipe(other.pipe), command(other.command) { other.pipe = NULL; other.command = {}; } -PipeReader& PipeReader::operator=(PipeReader&&other) noexcept{ - if(this != &other){ +PipeReader &PipeReader::operator=(PipeReader &&other) noexcept { + if (this != &other) { pipe = other.pipe; command = other.command; - other.pipe= NULL; + other.pipe = NULL; other.command = {}; } return *this; diff --git a/gpu-simulator/trace-parser/trace_parser.h b/gpu-simulator/trace-parser/trace_parser.h index bab5a0a1d..615a98096 100644 --- a/gpu-simulator/trace-parser/trace_parser.h +++ b/gpu-simulator/trace-parser/trace_parser.h @@ -88,12 +88,12 @@ class PipeReader { // It does not make sense to implement copy semantics for PipeReader, // because each instance should hold a unique Linux pipe handle - PipeReader(const PipeReader&) = delete; - PipeReader& operator=(const PipeReader&) = delete; + PipeReader(const PipeReader &) = delete; + PipeReader &operator=(const PipeReader &) = delete; // Move semantics can be supported PipeReader(PipeReader &&) noexcept; - PipeReader& operator=(PipeReader&&) noexcept; + PipeReader &operator=(PipeReader &&) noexcept; // Read one line bool readLine(std::string &line);