diff options
author | Sebastian Messmer <messmer@fb.com> | 2019-01-22 13:21:38 -0800 |
---|---|---|
committer | Facebook Github Bot <facebook-github-bot@users.noreply.github.com> | 2019-01-22 13:29:13 -0800 |
commit | 325df4ccfb046b3ded25e5f7787d33cc043a371e (patch) | |
tree | db4af8fc2d38f84b96abb877a001da043ae7f238 | |
parent | cd8f4154f41a88ccd4f55ce72af2036afbf826a7 (diff) | |
download | pytorch-325df4ccfb046b3ded25e5f7787d33cc043a371e.tar.gz pytorch-325df4ccfb046b3ded25e5f7787d33cc043a371e.tar.bz2 pytorch-325df4ccfb046b3ded25e5f7787d33cc043a371e.zip |
Make kernel registration constexpr again (#16166)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/16166
Since we now don't use std::function anymore, we can make kernel registration constexpr again.
Reviewed By: ezyang
Differential Revision: D13738630
fbshipit-source-id: 918fa3a3c8c6f0ddbd0f08b3b143cdf066265387
-rw-r--r-- | aten/src/ATen/core/dispatch/KernelRegistration.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/aten/src/ATen/core/dispatch/KernelRegistration.h b/aten/src/ATen/core/dispatch/KernelRegistration.h index 935b6c00c7..30626a1045 100644 --- a/aten/src/ATen/core/dispatch/KernelRegistration.h +++ b/aten/src/ATen/core/dispatch/KernelRegistration.h @@ -92,10 +92,10 @@ private: c10::optional<typename Schema::dispatch::dispatch_key_type> dispatch_key_; public: - KernelRegistrationBuilder() + constexpr KernelRegistrationBuilder() : KernelRegistrationBuilder(c10::nullopt, c10::nullopt) {} - KernelRegistrationBuilder( + constexpr KernelRegistrationBuilder( c10::optional<KernelFunction*> kernel, c10::optional<typename Schema::dispatch::dispatch_key_type> dispatch_key) : kernel_(std::move(kernel)), dispatch_key_(std::move(dispatch_key)) {} @@ -117,7 +117,7 @@ private: * @return "this" for method chaining */ template<KernelFunction* kernel_func> - KernelRegistrationBuilder<OpSchemaDef, FieldsPresentFlags | KERNEL_PRESENT> kernel() && { + constexpr KernelRegistrationBuilder<OpSchemaDef, FieldsPresentFlags | KERNEL_PRESENT> kernel() && { static_assert(!(FieldsPresentFlags & KERNEL_PRESENT), "Tried to define kernel twice in same op registration"); return KernelRegistrationBuilder<OpSchemaDef, FieldsPresentFlags | KERNEL_PRESENT>(kernel_func, std::move(dispatch_key_)); } @@ -128,7 +128,7 @@ private: * @return "this" for method chaining */ template<typename Schema::signature::func_type* kernel_func> - KernelRegistrationBuilder<OpSchemaDef, FieldsPresentFlags | KERNEL_PRESENT> kernel() && { + constexpr KernelRegistrationBuilder<OpSchemaDef, FieldsPresentFlags | KERNEL_PRESENT> kernel() && { return std::move(*this).template kernel<&Schema::signature::template wrap_kernel<kernel_func>>(); } @@ -137,7 +137,7 @@ private: * @param dispatch_key dispatch key to register the function to * @return "this" for method chaining */ - KernelRegistrationBuilder<OpSchemaDef, FieldsPresentFlags | DISPATCH_KEY_PRESENT> dispatchKey(typename Schema::dispatch::dispatch_key_type dispatch_key) && { + constexpr KernelRegistrationBuilder<OpSchemaDef, FieldsPresentFlags | DISPATCH_KEY_PRESENT> dispatchKey(typename Schema::dispatch::dispatch_key_type dispatch_key) && { static_assert(!(FieldsPresentFlags & DISPATCH_KEY_PRESENT), "Tried to define kernel twice in same op registration"); return KernelRegistrationBuilder<OpSchemaDef, FieldsPresentFlags | DISPATCH_KEY_PRESENT>(std::move(kernel_), std::move(dispatch_key)); } |