First I’d recommend using torch::Tensor instead of at::Tensor, as at::Tensor is now an implementation detail and torch::Tensor is the user-facing tensor class.
For the first example, we can try output = output.to(torch::Device(torch::kCUDA, 0)); to see if it works.
For the second example, this will work:
auto options = torch::TensorOptions().dtype(torch::kFloat32).device(torch::kCUDA, 0);
auto output = torch::rand({1, 3, img.rows, img.cols}, options); // maybe cols rows
for(int i = 0; i < img.rows; i++){
    for(int j = 0; j < img.cols; j++){
        output[0][0][i][j] = img.at<cv::Vec3f>(i, j)[0];
        output[0][1][i][j] = img.at<cv::Vec3f>(i, j)[1];
        output[0][2][i][j] = img.at<cv::Vec3f>(i, j)[2];
    }
}
assert(output.device().type() == torch::kCUDA);