What is the simplest way to check if my code is ru...
# kotlindl
m
What is the simplest way to check if my code is running on GPU. In python I would have something like this
Copy code
def gpu_is_available():
    """
    Returns True if Tensorflow is installed and uses GPU
    """
    return tf.test.is_gpu_available()
m
cc @zaleslaw
z
It's a good question. Unfortunately this API is not available on Java TF side. Personally, I used output in console to understand what device is used and what libraries are loaded (mean CUDA libraries). For instance,
Copy code
2020-12-09 21:09:10.748923: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2020-12-09 21:09:10.817212: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
2020-12-09 21:09:10.826129: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
2020-12-09 21:09:11.097180: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1618] Found device 0 with properties: 
name: GeForce GTX 1650 major: 7 minor: 5 memoryClockRate(GHz): 1.56
pciBusID: 0000:01:00.0
2020-12-09 21:09:11.097211: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_100.dll
2020-12-09 21:09:11.328995: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cublas64_100.dll
2020-12-09 21:09:11.558253: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cufft64_100.dll
2020-12-09 21:09:11.586795: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library curand64_100.dll
2020-12-09 21:09:11.846481: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusolver64_100.dll
2020-12-09 21:09:12.065723: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cusparse64_100.dll
2020-12-09 21:09:12.352519: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudnn64_7.dll
2020-12-09 21:09:12.352603: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1746] Adding visible gpu devices: 0
2020-12-09 21:09:12.904036: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1159] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-12-09 21:09:12.904053: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1165]      0 
2020-12-09 21:09:12.904057: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1178] 0:   N 
2020-12-09 21:09:12.904244: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1304] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 2917 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1650, pci bus id: 0000:01:00.0, compute capability: 7.5)
P.S. also I commited an option to specify the device to execute TF operand like deviceSpec in Python. Hope it will be available in the next releases. https://github.com/tensorflow/java/pull/159
@Michal Harakal I suppose it looks like a good feature request, if you have any questions related to device topic and could share some thoughts it will be grateful
m
@zaleslaw I happened already multiple times in my not so long DS experience, that either colab switched back to the CPU for reasons or PyCharm venv was not set properly so training ran on CPU. If you are having your doubts about changed hyper parameters or whatever, its a confusing experience. So my learning is to have simple assertion on start, that a code is running on GPU otherwise throws error. Regarding general ideas about devices capabilities is quite hard. I have to learn and play around with this project first, because I know this project just since today and exploring it. The idea with scopes from the TF PR sounds somehow familiar to me. Where did I see the last time. Yeah coroutines 😉