1

Does anyone know what the correct syntax for the cuda.jit decorator is if you want to write a device function that returns multiple arrays?

If my device function should return one float and had two integer parameters my decorator would be:

@cuda.jit('float64(int64,int64)', device=True, inline=True)

Now I want my function to take two integer paramters and two floats and return 2 arrays of floats and 2 arrays of integers, all of the same length (between 3 and 5) which depends on the input arguments. How do I do that? Would that be correct:

@cuda.jit(restype=[float64[:], int64[:], float64[:], int64[:]], argtypes=[int64, int64, float64, float64], device=True, inline = True)

Also in my function I would create the arrays I want to return by using: cuda.local.array() Since I use inline=True I would suspect that this will work and the arrays will be only accessable by the respective thread, right?

Escapado
  • 117
  • 2
  • 12

1 Answers1

1

Now I want my function to take two integer parameters and two floats and return 2 arrays of floats and 2 arrays of integers

What you are really saying there is you want your JIT kernel to return a tuple (of two arrays). Unfortunately, in the nopython frontend, I don't believe that is legal. There is no object support in nopython, so you can't instantiate and return a tuple object.

Also in my function I would create the arrays I want to return by using: cuda.local.array()

Unfortunately that isn't supported either. It is only legal to return an array which was passed as an argument to the function.

talonmies
  • 70,661
  • 34
  • 192
  • 269
  • Thank you for your answer! So my only option would be to pass the arrays as arguments beforehand but have several device functions to calculate the entries of those arrays and return one array per device function? – Escapado Nov 02 '15 at 13:25
  • @Escapado: I wouldn't think that would be very advisable, just from an efficiency point of view. Why not return the results in different slices of the same array? – talonmies Nov 02 '15 at 16:35
  • That would probably make more sense. But I figured out a completely different scheme to solve my problem so this doesn't apply more anyway in my code. But you are probably right! – Escapado Nov 03 '15 at 14:19