-
Notifications
You must be signed in to change notification settings - Fork 790
[SYCL] Add DPC++ RT support for SYCL 2020 spec constants (part 1) #3382
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
bader
merged 15 commits into
intel:sycl
from
dm-vodopyanov:private/dvodopya/spec_consts_dpcpp_rt_part_1
Apr 1, 2021
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
bff864d
[SYCL] Add DPC++ RT support for SYCL 2020 spec constants (part 1)
dm-vodopyanov 9fd5474
Code style fixes
dm-vodopyanov da5af9e
Fix pre-commit
dm-vodopyanov 4f2a03c
Minor changes
dm-vodopyanov 90dbbe3
Fix build failure on Windows
dm-vodopyanov fb62c8b
Fix CR commnets
dm-vodopyanov c6cf04f
Remove unnecessary changes
dm-vodopyanov f92ccfe
Fix compilation error with msvc
dm-vodopyanov 9c60d80
Apply CR comments
dm-vodopyanov 558f24b
Add TODO for support spec consts on host device
dm-vodopyanov 39c4df8
Add kind_specialization_constants_buffer to kernel_desc.hpp
dm-vodopyanov 9b167ab
Fix subsequent build failure
dm-vodopyanov dd4d260
Apply CR comments
dm-vodopyanov 1a0b200
Temporarily disabling spec const test for CUDA
dm-vodopyanov 73f1d19
Merge branch 'sycl' into private/dvodopya/spec_consts_dpcpp_rt_part_1
dm-vodopyanov 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ | |
#include <CL/sycl/interop_handle.hpp> | ||
#include <CL/sycl/interop_handler.hpp> | ||
#include <CL/sycl/kernel.hpp> | ||
#include <CL/sycl/kernel_handler.hpp> | ||
#include <CL/sycl/nd_item.hpp> | ||
#include <CL/sycl/range.hpp> | ||
|
||
|
@@ -122,6 +123,97 @@ class NDRDescT { | |
size_t Dims; | ||
}; | ||
|
||
template <typename, typename T> struct check_fn_signature { | ||
static_assert(std::integral_constant<T, false>::value, | ||
"Second template parameter is required to be of function type"); | ||
}; | ||
|
||
template <typename F, typename RetT, typename... Args> | ||
struct check_fn_signature<F, RetT(Args...)> { | ||
private: | ||
template <typename T> | ||
static constexpr auto check(T *) -> typename std::is_same< | ||
decltype(std::declval<T>().operator()(std::declval<Args>()...)), | ||
RetT>::type; | ||
|
||
template <typename> static constexpr std::false_type check(...); | ||
|
||
using type = decltype(check<F>(0)); | ||
|
||
public: | ||
static constexpr bool value = type::value; | ||
}; | ||
|
||
template <typename F, typename... Args> | ||
static constexpr bool check_kernel_lambda_takes_args() { | ||
return check_fn_signature<std::remove_reference_t<F>, void(Args...)>::value; | ||
} | ||
|
||
dm-vodopyanov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// isKernelLambdaCallableWithKernelHandlerImpl checks if LambdaArgType is void | ||
// (e.g., in single_task), and based on that, calls | ||
// check_kernel_lambda_takes_args with proper set of arguments. Also this type | ||
// trait workarounds compilation error which happens only with msvc. | ||
|
||
template <typename KernelType, typename LambdaArgType, | ||
typename std::enable_if_t<std::is_same<LambdaArgType, void>::value> | ||
* = nullptr> | ||
constexpr bool isKernelLambdaCallableWithKernelHandlerImpl() { | ||
return check_kernel_lambda_takes_args<KernelType, kernel_handler>(); | ||
} | ||
|
||
template <typename KernelType, typename LambdaArgType, | ||
typename std::enable_if_t<!std::is_same<LambdaArgType, void>::value> | ||
* = nullptr> | ||
constexpr bool isKernelLambdaCallableWithKernelHandlerImpl() { | ||
return check_kernel_lambda_takes_args<KernelType, LambdaArgType, | ||
kernel_handler>(); | ||
} | ||
|
||
// Type traits to find out if kernal lambda has kernel_handler argument | ||
|
||
template <typename KernelType> | ||
constexpr bool isKernelLambdaCallableWithKernelHandler() { | ||
return check_kernel_lambda_takes_args<KernelType, kernel_handler>(); | ||
} | ||
|
||
template <typename KernelType, typename LambdaArgType> | ||
constexpr bool isKernelLambdaCallableWithKernelHandler() { | ||
return isKernelLambdaCallableWithKernelHandlerImpl<KernelType, | ||
LambdaArgType>(); | ||
} | ||
|
||
// Helpers for running kernel lambda on the host device | ||
|
||
template <typename KernelType, | ||
typename std::enable_if_t<isKernelLambdaCallableWithKernelHandler< | ||
KernelType>()> * = nullptr> | ||
constexpr void runKernelWithoutArg(KernelType KernelName) { | ||
kernel_handler KH; | ||
KernelName(KH); | ||
} | ||
|
||
template <typename KernelType, | ||
typename std::enable_if_t<!isKernelLambdaCallableWithKernelHandler< | ||
KernelType>()> * = nullptr> | ||
constexpr void runKernelWithoutArg(KernelType KernelName) { | ||
KernelName(); | ||
} | ||
|
||
template <typename ArgType, typename KernelType, | ||
typename std::enable_if_t<isKernelLambdaCallableWithKernelHandler< | ||
KernelType, ArgType>()> * = nullptr> | ||
constexpr void runKernelWithArg(KernelType KernelName, ArgType Arg) { | ||
kernel_handler KH; | ||
KernelName(Arg, KH); | ||
} | ||
|
||
template <typename ArgType, typename KernelType, | ||
typename std::enable_if_t<!isKernelLambdaCallableWithKernelHandler< | ||
KernelType, ArgType>()> * = nullptr> | ||
constexpr void runKernelWithArg(KernelType KernelName, ArgType Arg) { | ||
KernelName(Arg); | ||
} | ||
|
||
// The pure virtual class aimed to store lambda/functors of any type. | ||
class HostKernelBase { | ||
public: | ||
|
@@ -197,7 +289,7 @@ class HostKernel : public HostKernelBase { | |
template <class ArgT = KernelArgType> | ||
typename detail::enable_if_t<std::is_same<ArgT, void>::value> | ||
runOnHost(const NDRDescT &) { | ||
MKernel(); | ||
runKernelWithoutArg(MKernel); | ||
} | ||
|
||
template <class ArgT = KernelArgType> | ||
|
@@ -218,18 +310,18 @@ class HostKernel : public HostKernelBase { | |
UpperBound[I] = Range[I] + Offset[I]; | ||
} | ||
|
||
detail::NDLoop<Dims>::iterate(/*LowerBound=*/Offset, Stride, UpperBound, | ||
[&](const sycl::id<Dims> &ID) { | ||
sycl::item<Dims, /*Offset=*/true> Item = | ||
IDBuilder::createItem<Dims, true>( | ||
Range, ID, Offset); | ||
|
||
if (StoreLocation) { | ||
store_id(&ID); | ||
store_item(&Item); | ||
} | ||
MKernel(ID); | ||
}); | ||
detail::NDLoop<Dims>::iterate( | ||
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. clang-format, the only change - runKernelWithArg... line |
||
/*LowerBound=*/Offset, Stride, UpperBound, | ||
[&](const sycl::id<Dims> &ID) { | ||
sycl::item<Dims, /*Offset=*/true> Item = | ||
IDBuilder::createItem<Dims, true>(Range, ID, Offset); | ||
|
||
if (StoreLocation) { | ||
store_id(&ID); | ||
store_item(&Item); | ||
} | ||
runKernelWithArg<const sycl::id<Dims> &>(MKernel, ID); | ||
}); | ||
} | ||
|
||
template <class ArgT = KernelArgType> | ||
|
@@ -253,7 +345,7 @@ class HostKernel : public HostKernelBase { | |
store_id(&ID); | ||
store_item(&ItemWithOffset); | ||
} | ||
MKernel(Item); | ||
runKernelWithArg<sycl::item<Dims, /*Offset=*/false>>(MKernel, Item); | ||
}); | ||
} | ||
|
||
|
@@ -276,18 +368,18 @@ class HostKernel : public HostKernelBase { | |
UpperBound[I] = Range[I] + Offset[I]; | ||
} | ||
|
||
detail::NDLoop<Dims>::iterate(/*LowerBound=*/Offset, Stride, UpperBound, | ||
[&](const sycl::id<Dims> &ID) { | ||
sycl::item<Dims, /*Offset=*/true> Item = | ||
IDBuilder::createItem<Dims, true>( | ||
Range, ID, Offset); | ||
|
||
if (StoreLocation) { | ||
store_id(&ID); | ||
store_item(&Item); | ||
} | ||
MKernel(Item); | ||
}); | ||
detail::NDLoop<Dims>::iterate( | ||
/*LowerBound=*/Offset, Stride, UpperBound, | ||
[&](const sycl::id<Dims> &ID) { | ||
sycl::item<Dims, /*Offset=*/true> Item = | ||
IDBuilder::createItem<Dims, true>(Range, ID, Offset); | ||
|
||
if (StoreLocation) { | ||
store_id(&ID); | ||
store_item(&Item); | ||
} | ||
runKernelWithArg<sycl::item<Dims, /*Offset=*/true>>(MKernel, Item); | ||
}); | ||
} | ||
|
||
template <class ArgT = KernelArgType> | ||
|
@@ -336,7 +428,7 @@ class HostKernel : public HostKernelBase { | |
auto g = NDItem.get_group(); | ||
store_group(&g); | ||
} | ||
MKernel(NDItem); | ||
runKernelWithArg<const sycl::nd_item<Dims>>(MKernel, NDItem); | ||
}); | ||
}); | ||
} | ||
|
@@ -364,7 +456,7 @@ class HostKernel : public HostKernelBase { | |
detail::NDLoop<Dims>::iterate(NGroups, [&](const id<Dims> &GroupID) { | ||
sycl::group<Dims> Group = | ||
IDBuilder::createGroup<Dims>(GlobalSize, LocalSize, NGroups, GroupID); | ||
MKernel(Group); | ||
runKernelWithArg<sycl::group<Dims>>(MKernel, Group); | ||
}); | ||
} | ||
|
||
|
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
Oops, something went wrong.
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.
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.
Moved from
handler.hpp
as is, exceptcheck_kernel_lambda_takes_args
- this is a new type trait