Skip to content
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

[FPGA][SYCL] Add support for memory attributes on device_global variables #12785

Merged
merged 17 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions clang/include/clang/Basic/Attr.td
Original file line number Diff line number Diff line change
Expand Up @@ -2730,9 +2730,6 @@ def : MutualExclusions<[SYCLIntelRegister, SYCLIntelBankWidth]>;
def SYCLIntelNumBanks : InheritableAttr {
let Spellings = [CXX11<"intel", "numbanks">];
let Args = [ExprArgument<"Value">];
let Subjects = SubjectList<[SYCLIntelConstVar,
SYCLIntelLocalStaticAgentMemVar,
Field], ErrorDiag>;
let LangOpts = [SYCLIsDevice, SilentlyIgnoreSYCLIsHost];
let Documentation = [SYCLIntelNumBanksAttrDocs];
}
Expand Down
4 changes: 4 additions & 0 deletions clang/include/clang/Basic/DiagnosticSemaKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -12215,6 +12215,10 @@ def err_sycl_attribute_internal_decl
"in an anonymous namespace">;
def err_sycl_attribute_not_device_global
: Error<"%0 attribute can only be applied to 'device_global' variables">;
def err_fpga_attribute_incorrrect_variable
smanna12 marked this conversation as resolved.
Show resolved Hide resolved
: Error<"%0 attribute only applies to constant variables, local variables, "
"static variables, agent memory arguments, non-static data "
"members, and non-constant device_global variables">;
smanna12 marked this conversation as resolved.
Show resolved Hide resolved
def err_sycl_compiletime_property_duplication : Error<
"can't apply %0 property twice to the same accessor">;
def err_sycl_invalid_property_list_param_number : Error<
Expand Down
10 changes: 10 additions & 0 deletions clang/lib/Sema/SemaDeclAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7745,6 +7745,16 @@ void Sema::AddSYCLIntelNumBanksAttr(Decl *D, const AttributeCommonInfo &CI,
}
}

if (auto *VD = dyn_cast<VarDecl>(D)) {
if (!(VD->getKind() != Decl::ImplicitParam &&
VD->getKind() != Decl::NonTypeTemplateParm &&
((VD->getStorageClass() == SC_Static || VD->hasLocalStorage()) ||
(isTypeDecoratedWithDeclAttribute<SYCLDeviceGlobalAttr>(VD->getType())
|| VD->getType().isConstQualified())))){
smanna12 marked this conversation as resolved.
Show resolved Hide resolved
Diag(CI.getLoc(), diag::err_fpga_attribute_incorrrect_variable) << CI;
}
}

// Check to see if there's a duplicate attribute with different values
// already applied to the declaration.
if (const auto *DeclAttr = D->getAttr<SYCLIntelNumBanksAttr>()) {
Expand Down
7 changes: 7 additions & 0 deletions clang/test/CodeGenSYCL/device_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ using namespace sycl;
queue q;

device_global<int> A;

[[intel::numbanks(2)]] /*const*/ device_global<int> A1;
smanna12 marked this conversation as resolved.
Show resolved Hide resolved

#ifdef SYCL_EXTERNAL
SYCL_EXTERNAL device_global<int> AExt;
#endif
Expand All @@ -20,8 +23,10 @@ struct Foo {
static device_global<int> C;
};
device_global<int> Foo::C;

// CHECK-RDC: @AExt = addrspace(1) global %"class.sycl::_V1::ext::oneapi::device_global" zeroinitializer, align 8 #[[AEXT_ATTRS:[0-9]+]]
// CHECK: @A = addrspace(1) global %"class.sycl::_V1::ext::oneapi::device_global" zeroinitializer, align 8 #[[A_ATTRS:[0-9]+]]
// CHECK: @A1 = addrspace(1) global %"class.sycl::_V1::ext::oneapi::device_global" zeroinitializer, align 8 #[[A1_ATTRS:[0-9]+]]
// CHECK: @_ZL1B = internal addrspace(1) global %"class.sycl::_V1::ext::oneapi::device_global" zeroinitializer, align 8 #[[B_ATTRS:[0-9]+]]
// CHECK: @_ZN3Foo1CE = addrspace(1) global %"class.sycl::_V1::ext::oneapi::device_global" zeroinitializer, align 8 #[[C_ATTRS:[0-9]+]]

Expand Down Expand Up @@ -70,6 +75,7 @@ void foo() {
q.submit([&](handler &h) {
h.single_task<class kernel_name_1>([=]() {
(void)A;
(void)A1;
(void)B;
(void)Foo::C;
(void)same_name;
Expand Down Expand Up @@ -103,6 +109,7 @@ void bar() {

// CHECK-RDC: attributes #[[AEXT_ATTRS]] = { "sycl-unique-id"="_Z4AExt" }
// CHECK: attributes #[[A_ATTRS]] = { "sycl-unique-id"="_Z1A" }
// CHECK: attributes #[[A1_ATTRS]] = { "sycl-unique-id"="_Z2A1" }
// CHECK: attributes #[[B_ATTRS]] = { "sycl-unique-id"="THE_PREFIX____ZL1B" }
// CHECK: attributes #[[C_ATTRS]] = { "sycl-unique-id"="_ZN3Foo1CE" }
// CHECK: attributes #[[SAME_NAME_ATTRS]] = { "sycl-unique-id"="_Z9same_name" }
Expand Down
44 changes: 44 additions & 0 deletions clang/test/SemaSYCL/intel-fpga-device-global.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// RUN: %clang_cc1 -fsycl-is-device -std=c++17 -sycl-std=2020 -verify %s
#include "Inputs/sycl.hpp"

// Tests that [[intel::numbanks()]] can be applied to device_global variables.
using namespace sycl::ext::oneapi;

[[intel::numbanks(2)]] device_global<int> dev_glob; // OK
smanna12 marked this conversation as resolved.
Show resolved Hide resolved
[[intel::numbanks(4)]] static device_global<float> static_dev_glob; // OK

// expected-error@+1{{'numbanks' attribute only applies to constant variables, local variables, static variables, agent memory arguments, non-static data members, and non-constant device_global variables}}
[[intel::numbanks(2)]] int K;

struct bar {
[[intel::numbanks(2)]] /*const*/ device_global<int> const_glob3; // OK
[[intel::numbanks(2)]] const device_global<int> const_glob4; // OK
smanna12 marked this conversation as resolved.
Show resolved Hide resolved
};

void foo() {
[[intel::numbanks(2)]] int A1; // OK
}

struct [[__sycl_detail__::global_variable_allowed]] GlobAllowedVarOnly {
};

// expected-error@+1{{'numbanks' attribute only applies to constant variables, local variables, static variables, agent memory arguments, non-static data members, and non-constant device_global variables}}
[[intel::numbanks(2)]] GlobAllowedVarOnly GAVO;

[[intel::numbanks(4)]] /*const*/ device_global<int> Good;
smanna12 marked this conversation as resolved.
Show resolved Hide resolved
[[intel::numbanks(4)]] extern device_global<int> Bad;

int main() {
sycl::kernel_single_task<class KernelName1>([=]() {
Good.get();
// expected-error@+1 {{invalid reference to 'device_global' variable; external 'device_global' variable must be marked with SYCL_EXTERNAL macro}}
Bad.get();
(void)GAVO;
});
return 0;
}
smanna12 marked this conversation as resolved.
Show resolved Hide resolved

//expected-error@+1{{'numbanks' attribute only applies to constant variables, local variables, static variables, agent memory arguments, non-static data members, and non-constant device_global variables}}
[[intel::numbanks(2)]]
__attribute__((opencl_global)) unsigned int ocl_glob_num_p2d[64] = {1, 2, 3};

Loading