How to get around passing "None" (NoneType) as an argument to functions in cuda.jit?

Take a function where there is an “optional” parameter called weights. if weights is None, then assume equal weights for everything. However, I don’t think cuda.jit handles NoneType, and if weights is a 2D array of float32, I believe it will error if anything other than a 2D array of float32 is passed in as an argument.

One alternative is to initialize it to a small “dummy” array that is a 2D array of float32 and conduct a check to see if weights matches the prespecified dummy array. Does this seem sound? Any other thoughts for how to do this?

You are correct, unfortunately passing None to kernels is not supported in the CUDA target. Your “dummy” array idea seems reasonable - I’d perhaps pass in a dummy array of very small size (e.g. 2x2) then check if the shape matches (2, 2) to see if the dummy array was passed. Alternatively you could pass another argument indicating whether the weights parameter is valid or not.

1 Like