sandbox.cuda.var – The Variables for Cuda-allocated arrays

API

class theano.sandbox.cuda.var.CudaNdarraySharedVariable(name, type, value, strict, allow_downcast=None, container=None)

Shared Variable interface to CUDA-allocated arrays.

get_value(borrow=False, return_internal_type=False)

Return the value of this SharedVariable’s internal array.

Parameters:
  • borrow – Permit the return of internal storage, when used in conjunction with return_internal_type=True.
  • return_internal_type – True to return the internal cuda_ndarray instance rather than a numpy.ndarray (Default False).
  • default get_value() copies from the GPU to a numpy.ndarray (By) –
  • returns that host-allocated array. (and) –
  • will return a GPU-allocated copy of the (get_value(False,True)) –
  • GPU array. (original) –
  • will return the original GPU-allocated array (get_value(True,True)) –
  • any copying. (without) –
set_value(value, borrow=False)

Assign value to the GPU-allocated array.

Parameters:borrow (bool) – True permits reusing value itself, False requires that this function copies value into internal storage.

Notes

Prior to Theano 0.3.1, set_value did not work in-place on the GPU. This meant that sometimes, GPU memory for the new value would be allocated before the old memory was released. If you’re running near the limits of GPU memory, this could cause you to run out of GPU memory.

Beginning with Theano 0.3.1, set_value will work in-place on the GPU, if the following conditions are met:

  • The destination on the GPU must be c_contiguous.
  • The source is on the CPU.
  • The old value must have the same dtype as the new value (which is a given for now, since only float32 is supported).
  • The old and new value must have the same shape.
  • The old value is being completely replaced by the new value (not partially modified, e.g. by replacing some subtensor of it).
  • You change the value of the shared variable via set_value, not via the .value accessors. You should not use the .value accessors anyway, since they will soon be deprecated and removed.

It is also worth mentioning that, for efficient transfer to the GPU, Theano will make the new data c_contiguous. This can require an extra copy of the data on the host.

The inplace on gpu memory work when borrow is either True or False.