So suppose I have the following, import theano as th import theano.tensor as T
x = th.shared( np.ones( ( 200, 1 ) ) ) y = th.ifelse.ifelse( x.sum()>0, (x+x).max(), x.min() ) Then x.sum() will hopefully be evaluated on the GPU transfered to CPU and then either (x+x).min() or x.max() will happen on the GPU as well. Ok thanks I think i've got that! Still I do see a slowdown if I use the ifelse node. I suspect then that it's because ifelse node acts as a synchroniser between CPU and GPU ( similar to CUDA_LAUNCH_BLOCKING flag) which limits the use of GPU. On Wednesday, 19 April 2017 21:12:24 UTC+3, nouiz wrote: > > It is more efficient then what you describe. > > The condition is evaluate first and is: > - completly evaluated on CPU > - or transfered to the CPU. > > Then we will evaluate one of the two branches depending of the result of > the condition. All those evaluation can be on the GPU. It won't transfer > them to the CPU. > > The only inneficiency is that sometimes, both branches get completly > evaluated. This can be fixed by disabling some other optimization, but this > have its own problem. If you want to try that, use the Theano flag: > optimizer_excluding=inplace > > The other non-efficiency is that if the else branch is taken, we will do a > copy of that value. But the copy should stay on the device device where the > original data is (so CPU or GPU). > > Fred > > On Fri, Mar 24, 2017 at 12:34 PM Šarūnas S. <[email protected] > <javascript:>> wrote: > >> I am using theano version 0.9.0.rc2.dev version. >> >> >> >> >> On Friday, 24 March 2017 17:32:33 UTC+1, Šarūnas S. wrote: >>> >>> In my graph I have a few IfElse nodes and I am wondering how and where >>> they are executed. >>> >>> At first I ran the code with linker=cvm in my THEANO_FLAGS but after >>> profiling it looked like the ifelse is being executed on the CPU. Then I >>> forced the linker=c to check whether the IfElse will go through and I got >>> the NotImplementedError: if{inplace, gpu} cannot produce C code. Btw >>> removing inline optimization did not help as it still gave the same error. >>> >>> So does IfElse have a GPU implementation? If yes how do I use it? Also, >>> does it do lazy evaluation or not? >>> >> -- >> >> --- >> You received this message because you are subscribed to the Google Groups >> "theano-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- --- You received this message because you are subscribed to the Google Groups "theano-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
