I am implementing the following function:
template <typename IndexType, typename BinaryType, typename... TupleTypes>
__global__ void apply_predicate_knl(cuda::std::tuple<const TupleTypes*...> data, const IndexType num, bool (*predicate)(cuda::std::tuple<TupleTypes...>), BinaryType* binary_flag)
{
for (IndexType idx = blockIdx.x * blockDim.x + threadIdx.x; idx < num; idx += gridDim.x * blockDim.x)
{
// get the total dimension of the current tuple (sequence)
constexpr size_t num_dim = cuda::std::tuple_size<cuda::std::tuple<const TupleTypes...>>::value;
if (num_dim == 0) // return true if input is empty set
{
binary_flag[idx] = static_cast<BinaryType>(1);
}
else
{
cuda::std::tuple<TupleTypes...> input_object = get_tuple_from_ptr_tuple(data, idx);
binary_flag[idx] = static_cast<BinaryType>(predicate(input_object));
}
}
}
The idea is, to group pointers of an DoA object into a cuda::std::tuple and apply some predicate to each object in the DoA and set 0 or 1 for that object. I am thinking about how to pass in the function pointer bool (*predicate)(cuda::std::tuple<TupleTypes...>). The first thing I thought of is a functor on device, e.g.,
struct predicate_on_tuple
{
__host__ __device__ bool operator()(cuda::std::tuple<uint32_t, uint64_t, uint16_t> input)
{
}
uint32_t some_var;
}
In this case, I am assuming that the functor object has to be created on device then somehow be passed in as a pointer. Is there a better way to do this?