#pragma once #include #include namespace c10 { namespace detail { // WrapRuntimeKernelFunctor: Wraps any runtime functor into a functor that // inherits from c10::OperatorKernel, so it can be used as a c10 kernel. // This can, for example, be used for lamdas, functors or even function pointers. // In the case of function pointers, since it is a runtime function pointer, // there is an overhead for calling it whenever the kernel is invoked. template class WrapRuntimeKernelFunctor_ {}; template class WrapRuntimeKernelFunctor_> final : public c10::OperatorKernel { public: template explicit WrapRuntimeKernelFunctor_(FuncType_&& kernel_func) : kernel_func_(std::forward(kernel_func)) {} auto operator()(Parameters... args) -> decltype(std::declval()(std::forward(args)...)) { return kernel_func_(std::forward(args)...); } private: FuncType kernel_func_; }; template using WrapRuntimeKernelFunctor = WrapRuntimeKernelFunctor_< FuncType, typename guts::infer_function_traits_t::return_type, typename guts::infer_function_traits_t::parameter_types >; } }