def backward_gpu(self, x, gy): gx = cuda.empty_like(x[0]) if cudnn.enabled and self.use_cudnn: handle = cudnn.get_default_handle() desc = cudnn.get_tensor_desc(self.y, 1, 1) libcudnn.cudnnActivationBackward(handle, _mode, 1, desc.value, cudnn.get_ptr(self.y), desc.value, cudnn.get_ptr(gy[0]), desc.value, cudnn.get_ptr(x[0]), 0, desc.value, cudnn.get_ptr(gx)) else: cuda.elementwise('float* gx, const float* y, const float* gy', 'gx[i] = gy[i] * y[i] * (1 - y[i])', 'sigmoid_bwd')(gx, self.y, gy[0]) return gx,
def backward_gpu(self, x, gy): gx = cuda.empty_like(x[0]) if cudnn.enabled and self.use_cudnn: handle = cudnn.get_default_handle() desc = cudnn.get_tensor_desc(self.y, 1, 1) libcudnn.cudnnActivationBackward( handle, _mode, 1, desc.value, cudnn.get_ptr(self.y), desc.value, cudnn.get_ptr(gy[0]), desc.value, cudnn.get_ptr(x[0]), 0, desc.value, cudnn.get_ptr(gx)) else: cuda.elementwise( 'float* gx, const float* y, const float* gy', 'gx[i] = gy[i] * y[i] * (1 - y[i])', 'sigmoid_bwd')(gx, self.y, gy[0]) return gx,
def backward_gpu(self, x, gy): gx = cuda.empty_like(x[0]) if cudnn.enabled and self.use_cudnn: handle = cudnn.get_default_handle() desc = cudnn.get_tensor_desc(self.y, 1, 1) libcudnn.cudnnActivationBackward( handle, _mode, 1, desc.value, cudnn.get_ptr(self.y), desc.value, cudnn.get_ptr(gy[0]), desc.value, cudnn.get_ptr(x[0]), 0, desc.value, cudnn.get_ptr(gx), ) else: cuda.elementwise("float* gx, const float* x, const float* gy", "gx[i] = x[i] > 0 ? gy[i] : 0", "relu_bwd")( gx, x[0], gy[0] ) return (gx,)