diff --git a/src/LocalHeader.cpp b/src/LocalHeader.cpp index 2d5e97545..06c0d0801 100644 --- a/src/LocalHeader.cpp +++ b/src/LocalHeader.cpp @@ -1,167 +1,281 @@ +/* +Copyright (c) 2026 - 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 "LocalHeader.h" +#include "LLVMCompat.h" -#include -#include -#include +#include +#include #include -#include -#include "llvm/Support/FileSystem.h" +#include "clang/Basic/SourceManager.h" +#include "clang/Frontend/CompilerInstance.h" +#include "clang/Frontend/FrontendActions.h" +#include "clang/Lex/PPCallbacks.h" +#include "clang/Lex/Preprocessor.h" +#include "clang/Tooling/CompilationDatabase.h" +#include "clang/Tooling/Tooling.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/Path.h" -#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" -#include "LLVMCompat.h" - using namespace clang; using namespace clang::tooling; using namespace llvm; using namespace std; -static std::string normalizeSmallStringPath(SmallString<256> &p) { - llvm::sys::path::remove_dots(p, true); - - SmallString<256> realBuf; - std::error_code ec = llvm::sys::fs::real_path(p, realBuf); - if (!ec) { - return std::string(realBuf.str()); - } +namespace { - return std::string(p.str()); +std::string getFilePathForID(const clang::SourceManager &SM, + clang::FileID FID) { + const clang::FileEntry *FE = SM.getFileEntryForID(FID); + if (!FE) + return std::string(); + StringRef RealPath = FE->tryGetRealPathName(); + if (!RealPath.empty()) + return RealPath.str(); + return SM.getFilename(SM.getLocForStartOfFile(FID)).str(); } -static bool pathExists(const std::string &p) { - SmallString<256> in(p.begin(), p.end()); +// Records every `#include` of a translation unit, except those issued from a +// system header or from the command line. +class IncludeCollectorCallbacks : public clang::PPCallbacks { + const clang::SourceManager &SM; + std::vector &Entries; - SmallString<256> realBuf; - std::error_code ec = llvm::sys::fs::real_path(in, realBuf); - if (!ec) return true; +public: + IncludeCollectorCallbacks(const clang::SourceManager &SM, + std::vector &Entries) + : SM(SM), Entries(Entries) {} - SmallString<256> norm = in; - llvm::sys::path::remove_dots(norm, true); - return llvm::sys::fs::exists(norm); -} + void InclusionDirective(clang::SourceLocation HashLoc, const clang::Token &, + StringRef FileName, bool IsAngled, + clang::CharSourceRange, +#if LLVM_VERSION_MAJOR < 15 + const clang::FileEntry *File, +#elif LLVM_VERSION_MAJOR == 15 + Optional File, +#else + clang::OptionalFileEntryRef File, +#endif + StringRef, StringRef, +#if LLVM_VERSION_MAJOR < 19 + const clang::Module * +#else + const clang::Module *, bool +#endif +#if LLVM_VERSION_MAJOR > 6 + , + clang::SrcMgr::CharacteristicKind FileType +#endif + ) override { + const clang::FileID IncluderID = SM.getFileID(HashLoc); + std::string IncluderPath = getFilePathForID(SM, IncluderID); + if (IncluderPath.empty() || SM.isInSystemHeader(HashLoc)) + return; -namespace { - static const std::regex LocalIncludeRe( - R"(^\s*#\s*include\s*\"([^\"\n]+)\"\s*(?://.*)?$)", std::regex::ECMAScript); + IncludeEntry Entry; + Entry.fileName = FileName.str(); + Entry.isAngled = IsAngled; + Entry.includerPath = std::move(IncluderPath); + Entry.isFromMainFile = IncluderID == SM.getMainFileID(); +#if LLVM_VERSION_MAJOR > 6 + Entry.isSystem = FileType != clang::SrcMgr::C_User; +#else + Entry.isSystem = IsAngled; +#endif + + if (File) { +#if LLVM_VERSION_MAJOR < 15 + Entry.resolvedPath = File->tryGetRealPathName().str(); + if (Entry.resolvedPath.empty()) + Entry.resolvedPath = File->getName().str(); +#else + Entry.resolvedPath = File->getFileEntry().tryGetRealPathName().str(); + if (Entry.resolvedPath.empty()) + Entry.resolvedPath = File->getName().str(); +#endif + } + + Entries.push_back(std::move(Entry)); + } +}; + +// PreprocessOnlyAction supplies the lexing loop and IgnorePragmas(). +class IncludeCollectorAction : public clang::PreprocessOnlyAction { + std::vector &Entries; - bool readFile(const std::string &path, std::string &out) { - auto MBOrErr = llvm::MemoryBuffer::getFile(path); - if (!MBOrErr) return false; - out = MBOrErr->get()->getBuffer().str(); +public: + explicit IncludeCollectorAction(std::vector &Entries) + : Entries(Entries) {} + +protected: +#if LLVM_VERSION_MAJOR < 5 + bool BeginSourceFileAction(clang::CompilerInstance &CI, StringRef) override { +#else + bool BeginSourceFileAction(clang::CompilerInstance &CI) override { +#endif + CI.getPreprocessor().addPPCallbacks( + std::make_unique(CI.getSourceManager(), + Entries)); return true; } +}; - bool resolveLocalIncludeInternal(const std::string &mainSourceAbsPath, - const std::string &includeTok, - std::string &outAbs) { - SmallString<256> base(mainSourceAbsPath); - sys::path::remove_filename(base); - SmallString<256> candidate(base); - sys::path::append(candidate, includeTok); - sys::path::remove_dots(candidate, true); - if (pathExists(std::string(candidate.str()))) { - outAbs = normalizeSmallStringPath(candidate); - return true; - } - return false; +class IncludeCollectorActionFactory : public FrontendActionFactory { + std::vector &Entries; + +public: + explicit IncludeCollectorActionFactory(std::vector &entries) + : Entries(entries) {} + +#if LLVM_VERSION_MAJOR >= 10 + std::unique_ptr create() override { + return std::make_unique(Entries); + } +#else + clang::FrontendAction *create() override { + return new IncludeCollectorAction(Entries); } -} +#endif +}; -bool resolveLocalInclude(const std::string &mainSourceAbsPath, - const std::string &includeToken, - std::string &outAbsPath) { - return resolveLocalIncludeInternal(mainSourceAbsPath, includeToken, outAbsPath); +// Returns entries.size() when headerPath was never included. +size_t findFirstInclusion(const std::vector &entries, + StringRef headerPath) { + size_t i = 0; + for (; i < entries.size(); ++i) + if (entries[i].resolvedPath == headerPath) + break; + return i; } -bool collectLocalQuotedIncludes(const std::string &mainSourceAbsPath, - std::vector &outHeaders) { - std::string content; - if (!readFile(mainSourceAbsPath, content)) { - errs() << "\n" << sHipify << sError << "Cannot read source file: " << mainSourceAbsPath << "\n"; - return false; +// Files to `-include` in front of headerPath so that a header which is not +// self-contained still sees what its ancestors included before it. +std::vector +buildIncludeContext(const std::vector &entries, + StringRef headerPath) { + const size_t pos = findFirstInclusion(entries, headerPath); + if (pos == entries.size()) + return std::vector(); + + StringSet<> ancestors; + std::string file = entries[pos].includerPath; + while (!file.empty() && ancestors.insert(file).second) { + const size_t idx = findFirstInclusion(entries, file); + file = idx == entries.size() ? std::string() : entries[idx].includerPath; } - std::set uniq; - std::smatch m; - std::istringstream iss(content); - std::string line; - while (std::getline(iss, line)) { - if (std::regex_match(line, m, LocalIncludeRe)) { - std::string rel = m[1].str(); - std::string abs; - if (resolveLocalIncludeInternal(mainSourceAbsPath, rel, abs)){ - uniq.insert(abs); - } else { - errs() << sHipify << sWarning - << "Missing local header referenced: \"" << rel - << "\" in " << mainSourceAbsPath << "\n"; - } - } + std::vector context; + StringSet<> seen; + for (size_t i = 0; i < pos; ++i) { + const IncludeEntry &e = entries[i]; + // An ancestor would re-include headerPath, whose guard then empties the + // copy being hipified. + if (!ancestors.count(e.includerPath) || ancestors.count(e.resolvedPath)) + continue; + // System headers are injected as spelled, to be found via the search paths. + std::string arg = e.isSystem ? e.fileName : e.resolvedPath; + if (arg.empty() || !seen.insert(arg).second) + continue; + context.push_back(std::move(arg)); } - outHeaders.assign(uniq.begin(), uniq.end()); - return true; + return context; } -bool hipifyLocalHeaders(const std::string &mainSourceAbsPath, - const ct::CompilationDatabase *compDB, - ct::CommonOptionsParser *OptionsParserPtr, - const char *hipify_exe, - bool recursive) { +} // namespace - std::vector initial; - if (!collectLocalQuotedIncludes(mainSourceAbsPath, initial)) { +bool collectIncludeTree(const std::string &srcPath, + const ct::CompilationDatabase *compDB, + ct::CommonOptionsParser *OptionsParserPtr, + const char *hipify_exe, + std::vector &outEntries) { + outEntries.clear(); + + ct::RefactoringTool Tool( + compDB ? *compDB : OptionsParserPtr->getCompilations(), {srcPath}); + + if (!appendArgumentsAdjusters(Tool, srcPath, hipify_exe)) { return false; } - - if (initial.empty()) { - outs() << sHipify << "No local headers detected in " << mainSourceAbsPath << "\n"; - return true; - } - std::vector work(initial.begin(), initial.end()); - std::set processed; + IncludeCollectorActionFactory factory(outEntries); + return Tool.run(&factory) == 0; +} - while (!work.empty()) { - std::string hdr = work.back(); - work.pop_back(); - if (processed.count(hdr)) { - errs() << sHipify << sWarning << "Duplicate local header reference ignored: " << hdr << "\n"; - continue; - } - processed.insert(hdr); +bool hipifyLocalHeaders(const std::string &mainSourceAbsPath, + const ct::CompilationDatabase *compDB, + ct::CommonOptionsParser *OptionsParserPtr, + const char *hipify_exe, bool recursive) { + std::vector entries; + if (!collectIncludeTree(mainSourceAbsPath, compDB, OptionsParserPtr, + hipify_exe, entries)) { + errs() << "\n" + << sHipify << sError + << "Failed to collect includes from: " << mainSourceAbsPath << "\n"; + return false; + } - std::string original; - if (!readFile(hdr, original)) { - errs() << sHipify << sError << "Cannot read header: " << hdr << "\n"; + // The single run already walked the whole tree; recursion is just the + // unfiltered result. Include guards make each path appear at most once. + std::vector headers; + StringSet<> seen; + for (const IncludeEntry &e : entries) { + if (e.isAngled || e.isSystem || e.resolvedPath.empty()) continue; - } + if (!recursive && !e.isFromMainFile) + continue; + if (seen.insert(e.resolvedPath).second) + headers.push_back(e.resolvedPath); + } - std::string hipOut = hdr + ".hip"; - bool ok = hipifySingleSource(hdr, hipOut, compDB, OptionsParserPtr, - hipify_exe, mainSourceAbsPath, false); + if (headers.empty()) { + outs() << "\n" << sHipify << "No local headers detected in " + << sys::path::filename(mainSourceAbsPath) << "\n"; + return true; + } - if (!ok) { - errs() << sHipify << sError << "Hipify failed for header: " << hdr << "\n"; - return false; - } + outs() << "\n" << sHipify << "Local headers found: " << headers.size() + << " in " << sys::path::filename(mainSourceAbsPath) << "\n"; + for (size_t i = 0; i < headers.size(); ++i) { + outs() << (i + 1) << "/" << headers.size() << ": " + << sys::path::filename(headers[i]) << "\n"; + } - if (recursive) { - std::smatch m; - std::istringstream iss(original); - std::string line; - while (std::getline(iss, line)) { - if (std::regex_match(line, m, LocalIncludeRe)) { - std::string rel = m[1].str(); - std::string abs; - if (resolveLocalIncludeInternal(hdr, rel, abs) && - !processed.count(abs)) - work.push_back(abs); - } - } + for (size_t i = 0; i < headers.size(); ++i) { + const std::string &hdr = headers[i]; + std::string hipOut = hdr + ".hip"; + if (!hipifySingleSource(hdr, hipOut, compDB, OptionsParserPtr, hipify_exe, + mainSourceAbsPath, false, + buildIncludeContext(entries, hdr))) { + errs() << "\n" << sHipify << sError << "Hipify failed for header [" + << (i + 1) << "/" << headers.size() << "]: " + << sys::path::filename(hdr) << "\n"; + return false; } + outs() << sHipify << "Successfully hipified header file" << "\n"; } + outs() << "\n" << sHipify << "Local header hipification complete: " + << headers.size() << " header(s) processed.\n"; return true; } diff --git a/src/LocalHeader.h b/src/LocalHeader.h index 31763c697..09ac6f6f4 100644 --- a/src/LocalHeader.h +++ b/src/LocalHeader.h @@ -1,18 +1,56 @@ +/* +Copyright (c) 2026 - 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" +#include "clang/Tooling/Refactoring.h" #include #include -#include "clang/Tooling/CommonOptionsParser.h" namespace ct = clang::tooling; +// A single `#include` directive, recorded in preprocessing order. +struct IncludeEntry { + std::string fileName; + std::string resolvedPath; + std::string includerPath; + bool isAngled = false; + bool isSystem = false; + bool isFromMainFile = false; +}; + +extern bool appendArgumentsAdjusters(ct::RefactoringTool &Tool, + const std::string &sSourceAbsPath, + const char *hipify_exe); + extern bool hipifySingleSource(const std::string &srcPath, const std::string &dstPath, const ct::CompilationDatabase *compDB, ct::CommonOptionsParser *OptionsParserPtr, const char *hipify_exe_path, const std::string &mainContextPath, - bool preserveTemp); + bool preserveTemp, + const std::vector &additionalIncludes = {}); bool hipifyLocalHeaders(const std::string &srcPath, const ct::CompilationDatabase *compDB, @@ -20,9 +58,9 @@ bool hipifyLocalHeaders(const std::string &srcPath, const char *hipify_exe, bool recursive = false); -bool resolveLocalInclude(const std::string &mainSourceAbsPath, - const std::string &includeToken, - std::string &outAbsPath); - -bool collectLocalQuotedIncludes(const std::string &mainSourceAbsPath, - std::vector &outHeaders); +// Preprocesses srcPath and records its whole include tree in outEntries. +bool collectIncludeTree(const std::string &srcPath, + const ct::CompilationDatabase *compDB, + ct::CommonOptionsParser *OptionsParserPtr, + const char *hipify_exe, + std::vector &outEntries); diff --git a/src/main.cpp b/src/main.cpp index 0675bdfce..2742810b0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,6 +21,7 @@ THE SOFTWARE. */ #include +#include #include "CUDA2HIP.h" #include "CUDA2HIP_Scripting.h" #include "LLVMCompat.h" @@ -241,7 +242,8 @@ bool hipifySingleSource(const std::string &srcPath, ct::CommonOptionsParser *OptionsParserPtr, const char *hipify_exe_path, const std::string &mainContextPath, - bool preserveTemp) { + bool preserveTemp, + const std::vector &additionalIncludes) { std::error_code EC; SmallString<128> tmpFile; StringRef srcFileName = sys::path::filename(srcPath); @@ -276,6 +278,27 @@ bool hipifySingleSource(const std::string &srcPath, return false; } + // The copy is preprocessed from a temporary directory, so includes quoted + // relative to the original one need an explicit search path. + StringRef srcDir = sys::path::parent_path(srcPath); + if (!srcDir.empty()) { + std::string sSrcDir = "-I" + srcDir.str(); + Tool.appendArgumentsAdjuster(ct::getInsertArgumentAdjuster( + sSrcDir.c_str(), ct::ArgumentInsertPosition::BEGIN)); + } + + // Appended at the end to follow the implicit CUDA headers, inserted at the + // beginning: a header may use CUDA declarations without including any. + if (!additionalIncludes.empty()) { + ct::CommandLineArguments includeArgs; + for (const std::string &include : additionalIncludes) { + includeArgs.push_back("-include"); + includeArgs.push_back(include); + } + Tool.appendArgumentsAdjuster(ct::getInsertArgumentAdjuster( + includeArgs, ct::ArgumentInsertPosition::END)); + } + // Hipify _all_ the things! if (Tool.runAndSave(&actionFactory)) { llvm::errs() << "\n" << sHipify << sError @@ -516,26 +539,25 @@ int main(int argc, const char **argv) { } // Initialise the statistics counters for this file. Statistics::setActive(src); - // Checks the local headers if --local-headers/--local-header-recursive specified. if (OptLocalHeaders || OptLocalHeadersRecursive) { - if (!hipifyLocalHeaders(sSourceAbsPath, - compilationDatabase.get(), - &OptionsParser, - argv[0], + if (!hipifyLocalHeaders(sSourceAbsPath, compilationDatabase.get(), + &OptionsParser, argv[0], OptLocalHeadersRecursive)) { + llvm::errs() << "\n" << sHipify << sError + << "Local header hipification failed for: " + << sys::path::filename(sSourceAbsPath) << "\n"; Statistics::current().hasErrors = true; - LLVM_DEBUG(llvm::dbgs() << "Local header hipification failed for: " << sSourceAbsPath << "\n"); Result = 1; } } - + std::string outputPath = NoOutput ? "" : dst; if (!hipifySingleSource(src, outputPath, compilationDatabase.get(), &OptionsParser, argv[0], sSourceAbsPath, - false)) { + false, {})) { Statistics::current().hasErrors = true; Result = 1; LLVM_DEBUG(llvm::dbgs() << "Hipification failed for: " << src << "\n"); diff --git a/tests/lit.cfg b/tests/lit.cfg index 96f17b461..ebf164199 100644 --- a/tests/lit.cfg +++ b/tests/lit.cfg @@ -19,6 +19,13 @@ config.excludes.append('inc.h') config.excludes.append('inet.h') config.excludes.append('types.h') config.excludes.append('socket.h') +config.excludes.append('transitive_parent.h') +config.excludes.append('transitive_child.h') +config.excludes.append('diamond_left.h') +config.excludes.append('diamond_right.h') +config.excludes.append('diamond_shared.h') +# Not self-contained by design; only hipifiable through non_self_contained.cu. +config.excludes.append('nsc_dependent.h') delimiter = "==============================================================="; print(delimiter) diff --git a/tests/unit_tests/headers/local_headers/angle_bracket.cu b/tests/unit_tests/headers/local_headers/angle_bracket.cu index e9628f061..040d9367d 100644 --- a/tests/unit_tests/headers/local_headers/angle_bracket.cu +++ b/tests/unit_tests/headers/local_headers/angle_bracket.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/block_comment_include.h b/tests/unit_tests/headers/local_headers/block_comment_include.h new file mode 100644 index 000000000..ba14e41bd --- /dev/null +++ b/tests/unit_tests/headers/local_headers/block_comment_include.h @@ -0,0 +1,15 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef BLOCK_COMMENT_INCLUDE_H +#define BLOCK_COMMENT_INCLUDE_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline void block_comment_sync() { + // CHECK: hipDeviceSynchronize(); + cudaDeviceSynchronize(); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/common.h b/tests/unit_tests/headers/local_headers/common.h index cb5844475..3903ec5c7 100644 --- a/tests/unit_tests/headers/local_headers/common.h +++ b/tests/unit_tests/headers/local_headers/common.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args #ifndef COMMON_H #define COMMON_H diff --git a/tests/unit_tests/headers/local_headers/cyclic_header.cu b/tests/unit_tests/headers/local_headers/cyclic_header.cu index 3d3e6c692..059d1651a 100644 --- a/tests/unit_tests/headers/local_headers/cyclic_header.cu +++ b/tests/unit_tests/headers/local_headers/cyclic_header.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers-recursive %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers-recursive %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/diamond_dep.cu b/tests/unit_tests/headers/local_headers/diamond_dep.cu new file mode 100644 index 000000000..83e7ad02e --- /dev/null +++ b/tests/unit_tests/headers/local_headers/diamond_dep.cu @@ -0,0 +1,13 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers-recursive %clang_args + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "diamond_left.h" +// CHECK: #include "diamond_right.h" +#include +#include "diamond_left.h" +#include "diamond_right.h" + +int main() { + return 0; +} diff --git a/tests/unit_tests/headers/local_headers/diamond_left.h b/tests/unit_tests/headers/local_headers/diamond_left.h new file mode 100644 index 000000000..919e6c8ba --- /dev/null +++ b/tests/unit_tests/headers/local_headers/diamond_left.h @@ -0,0 +1,11 @@ +#ifndef DIAMOND_LEFT_H +#define DIAMOND_LEFT_H + +#include "diamond_shared.h" + +inline void left_sync() { + // CHECK: hipDeviceSynchronize(); + cudaDeviceSynchronize(); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/diamond_right.h b/tests/unit_tests/headers/local_headers/diamond_right.h new file mode 100644 index 000000000..0762747d5 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/diamond_right.h @@ -0,0 +1,11 @@ +#ifndef DIAMOND_RIGHT_H +#define DIAMOND_RIGHT_H + +#include "diamond_shared.h" + +inline void right_free(void *p) { + // CHECK: hipFree(p); + cudaFree(p); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/diamond_shared.h b/tests/unit_tests/headers/local_headers/diamond_shared.h new file mode 100644 index 000000000..ffb326f9e --- /dev/null +++ b/tests/unit_tests/headers/local_headers/diamond_shared.h @@ -0,0 +1,9 @@ +#ifndef DIAMOND_SHARED_H +#define DIAMOND_SHARED_H + +inline void shared_alloc(void **p, size_t size) { + // CHECK: hipMalloc(p, size); + cudaMalloc(p, size); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/duplicate.h b/tests/unit_tests/headers/local_headers/duplicate.h index 030c7dbba..8ef0d1ea2 100644 --- a/tests/unit_tests/headers/local_headers/duplicate.h +++ b/tests/unit_tests/headers/local_headers/duplicate.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #ifndef DUP_H #define DUP_H diff --git a/tests/unit_tests/headers/local_headers/duplicate_header.cu b/tests/unit_tests/headers/local_headers/duplicate_header.cu index d07f7f74d..d87270043 100644 --- a/tests/unit_tests/headers/local_headers/duplicate_header.cu +++ b/tests/unit_tests/headers/local_headers/duplicate_header.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK: #include "duplicate.h" diff --git a/tests/unit_tests/headers/local_headers/injection_has_cmath.h b/tests/unit_tests/headers/local_headers/injection_has_cmath.h new file mode 100644 index 000000000..fcc8ae96e --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_has_cmath.h @@ -0,0 +1,16 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef INJECTION_HAS_CMATH_H +#define INJECTION_HAS_CMATH_H + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include +#include +#include + +inline float compute_value(float x) { + return sqrtf(x) + 1.0f; +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/injection_helper.h b/tests/unit_tests/headers/local_headers/injection_helper.h new file mode 100644 index 000000000..150920889 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_helper.h @@ -0,0 +1,22 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef INJECTION_HELPER_H +#define INJECTION_HELPER_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline __device__ float3 add_vectors(float3 a, float3 b) { + return make_float3(0.0f, 0.0f, 0.0f); +} + +inline __device__ void accumulate(float3* sum, float3 val) { + return; +} + +inline __device__ float3 scale_and_diff(float3 a, float3 b, float s) { + return make_float3(0.0f, 0.0f, 0.0f); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/injection_inner.h b/tests/unit_tests/headers/local_headers/injection_inner.h new file mode 100644 index 000000000..0c213c7fe --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_inner.h @@ -0,0 +1,14 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef INJECTION_INNER_H +#define INJECTION_INNER_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline __device__ void inner_add(float3* data, int idx) { + return; +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/injection_multi.cu b/tests/unit_tests/headers/local_headers/injection_multi.cu new file mode 100644 index 000000000..0283d1047 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_multi.cu @@ -0,0 +1,22 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include +// CHECK: #include "vector_math.h" +// CHECK: #include "injection_helper.h" +// CHECK: #include "injection_uses_cmath.h" +#include +#include +#include "vector_math.h" +#include "injection_helper.h" +#include "injection_uses_cmath.h" + +__global__ void multiKernel(float3* data, float* vals) { + int idx = threadIdx.x; + dummy_vector_op(); + add_vectors(data[idx], data[idx + 1]); + vals[idx] = compute_sqrt(vals[idx]); +} + +int main() { return 0; } diff --git a/tests/unit_tests/headers/local_headers/injection_no_duplicate.cu b/tests/unit_tests/headers/local_headers/injection_no_duplicate.cu new file mode 100644 index 000000000..05747193d --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_no_duplicate.cu @@ -0,0 +1,14 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include +// CHECK: #include "injection_has_cmath.h" +#include +#include +#include "injection_has_cmath.h" + +int main() { + float x = compute_value(4.0f); + return (int)x; +} diff --git a/tests/unit_tests/headers/local_headers/injection_outer.h b/tests/unit_tests/headers/local_headers/injection_outer.h new file mode 100644 index 000000000..e742b9699 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_outer.h @@ -0,0 +1,16 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef INJECTION_OUTER_H +#define INJECTION_OUTER_H + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "injection_inner.h" +#include +#include "injection_inner.h" + +inline __device__ void outer_process(float3* data, int idx) { + inner_add(data, idx); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/injection_pragma_header.h b/tests/unit_tests/headers/local_headers/injection_pragma_header.h new file mode 100644 index 000000000..86f68bc53 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_pragma_header.h @@ -0,0 +1,11 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#pragma once + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline __device__ void pragma_add(float3* data, int idx) { + return; +} diff --git a/tests/unit_tests/headers/local_headers/injection_pragma_once.cu b/tests/unit_tests/headers/local_headers/injection_pragma_once.cu new file mode 100644 index 000000000..4887bd592 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_pragma_once.cu @@ -0,0 +1,17 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "vector_math.h" +// CHECK: #include "injection_pragma_header.h" +#include +#include "vector_math.h" +#include "injection_pragma_header.h" + +__global__ void pragmaKernel(float3* data) { + int idx = threadIdx.x; + dummy_vector_op(); + pragma_add(data, idx); +} + +int main() { return 0; } diff --git a/tests/unit_tests/headers/local_headers/injection_recursive.cu b/tests/unit_tests/headers/local_headers/injection_recursive.cu new file mode 100644 index 000000000..e943933b5 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_recursive.cu @@ -0,0 +1,17 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers-recursive %clang_args + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "vector_math.h" +// CHECK: #include "injection_outer.h" +#include +#include "vector_math.h" +#include "injection_outer.h" + +__global__ void recursiveKernel(float3* data) { + int idx = threadIdx.x; + dummy_vector_op(); + outer_process(data, idx); +} + +int main() { return 0; } diff --git a/tests/unit_tests/headers/local_headers/injection_test.cu b/tests/unit_tests/headers/local_headers/injection_test.cu new file mode 100644 index 000000000..8bcc93801 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_test.cu @@ -0,0 +1,17 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "vector_math.h" +// CHECK: #include "injection_helper.h" +#include +#include "vector_math.h" +#include "injection_helper.h" + +__global__ void testKernel(float3* data) { + int idx = threadIdx.x; + dummy_vector_op(); + add_vectors(data[idx], data[idx + 1]); +} + +int main() { return 0; } diff --git a/tests/unit_tests/headers/local_headers/injection_uses_cmath.h b/tests/unit_tests/headers/local_headers/injection_uses_cmath.h new file mode 100644 index 000000000..8ea1b31f2 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/injection_uses_cmath.h @@ -0,0 +1,18 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef INJECTION_USES_CMATH_H +#define INJECTION_USES_CMATH_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline __device__ float compute_sqrt(float x) { + return sqrtf(x); +} + +inline __device__ float compute_magnitude(float x, float y) { + return sqrtf(x * x + y * y); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/local_angle.h b/tests/unit_tests/headers/local_headers/local_angle.h index 37450404b..7a8cbba1f 100644 --- a/tests/unit_tests/headers/local_headers/local_angle.h +++ b/tests/unit_tests/headers/local_headers/local_angle.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #ifndef LOCAL_ANGLE_H #define LOCAL_ANGLE_H // CHECK: #include diff --git a/tests/unit_tests/headers/local_headers/main.cu b/tests/unit_tests/headers/local_headers/main.cu index 17850a78e..79b1bb617 100644 --- a/tests/unit_tests/headers/local_headers/main.cu +++ b/tests/unit_tests/headers/local_headers/main.cu @@ -1,12 +1,25 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK-NOT: #include // CHECK: #include "common.h" // CHECK: #include "single_header.h" // CHECK: #include "shared.h" +// CHECK: #include "block_comment_include.h" +// CHECK: #include "parent_a.h" +// CHECK: #include "parent_b.h" +// CHECK: #include "subdir_a/dup_name.h" +// CHECK: #include "subdir_b/dup_name.h" #include #include "common.h" #include "single_header.h" -#include "shared.h" \ No newline at end of file +#include "shared.h" + +#include "block_comment_include.h" /* block comment after include */ + +#include "parent_a.h" +#include "parent_b.h" + +#include "subdir_a/dup_name.h" +#include "subdir_b/dup_name.h" diff --git a/tests/unit_tests/headers/local_headers/mixed.h b/tests/unit_tests/headers/local_headers/mixed.h index 285a79150..7e6413cff 100644 --- a/tests/unit_tests/headers/local_headers/mixed.h +++ b/tests/unit_tests/headers/local_headers/mixed.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args #ifndef MIXED_H #define MIXED_H // CHECK: #include diff --git a/tests/unit_tests/headers/local_headers/no_local_headers.cu b/tests/unit_tests/headers/local_headers/no_local_headers.cu index e6de738eb..24b2d11cc 100644 --- a/tests/unit_tests/headers/local_headers/no_local_headers.cu +++ b/tests/unit_tests/headers/local_headers/no_local_headers.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/non_cuda.h b/tests/unit_tests/headers/local_headers/non_cuda.h index 6680ef38f..78943ad00 100644 --- a/tests/unit_tests/headers/local_headers/non_cuda.h +++ b/tests/unit_tests/headers/local_headers/non_cuda.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #ifndef NON_CUDA_H #define NON_CUDA_H diff --git a/tests/unit_tests/headers/local_headers/non_cuda_header.cu b/tests/unit_tests/headers/local_headers/non_cuda_header.cu index 5ae03f26b..9d1dbce17 100644 --- a/tests/unit_tests/headers/local_headers/non_cuda_header.cu +++ b/tests/unit_tests/headers/local_headers/non_cuda_header.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK: #include "non_cuda.h" diff --git a/tests/unit_tests/headers/local_headers/non_self_contained.cu b/tests/unit_tests/headers/local_headers/non_self_contained.cu new file mode 100644 index 000000000..ed787c5a7 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/non_self_contained.cu @@ -0,0 +1,23 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args + +// nsc_dependent.h uses a type from nsc_context.h without including it, so it +// hipifies only if the includes preceding it here are replayed in front of it. + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "nsc_context.h" +// CHECK: #include "nsc_dependent.h" +#include +#include "nsc_context.h" +#include "nsc_dependent.h" + +__global__ void nscKernel(NscVec* vectors) { + int idx = threadIdx.x; + vectors[idx].data = make_float3(0.0f, 0.0f, 0.0f); +} + +int main() { + NscVec vec; + nsc_fill(&vec, 1); + return 0; +} diff --git a/tests/unit_tests/headers/local_headers/nsc_context.h b/tests/unit_tests/headers/local_headers/nsc_context.h new file mode 100644 index 000000000..8a9691f56 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/nsc_context.h @@ -0,0 +1,15 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef NSC_CONTEXT_H +#define NSC_CONTEXT_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +struct NscVec { + float3 data; + cudaError_t status; +}; + +#endif diff --git a/tests/unit_tests/headers/local_headers/nsc_dependent.h b/tests/unit_tests/headers/local_headers/nsc_dependent.h new file mode 100644 index 000000000..4553c07eb --- /dev/null +++ b/tests/unit_tests/headers/local_headers/nsc_dependent.h @@ -0,0 +1,12 @@ +#ifndef NSC_DEPENDENT_H +#define NSC_DEPENDENT_H + +// Deliberately not self-contained: NscVec comes from the includer. Driven by +// non_self_contained.cu, and excluded from standalone testing in tests/lit.cfg. + +inline cudaError_t nsc_fill(NscVec *v, int count) { + v->status = cudaMemset(&v->data, 0, count * sizeof(float3)); + return v->status; +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/parent_a.h b/tests/unit_tests/headers/local_headers/parent_a.h new file mode 100644 index 000000000..8c67626d7 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/parent_a.h @@ -0,0 +1,17 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef PARENT_A_H +#define PARENT_A_H + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "shared_dep.h" +#include +#include "shared_dep.h" + +inline void parent_a_malloc(void **p) { + // CHECK: hipMalloc(p, 32); + cudaMalloc(p, 32); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/parent_b.h b/tests/unit_tests/headers/local_headers/parent_b.h new file mode 100644 index 000000000..e5fa7b2a5 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/parent_b.h @@ -0,0 +1,17 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef PARENT_B_H +#define PARENT_B_H + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "shared_dep.h" +#include +#include "shared_dep.h" + +inline void parent_b_free(void *p) { + // CHECK: hipFree(p); + cudaFree(p); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/rec_1.h b/tests/unit_tests/headers/local_headers/rec_1.h index ddfc81b6f..8690e0ee4 100644 --- a/tests/unit_tests/headers/local_headers/rec_1.h +++ b/tests/unit_tests/headers/local_headers/rec_1.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers-recursive %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #ifndef REC_H #define REC_H diff --git a/tests/unit_tests/headers/local_headers/recursive-header.cu b/tests/unit_tests/headers/local_headers/recursive-header.cu index 542d4d42f..9f2c48fde 100644 --- a/tests/unit_tests/headers/local_headers/recursive-header.cu +++ b/tests/unit_tests/headers/local_headers/recursive-header.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers-recursive %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers-recursive %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/relative/common1.h b/tests/unit_tests/headers/local_headers/relative/common1.h index d8ade3b73..70ac3ef44 100644 --- a/tests/unit_tests/headers/local_headers/relative/common1.h +++ b/tests/unit_tests/headers/local_headers/relative/common1.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers-recursive %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #ifndef COMMON1_H #define COMMON1_H diff --git a/tests/unit_tests/headers/local_headers/relative/sub/common2.h b/tests/unit_tests/headers/local_headers/relative/sub/common2.h index 6cc5db120..2e208c192 100644 --- a/tests/unit_tests/headers/local_headers/relative/sub/common2.h +++ b/tests/unit_tests/headers/local_headers/relative/sub/common2.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers-recursive %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #ifndef COMMON2_H #define COMMON2_H diff --git a/tests/unit_tests/headers/local_headers/relative_path.cu b/tests/unit_tests/headers/local_headers/relative_path.cu index b5a75791c..800e1dd01 100644 --- a/tests/unit_tests/headers/local_headers/relative_path.cu +++ b/tests/unit_tests/headers/local_headers/relative_path.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/shared.h b/tests/unit_tests/headers/local_headers/shared.h index 45693dfb5..088605f34 100644 --- a/tests/unit_tests/headers/local_headers/shared.h +++ b/tests/unit_tests/headers/local_headers/shared.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #ifndef SHARED_H #define SHARED_H // CHECK: #include diff --git a/tests/unit_tests/headers/local_headers/shared_dep.h b/tests/unit_tests/headers/local_headers/shared_dep.h new file mode 100644 index 000000000..bf7dd270b --- /dev/null +++ b/tests/unit_tests/headers/local_headers/shared_dep.h @@ -0,0 +1,15 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef SHARED_DEP_H +#define SHARED_DEP_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline void shared_dep_sync() { + // CHECK: hipDeviceSynchronize(); + cudaDeviceSynchronize(); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/shared_header_1.cu b/tests/unit_tests/headers/local_headers/shared_header_1.cu index 669bedbad..f3815e6d2 100644 --- a/tests/unit_tests/headers/local_headers/shared_header_1.cu +++ b/tests/unit_tests/headers/local_headers/shared_header_1.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/shared_header_2.cu b/tests/unit_tests/headers/local_headers/shared_header_2.cu index 669bedbad..f3815e6d2 100644 --- a/tests/unit_tests/headers/local_headers/shared_header_2.cu +++ b/tests/unit_tests/headers/local_headers/shared_header_2.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/single_header.cu b/tests/unit_tests/headers/local_headers/single_header.cu index d8efd6154..d1f415042 100644 --- a/tests/unit_tests/headers/local_headers/single_header.cu +++ b/tests/unit_tests/headers/local_headers/single_header.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/single_header.h b/tests/unit_tests/headers/local_headers/single_header.h index 97570f3ea..7291c7315 100644 --- a/tests/unit_tests/headers/local_headers/single_header.h +++ b/tests/unit_tests/headers/local_headers/single_header.h @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args #ifndef SINGLE_HEADER_H #define SINGLE_HEADER_H // CHECK: #include diff --git a/tests/unit_tests/headers/local_headers/stress_test.cu b/tests/unit_tests/headers/local_headers/stress_test.cu index 95022efea..ffbf59347 100644 --- a/tests/unit_tests/headers/local_headers/stress_test.cu +++ b/tests/unit_tests/headers/local_headers/stress_test.cu @@ -1,4 +1,4 @@ -// RUN: %run_test hipify "%s" "%t" %hipify_args --local-headers %clang_args +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers %clang_args // CHECK: #include // CHECK-NOT: #include diff --git a/tests/unit_tests/headers/local_headers/subdir_a/dup_name.h b/tests/unit_tests/headers/local_headers/subdir_a/dup_name.h new file mode 100644 index 000000000..f4c641b2f --- /dev/null +++ b/tests/unit_tests/headers/local_headers/subdir_a/dup_name.h @@ -0,0 +1,15 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef SUBDIR_A_DUP_NAME_H +#define SUBDIR_A_DUP_NAME_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline void subdir_a_sync() { + // CHECK: hipDeviceSynchronize(); + cudaDeviceSynchronize(); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/subdir_b/dup_name.h b/tests/unit_tests/headers/local_headers/subdir_b/dup_name.h new file mode 100644 index 000000000..9220166d5 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/subdir_b/dup_name.h @@ -0,0 +1,15 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef SUBDIR_B_DUP_NAME_H +#define SUBDIR_B_DUP_NAME_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline void subdir_b_sync() { + // CHECK: hipDeviceSynchronize(); + cudaDeviceSynchronize(); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/transitive_child.h b/tests/unit_tests/headers/local_headers/transitive_child.h new file mode 100644 index 000000000..ff86eaeb8 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/transitive_child.h @@ -0,0 +1,12 @@ +#ifndef TRANSITIVE_CHILD_H +#define TRANSITIVE_CHILD_H + +#include + +inline void child_sort_alloc(int *data, int n, void **p) { + std::sort(data, data + n); + // CHECK: hipMalloc(p, n * sizeof(int)); + cudaMalloc(p, n * sizeof(int)); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/transitive_parent.h b/tests/unit_tests/headers/local_headers/transitive_parent.h new file mode 100644 index 000000000..34b473e62 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/transitive_parent.h @@ -0,0 +1,15 @@ +#ifndef TRANSITIVE_PARENT_H +#define TRANSITIVE_PARENT_H + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "transitive_child.h" +#include +#include "transitive_child.h" + +inline void parent_sync() { + // CHECK: hipDeviceSynchronize(); + cudaDeviceSynchronize(); +} + +#endif diff --git a/tests/unit_tests/headers/local_headers/transitive_system_include.cu b/tests/unit_tests/headers/local_headers/transitive_system_include.cu new file mode 100644 index 000000000..235e9e8a5 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/transitive_system_include.cu @@ -0,0 +1,10 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args 1 --local-headers-recursive %clang_args + +// CHECK: #include +// CHECK-NOT: #include +// CHECK: #include "transitive_parent.h" +#include +#include +#include "transitive_parent.h" + +int main() { return 0; } diff --git a/tests/unit_tests/headers/local_headers/vector_math.h b/tests/unit_tests/headers/local_headers/vector_math.h new file mode 100644 index 000000000..ae4eb4a25 --- /dev/null +++ b/tests/unit_tests/headers/local_headers/vector_math.h @@ -0,0 +1,12 @@ +// RUN: %run_test hipify "%s" "%t" %hipify_args %clang_args + +#ifndef VECTOR_MATH_H +#define VECTOR_MATH_H + +// CHECK: #include +// CHECK-NOT: #include +#include + +inline __host__ __device__ void dummy_vector_op() { return; } + +#endif