RegisterOperators(RegisterOperators&&) noexcept;
RegisterOperators& operator=(RegisterOperators&&);
-
/**
* Register an operator based on a function schema and a set of configuration
* parameters (i.e. kernel function, dispatch key, ...).
"Invalid argument passed to op(). Examples for valid arguments are c10::kernel(...) for defining a kernel "
" and c10::dispatchKey(...) for defining a dispatch key. Please see the documentation for registering c10 operators.");
- registerOp_(std::move(schema), detail::make_registration_config(std::forward<ConfigParameters>(configParameters)...));
+ op_(std::move(schema), std::forward<ConfigParameters>(configParameters)...);
return std::move(*this);
}
+ template<class FuncType>
+ C10_DEPRECATED_MESSAGE("Registering kernels via passing arguments to RegisterOperators(...) is deprecated. " \
+ "Please use RegisterOperators().op(...) instead.")
+ // enable_if: only enable it if FuncType is actually a function, but not a stack based KernelFunction.
+ explicit RegisterOperators(guts::enable_if_t<guts::is_function_type<FuncType>::value && !std::is_same<FuncType, KernelFunction>::value, FunctionSchema> schema, FuncType* func)
+ : RegisterOperators() {
+ legacyAPIOp_(std::move(schema), func);
+ }
+
+ template<class FuncType>
+ C10_DEPRECATED_MESSAGE("Registering kernels via passing arguments to RegisterOperators(...) is deprecated. " \
+ "Please use RegisterOperators().op(...) instead.")
+ // enable_if: only enable it if FuncType is actually a functor
+ explicit RegisterOperators(guts::enable_if_t<guts::is_functor<FuncType>::value, FunctionSchema> schema, FuncType&& func)
+ : RegisterOperators() {
+ legacyAPIOp_(std::move(schema), std::forward<FuncType>(func));
+ }
+
/**
* Deprecated. For backwards compatibility only.
* Don't use this, it introduces a performance overhead on each kernel call
// and the like to push people towards using the new API.
static_assert(sizeof...(OtherArgs) == 0, "The deprecated function pointer based API to register kernels doesn't allow additional arguments for dispatch keys or other things. Please use the new c10::kernel() based API instead.");
- return std::move(*this).op(std::move(schema), kernel<detail::WrapRuntimeKernelFunctor<FuncType*>>(func));
+ legacyAPIOp_(std::move(schema), func);
+ return std::move(*this);
}
/**
static_assert(!std::is_base_of<OperatorKernel, FuncType>::value, "c10::OperatorKernel is part of the new kernel registration API and shouldn't be used together with the deprecated registration API. Please use the new c10::kernel() based API instead.");
- return std::move(*this).op(std::move(schema), kernel<detail::WrapRuntimeKernelFunctor<FuncType>>(std::forward<FuncType>(func)));
+ legacyAPIOp_(std::move(schema), std::forward<FuncType>(func));
+ return std::move(*this);
}
// TODO allow input schema to be just the operator name + overload name, in that case use schema generated from kernel function
private:
+ template<class... ConfigParameters>
+ void op_(FunctionSchema&& schema, ConfigParameters&&... configParameters) {
+ registerOp_(std::move(schema), detail::make_registration_config(std::forward<ConfigParameters>(configParameters)...));
+ }
+
+ template<class FuncType>
+ void legacyAPIOp_(FunctionSchema&& schema, FuncType&& func) {
+ op_(std::move(schema), kernel<detail::WrapRuntimeKernelFunctor<guts::decay_t<FuncType>>>(std::forward<FuncType>(func)));
+ }
+
void registerOp_(FunctionSchema&& schema, detail::KernelRegistrationConfig&& config);
class OperatorRegistrar;