I am following the PyTorch C FFI examples 157 to build a C extension with CUDA.
When I took the data from CudaTensor as follows, I got a Segmentation fault. Is there any way to access the cuda memory like this and to run the loop (for/while) in parallel in the C extension with CUDA.
#include <THC/THC.h>

extern THCState *state;

int my_lib_add_forward_cuda(THCudaTensor *input, THCudaTensor *output)
{
  float * pinput = THCudaTensor_data(state, input);
  float * poutput = THCudaTensor_data(state, output);
  for(...)
  {
    poutput[i] = do_something(pinput[i]);
  }
  return 1;
}