Skip to content

Commit

Permalink
Fix constexpr in KernelRegistrationBuilder (pytorch#16906)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: pytorch#16906

In C++11, constexpr implies const, so these methods actually wouldn't be rvalue overloads as intended but const rvalue overloads.
Let's only apply the constexpr flag in C++14 to be safe.

Reviewed By: bddppq

Differential Revision: D13998486

fbshipit-source-id: a04d17ef0cc8f45e3d0a1ca9843d194f4f0f6f7f
  • Loading branch information
smessmer authored and facebook-github-bot committed Feb 11, 2019
1 parent 6fbb2f7 commit 2d9879c
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions aten/src/ATen/core/dispatch/KernelRegistration.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ class KernelRegistrationBuilder final {
* @param dispatch_key dispatch key to register the function to
* @return "this" for method chaining
*/
constexpr KernelRegistrationBuilder<CacheTypeOrVoid, FieldsPresentFlags | DISPATCH_KEY_PRESENT> dispatchKey(TensorTypeId dispatch_key) && {
AT_CPP14_CONSTEXPR KernelRegistrationBuilder<CacheTypeOrVoid, FieldsPresentFlags | DISPATCH_KEY_PRESENT> dispatchKey(TensorTypeId dispatch_key) && {
static_assert(!(FieldsPresentFlags & DISPATCH_KEY_PRESENT), "Tried to define kernel twice in same op registration");
return KernelRegistrationBuilder<CacheTypeOrVoid, FieldsPresentFlags | DISPATCH_KEY_PRESENT>(std::move(op_), std::move(dispatch_key), kernel_, cache_creator_);
}
Expand All @@ -239,7 +239,7 @@ class KernelRegistrationBuilder final {
* @return "this" for method chaining
*/
template<KernelFunction* kernel_func>
constexpr KernelRegistrationBuilder<CacheTypeOrVoid, FieldsPresentFlags | KERNEL_PRESENT> kernel() && {
AT_CPP14_CONSTEXPR KernelRegistrationBuilder<CacheTypeOrVoid, FieldsPresentFlags | KERNEL_PRESENT> kernel() && {
static_assert(!(FieldsPresentFlags & KERNEL_PRESENT), "Tried to define kernel twice in same op registration");
// TODO Better error message when kernel function mismatches, one common mismatch is missing cache parameter or cache parameter present while not expected.
return KernelRegistrationBuilder<CacheTypeOrVoid, FieldsPresentFlags | KERNEL_PRESENT>(std::move(op_), std::move(dispatch_key_), kernel_func, cache_creator_);
Expand All @@ -251,7 +251,7 @@ class KernelRegistrationBuilder final {
* @return "this" for method chaining
*/
template<class FuncType, FuncType* kernel_func>
constexpr KernelRegistrationBuilder<CacheTypeOrVoid, FieldsPresentFlags | KERNEL_PRESENT> kernel() && {
AT_CPP14_CONSTEXPR KernelRegistrationBuilder<CacheTypeOrVoid, FieldsPresentFlags | KERNEL_PRESENT> kernel() && {
// TODO Better error message if FuncType is not a func type
return std::move(*this).template kernel<&detail::wrap_kernel<CacheTypeOrVoid, FuncType, kernel_func>::call>();
}
Expand All @@ -262,7 +262,7 @@ class KernelRegistrationBuilder final {
* @return "this" for method chaining
*/
template<class Cache>
constexpr KernelRegistrationBuilder<Cache, FieldsPresentFlags | CACHE_PRESENT> withCache() && {
AT_CPP14_CONSTEXPR KernelRegistrationBuilder<Cache, FieldsPresentFlags | CACHE_PRESENT> withCache() && {
static_assert(!(FieldsPresentFlags & CACHE_PRESENT), "Tried to define cache twice in same op registration");
static_assert(std::is_base_of<c10::KernelCache, Cache>::value, "Cache must inherit from c10::KernelCache");

Expand Down

0 comments on commit 2d9879c

Please sign in to comment.