"switch" like functionality on GPUarray
Show older comments
I am running code that involves a Markov chain process, and I would like to implement it so that 10,000+ such transitions can be simultaneously performed on the GPUarray.
Basically my Markov chain involves 8 states, but could involve an arbitrary number, with arbitrary couplings/transitions. What I'd really like to do is use arrayfun, and have the code describing transition probabilities be contained in a standard switch statement (not currently supported on GPU). Some generalized code is below:
function newstate=junk(oldstate)
switch(oldstate)
case 1
if (condition1, determined partially by a random number)
newstate=6
if (condition2, determined partially by a random number)
newstate=4
case 2
....
case 8
...
return
and then store "oldstates" on the GPU, and call: newstates=arrayfun(@junk, oldstates);
I guess I am wondering if there is a more elegant way to do this than to do serial if and if-else statements in my "junk" function that is passed to arrayfun. If I am way off on this, please let me know a better way.
1 Comment
Adam
on 5 Feb 2016
I'm far from an expert in GPU programming, but from what I know you really don't want to be executing switch-type functionality on a GPU even if it were supported. GPU cores are highly optimised for doing mass parallel calculations with each core running effectively the same code but on different input data, but not for decision trees that fork code off onto one of numerous paths which would cause each core to be running different code at any given moment.
Accepted Answer
More Answers (0)
Categories
Find more on GPU Computing in MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!