How do I take poisson draws with poissrnd() using GPU resources via arrayfun?

1 view (last 30 days)
Michael Norton
Michael Norton on 21 Jun 2020
Answered: Joss Knight on 28 Jun 2020
Everything works as expected; however, I need to model a different stochastic process.
When I swap out "randn()" for "poissrnd(1)" (the argument does not matter), I get the following error:
"Error using call_test (line 89)
Variable number of inputs is not supported.
For more information see Tips.
Error in 'poissrnd' (line: 1)"
How do I modify my poisson draw to avoid this error? Is there another function I should use instead?
"poissrnd" is listed as supported, so I imagine I'm just using it incorrectly, but I haven't found a GPU-specific use case example: https://www.mathworks.com/help/stats/referencelist.html?type=function&capability=gpuarrays
I've also tried using "random('Poisson',0.1,1,1)" but then the different error:
"Character arrays are not supported.
For more information see Tips."
I don't think this is a hardware/cuda issue, but here is the result of "gpuDevice" in case it is helpful.
CUDADevice with properties:
Name: 'TITAN RTX'
Index: 1
ComputeCapability: '7.5'
SupportsDouble: 1
DriverVersion: 10.2000
ToolkitVersion: 10.1000
MaxThreadsPerBlock: 1024
MaxShmemPerBlock: 49152
MaxThreadBlockSize: [1024 1024 64]
MaxGridSize: [2.1475e+09 65535 65535]
SIMDWidth: 32
TotalMemory: 2.5394e+10
AvailableMemory: 2.3413e+10
MultiprocessorCount: 72
ClockRateKHz: 1770000
ComputeMode: 'Default'
GPUOverlapsTransfers: 1
KernelExecutionTimeout: 1
CanMapHostMemory: 1
DeviceSupported: 1
DeviceSelected: 1

Answers (1)

Joss Knight
Joss Knight on 28 Jun 2020
As you can see from the documentation, poissrnd is not a function that is support by the FUN argument of gpuArray/arrayfun. You are seeing this error because the poissrnd function is implemented in MATLAB code and so arrayfun is trying to flow through and execute the code as a sub-function. However, poissrnd uses varargin, which isn't supported by gpuArray/arrayfun's support for sub-functions.
You could try taking a copy of the poissrnd code and seeing if you can modify it to remove the limitations.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!