-
Notifications
You must be signed in to change notification settings - Fork 787
[SYCL] Refactor C++14 support #4303
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
Changes from all commits
c0fc6dd
063a9b5
54b4b2e
626b9a1
5e19563
041cec1
d40ac3a
59f8cab
2dd073f
cfbd569
03f0e79
97b4e80
ef92812
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,39 +169,41 @@ constexpr bool isKernelLambdaCallableWithKernelHandlerImpl() { | |
kernel_handler>(); | ||
} | ||
|
||
// Type traits to find out if kernal lambda has kernel_handler argument | ||
// Type trait to find out if kernal lambda has kernel_handler argument | ||
template <typename KernelType, typename LambdaArgType = void> | ||
struct KernelLambdaHasKernelHandlerArgT { | ||
constexpr static bool value = | ||
isKernelLambdaCallableWithKernelHandlerImpl<KernelType, LambdaArgType>(); | ||
}; | ||
|
||
// Helpers for running kernel lambda on the host device | ||
|
||
template <typename KernelType> | ||
constexpr bool isKernelLambdaCallableWithKernelHandler() { | ||
return check_kernel_lambda_takes_args<KernelType, kernel_handler>(); | ||
typename std::enable_if_t<KernelLambdaHasKernelHandlerArgT<KernelType>::value> | ||
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. I believe the keyword 'typename' is not required when you use std::enable_if_t, but Ok. Thank you for the additional changes anyway. |
||
runKernelWithoutArg(KernelType KernelName) { | ||
kernel_handler KH; | ||
KernelName(KH); | ||
} | ||
|
||
template <typename KernelType, typename LambdaArgType> | ||
constexpr bool isKernelLambdaCallableWithKernelHandler() { | ||
return isKernelLambdaCallableWithKernelHandlerImpl<KernelType, | ||
LambdaArgType>(); | ||
template <typename KernelType> | ||
typename std::enable_if_t<!KernelLambdaHasKernelHandlerArgT<KernelType>::value> | ||
runKernelWithoutArg(KernelType KernelName) { | ||
KernelName(); | ||
} | ||
|
||
// Helpers for running kernel lambda on the host device | ||
|
||
template <typename KernelType> void runKernelWithoutArg(KernelType KernelName) { | ||
if constexpr (isKernelLambdaCallableWithKernelHandler<KernelType>()) { | ||
kernel_handler KH; | ||
KernelName(KH); | ||
} else { | ||
KernelName(); | ||
} | ||
template <typename ArgType, typename KernelType> | ||
typename std::enable_if_t< | ||
KernelLambdaHasKernelHandlerArgT<KernelType, ArgType>::value> | ||
runKernelWithArg(KernelType KernelName, ArgType Arg) { | ||
kernel_handler KH; | ||
KernelName(Arg, KH); | ||
} | ||
|
||
template <typename ArgType, typename KernelType> | ||
constexpr void runKernelWithArg(KernelType KernelName, ArgType Arg) { | ||
if constexpr (isKernelLambdaCallableWithKernelHandler<KernelType, | ||
ArgType>()) { | ||
kernel_handler KH; | ||
KernelName(Arg, KH); | ||
} else { | ||
KernelName(Arg); | ||
} | ||
typename std::enable_if_t< | ||
!KernelLambdaHasKernelHandlerArgT<KernelType, ArgType>::value> | ||
runKernelWithArg(KernelType KernelName, ArgType Arg) { | ||
KernelName(Arg); | ||
} | ||
|
||
// The pure virtual class aimed to store lambda/functors of any type. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,38 @@ | ||
// RUN: %clangxx -fsycl -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s -c -o %t.out | ||
// RUN: %clangxx -fsycl -std=c++14 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s -c -o %t.out | ||
// RUN: %clangxx -fsycl -std=c++17 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s -c -o %t.out | ||
// RUN: %clangxx -fsycl -std=c++20 -fsyntax-only -Xclang -verify -Xclang -verify-ignore-unexpected=note,warning %s -c -o %t.out | ||
// expected-no-diagnostics | ||
// RUN: %clangxx -std=c++14 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify=expected,cxx14 %s -c -o %t.out | ||
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. Planning to unify/merge with |
||
// RUN: %clangxx -std=c++14 -fsycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out -DSYCL_DISABLE_CPP_VERSION_CHECK_WARNING=1 | ||
// RUN: %clangxx -std=c++14 -fsycl --no-system-header-prefix=CL/sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify=cxx14,warning_extension,expected %s -c -o %t.out | ||
// RUN: %clangxx -std=c++17 -fsycl --no-system-header-prefix=CL/sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out | ||
// RUN: %clangxx -std=c++20 -fsycl --no-system-header-prefix=CL/sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out | ||
// RUN: %clangxx -fsycl --no-system-header-prefix=CL/sycl -Wall -pedantic -Wno-c99-extensions -Wno-deprecated -fsyntax-only -Xclang -verify %s -c -o %t.out | ||
|
||
// The test checks SYCL headers C++ compiance and that a warning is emitted | ||
// when compiling in < C++17 mode. | ||
|
||
#include <CL/sycl.hpp> | ||
|
||
// cxx14-warning@* {{DPCPP does not support C++ version earlier than C++17. Some features might not be available.}} | ||
// | ||
// The next warning is not emitted in device compilation for some reason | ||
// warning_extension-warning@* 0-1 {{#warning is a language extension}} | ||
// | ||
// The next warning is emitted for windows only | ||
// expected-warning@* 0-1 {{Alignment of class vec is not in accordance with SYCL specification requirements, a limitation of the MSVC compiler(Error C2719).Applied default alignment.}} | ||
|
||
|
||
class KernelName1; | ||
|
||
int main() { | ||
|
||
// Simple code to trigger instantiation of basic classes | ||
sycl::buffer<int, 1> Buf(sycl::range<1>{42}); | ||
|
||
sycl::queue Q; | ||
|
||
Q.submit([&](sycl::handler &CGH) { | ||
auto Acc = Buf.get_access<cl::sycl::access::mode::read>(CGH); | ||
|
||
CGH.parallel_for<KernelName1>(sycl::range<1>{42}, | ||
[=](sycl::id<1> ID) { (void)Acc; }); | ||
}); | ||
Q.wait(); | ||
} |
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.
GCC complained about multi line comments.