-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Collect sycl_declared_aspects metadata #7359
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
Closed
Closed
Changes from all commits
Commits
Show all changes
5 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
66 changes: 66 additions & 0 deletions
66
llvm/test/tools/sycl-post-link/device-requirements/sycl-declared-aspects.ll
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,66 @@ | ||
; RUN: sycl-post-link -split=auto %s -o %t.files.table | ||
; RUN: FileCheck %s -input-file=%t.files_0.prop --check-prefix CHECK-AUTO | ||
|
||
; RUN: sycl-post-link -split=kernel %s -o %t.files.table | ||
; RUN: FileCheck %s -input-file=%t.files_0.prop --check-prefix CHECK-KERNEL-0 | ||
; RUN: FileCheck %s -input-file=%t.files_1.prop --check-prefix CHECK-KERNEL-1 | ||
; RUN: FileCheck %s -input-file=%t.files_2.prop --check-prefix CHECK-KERNEL-2 | ||
|
||
; CHECK-AUTO: aspects=2|gBAAAAAAAAQBAAAAGAAAAkAAAAA | ||
; CHECK-KERNEL-0: aspects=2|gBAAAAAAAAQBAAAAGAAAAkAAAAA | ||
; CHECK-KERNEL-1: aspects=2|ABAAAAAAAAQBAAAAGAAAAA | ||
; CHECK-KERNEL-2: aspects=2|gAAAAAAAAAQBAAAA | ||
|
||
source_filename = "source.cpp" | ||
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64" | ||
target triple = "spir64-unknown-unknown" | ||
|
||
$kernel1 = comdat any | ||
|
||
$kernel2 = comdat any | ||
|
||
$kernel3 = comdat any | ||
|
||
define weak_odr dso_local spir_kernel void @kernel1() #0 { | ||
entry: | ||
call spir_func void @_Z3foov() | ||
ret void | ||
} | ||
|
||
define dso_local spir_func void @_Z3foov() !sycl_declared_aspects !4 { | ||
entry: | ||
ret void | ||
} | ||
|
||
define weak_odr dso_local spir_kernel void @kernel2() #0 { | ||
entry: | ||
call spir_func void @_Z3barv() | ||
ret void | ||
} | ||
|
||
define dso_local spir_func void @_Z3barv() !sycl_declared_aspects !5 { | ||
entry: | ||
ret void | ||
} | ||
|
||
define weak_odr dso_local spir_kernel void @kernel3() #0 { | ||
entry: | ||
call spir_func void @_Z3bazv() | ||
ret void | ||
} | ||
|
||
define dso_local spir_func void @_Z3bazv() !sycl_declared_aspects !6 { | ||
entry: | ||
ret void | ||
} | ||
|
||
attributes #0 = { "sycl-module-id"="source.cpp" } | ||
|
||
!sycl_aspects = !{!1, !2, !3} | ||
|
||
!1 = !{!"fp16", i32 5} | ||
!2 = !{!"fp64", i32 6} | ||
!3 = !{!"image", i32 9} | ||
!4 = !{i32 5} | ||
!5 = !{i32 5, i32 6} | ||
!6 = !{i32 5, i32 6, i32 9} |
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 |
---|---|---|
|
@@ -18,32 +18,31 @@ using namespace llvm; | |
|
||
void llvm::getSYCLDeviceRequirements( | ||
const Module &M, std::map<StringRef, std::vector<uint32_t>> &Requirements) { | ||
auto ExtractIntegerFromMDNodeOperand = [=](const MDNode *N, | ||
unsigned OpNo) -> unsigned { | ||
Constant *C = | ||
cast<ConstantAsMetadata>(N->getOperand(OpNo).get())->getValue(); | ||
return static_cast<uint32_t>(C->getUniqueInteger().getZExtValue()); | ||
std::set<uint32_t> Aspects; | ||
auto FindAspectsByMDName = [&](const Function &F, std::string MDName) { | ||
if (const MDNode *MDN = F.getMetadata(MDName)) | ||
for (size_t I = 0, E = MDN->getNumOperands(); I < E; ++I) { | ||
Constant *C = | ||
cast<ConstantAsMetadata>(MDN->getOperand(I).get())->getValue(); | ||
Aspects.insert( | ||
static_cast<uint32_t>(C->getUniqueInteger().getZExtValue())); | ||
} | ||
}; | ||
|
||
// { LLVM-IR metadata name , [SYCL/Device requirements] property name }, see: | ||
// https://github.com/intel/llvm/blob/sycl/sycl/doc/design/OptionalDeviceFeatures.md#create-the-sycldevice-requirements-property-set | ||
// Scan the module and if the metadata is present fill the corresponing | ||
// property with metadata's aspects | ||
KornevNikita marked this conversation as resolved.
Show resolved
Hide resolved
|
||
constexpr std::pair<const char *, const char *> ReqdMDs[] = { | ||
{"sycl_used_aspects", "aspects"}, {"sycl_fixed_targets", "fixed_target"}}; | ||
for (const Function &F : M) { | ||
FindAspectsByMDName(F, "sycl_used_aspects"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
FindAspectsByMDName(F, "sycl_declared_aspects"); | ||
} | ||
Requirements["aspects"] = | ||
std::vector<uint32_t>(Aspects.begin(), Aspects.end()); | ||
|
||
for (const auto &MD : ReqdMDs) { | ||
std::set<uint32_t> Aspects; | ||
for (const Function &F : M) { | ||
if (const MDNode *MDN = F.getMetadata(MD.first)) { | ||
for (size_t I = 0, E = MDN->getNumOperands(); I < E; ++I) | ||
Aspects.insert(ExtractIntegerFromMDNodeOperand(MDN, I)); | ||
} | ||
} | ||
// We don't need the "fixed_target" property if it's empty | ||
if (std::string(MD.first) == "sycl_fixed_targets" && Aspects.empty()) | ||
continue; | ||
Requirements[MD.second] = | ||
Aspects.clear(); | ||
for (const Function &F : M) | ||
FindAspectsByMDName(F, "sycl_fixed_targets"); | ||
// We don't need the "fixed_target" property if it's empty | ||
if (!Aspects.empty()) | ||
Requirements["fixed_target"] = | ||
std::vector<uint32_t>(Aspects.begin(), Aspects.end()); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.