koba-jon / pytorch_cpp

Deep Learning sample programs using PyTorch in C++
MIT License
241 stars 52 forks source link

AE2d test() throws exception on non-GPU environment #21

Closed wagavulin closed 2 years ago

wagavulin commented 2 years ago

Hello. I tried to run test.sh of Dimensionality_Reduction/AE2d on my PC which doesn't have GPU, but failed with the below error message.

terminate called after throwing an instance of 'c10::Error'
  what():  No CUDA GPUs are available

It's because test() in AE2d/test.cpp calls torch::cuda::synchronize() regardless of device type. I think it should be called only on GPU environment. For example:

        if (!device.is_cpu()) torch::cuda::synchronize();
koba-jon commented 2 years ago

Thank you for reporting the bug and solution. I changed the source code and confirmed that it works normally.

I reflected it in master branch, and the modified code was archived as support/v1.10.1. https://github.com/koba-jon/pytorch_cpp/tree/support/v1.10.1

Thank you so much!