hughperkins / DeepCL

OpenCL library to train deep convolutional neural networks
Mozilla Public License 2.0
867 stars 199 forks source link

Replace the #defines in some of the opencl cl files with inline method calls #8

Closed hughperkins closed 9 years ago

hughperkins commented 9 years ago

Whoever does this would ideally need to benchmark before and after, on a fairly standard gpu, to check that the change doesnt in fact cause a speed reduction.

hughperkins commented 9 years ago

Changed my mind about doing this. I think some of the macros are actually quite more readable than removing them, eg propagate4.cl:

                #if gPadZeros == 1
                    #define inputRow ( outputRow + u )
                #else
                    #define inputRow ( outputRow + u + gHalfFilterSize )
                #endif
                int inputimagerowoffset = inputRow * gInputImageSize;
                int filterrowoffset = (u+gHalfFilterSize) * gFilterSize + gHalfFilterSize;
                bool rowOk = inputRow >= 0 && inputRow < gInputImageSize;
                for( int v = -gHalfFilterSize; v <= gHalfFilterSize - gEven; v++ ) {
                    #if gPadZeros == 1
                        #define inputCol ( outputCol + v )
                    #else
                        #define inputCol ( outputCol + v + gHalfFilterSize )
                    #endif
                    bool process = rowOk && inputCol >= 0 && inputCol < gInputImageSize;
                    if( process ) {
                            sum += _upstreamImage[ inputimagerowoffset + inputCol] * _filterCube[ filterrowoffset + v ];