Skip to content

SpatialConvolutionMM cuda/cpu interoperability broken #211

@mys007

Description

@mys007

There are two caches in SpatialConvolutionMM: fgradInput and finput. The problem is that they are used in a different way in the 'nn' and 'cunn' C-implementations. Specifically, the cunn-implementation expects to find 1s in fgradInput while the nn-implementation stores arbitrary data in it. Thus, converting the module from CPU to CUDA makes it produce garbage in a very evil way because nothing crashes. For example

require 'nn'
require 'cunn'
require 'cutorch'

torch.setdefaulttensortype('torch.FloatTensor')

T = torch.Tensor(10,10,10):zero()
M = nn.SpatialConvolutionMM(10,1,5,5,1,1,0)

F = M:forward(T)
M:backward(T,F)

--M.fgradInput = torch.Tensor()   --UNCOMMENT ME TO FIX THIS

M=M:cuda()
C = M(T:cuda())

assert(math.abs( torch.norm(F:cuda()-C)) < 1e-5)

The proposed fix is to clear the caches at type conversion:

function SpatialConvolutionMM:type(type)
   self.finput = torch.Tensor()
   self.fgradInput = torch.Tensor()
   return parent.type(self,type)
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions