Tensorflow: switch between CPU and GPU [Windows 10] - python-3.x

How can I quickly switch between running tensorflow code with my CPU and my GPU?
My setup:
OS = Windows 10
Python = 3.5
Tensorflow-gpu = 1.0.0
CUDA = 8.0.61
cuDNN = 5.1
I saw a post suggesting something about setting CUDA_VISIBLE_DEVICES=0 but I don't have this variable in my environment (not sure if it's because I'm running windows or what) but if I do set it using something like os.environ it doesn't effect how tensorflow runs code.

If you set the environment variable CUDA_VISIBLE_DEVICES=-1 you will use the CPU only. If you don't set that environment variable you will allocate memory to all GPUs but by default only use GPU 0. You can also set it to the specific GPU you want to use. CUDA_VISIBLE_DEVICES=0 will only use GPU 0.
This environment variable is created by the user, it won't exist until you create it. You need to set the variable before tensorflow is imported (usually that is before you start your script).

Related

why `local_rank` is zero in DDP even I set visible CUDA as 2?

There are 3 GPUs in my system.
I want to run on the last one i.e. 2. For this reason, I set gpu_id as 2 in my configuration file as well as CUDA_VISIBLE_DEVICES=2. But in my program, the following line always assigns the 0th GPU.
local_rank = torch.distributed.get_rank()
torch.cuda.set_device(local_rank)
How to fix this issue?
When setting CUDA_VISIBLE_DEVICES=2 you tell the OS to only expose the third GPU to your process. That is, as far as PyTorch is concerned, there is only one GPU. Therefore torch.distributed.get_world_size() returns 1 (and not 3).
The rank of this GPU, in your process, will be 0 - since there are no other GPUs available for the process. But as far as the OS is concerned - all processing are done on the third GPU that was allocated to the job.

Issue Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

I met this issue when I running my python file in linux.
I searched some answers in google like use the code below:
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
The system can be running but without ant out information. Actually I found the 2 measn ignore all information while 1 means give all information like error or normal output.
because I need to use GPU so my original code is:
os.environ["CUDA_VISIBLE_DEVICES"]="0"
But if I keep the code my output would be an error information like the title.
How can I do? and of course I need use the GPU and the codes can be running in colab which indicated that my code has no problem.
some guys even said uninstall tensorboard...that must a wrong way.
Or should I download tensorflow gpu not tensorflow in m,y virtual enviroment? when I USE THE tensorflow gpu version, the error is core dumped.
If when forcing the os.environ["CUDA_VISIBLE_DEVICES"]="0" doesn't work, then this means that your tensorflow gpu installation did not succeed. You must ensure you have the right combination of TensorFlow + CUDA + CUDNN. That is why you get the error, because due to improper versions/installation TF falls back on CPU.

Limit Tensorflow GPU memory usage via environmental variable

I am using a C++ library that internally uses Tensorflow, so I do not have access to session parameters.
When Tensorflow session is created one can limit GPU memory usage by setting per_process_gpu_memory_fraction value and allow growth flag (example in Python):
memory_config = tf.ConfigProto(gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.3))
memory_config.gpu_options.allow_growth=True
It is also possible to set global value for allow growth using environmental variable that will be used if this option is not specified in the tf.ConfigProto: export TF_FORCE_GPU_ALLOW_GROWTH=true in linux shell.
I wonder if there's an environmental variable for setting per_process_gpu_memory_fraction globally?

how to get full cpu utilization from MXNET in mac os x ?

We are playing mxnet for a while. still couldnt get full cpu utilization as we have in tensorflow in default.
we have:
python 3.6
mxnet 1.2.1 pos1
mxnet-mkl 1.2.1 pos1
installed via pip (in Pycharm).
mac os x Sierra 10.12.6
we have only 2 core of the cpu used out of the 8 cores.
Thanks
MXNET has a number of environment variables that determine the thread count. Try increasing MXNET_CPU_WORKER_NTHREADS. (The default value is 1.)
For more information:
MXNET: Environment variables
MXNET: Some tips for improving MXNET performance

Theano Installation On windows 64

Im new in Python and Theano library. I want to install Theano on windows 7-64. I have a display adapters :
Intel(R) HD Graphics 3000 which is not compatible with NVIDA.
My QUESTIONS:
1-Is obligatory to install CUDA to i can use Theano?
2- Even if i have an Ubuntu opearting system, with the same display adapters, CUDA still mandatory?
Any help!
Thanks
You do not need CUDA to run Theano.
Theano can run on either CPU or GPU. If you want to run on GPU you must (currently) use CUDA which means you must be using a NVIDIA display adapter. Without CUDA/NVIDIA you must run on CPU.
There is no disadvantage to running on CPU other than speed -- Theano can be much faster on GPU but everything that runs on a GPU will also run on a CPU as long as it has been coded generically (the default and standard method for Theano code).

Resources