Rate this Page

Class CppFunction#

Class Documentation#

classCppFunction#

Represents a C++ function that implements an operator.

Most users won’t interact directly with this class, except via error messages: the constructors this function define the set of permissible “function”-like things you can bind via the interface.

This class erases the type of the passed in function, but durably records the type via an inferred schema for the function.

Public Functions

template<typenameFunc>
inlineexplicitCppFunction(Func*f,std::enable_if_t<c10::guts::is_function_type<Func>::value,std::nullptr_t>=nullptr)#

This overload accepts function pointers, e.g.,CppFunction(&add_impl)

template<typenameFuncPtr>
inlineexplicitCppFunction(FuncPtrf,std::enable_if_t<c10::is_compile_time_function_pointer<FuncPtr>::value,std::nullptr_t>=nullptr)#

This overload accepts compile time function pointers, e.g.,CppFunction(TORCH_FN(add_impl))

template<typenameLambda>
inlineexplicitCppFunction(Lambda&&f,std::enable_if_t<c10::guts::is_functor<std::decay_t<Lambda>>::value,std::nullptr_t>=nullptr)#

This overload accepts lambdas, e.g.,CppFunction([](constTensor&self){...

})

~CppFunction()#
CppFunction(constCppFunction&)=delete#
CppFunction&operator=(constCppFunction&)=delete#
CppFunction(CppFunction&&)noexcept=default#
CppFunction&operator=(CppFunction&&)=default#
inlineCppFunction&&debug(std::stringd)&&#

Public Static Functions

staticinlineCppFunctionmakeFallthrough()#

This creates a fallthrough function.

Fallthrough functions immediately redispatch to the next available dispatch key, but are implemented more efficiently than a hand written function done in the same way.

template<c10::BoxedKernel::BoxedKernelFunction*func>
staticinlineCppFunctionmakeFromBoxedFunction()#

Create a function from a boxed kernel function with signaturevoid(constOperatorHandle&,Stack*); i.e., they receive a stack of arguments in a boxed calling convention, rather than in the native C++ calling convention.

Boxed functions are typically only used to register backend fallbacks viatorch::Library::fallback().

template<c10::BoxedKernel::BoxedKernelFunction_withDispatchKeys*func>
staticinlineCppFunctionmakeFromBoxedFunction()#
template<classKernelFunctor>
staticinlineCppFunctionmakeFromBoxedFunctor(std::unique_ptr<KernelFunctor>kernelFunctor)#

Create a function from a boxed kernel functor which definesoperator()(constOperatorHandle&,DispatchKeySet,Stack*) (receiving arguments from boxed calling convention) and inherits fromc10::OperatorKernel.

Unlike makeFromBoxedFunction, functions registered in this way can also carry additional state which is managed by the functor; this is useful if you’re writing an adapter to some other implementation, e.g., a Python callable, which is dynamically associated with the registered kernel.

template<typenameFuncPtr,std::enable_if_t<c10::guts::is_function_type<FuncPtr>::value,std::nullptr_t>=nullptr>
staticinlineCppFunctionmakeFromUnboxedFunction(FuncPtr*f)#

Create a function from an unboxed kernel function.

This is typically used to register common operators.

template<typenameFuncPtr,std::enable_if_t<c10::is_compile_time_function_pointer<FuncPtr>::value,std::nullptr_t>=nullptr>
staticinlineCppFunctionmakeFromUnboxedFunction(FuncPtrf)#

Create a function from a compile time unboxed kernel function pointer.

This is typically used to register common operators. Compile time function pointers can be used to allow the compiler to optimize (e.g. inline) calls to it.