Segmentation fault in cpp

Hi, I’m trying to use ATen in C++ and often get segmentation faults even for very simple cases as below.

Using pytorch ‘0.4.0a0+da6c3c9’. Compiled with g++, c++11. Linking to libcudart and ATen. NVIDIA 390.48 and Cuda 9.1. On Ubuntu 16.04.

#include "torch/torch.h"

int main()
{
    std::cout << "Hello world!" << std::endl;
    at::Tensor x = at::CUDA(at::kFloat).ones({4,3});  // <-- triggers segfault
    at::Tensor z = at::CPU(at::kFloat).ones({4,3});   // <-- triggers segfault
    at::Tensor y = at::CUDA(at::kFloat).rand({4,3});  // <-- works!
    std::cout << y.size(0) << std::endl;              // <-- triggers segfault
    std::cout << y.add(25) << std::endl;              // <-- works!
    return 0;
}