Theano/Theano — pull request #1208 by viveksck (2013-02-07 23:24:25+00:00)
Title: C code for GPUAdvancedIncSubtensor1.Handles one case to make it faster

The GPU's advanced_inc_subtensor1 op was pretty slow for inputs of the same dimensions.The following optimizes that case. For more context , please see the following thread on theano-users:
[Theano Performance] : GPUAdvancedIncSubtensor1 seems to be pretty slow on the GPU

In the case when x and y have exactly the same dimension and we are not setting (and only incrementing), the following loop is implemented in C:
if y.ndim == x.ndim:
assert len(y) == len(idx)
for (j, i) in enumerate(idx):
x[i] += y[j]

We use the already available APi's: CudaNdarraySubscript and CudaNdArray_inplace_add

Subsequent optimizations can be made incrementally.

Unit test:
(mytheano)vvkulkarni@kant:~/polyglot/snippets$ python sparse.py
Using gpu device 0: GeForce GTX 560
******Testing advanced and sparse indexing***********
Using advanced Indexing
Time for Forward Pass: 0.364514112473
Time for Backward Pass: 0.756240844727
-----------------------------------------------------
Using sparse indexing
Time for Forward Pass: 1.07905602455
Time for Backward Pass: 3.2830221653
[[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
...,
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]
[ 0. 0. 0. ..., 0. 0. 0.]]
Test Passed