Thanks for the hint. Matrix multiplication with preallocated tensor can be done like this:
  torch::Tensor m = torch::rand({size, size});
  torch::Tensor v = torch::rand({size, 1});
  torch::Tensor r = torch::rand({size, 1});
  mm_out(r, m, v);