mardi 28 juin 2016

Passing a function pointer and its parameters as a thrust::tuple to a global function


I want to do the following:

#include <thrust/tuple.h>
#include <tuple>

template<typename... Args>
void someFunction(void (*fp)(Args...), thrust::tuple<Args...> params) {
}

void otherFunction(int n) {
}

int main(int argc, char **argv) {
    //// template argument deduction/substitution failed ////
    someFunction<int>(&otherFunction, thrust::make_tuple(1));
    return 0;
}

What I have tried:

  1. Removing one of the two parameter leads to a working solution of course.
  2. It works when I make someFunction a static function in a struct with template parameter. But in the original code someFunction is a CUDA kernel, so I can't do that. Any further ideas?
  3. It works when I change thrust::tuple to std::tuple. Is there a way to construct a thrust::tuple out of a std::tuple?

EDIT:

To make it clearer: someFunction and otherFunction are __global__!

#include <thrust/tuple.h>
#include <tuple>

template<typename... Args>
__global__ void someFunction(void (*fp)(Args...), thrust::tuple<Args...> params) {
}

__global__ void otherFunction(int n) {
}
__constant__ void (*kfp)(int) = &otherFunction;

int testPassMain(int argc, char **argv) {
    void (*h_kfp)(int);
    cudaMemcpyFromSymbol(&h_kfp, kfp, sizeof(void *), 0, cudaMemcpyDeviceToHost);
    someFunction<int><<<1,1>>>(h_kfp, thrust::make_tuple(1));
    return 0;
}

I get a compiler error: template argument deduction/substitution failed in both examples.


Aucun commentaire:

Enregistrer un commentaire