skip to Main Content

I have installed tensorflow and the required dependencies for GPU support for Ubuntu 22.04 as mentioned in https://www.tensorflow.org/install/pip.

I tested that the GPU was detected as mentioned in the above tutorial and it detected my Nvidia GTX 1060. But if I try to run tensorflow on GPU in VSCode, the GPU is not detected.

I have a python script test-tf.py with the following code:

import tensorflow as tf
print(tf.config.list_physical_devices('GPU'))

When I run this, I get the following:

[PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

When I run the same code in a .ipynb file in VSCode, I get:

[]
2022-12-27 18:59:38.079947: I tensorflow/compiler/xla/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2022-12-27 18:59:38.080624: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080767: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublas.so.11'; dlerror: libcublas.so.11: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080843: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcublasLt.so.11'; dlerror: libcublasLt.so.11: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080894: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcufft.so.10'; dlerror: libcufft.so.10: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080940: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcurand.so.10'; dlerror: libcurand.so.10: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.080986: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusolver.so.11'; dlerror: libcusolver.so.11: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.081032: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcusparse.so.11'; dlerror: libcusparse.so.11: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.081076: W tensorflow/compiler/xla/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudnn.so.8'; dlerror: libcudnn.so.8: cannot open shared object file: No such file or directory
2022-12-27 18:59:38.081087: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1934] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...

If I run the same .ipynb file using Jupyter Notebook, the GPU is detected as expected. It is not detected only when using the notebook from VSCode. I have made sure to use the proper conda environment.

2

Answers


  1. Chosen as BEST ANSWER

    As mentioned by @TFer2 in the comments to the question, you need to open VSCode from the conda environment and add "terminal.integrated.inheritEnv": false to the user settings.json for tensorflow-gpu to work with .ipynb files.


  2. same problem occured to me but doing following solved my problem

    go to terminal tab in vscode-> click on new terminal

    In bottom left click on drop down button near ‘+’ sign and click on ‘set default profile’ and select ‘Command Prompt’.

    now run the code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search