 
 static int cunn_LogSigmoid_updateOutput(lua_State *L)
 {
+  THCState *state = getCutorchState(L);
   THCudaTensor *input = (THCudaTensor*)luaT_checkudata(L, 2, "torch.CudaTensor");
   THCudaTensor *output = (THCudaTensor*)luaT_getfieldcheckudata(L, 1, "output", "torch.CudaTensor");
-  long size = THCudaTensor_nElement(input);
+  long size = THCudaTensor_nElement(state, input);
 
-  input = THCudaTensor_newContiguous(input);
+  input = THCudaTensor_newContiguous(state, input);
 
-  THCudaTensor_resizeAs(output, input);
+  THCudaTensor_resizeAs(state, output, input);
 
-  thrust::device_ptr<float> output_data(THCudaTensor_data(output));
-  thrust::device_ptr<float> input_data(THCudaTensor_data(input));
+  thrust::device_ptr<float> output_data(THCudaTensor_data(state, output));
+  thrust::device_ptr<float> input_data(THCudaTensor_data(state, input));
   thrust::transform(input_data, input_data+size, output_data, logSigmoid_updateOutput_functor());
 
-  THCudaTensor_free(input);
+  THCudaTensor_free(state, input);
   return 1;
 }
 

struct logSigmoid_updateOutput_functor
{
  __host__ __device__ float operator()(const float& input) const


static int cunn_LogSigmoid_updateGradInput(lua_State *L)
{
  THCState *state = getCutorchState(L);
  THCudaTensor *input = (THCudaTensor*)luaT_checkudata(L, 2, "torch.CudaTensor");
  THCudaTensor *gradOutput = (THCudaTensor*)luaT_checkudata(L, 3, "torch.CudaTensor");
  THCudaTensor *gradInput = (THCudaTensor*)luaT_getfieldcheckudata(L, 1, "gradInput", "torch.CudaTensor");
  long size = THCudaTensor_nElement(state, input);

  input = THCudaTensor_newContiguous(state, input);
  gradOutput = THCudaTensor_newContiguous(state, gradOutput);

  THCudaTensor_resizeAs(state, gradInput, input);

  thrust::device_ptr<float> input_data(THCudaTensor_data(state, input));
  thrust::device_ptr<float> gradOutput_data(THCudaTensor_data(state, gradOutput));
  thrust::device_ptr<float> gradInput_data(THCudaTensor_data(state, gradInput));
  thrust::transform(input_data, input_data+size, gradOutput_data, gradInput_data, logSigmoid_updateGradInput_functor());

  THCudaTensor_free(state, input);
  THCudaTensor_free(state, gradOutput);
  return 1;
}

