0

Hello I have a method to pass in a variable, is it possible to do it without puut the method cpu_kernel_trainMe in static ?

class StarPuNet
{
 public:

   void cpu_kernel_trainMe(void *buffers[], void *cl_arg) {}

   int initStarPu() 
   {
     starpu_codelet_init(&cl_);
     cl_.cpu_funcs     [0] = cpu_kernel_trainMe;   //The problem is here
     cl_.cpu_funcs_name[0] = "cpu_kernel_trainMe";
     cl_.nbuffers          = 3;
     cl_.modes         [0] = STARPU_R;
     cl_.modes         [1] = STARPU_R;
     cl_.modes         [2] = STARPU_W;
     cl_.name              = "trainMe";
     return 0;
   };

 private:
   starpu_codelet cl_;
}

The compiler :

In member function ‘int StarPuNet::initStarPu()’:
error: cannot convert ‘StarPuNet::cpu_kernel_trainMe’ from type 
‘void (StarPuNet::)(void**, void*)’ to type ‘starpu_cpu_func_t’ {aka ‘void (*)(void**, void*)’}

I also tried :

cl_.cpu_funcs[0] = void (*cpu_kernel_trainMe)(void **, void *);

The compiler :

error: invalid use of member function ‘void StarPuNet::cpu_kernel_trainMe(void**, void*)’ 
(did you forget the ‘()’ ?)

Here the doc for cpu_funcs

Best regard

Awesome JSF
  • 85
  • 1
  • 8
  • 1
    A pointer to a non-member function is not the same as a pointer to a non-static member function. The difference is that a non-static member function needs an object to be called with. If such an object isn't needed, then use a `static` member function. – Some programmer dude Sep 14 '21 at 15:24
  • 1
    If, on the other hand, you *need* an object (for access to other members, for example) then you might be able to use a `static` wrapper function, which is passed a pointer to the object as some kind of user-data. Then cast this user-data to a pointer to the object and call the actual member function. If the API you use have support for user-data like that I don't know, you have to read its documentation and examples, but the `cl_arg` argument indicate there's some such support. – Some programmer dude Sep 14 '21 at 15:26
  • 1
    This is a C++ FAQ. Search the internet for "C++ FAQ member function pointer. – Thomas Matthews Sep 14 '21 at 17:12

0 Answers0