Run python code on specific gpu for lower python versions - python

I am trying to run a python code on a specific GPU on our server. The server has four GPUs. When I run the code using a virtual environment installed with python 3.8 and tensorflow 2.2, it works correctly on the specific GPU just by adding the below few lines at the first of the script.
import os
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "2"
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "2" # run the code on a specified GPU
Many threads recommend use the above code to run python scripts on a specific GPU such as here and here.
However, When I tried to use the same way to run another python code on another virtual environment (with lower specifications) that was installed with python version 3.6.9 and tensorflow 1.12, it does not run on the GPU but on the CPU.
How can I run python code on a specific GPU in the case of the second virtual environment?

You can use export CUDA_VISIBLE_DEVICES to define which GPUs are visible to the application. For example, if you want GPUs 0 and 2 visible, use export CUDA_VISIBLE_DEVICES=0,2.

Related

Issues with flask in Windows PowerShell

I use Windows PowerShell to install flask but when I execute python app.py I get this error
C:\Users\User\Desktop\flask\Deployed Model> python app.py
Using TensorFlow backend.
2020-06-01 12:36:45.548048: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
Model loaded. Start serving...
Can anyone help me with this error? I installed all the libraries in Windows PowerShell and I also installed tensorflow==2.0
Since I cannot comment I'm writing this answer instead.
It seems like you don't have a GPU installed on your PC and if its true then you need to compile tensorflow binary for use.
This warning is specific to your CPU and it tells that your CPU dosen't support AVX2.
But if you have a GPU then simply disable the warning using
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'

How to prevent specific GPU to be used in Python code

My this problem is same as 1: How to set specific gpu in tensorflow?
but it didn't solve my problem.
I have 4 GPUs in my PC and I want to run code on GPU 0 but whenever I run my tensorflow code, my code is always running only on GPU 2. As reading these (2, 3, 4) solutions and information I tried to solve my problem by adding:
os.environ['CUDA_VISIBLE_DEVICES']= '0' in python code
orCUDA_VISIBLE_DEVICES as environment variable in PyCharm project configuration settings.
furthermore I also add CUDA_LAUNCH_BLOCKING=2in code or environment variable to block the GPU 2. Is it right way to block any GPU?
Above solutions are not working for me. Code is always running on GPU 2. I checked it by watch nvidia-smi.
My system environment is
Ubuntu 16.04
RTX2080Ti (all 4 GPUs)
Driver version 418.74
CUDA 9.0 and CuDNN 7.5
Tensorflow-gpu 1.9.0
Any suggestions for this problem? It's wired that adding environment variable in project settings in PyCharm or in python code... still only GPU 2 is visible. When I remove CUDA_VISIBLE_DEVICESthen tensorflow detects all 4 GPUs but code run on only GPU 2.
I tried this in tensorflow 2.0.0
physical_devices = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_visible_devices(physical_devices[0], 'GPU')
logical_devices = tf.config.experimental.list_logical_devices('GPU')
This should make u r code run in GPU index 0

Specifying the GPU ID using tensorflow backend

I am trying to train the two different models using GPU ID.
I have tried the command CUDA_VISIBLE_DEVICES=1 python filename.py but it picks up the GPU 0 rather than 1.
I also added the os environment variable in my code, but I got the same behavior.
I am not sure how can I fix this as this is first time to use GPU.

Is it possible to run tensorflow-gpu on a computer without a GPU or CUDA?

I have two Windows computers, one with and one without a GPU.
I would like to deploy the same python script on both (TensorFlow 1.8 Object Detection), without changing the packaged version of TensorFlow. In other words, I want to run tensorflow-gpu on a CPU.
In the event where my script cannot detect nvcuda.dll, I've tried using a Session config to disable the GPU, like so:
config = tf.ConfigProto(
device_count = {'GPU': 0}
)
and:
with tf.Session(graph=detection_graph, config=config) as sess:
However, this is not sufficient, as TensorFlow still returns the error:
ImportError: Could not find 'nvcuda.dll'. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable.
Typically it is installed in 'C:\Windows\System32'. If it is not present, ensure that you have a CUDA-capable GPU with the correct driver installed.
Is there any way to disable checking for a GPU/CUDA entirely and default to CPU?
EDIT: I have read the year-old answer regarding tensorflow-gpu==1.0 on Linux posted here, which suggests this is impossible. I'm interested to know if this is still how tensorflow-gpu is compiled, 9 versions later.

Tensorflow GPU doesn't work in Pycharm

When i'm running my tensorflow training module in pycharm IDE in Ubuntu 16.04, it doesn't show any training with GPU and it trains usually with CPU. But When i run the same python script using terminal it runs using GPU training. I want to know how to configure GPU training in Pycharm IDE.
Actually the problem was, the python environment for the pycharm project is not the same as which is in run configurations. This issue was fixed by changing the environment in run configurations.

Categories

Resources