Error: ‘synchronize’ is not a member of ‘torch::cuda’

username: Supertom666
cooked: <p>i am using libtorch (1.2),but i can run    std::cout &lt;&lt; “cuda is used:” &lt;&lt; torch::cuda::is_available()  and torch::cuda::cudnn_is_available() . i dont know why can’t  run torch::cuda::synchronize().</p>
<pre><code class="lang-auto">type or paste code here
```int main(int agrc, const char *agrv[]) {
    torch::Tensor tensor = torch::rand({2, 3});
    std::cout &lt;&lt; tensor &lt;&lt; std::endl;
    std::cout &lt;&lt; "cuda is used:" &lt;&lt; torch::cuda::is_available() &lt;&lt; std::endl;
    std::cout &lt;&lt; "cudnn is used:" &lt;&lt; torch::cuda::cudnn_is_available() &lt;&lt; std::endl;
    torch::cuda::synchronize();
    torch::DeviceType device_type;
    device_type = torch::kCUDA;
    torch::Device device(device_type);
    std::cout &lt;&lt; "cuda:" &lt;&lt; device_type &lt;&lt; std::endl;
  
    torch::jit::script::Module module = torch::jit::load("/home/yu/code/model22.pt", device);
      
      // Deserialize the ScriptModule from a file using torch::jit::load().
    std::vector&lt;torch::jit::IValue&gt; inputs;
    //start = clock();
    inputs.push_back(torch::ones({1, 3, 224, 224}).to(device));
    //end =clock();
    //std::cout &lt;&lt; (double)(end-start)/ CLOCKS_PER_SEC &lt;&lt; "seconds" &lt;&lt; std::endl;
  
    std::cout &lt;&lt; "cuda used at:" &lt;&lt; torch::cuda::device_count() &lt;&lt; std::endl;
  
    
      // Exectute the model
    at::Tensor output = module.forward(inputs).toTensor();
  
    std::cout &lt;&lt; output.slice(/*dims=*/1, /*start=*/0, /*end=*/5) &lt;&lt; '\n';
    
    std::cout &lt;&lt; "ok\n";

  
}</code></pre>

username: Supertom666
cooked: <p>i already add<br>
include &lt;torch/torch.h&gt;</p>
<p>//<span class="hashtag">#include</span> &lt;torch/script.h&gt;</p>
<p><span class="hashtag">#include</span> </p>
<p><span class="hashtag">#include</span> </p>
<p><span class="hashtag">#include</span> &lt;ATen/Context.h&gt;</p>
<p><span class="hashtag">#include</span> &lt;torch/script.h&gt;</p>
<p><span class="hashtag">#include</span> &lt;torch/cuda.h&gt;</p>
<p><span class="hashtag">#include</span> </p>
<p><span class="hashtag">#include</span>  but still not work.</p>
<pre><code class="lang-auto">type or paste code here
```/home/yuy/code/test12/pytorch/example-app/example-app.cpp: In function ‘int main(int, const char**)’:
/home/yu/code/test12/pytorch/example-app/example-app.cpp:29:16: error: ‘synchronize’ is not a member of ‘torch::cuda’
   torch::cuda::synchronize();
                ^~~~~~~~~~~
CMakeFiles/example-app.dir/build.make:62: recipe for target 'CMakeFiles/example-app.dir/example-app.cpp.o' failed
make[2]: *** [CMakeFiles/example-app.dir/example-app.cpp.o] Error 1
CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/example-app.dir/all' failed
make[1]: *** [CMakeFiles/example-app.dir/all] Error 2
Makefile:83: recipe for ta</code></pre>

username: ptrblck
cooked: <p>If you have trouble using this op you could try <code>at::detail::getCUDAHooks().deviceSynchronize(device_index);</code> or</p>
<pre><code class="lang-auto">CUDAStream stream = getCurrentCUDAStream();
AT_CUDA_CHECK(cudaStreamSynchronize(stream));
</code></pre>
<p>instead.</p>