-
Notifications
You must be signed in to change notification settings - Fork 96
[SYCLomatic] Support migration of __cvta_generic_to_shared #2521
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+121
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| //===--------------- RulesLangAddrSpaceConv.cpp ---------------------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "AnalysisInfo.h" | ||
| #include "RuleInfra/ExprAnalysis.h" | ||
| #include "RulesLang.h" | ||
| #include "Utility.h" | ||
| #include "clang/AST/Decl.h" | ||
| #include "clang/AST/Expr.h" | ||
| #include "clang/AST/Stmt.h" | ||
| #include "clang/ASTMatchers/ASTMatchers.h" | ||
| #include "llvm/Support/Casting.h" | ||
|
|
||
| namespace clang { | ||
| namespace dpct { | ||
|
|
||
| using namespace clang::ast_matchers; | ||
|
|
||
| void RulesLangAddrSpaceConvRule::registerMatcher(MatchFinder &MF) { | ||
| MF.addMatcher( | ||
| callExpr(callee(functionDecl(hasName("__cvta_generic_to_shared")))) | ||
| .bind("call"), | ||
| this); | ||
| } | ||
|
|
||
| void RulesLangAddrSpaceConvRule::runRule( | ||
| const MatchFinder::MatchResult &Result) { | ||
| const auto *CE = getNodeAsType<CallExpr>(Result, "call"); | ||
| if (!CE) | ||
| return; | ||
| // Check if meets below conditions: | ||
| // (1) A vardecl's init value is the "call" (or after type cast). | ||
| // (2) The var is only used as the asm stmt parameter. | ||
|
|
||
| // Check (1) | ||
| const auto *DS = DpctGlobalInfo::findAncestor<DeclStmt>(CE); | ||
| if (!DS) | ||
| return; | ||
| const auto *VD = | ||
| DS->isSingleDecl() ? dyn_cast<VarDecl>(DS->getSingleDecl()) : nullptr; | ||
| if (!VD) | ||
| return; | ||
| const auto *Init = VD->getInit(); | ||
| if (!Init) | ||
| return; | ||
| if (Init->IgnoreCasts() != CE) | ||
| return; | ||
|
|
||
| // Check (2) | ||
| const auto *Ctx = VD->getDeclContext(); | ||
| const auto *FD = dyn_cast<FunctionDecl>(Ctx); | ||
| if (!FD) | ||
| return; | ||
| if (!FD->hasBody()) | ||
| return; | ||
| std::set<const clang::DeclRefExpr *> DREs = | ||
| matchTargetDREInScope(VD, FD->getBody()); | ||
| if (DREs.size() != 1) | ||
| return; | ||
| const auto *DRE = *DREs.begin(); | ||
| const auto *AS = DpctGlobalInfo::findAncestor<AsmStmt>(DRE); | ||
| if (!AS) | ||
| return; | ||
|
|
||
| // Generate replacement | ||
| std::string ReplacementStr = "auto " + VD->getNameAsString() + " = " + | ||
| ExprAnalysis::ref(CE->getArg(0)) + ";"; | ||
| emplaceTransformation(new ReplaceDecl(VD, std::move(ReplacementStr))); | ||
| } | ||
|
|
||
| } // namespace dpct | ||
| } // namespace clang | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // UNSUPPORTED: cuda-8.0, cuda-9.0, cuda-9.1, cuda-9.2, cuda-10.0, cuda-10.1, cuda-10.2 | ||
| // UNSUPPORTED: v8.0, v9.0, v9.1, v9.2, v10.0, v10.1, v10.2 | ||
| // RUN: dpct --format-range=none --out-root %T/addr_space_conv %s --cuda-include-path="%cuda-path/include" | ||
| // RUN: FileCheck --input-file %T/addr_space_conv/addr_space_conv.dp.cpp --match-full-lines %s | ||
| // RUN: %if build_lit %{icpx -c -DNO_BUILD_TEST -fsycl %T/addr_space_conv/addr_space_conv.dp.cpp -o %T/addr_space_conv/addr_space_conv.dp.o %} | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| __global__ void kernel1(const void* ptr) { | ||
| // In PTX, addresses of the local and shared memory spaces are always 32 bits in size. | ||
| __shared__ float shared_array[1024]; | ||
| // CHECK: auto smem = shared_array; | ||
| uint32_t smem = static_cast<uint32_t>(__cvta_generic_to_shared(shared_array)); | ||
| #ifndef NO_BUILD_TEST | ||
| asm volatile( | ||
| "{\n" | ||
| " cp.async.cg.shared.global [%0], [%1], 16;\n" | ||
| "}\n" :: "r"(smem), "l"(ptr) | ||
| ); | ||
| #endif | ||
| } | ||
|
|
||
| void foo(const void* ptr) { | ||
| kernel1<<<1, 1>>>(ptr); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.