It is working correctly. In the make_thunk, we create a new op if the
values are None (default). Then we call make_thunk on this new op. So it is
the right op that is associated to the thunk/key.

We can't put it in `__init__` as we need to be able to build those ops when
the gpu isn't initialized. The other alternative to make_thunk would be to
do this in an optimization. But as he replicate the same logic that is used
elsewhere, I think we can keep that. If we decide we don't want to continue
to do it like this, we could in another PR change the few ops that do this
to use an opt. But as this work and reuse the same logic as elsewhere, I
don't think we should postpone this PR.

So the other question, why it wasn't an opt? I'm not sure, at some point in
the past, we could have started the gpu optimization and we didn't know
which gpu was used. I think it changed, but I'm not sure. If it changed, I
don't have a preferece for opt vs make_thunk, except I don't want to spend
time on this:) But yes, it would be a fast change to do. We have an opt
that use the do this for the op: GpuAdvancedIncSubtensor1_dev20


On Tue, Mar 11, 2014 at 4:50 PM, abergeron <notifications@github.com> wrote:

> In theano/sandbox/cuda/extra_ops.py:
>
> > +            cuda = theano.sandbox.cuda
> > +            device_id = cuda.use.device_number
> > +            if device_id is None:
> > +                cuda.use("gpu",
> > +                         force=False,
> > +                         default_to_move_computation_to_gpu=False,
> > +                         move_shared_float32_to_gpu=False,
> > +                         enable_cuda=False,
> > +                         test_driver=True)
> > +                device_id = cuda.use.device_number
> > +            cuda_ndarray = theano.sandbox.cuda.cuda_ndarray.cuda_ndarray
> > +            prop = cuda_ndarray.device_properties(device_id)
> > +            node_.op.max_threads_dim0 = prop['maxThreadsDim0']
> > +            node_.op.max_grid_size1 = prop['maxGridSize1']
> > +        return super(GpuCumsum, node_.op).make_thunk(node_, storage_map,
> > +                                                     compute_map, no_recycling)
>
> I know the op is in the key, but the optimizer may also call *eq* and the
> fields won't be set there. So we need to make sure the info is there before
> the call to make_thunk(), which is why I insist on using the constructor.
>
> Apart from this disagreement, I feel the rest is ok.
>
> --
> Reply to this email directly or view it on GitHub<https://github.com/Theano/Theano/pull/1760/files#r10495376>
> .
>