How to get result type of device lambda

auto fun = device(int i)->float{
return
}

fun is a cuda lambda, how can I use type traits get its result type and argument type.

#include <tuple>

template <typename T>
struct function_traits
	: public function_traits<decltype(&T::operator())>
{
	typedef double type;
};


template <typename _ClassType, typename _ReturnType, typename... _Args>
struct function_traits<_ReturnType(_ClassType::*)(_Args...) const> {
	enum { arguments_size = sizeof...(_Args) };

	typedef _ReturnType result_type;

	template <size_t _index>
	struct arguments
	{
		typedef typename std::tuple_element<_index, std::tuple<_Args...>>::type type;
		// the i-th argument is equivalent to the i-th tuple element of a tuple
		// composed of those arguments.
	};
};

int main() {

	//auto fun = [] __host__ __device__(int i)->float {
	//	return 3.0f;
	//}; compile OK!

	auto fun = [] __device__(int i)->float {
		return 3.0f;
	}; // compile Error!

	auto size = function_traits<decltype(fun)>::arguments_size;

}

Ignoring the complexity added by lambdas, you can’t take the address of a device function inside the body of a host function. Your host device version works because that’s defining two functions, a host and a device one, and its taking the pointer of the (accessable) host one.

You can store a device function pointer in a statically defined device variable, but that has to be declared outside of your main() host code. But… upon trying this, I get an error " dynamic initialization is not supported for device, constant and shared variables.", so it seems as if static device pointers aren’t supported for lambdas. The CUDA documentation is vague on the device static variable requirements in that it doesn’t mention lambdas.