From 9d223f0f65295a5652337b78a8cf7579ef9db326 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Wed, 12 Dec 2018 21:33:00 +0300 Subject: [PATCH 1/6] [HIPIFY][fix] Fixer for #801 [issue #801] Errors in hipification statistics --- hipify-clang/src/Statistics.cpp | 31 ++++++++++++++++++++++--------- hipify-clang/src/Statistics.h | 6 ++++-- hipify-clang/src/main.cpp | 2 ++ 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/hipify-clang/src/Statistics.cpp b/hipify-clang/src/Statistics.cpp index 474acf724d..c37226ed66 100644 --- a/hipify-clang/src/Statistics.cpp +++ b/hipify-clang/src/Statistics.cpp @@ -130,8 +130,12 @@ Statistics::Statistics(const std::string& name): fileName(name) { std::ifstream src_file(name, std::ios::binary | std::ios::ate); src_file.clear(); src_file.seekg(0); - totalLines = (int) std::count(std::istreambuf_iterator(src_file), std::istreambuf_iterator(), '\n'); + totalLines = (unsigned) std::count(std::istreambuf_iterator(src_file), std::istreambuf_iterator(), '\n'); totalBytes = (int) src_file.tellg(); + if (totalBytes < 0) { + totalBytes = 0; + hasErrors = true; + } startTime = chr::steady_clock::now(); } @@ -171,23 +175,24 @@ void Statistics::print(std::ostream* csv, llvm::raw_ostream* printOut, bool skip std::string str = "file \'" + fileName + "\' statistics:\n"; conditionalPrint(csv, printOut, "\n" + str, "\n[HIPIFY] info: " + str); } + if (hasErrors || totalBytes <= 0 || totalLines <= 0) { + std::string str = "\n ERROR: Statistics is invalid due to failed hipification.\n\n"; + conditionalPrint(csv, printOut, str, str); + } size_t changedLines = touchedLines.size(); // Total number of (un)supported refs that were converted. int supportedSum = supported.getConvSum(); int unsupportedSum = unsupported.getConvSum(); + int allSum = supportedSum + unsupportedSum; printStat(csv, printOut, "CONVERTED refs count", supportedSum); printStat(csv, printOut, "UNCONVERTED refs count", unsupportedSum); - printStat(csv, printOut, "CONVERSION %", 100 - std::lround(double(unsupportedSum * 100) / double(supportedSum + unsupportedSum))); + printStat(csv, printOut, "CONVERSION %", 100 - (0 == allSum ? 100 : std::lround(double(unsupportedSum * 100) / double(allSum)))); printStat(csv, printOut, "REPLACED bytes", touchedBytes); printStat(csv, printOut, "TOTAL bytes", totalBytes); printStat(csv, printOut, "CHANGED lines of code", changedLines); printStat(csv, printOut, "TOTAL lines of code", totalLines); - if (totalBytes > 0) { - printStat(csv, printOut, "CODE CHANGED (in bytes) %", std::lround(double(touchedBytes * 100) / double(totalBytes))); - } - if (totalLines > 0) { - printStat(csv, printOut, "CODE CHANGED (in lines) %", std::lround(double(changedLines * 100) / double(totalLines))); - } + printStat(csv, printOut, "CODE CHANGED (in bytes) %", 0 == totalBytes ? 0 : std::lround(double(touchedBytes * 100) / double(totalBytes))); + printStat(csv, printOut, "CODE CHANGED (in lines) %", 0 == totalLines ? 0 : std::lround(double(changedLines * 100) / double(totalLines))); typedef std::chrono::duration duration; duration elapsed = completionTime - startTime; std::stringstream stream; @@ -199,6 +204,7 @@ void Statistics::print(std::ostream* csv, llvm::raw_ostream* printOut, bool skip void Statistics::printAggregate(std::ostream *csv, llvm::raw_ostream* printOut) { Statistics globalStats = getAggregate(); + globalStats.hasErrors = false; conditionalPrint(csv, printOut, "\nTOTAL statistics:\n", "\n[HIPIFY] info: TOTAL statistics:\n"); // A file is considered "converted" if we made any changes to it. int convertedFiles = 0; @@ -206,16 +212,23 @@ void Statistics::printAggregate(std::ostream *csv, llvm::raw_ostream* printOut) if (!p.second.touchedLines.empty()) { convertedFiles++; } + if (!globalStats.hasErrors && p.second.hasErrors) { + globalStats.hasErrors = true; + } + if (globalStats.startTime > p.second.startTime) { + globalStats.startTime = p.second.startTime; + } } printStat(csv, printOut, "CONVERTED files", convertedFiles); printStat(csv, printOut, "PROCESSED files", stats.size()); + globalStats.markCompletion(); globalStats.print(csv, printOut); } //// Static state management //// Statistics Statistics::getAggregate() { - Statistics globalStats("global"); + Statistics globalStats("GLOBAL"); for (const auto& p : stats) { globalStats.add(p.second); } diff --git a/hipify-clang/src/Statistics.h b/hipify-clang/src/Statistics.h index c20278d176..2b3dcf9e9c 100644 --- a/hipify-clang/src/Statistics.h +++ b/hipify-clang/src/Statistics.h @@ -158,8 +158,8 @@ class Statistics { StatCounter unsupported; std::string fileName; std::set touchedLines = {}; - int touchedBytes = 0; - int totalLines = 0; + unsigned touchedBytes = 0; + unsigned totalLines = 0; int totalBytes = 0; chr::steady_clock::time_point startTime; chr::steady_clock::time_point completionTime; @@ -202,4 +202,6 @@ public: * timestamp into the currently active one. */ static void setActive(const std::string& name); + // Set this flag in case of hipification errors + bool hasErrors = false; }; diff --git a/hipify-clang/src/main.cpp b/hipify-clang/src/main.cpp index f7541ff4c6..951bffd5e8 100644 --- a/hipify-clang/src/main.cpp +++ b/hipify-clang/src/main.cpp @@ -117,6 +117,8 @@ int main(int argc, const char **argv) { Tool.appendArgumentsAdjuster(ct::getClangSyntaxOnlyAdjuster()); // Hipify _all_ the things! if (Tool.runAndSave(&actionFactory)) { + Statistics& currentStat = Statistics::current(); + currentStat.hasErrors = true; LLVM_DEBUG(llvm::dbgs() << "Skipped some replacements.\n"); } // Either move the tmpfile to the output, or remove it. From bffacb6c72c19a4517dcdfe244bb99c7268cf362 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Thu, 13 Dec 2018 18:35:45 +0300 Subject: [PATCH 2/6] [HIPIFY][fix] Fix for the rest of found bugs in Statistics + Signs of the converted file are extended + Total converted lines and total elapsed time are fixed + Zero rates are excluded from statistics --- hipify-clang/src/Statistics.cpp | 67 +++++++++++++++++++++------------ hipify-clang/src/Statistics.h | 5 ++- 2 files changed, 45 insertions(+), 27 deletions(-) diff --git a/hipify-clang/src/Statistics.cpp b/hipify-clang/src/Statistics.cpp index c37226ed66..7d86f8ae62 100644 --- a/hipify-clang/src/Statistics.cpp +++ b/hipify-clang/src/Statistics.cpp @@ -51,7 +51,7 @@ const char *apiNames[NUM_API_TYPES] = { "cuRAND API", "cuDNN API", "cuFFT API", - "cuSPARSE" + "cuSPARSE API" }; namespace { @@ -109,19 +109,33 @@ int StatCounter::getConvSum() { } void StatCounter::print(std::ostream* csv, llvm::raw_ostream* printOut, const std::string& prefix) { - conditionalPrint(csv, printOut, "\nCUDA ref type;Count\n", "[HIPIFY] info: " + prefix + " refs by type:\n"); + for (int i = 0; i < NUM_CONV_TYPES; i++) { + if (convTypeCounters[i] > 0) { + conditionalPrint(csv, printOut, "\nCUDA ref type;Count\n", "[HIPIFY] info: " + prefix + " refs by type:\n"); + break; + } + } for (int i = 0; i < NUM_CONV_TYPES; i++) { if (convTypeCounters[i] > 0) { printStat(csv, printOut, counterNames[i], convTypeCounters[i]); } } - conditionalPrint(csv, printOut, "\nCUDA API;Count\n", "[HIPIFY] info: " + prefix + " refs by API:\n"); for (int i = 0; i < NUM_API_TYPES; i++) { - printStat(csv, printOut, apiNames[i], apiCounters[i]); + if (apiCounters[i] > 0) { + conditionalPrint(csv, printOut, "\nCUDA API;Count\n", "[HIPIFY] info: " + prefix + " refs by API:\n"); + break; + } } - conditionalPrint(csv, printOut, "\nCUDA ref name;Count\n", "[HIPIFY] info: " + prefix + " refs by names:\n"); - for (const auto &it : counters) { - printStat(csv, printOut, it.first, it.second); + for (int i = 0; i < NUM_API_TYPES; i++) { + if (apiCounters[i] > 0) { + printStat(csv, printOut, apiNames[i], apiCounters[i]); + } + } + if (counters.size() > 0) { + conditionalPrint(csv, printOut, "\nCUDA ref name;Count\n", "[HIPIFY] info: " + prefix + " refs by names:\n"); + for (const auto &it : counters) { + printStat(csv, printOut, it.first, it.second); + } } } @@ -134,7 +148,6 @@ Statistics::Statistics(const std::string& name): fileName(name) { totalBytes = (int) src_file.tellg(); if (totalBytes < 0) { totalBytes = 0; - hasErrors = true; } startTime = chr::steady_clock::now(); } @@ -153,17 +166,27 @@ void Statistics::incrementCounter(const hipCounter &counter, const std::string& void Statistics::add(const Statistics &other) { supported.add(other.supported); unsupported.add(other.unsupported); - totalBytes += other.totalBytes; - totalLines += other.totalLines; touchedBytes += other.touchedBytes; + totalBytes += other.totalBytes; + touchedLines += other.touchedLines; + totalLines += other.totalLines; + if (other.hasErrors && !hasErrors) { + hasErrors = true; + } + if (startTime > other.startTime) { + startTime = other.startTime; + } } void Statistics::lineTouched(int lineNumber) { - touchedLines.insert(lineNumber); + touchedLinesSet.insert(lineNumber); + touchedLines = touchedLinesSet.size(); } + void Statistics::bytesChanged(int bytes) { touchedBytes += bytes; } + void Statistics::markCompletion() { completionTime = chr::steady_clock::now(); } @@ -179,7 +202,6 @@ void Statistics::print(std::ostream* csv, llvm::raw_ostream* printOut, bool skip std::string str = "\n ERROR: Statistics is invalid due to failed hipification.\n\n"; conditionalPrint(csv, printOut, str, str); } - size_t changedLines = touchedLines.size(); // Total number of (un)supported refs that were converted. int supportedSum = supported.getConvSum(); int unsupportedSum = unsupported.getConvSum(); @@ -189,10 +211,10 @@ void Statistics::print(std::ostream* csv, llvm::raw_ostream* printOut, bool skip printStat(csv, printOut, "CONVERSION %", 100 - (0 == allSum ? 100 : std::lround(double(unsupportedSum * 100) / double(allSum)))); printStat(csv, printOut, "REPLACED bytes", touchedBytes); printStat(csv, printOut, "TOTAL bytes", totalBytes); - printStat(csv, printOut, "CHANGED lines of code", changedLines); + printStat(csv, printOut, "CHANGED lines of code", touchedLines); printStat(csv, printOut, "TOTAL lines of code", totalLines); printStat(csv, printOut, "CODE CHANGED (in bytes) %", 0 == totalBytes ? 0 : std::lround(double(touchedBytes * 100) / double(totalBytes))); - printStat(csv, printOut, "CODE CHANGED (in lines) %", 0 == totalLines ? 0 : std::lround(double(changedLines * 100) / double(totalLines))); + printStat(csv, printOut, "CODE CHANGED (in lines) %", 0 == totalLines ? 0 : std::lround(double(touchedLines * 100) / double(totalLines))); typedef std::chrono::duration duration; duration elapsed = completionTime - startTime; std::stringstream stream; @@ -204,25 +226,20 @@ void Statistics::print(std::ostream* csv, llvm::raw_ostream* printOut, bool skip void Statistics::printAggregate(std::ostream *csv, llvm::raw_ostream* printOut) { Statistics globalStats = getAggregate(); - globalStats.hasErrors = false; - conditionalPrint(csv, printOut, "\nTOTAL statistics:\n", "\n[HIPIFY] info: TOTAL statistics:\n"); // A file is considered "converted" if we made any changes to it. int convertedFiles = 0; for (const auto& p : stats) { - if (!p.second.touchedLines.empty()) { + if (p.second.touchedLines && p.second.totalBytes && + p.second.totalLines && !p.second.hasErrors) { convertedFiles++; } - if (!globalStats.hasErrors && p.second.hasErrors) { - globalStats.hasErrors = true; - } - if (globalStats.startTime > p.second.startTime) { - globalStats.startTime = p.second.startTime; - } } - printStat(csv, printOut, "CONVERTED files", convertedFiles); - printStat(csv, printOut, "PROCESSED files", stats.size()); globalStats.markCompletion(); globalStats.print(csv, printOut); + std::string str = "TOTAL statistics:"; + conditionalPrint(csv, printOut, "\n" + str + "\n", "\n[HIPIFY] info: " + str + "\n"); + printStat(csv, printOut, "CONVERTED files", convertedFiles); + printStat(csv, printOut, "PROCESSED files", stats.size()); } //// Static state management //// diff --git a/hipify-clang/src/Statistics.h b/hipify-clang/src/Statistics.h index 2b3dcf9e9c..9e7c94d7b9 100644 --- a/hipify-clang/src/Statistics.h +++ b/hipify-clang/src/Statistics.h @@ -157,9 +157,10 @@ class Statistics { StatCounter supported; StatCounter unsupported; std::string fileName; - std::set touchedLines = {}; - unsigned touchedBytes = 0; + std::set touchedLinesSet = {}; + unsigned touchedLines = 0; unsigned totalLines = 0; + unsigned touchedBytes = 0; int totalBytes = 0; chr::steady_clock::time_point startTime; chr::steady_clock::time_point completionTime; From da6fdc039766747898292b5d651e5bdbe39cb4c6 Mon Sep 17 00:00:00 2001 From: Evgeny Mankov Date: Mon, 17 Dec 2018 20:48:48 +0300 Subject: [PATCH 3/6] [HIPIFY] Temporary files in system temps introducing + Files are not being placed near original source before hipification anymore, system tmp is used for them now. + Additional include (-I) to absolute original source dir is added + Partially implements #812 + Tested on windows/linux, single/multiple inputs, with and without includes to user header files --- hipify-clang/src/main.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/hipify-clang/src/main.cpp b/hipify-clang/src/main.cpp index 951bffd5e8..508eb46269 100644 --- a/hipify-clang/src/main.cpp +++ b/hipify-clang/src/main.cpp @@ -37,6 +37,7 @@ THE SOFTWARE. #include "HipifyAction.h" #include "ArgParse.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/Path.h" #define DEBUG_TYPE "cuda2hip" @@ -95,19 +96,35 @@ int main(int argc, const char **argv) { llvm::errs() << "[HIPIFY] conflict: both -o and -inplace options are specified.\n"; return 1; } - std::string tmpFile = src + ".hipify-tmp"; // Create a copy of the file to work on. When we're done, we'll move this onto the // output (which may mean overwriting the input, if we're in-place). // Should we fail for some reason, we'll just leak this file and not corrupt the input. - copyFile(src, tmpFile); + SmallString<128> tmpFile; + int FD; + StringRef Extension = "hipified-tmp"; + std::error_code EC = sys::fs::createTemporaryFile("hipify-clang", Extension, FD, tmpFile); + if (EC) { + llvm::errs() << EC.message() << "\n"; + return 1; + } + SmallString<256> sourceAbsPath; + EC = llvm::sys::fs::real_path(src.c_str(), sourceAbsPath, true); + if (EC) { + llvm::errs() << EC.message() << "\n"; + return 1; + } + StringRef sourceDir = llvm::sys::path::parent_path(sourceAbsPath); + copyFile(src, tmpFile.c_str()); // Initialise the statistics counters for this file. Statistics::setActive(src); // RefactoringTool operates on the file in-place. Giving it the output path is no good, // because that'll break relative includes, and we don't want to overwrite the input file. // So what we do is operate on a copy, which we then move to the output. - ct::RefactoringTool Tool(OptionsParser.getCompilations(), tmpFile); - ct::Replacements& replacementsToUse = llcompat::getReplacements(Tool, tmpFile); + ct::RefactoringTool Tool(OptionsParser.getCompilations(), std::string(tmpFile.c_str())); + ct::Replacements& replacementsToUse = llcompat::getReplacements(Tool, tmpFile.c_str()); ReplacementsFrontendActionFactory actionFactory(&replacementsToUse); + std::string sInclude = "-I" + sourceDir.str(); + Tool.appendArgumentsAdjuster(ct::getInsertArgumentAdjuster(sInclude.c_str(), ct::ArgumentInsertPosition::BEGIN)); Tool.appendArgumentsAdjuster(ct::getInsertArgumentAdjuster("--cuda-host-only", ct::ArgumentInsertPosition::BEGIN)); // Ensure at least c++11 is used. Tool.appendArgumentsAdjuster(ct::getInsertArgumentAdjuster("-std=c++11", ct::ArgumentInsertPosition::BEGIN)); From fcaf9549988e03b1b765ba8f0116402df9c55894 Mon Sep 17 00:00:00 2001 From: emankov Date: Thu, 20 Dec 2018 18:47:57 +0300 Subject: [PATCH 4/6] [HIPIFY] Add the legal right comment to all the sources --- hipify-clang/src/ArgParse.cpp | 22 +++++++++++++++++++ hipify-clang/src/ArgParse.h | 22 +++++++++++++++++++ hipify-clang/src/CUDA2HIP.cpp | 22 +++++++++++++++++++ hipify-clang/src/CUDA2HIP.h | 22 +++++++++++++++++++ .../src/CUDA2HIP_BLAS_API_functions.cpp | 22 +++++++++++++++++++ hipify-clang/src/CUDA2HIP_BLAS_API_types.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_Complex_API_functions.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_Complex_API_types.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_DNN_API_functions.cpp | 22 +++++++++++++++++++ hipify-clang/src/CUDA2HIP_DNN_API_types.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_Driver_API_functions.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_Driver_API_types.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_FFT_API_functions.cpp | 22 +++++++++++++++++++ hipify-clang/src/CUDA2HIP_FFT_API_types.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_RAND_API_functions.cpp | 22 +++++++++++++++++++ hipify-clang/src/CUDA2HIP_RAND_API_types.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_Runtime_API_functions.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_Runtime_API_types.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_SPARSE_API_functions.cpp | 22 +++++++++++++++++++ .../src/CUDA2HIP_SPARSE_API_types.cpp | 22 +++++++++++++++++++ hipify-clang/src/HipifyAction.cpp | 22 +++++++++++++++++++ hipify-clang/src/HipifyAction.h | 22 +++++++++++++++++++ hipify-clang/src/LLVMCompat.cpp | 22 +++++++++++++++++++ hipify-clang/src/LLVMCompat.h | 22 +++++++++++++++++++ .../src/ReplacementsFrontendActionFactory.h | 22 +++++++++++++++++++ hipify-clang/src/Statistics.cpp | 22 +++++++++++++++++++ hipify-clang/src/Statistics.h | 22 +++++++++++++++++++ hipify-clang/src/StringUtils.cpp | 22 +++++++++++++++++++ hipify-clang/src/StringUtils.h | 22 +++++++++++++++++++ hipify-clang/src/main.cpp | 2 +- 30 files changed, 639 insertions(+), 1 deletion(-) diff --git a/hipify-clang/src/ArgParse.cpp b/hipify-clang/src/ArgParse.cpp index 54a432bed3..971d5d1ee0 100644 --- a/hipify-clang/src/ArgParse.cpp +++ b/hipify-clang/src/ArgParse.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "ArgParse.h" cl::OptionCategory ToolTemplateCategory("CUDA to HIP source translator options"); diff --git a/hipify-clang/src/ArgParse.h b/hipify-clang/src/ArgParse.h index e0a12657e2..d1e7e1a65a 100644 --- a/hipify-clang/src/ArgParse.h +++ b/hipify-clang/src/ArgParse.h @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #pragma once #include "clang/Tooling/CommonOptionsParser.h" diff --git a/hipify-clang/src/CUDA2HIP.cpp b/hipify-clang/src/CUDA2HIP.cpp index 4bb47531cb..0dcef4da35 100644 --- a/hipify-clang/src/CUDA2HIP.cpp +++ b/hipify-clang/src/CUDA2HIP.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Maps CUDA header names to HIP header names diff --git a/hipify-clang/src/CUDA2HIP.h b/hipify-clang/src/CUDA2HIP.h index 4222cf51d9..d95d4fea30 100644 --- a/hipify-clang/src/CUDA2HIP.h +++ b/hipify-clang/src/CUDA2HIP.h @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #pragma once #include "llvm/ADT/StringRef.h" diff --git a/hipify-clang/src/CUDA2HIP_BLAS_API_functions.cpp b/hipify-clang/src/CUDA2HIP_BLAS_API_functions.cpp index 3d8fe3547e..e6f5033038 100644 --- a/hipify-clang/src/CUDA2HIP_BLAS_API_functions.cpp +++ b/hipify-clang/src/CUDA2HIP_BLAS_API_functions.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all functions diff --git a/hipify-clang/src/CUDA2HIP_BLAS_API_types.cpp b/hipify-clang/src/CUDA2HIP_BLAS_API_types.cpp index 147d17d15a..26c42af0a6 100644 --- a/hipify-clang/src/CUDA2HIP_BLAS_API_types.cpp +++ b/hipify-clang/src/CUDA2HIP_BLAS_API_types.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all functions diff --git a/hipify-clang/src/CUDA2HIP_Complex_API_functions.cpp b/hipify-clang/src/CUDA2HIP_Complex_API_functions.cpp index a41871e720..af012e27cb 100644 --- a/hipify-clang/src/CUDA2HIP_Complex_API_functions.cpp +++ b/hipify-clang/src/CUDA2HIP_Complex_API_functions.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Maps the names of CUDA Complex API types to the corresponding HIP types diff --git a/hipify-clang/src/CUDA2HIP_Complex_API_types.cpp b/hipify-clang/src/CUDA2HIP_Complex_API_types.cpp index 3014208f3e..87016a21a0 100644 --- a/hipify-clang/src/CUDA2HIP_Complex_API_types.cpp +++ b/hipify-clang/src/CUDA2HIP_Complex_API_types.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Maps the names of CUDA Complex API types to the corresponding HIP types diff --git a/hipify-clang/src/CUDA2HIP_DNN_API_functions.cpp b/hipify-clang/src/CUDA2HIP_DNN_API_functions.cpp index aabd717483..3e58ec0418 100644 --- a/hipify-clang/src/CUDA2HIP_DNN_API_functions.cpp +++ b/hipify-clang/src/CUDA2HIP_DNN_API_functions.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all functions diff --git a/hipify-clang/src/CUDA2HIP_DNN_API_types.cpp b/hipify-clang/src/CUDA2HIP_DNN_API_types.cpp index 0e58f65458..f2e1dd6709 100644 --- a/hipify-clang/src/CUDA2HIP_DNN_API_types.cpp +++ b/hipify-clang/src/CUDA2HIP_DNN_API_types.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all functions diff --git a/hipify-clang/src/CUDA2HIP_Driver_API_functions.cpp b/hipify-clang/src/CUDA2HIP_Driver_API_functions.cpp index ce7c5a4968..f7990b2df4 100644 --- a/hipify-clang/src/CUDA2HIP_Driver_API_functions.cpp +++ b/hipify-clang/src/CUDA2HIP_Driver_API_functions.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all CUDA Driver API functions diff --git a/hipify-clang/src/CUDA2HIP_Driver_API_types.cpp b/hipify-clang/src/CUDA2HIP_Driver_API_types.cpp index 197b50b6fb..4737ddd8f2 100644 --- a/hipify-clang/src/CUDA2HIP_Driver_API_types.cpp +++ b/hipify-clang/src/CUDA2HIP_Driver_API_types.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Maps the names of CUDA DRIVER API types to the corresponding HIP types diff --git a/hipify-clang/src/CUDA2HIP_FFT_API_functions.cpp b/hipify-clang/src/CUDA2HIP_FFT_API_functions.cpp index 51d845656d..29e51f9b5c 100644 --- a/hipify-clang/src/CUDA2HIP_FFT_API_functions.cpp +++ b/hipify-clang/src/CUDA2HIP_FFT_API_functions.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all functions diff --git a/hipify-clang/src/CUDA2HIP_FFT_API_types.cpp b/hipify-clang/src/CUDA2HIP_FFT_API_types.cpp index 81ee4528fc..499afe7695 100644 --- a/hipify-clang/src/CUDA2HIP_FFT_API_types.cpp +++ b/hipify-clang/src/CUDA2HIP_FFT_API_types.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all functions diff --git a/hipify-clang/src/CUDA2HIP_RAND_API_functions.cpp b/hipify-clang/src/CUDA2HIP_RAND_API_functions.cpp index 78858cdcee..65985d6f5c 100644 --- a/hipify-clang/src/CUDA2HIP_RAND_API_functions.cpp +++ b/hipify-clang/src/CUDA2HIP_RAND_API_functions.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all functions diff --git a/hipify-clang/src/CUDA2HIP_RAND_API_types.cpp b/hipify-clang/src/CUDA2HIP_RAND_API_types.cpp index 3f9e631a5d..6bf3223cb0 100644 --- a/hipify-clang/src/CUDA2HIP_RAND_API_types.cpp +++ b/hipify-clang/src/CUDA2HIP_RAND_API_types.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all functions diff --git a/hipify-clang/src/CUDA2HIP_Runtime_API_functions.cpp b/hipify-clang/src/CUDA2HIP_Runtime_API_functions.cpp index dcc4903bad..694c1efcfe 100644 --- a/hipify-clang/src/CUDA2HIP_Runtime_API_functions.cpp +++ b/hipify-clang/src/CUDA2HIP_Runtime_API_functions.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Map of all CUDA Runtime API functions diff --git a/hipify-clang/src/CUDA2HIP_Runtime_API_types.cpp b/hipify-clang/src/CUDA2HIP_Runtime_API_types.cpp index 27347a05b4..3cc9345644 100644 --- a/hipify-clang/src/CUDA2HIP_Runtime_API_types.cpp +++ b/hipify-clang/src/CUDA2HIP_Runtime_API_types.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Maps the names of CUDA RUNTIME API types to the corresponding HIP types diff --git a/hipify-clang/src/CUDA2HIP_SPARSE_API_functions.cpp b/hipify-clang/src/CUDA2HIP_SPARSE_API_functions.cpp index 7cb736e4b9..d89e292852 100644 --- a/hipify-clang/src/CUDA2HIP_SPARSE_API_functions.cpp +++ b/hipify-clang/src/CUDA2HIP_SPARSE_API_functions.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Maps the names of CUDA SPARSE API types to the corresponding HIP types diff --git a/hipify-clang/src/CUDA2HIP_SPARSE_API_types.cpp b/hipify-clang/src/CUDA2HIP_SPARSE_API_types.cpp index 91a93f895f..02e5785c4c 100644 --- a/hipify-clang/src/CUDA2HIP_SPARSE_API_types.cpp +++ b/hipify-clang/src/CUDA2HIP_SPARSE_API_types.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "CUDA2HIP.h" // Maps the names of CUDA SPARSE API types to the corresponding HIP types diff --git a/hipify-clang/src/HipifyAction.cpp b/hipify-clang/src/HipifyAction.cpp index 31632715ac..a021fb3f74 100644 --- a/hipify-clang/src/HipifyAction.cpp +++ b/hipify-clang/src/HipifyAction.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "HipifyAction.h" #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CompilerInstance.h" diff --git a/hipify-clang/src/HipifyAction.h b/hipify-clang/src/HipifyAction.h index 99cb52e74c..cc7f3799ba 100644 --- a/hipify-clang/src/HipifyAction.h +++ b/hipify-clang/src/HipifyAction.h @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #pragma once #include "clang/Lex/PPCallbacks.h" diff --git a/hipify-clang/src/LLVMCompat.cpp b/hipify-clang/src/LLVMCompat.cpp index 611bb28cbe..f96bd86bb0 100644 --- a/hipify-clang/src/LLVMCompat.cpp +++ b/hipify-clang/src/LLVMCompat.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "LLVMCompat.h" namespace llcompat { diff --git a/hipify-clang/src/LLVMCompat.h b/hipify-clang/src/LLVMCompat.h index a43af857bf..4d6edcc9f8 100644 --- a/hipify-clang/src/LLVMCompat.h +++ b/hipify-clang/src/LLVMCompat.h @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #pragma once #include diff --git a/hipify-clang/src/ReplacementsFrontendActionFactory.h b/hipify-clang/src/ReplacementsFrontendActionFactory.h index 9e0decdeb9..5fa1274901 100644 --- a/hipify-clang/src/ReplacementsFrontendActionFactory.h +++ b/hipify-clang/src/ReplacementsFrontendActionFactory.h @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #pragma once #include "clang/Tooling/Tooling.h" diff --git a/hipify-clang/src/Statistics.cpp b/hipify-clang/src/Statistics.cpp index 7d86f8ae62..1943d82f98 100644 --- a/hipify-clang/src/Statistics.cpp +++ b/hipify-clang/src/Statistics.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "Statistics.h" #include #include diff --git a/hipify-clang/src/Statistics.h b/hipify-clang/src/Statistics.h index 9e7c94d7b9..4d51b71697 100644 --- a/hipify-clang/src/Statistics.h +++ b/hipify-clang/src/Statistics.h @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #pragma once #include diff --git a/hipify-clang/src/StringUtils.cpp b/hipify-clang/src/StringUtils.cpp index 3aaa4d7909..a8edf3661f 100644 --- a/hipify-clang/src/StringUtils.cpp +++ b/hipify-clang/src/StringUtils.cpp @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #include "StringUtils.h" llvm::StringRef unquoteStr(llvm::StringRef s) { diff --git a/hipify-clang/src/StringUtils.h b/hipify-clang/src/StringUtils.h index 8c5bf58da8..b18c864244 100644 --- a/hipify-clang/src/StringUtils.h +++ b/hipify-clang/src/StringUtils.h @@ -1,3 +1,25 @@ +/* +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. +*/ + #pragma once #include diff --git a/hipify-clang/src/main.cpp b/hipify-clang/src/main.cpp index 508eb46269..8d1e83bd4d 100644 --- a/hipify-clang/src/main.cpp +++ b/hipify-clang/src/main.cpp @@ -1,5 +1,5 @@ /* -Copyright (c) 2015-2018 Advanced Micro Devices, Inc. All rights reserved. +Copyright (c) 2015 - present Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 8bf3b42e7ea9dd0ad18dc0155e24a6b1f609095f Mon Sep 17 00:00:00 2001 From: emankov Date: Thu, 20 Dec 2018 20:43:50 +0300 Subject: [PATCH 5/6] [HIPIFY][fix][#824] Fix the bug with -inplace option + Do temp file copying instead of renaming + Replace all file routine functions with LLVM's + Do not output hipified file in case of errors --- hipify-clang/src/main.cpp | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/hipify-clang/src/main.cpp b/hipify-clang/src/main.cpp index 8d1e83bd4d..a165ec31e9 100644 --- a/hipify-clang/src/main.cpp +++ b/hipify-clang/src/main.cpp @@ -43,16 +43,6 @@ THE SOFTWARE. namespace ct = clang::tooling; -namespace { - -void copyFile(const std::string& src, const std::string& dst) { - std::ifstream source(src, std::ios::binary); - std::ofstream dest(dst, std::ios::binary); - dest << source.rdbuf(); -} - -} // anonymous namespace - int main(int argc, const char **argv) { llcompat::PrintStackTraceOnErrorSignal(); ct::CommonOptionsParser OptionsParser(argc, argv, ToolTemplateCategory, llvm::cl::OneOrMore); @@ -108,13 +98,17 @@ int main(int argc, const char **argv) { return 1; } SmallString<256> sourceAbsPath; - EC = llvm::sys::fs::real_path(src.c_str(), sourceAbsPath, true); + EC = sys::fs::real_path(src.c_str(), sourceAbsPath, true); + if (EC) { + llvm::errs() << EC.message() << "\n"; + return 1; + } + StringRef sourceDir = sys::path::parent_path(sourceAbsPath); + EC = sys::fs::copy_file(src, tmpFile); if (EC) { llvm::errs() << EC.message() << "\n"; return 1; } - StringRef sourceDir = llvm::sys::path::parent_path(sourceAbsPath); - copyFile(src, tmpFile.c_str()); // Initialise the statistics counters for this file. Statistics::setActive(src); // RefactoringTool operates on the file in-place. Giving it the output path is no good, @@ -132,18 +126,22 @@ int main(int argc, const char **argv) { Tool.appendArgumentsAdjuster(ct::getInsertArgumentAdjuster("-resource-dir=" HIPIFY_CLANG_RES)); #endif Tool.appendArgumentsAdjuster(ct::getClangSyntaxOnlyAdjuster()); + Statistics& currentStat = Statistics::current(); // Hipify _all_ the things! if (Tool.runAndSave(&actionFactory)) { - Statistics& currentStat = Statistics::current(); currentStat.hasErrors = true; LLVM_DEBUG(llvm::dbgs() << "Skipped some replacements.\n"); } - // Either move the tmpfile to the output, or remove it. - if (!NoOutput) { - rename(tmpFile.c_str(), dst.c_str()); - } else { - remove(tmpFile.c_str()); + // Copy the tmpfile to the output + if (!NoOutput && !currentStat.hasErrors) { + EC = sys::fs::copy_file(tmpFile, dst); + if (EC) { + llvm::errs() << EC.message() << "\n"; + return 1; + } } + // Remove the tmp file without error check + sys::fs::remove(tmpFile); Statistics::current().markCompletion(); Statistics::current().print(csv.get(), statPrint); dst.clear(); From cc59af5dbd153da756c9bfad1098c54ec6a61f24 Mon Sep 17 00:00:00 2001 From: emankov Date: Sat, 22 Dec 2018 00:47:19 +0300 Subject: [PATCH 6/6] [HIPIFY][#812] Finishing with temps 1. Option -temp-dir for temporary directory: + if not specified system temp is used; + creates the directory if the directory doesn't exist (only one level in a tree); + reports an error in case of a wrong directory specified, in case of necessity of creating a tree of subfolders, or in case of a filename specified. 2. Option -save-temps for preserving temporary files: + if specified temporary files are not being deleted from system temps and user temps as well. 3. Work with files in terms of calculated absolute paths by collapsing all '.' and '..' patterns, resolving symlinks and expanding '~' expression to the user's home directory: + to produce correct include paths; + to avoid possible errors on file routines. --- hipify-clang/src/ArgParse.cpp | 10 ++++ hipify-clang/src/ArgParse.h | 2 + hipify-clang/src/main.cpp | 101 ++++++++++++++++++++++------------ 3 files changed, 77 insertions(+), 36 deletions(-) diff --git a/hipify-clang/src/ArgParse.cpp b/hipify-clang/src/ArgParse.cpp index 971d5d1ee0..87aa8b6755 100644 --- a/hipify-clang/src/ArgParse.cpp +++ b/hipify-clang/src/ArgParse.cpp @@ -29,6 +29,16 @@ cl::opt OutputFilename("o", cl::value_desc("filename"), cl::cat(ToolTemplateCategory)); +cl::opt TemporaryDir("temp-dir", + cl::desc("Temporary direcory"), + cl::value_desc("directory"), + cl::cat(ToolTemplateCategory)); + +cl::opt SaveTemps("save-temps", + cl::desc("Save temporary files"), + cl::value_desc("save-temps"), + cl::cat(ToolTemplateCategory)); + cl::opt TranslateToRoc("roc", cl::desc("Translate to roc instead of hip where it is possible"), cl::value_desc("roc"), diff --git a/hipify-clang/src/ArgParse.h b/hipify-clang/src/ArgParse.h index d1e7e1a65a..efffe9e5de 100644 --- a/hipify-clang/src/ArgParse.h +++ b/hipify-clang/src/ArgParse.h @@ -30,7 +30,9 @@ namespace ct = clang::tooling; extern cl::OptionCategory ToolTemplateCategory; extern cl::opt OutputFilename; +extern cl::opt TemporaryDir; extern cl::opt Inplace; +extern cl::opt SaveTemps; extern cl::opt NoBackup; extern cl::opt NoOutput; extern cl::opt PrintStats; diff --git a/hipify-clang/src/main.cpp b/hipify-clang/src/main.cpp index a165ec31e9..5417dda783 100644 --- a/hipify-clang/src/main.cpp +++ b/hipify-clang/src/main.cpp @@ -19,11 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -/** - * @file Cuda2Hip.cpp - * - * This file is compiled and linked into clang based hipify tool. - */ #include #include @@ -47,25 +42,54 @@ int main(int argc, const char **argv) { llcompat::PrintStackTraceOnErrorSignal(); ct::CommonOptionsParser OptionsParser(argc, argv, ToolTemplateCategory, llvm::cl::OneOrMore); std::vector fileSources = OptionsParser.getSourcePathList(); - std::string dst = OutputFilename; - if (!dst.empty() && fileSources.size() > 1) { - llvm::errs() << "[HIPIFY] conflict: -o and multiple source files are specified.\n"; - return 1; - } - if (NoOutput) { + std::string dst = OutputFilename, sHipify = "[HIPIFY] ", sConflict = "conflict: ", sError = "error: "; + if (!dst.empty()) { + if (fileSources.size() > 1) { + llvm::errs() << sHipify << sConflict << "-o and multiple source files are specified.\n"; + return 1; + } if (Inplace) { - llvm::errs() << "[HIPIFY] conflict: both -no-output and -inplace options are specified.\n"; + llvm::errs() << sHipify << sConflict << "both -o and -inplace options are specified.\n"; return 1; } - if (!dst.empty()) { - llvm::errs() << "[HIPIFY] conflict: both -no-output and -o options are specified.\n"; + if (NoOutput) { + llvm::errs() << sHipify << sConflict << "both -no-output and -o options are specified.\n"; return 1; } } + if (NoOutput && Inplace) { + llvm::errs() << sHipify << sConflict << "both -no-output and -inplace options are specified.\n"; + return 1; + } if (Examine) { NoOutput = PrintStats = true; } int Result = 0; + std::error_code EC; + SmallString<128> tmpFile; + SmallString<256> sourceAbsPath, tmpDirAbsPath; + StringRef sourceFileName, sourceDir, ext = "hip"; + std::string sTmpDirAbsParh, sTmpFileName; + if (!TemporaryDir.empty()) { + EC = sys::fs::real_path(TemporaryDir, tmpDirAbsPath, true); + if (!EC && sys::fs::is_regular_file(tmpDirAbsPath)) { + llvm::errs() << "\n" << sHipify << sError << TemporaryDir << " is not a directory\n"; + return 1; + } + if (EC) { + EC = sys::fs::create_directory(TemporaryDir); + if (EC) { + llvm::errs() << "\n" << sHipify << sError << EC.message() << ": temporary directory: " << TemporaryDir << "\n"; + return 1; + } + EC = sys::fs::real_path(TemporaryDir, tmpDirAbsPath, true); + if (EC) { + llvm::errs() << "\n" << sHipify << sError << EC.message() << ": temporary directory: " << TemporaryDir << "\n"; + return 1; + } + } + sTmpDirAbsParh = tmpDirAbsPath.c_str(); + } // Arguments for the Statistics print routines. std::unique_ptr csv = nullptr; llvm::raw_ostream* statPrint = nullptr; @@ -75,39 +99,41 @@ int main(int argc, const char **argv) { if (PrintStats) { statPrint = &llvm::errs(); } + int FD; for (const auto & src : fileSources) { if (dst.empty()) { if (Inplace) { dst = src; } else { - dst = src + ".hip"; + dst = src + "." + ext.str(); } - } else if (Inplace) { - llvm::errs() << "[HIPIFY] conflict: both -o and -inplace options are specified.\n"; - return 1; } // Create a copy of the file to work on. When we're done, we'll move this onto the // output (which may mean overwriting the input, if we're in-place). // Should we fail for some reason, we'll just leak this file and not corrupt the input. - SmallString<128> tmpFile; - int FD; - StringRef Extension = "hipified-tmp"; - std::error_code EC = sys::fs::createTemporaryFile("hipify-clang", Extension, FD, tmpFile); + EC = sys::fs::real_path(src, sourceAbsPath, true); if (EC) { - llvm::errs() << EC.message() << "\n"; - return 1; + llvm::errs() << "\n" << sHipify << sError << EC.message() << ": " << src << "\n"; + Result = 1; + continue; } - SmallString<256> sourceAbsPath; - EC = sys::fs::real_path(src.c_str(), sourceAbsPath, true); - if (EC) { - llvm::errs() << EC.message() << "\n"; - return 1; + if (TemporaryDir.empty()) { + EC = sys::fs::createTemporaryFile(src, ext, FD, tmpFile); + if (EC) { + llvm::errs() << "\n" << sHipify << sError << EC.message() << ": " << tmpFile << "\n"; + Result = 1; + continue; + } + } else { + sourceFileName = sys::path::filename(sourceAbsPath); + sTmpFileName = sTmpDirAbsParh + "/" + sourceFileName.str() + "." + ext.str(); + tmpFile = sTmpFileName; } - StringRef sourceDir = sys::path::parent_path(sourceAbsPath); EC = sys::fs::copy_file(src, tmpFile); if (EC) { - llvm::errs() << EC.message() << "\n"; - return 1; + llvm::errs() << "\n" << sHipify << sError << EC.message() << ": while copying " << src << " to " << tmpFile << "\n"; + Result = 1; + continue; } // Initialise the statistics counters for this file. Statistics::setActive(src); @@ -117,7 +143,7 @@ int main(int argc, const char **argv) { ct::RefactoringTool Tool(OptionsParser.getCompilations(), std::string(tmpFile.c_str())); ct::Replacements& replacementsToUse = llcompat::getReplacements(Tool, tmpFile.c_str()); ReplacementsFrontendActionFactory actionFactory(&replacementsToUse); - std::string sInclude = "-I" + sourceDir.str(); + std::string sInclude = "-I" + sys::path::parent_path(sourceAbsPath).str(); Tool.appendArgumentsAdjuster(ct::getInsertArgumentAdjuster(sInclude.c_str(), ct::ArgumentInsertPosition::BEGIN)); Tool.appendArgumentsAdjuster(ct::getInsertArgumentAdjuster("--cuda-host-only", ct::ArgumentInsertPosition::BEGIN)); // Ensure at least c++11 is used. @@ -136,12 +162,15 @@ int main(int argc, const char **argv) { if (!NoOutput && !currentStat.hasErrors) { EC = sys::fs::copy_file(tmpFile, dst); if (EC) { - llvm::errs() << EC.message() << "\n"; - return 1; + llvm::errs() << "\n" << sHipify << sError << EC.message() << ": while copying " << tmpFile << " to " << dst << "\n"; + Result = 1; + continue; } } // Remove the tmp file without error check - sys::fs::remove(tmpFile); + if (!SaveTemps) { + sys::fs::remove(tmpFile); + } Statistics::current().markCompletion(); Statistics::current().print(csv.get(), statPrint); dst.clear();