вторник, 16 ноември 2021 г.

Enable grub on manjaro

 For unknown reasons, someone decided that GRUB should be hidden by default. Because of course, why would you need to see your previous kernels or other OS. Anyway, to recover it:

$nano  /etc/default/grub

Change:

GRUB_TIMEOUT=5
GRUB_TIMEOUT_STYLE=hidden

 to "menu"

GRUB_TIMEOUT=5
GRUB_TIMEOUT_STYLE=menu

$sudo update-grub

or alternatively:

sudo grub-mkconfig -o /boot/grub/grub.cfg

And reboot and there it is. Now the next question is what did they do to xanmod kernel (5.13.19) that it can no longer Hibernate properly. Good news is that I installed it rather easily from Aur, bad news, I'm not sure it was worth it. Previous xanmod was pure iron, it lasted for something like 90 days without restart, during which I flew a number of times, so it was hibernated at least then. And it worked great. Yesterday I hibernated and the laptop simply couldn't wake up. Oh well. Old problems, new iteration. I really don't get WTF with hibernation on Linux. On Sabayon it used to work great. On manjaro, it sometimes works, mostly doesn't.


понеделник, 26 април 2021 г.

error: cuda_runtime.h: No such file or directory

 

export CPATH=/opt/cuda/targets/x86_64-linux/include:$CPATH
export LD_LIBRARY_PATH=/opt/cuda/targets/x86_64-linux/lib:$LD_LIBRARY_PATH
export PATH=/opt/cuda/bin:$PATH     
source

вторник, 9 март 2021 г.

How to send files over ssh

To send a file over ssh from your computer to a server, you use the following command

 rsync -avc local/path/to/file user@server:path/on/server

Where you shouldn't be connected with ssh (it's gonna ask you for your password).

It seems silly to do it like this, but for some reasons, my Dolphin doesn't like to connect with network places. So I have to do everything from konsole.

петък, 12 февруари 2021 г.

PyTorch and TensorFlow don't find cuda after wake up

So this seems to be a bug. After suspend, nvidia works (i.e. $optirun glxshperes works fine), yet, torch.cuda.is_available() gives "False". 

So there are two things one could do: 1) restart 2) To try to reload nvidia and company. 

The second should be done carefully, as I froze my PC once and had to restart anyway. So you have to do (source): 

sudo rmmod nvidia_uvm
sudo rmmod nvidia_drm
sudo rmmod nvidia_modeset
sudo rmmod nvidia
sudo modprobe nvidia
sudo modprobe nvidia_modeset
sudo modprobe nvidia_drm
sudo modprobe nvidia_uvm
 
Another way to try is to use to "modprobe -r" resolve the dependency issues. 
You could find what is in use with (source):
lsmod | grep nvidia
sudo modprobe -r <module found from lsmod> <module you want to remove> 
  
A good practice obviously is to stop your Jupyter nootebook before suspending which they claim would release the nvidia driver but I still have to try this.

четвъртък, 11 февруари 2021 г.

How to enable GPU in tensorflow

Fist, you have to have CUDA installed. That was not obvious as it comes with: 

$sudo equo install nvidia-cuda-toolkit

So after we install the nvidia-cuda-toolkit, we have to tell Linux, where the CUDA bin and libs are: 

$nano /home/$USER/.bashrc
Add the following lines:
export PATH="/usr/local/cuda-8.0/bin:$PATH"
export LD_LIBRARY_PATH="/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH"

In my case, cuda is located in /opt/cuda so that replaces /usr/local/cuda. Save file.

$source /home/$USER/.bashrc

Now, you have nvcc. source 

We can test if it works with this simple code. (see comment Compile and run a CUDA hello world)

Also you can do

$nvcc -V 

to see the version and everything.

I think at some point I did:

export CUDA_VISIBLE_DEVICES=1

but then I added it to my notebook as: 

import os
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
os.environ["CUDA_VISIBLE_DEVICES"] = "0"

Now for the fun part, it seems that TensorFlow requires not only cuda, but CudaNN. Which doesn't come with cuda-toolkit but has to be downloaded independently from Nvidia's website https://developer.nvidia.com/cudnn).After registration and a survey and a warning for ethical use of AI (WTF?). The installation is very simple. You download the tar file and then you do:

  1. $ sudo cp cuda/include/cudnn*.h /opt/cuda/include 
    $ sudo cp -P cuda/lib64/libcudnn* /opt/cuda/lib64 
    $ sudo chmod a+r /opt/cuda/include/cudnn*.h /opt/cuda/lib64/libcudnn*
    

where /opt/cuda is the path to my cuda installation, but it may also be in /usr/local/cuda. And you have to do that from Downloads i.e. from outside of the folder where you untarred your file. And that's it, tensorflow works with GPU. 



Also to test it, you can use:

import tensorflow as tf
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
with tf.device('/gpu:0'):
    a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
    b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
    c = tf.matmul(a, b)

with tf.Session() as sess:
    print (sess.run(c))


Another way to test cuda with tensorflow is:


python3 -c "import tensorflow as tf;import os; os.environ['TF_XLA_FLAGS'] = '--tf_xla_enable_xla_devices';print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

 

or just :

python3 -c "import tensorflow as tf;print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
 



събота, 16 януари 2021 г.

How to enable cuda in python with optirun

Today I wanted to try fast.ai notebooks. The require cuda, which obviously wasn't enabled on my python. To do that I had to search with kfind for kernel.json, because of course they weren't in the place they were supposed to be (~/.local/share/jupyter/kernels/) source and also here. I found two json files, so I started with the first one, which was sufficient (it seems).

So to enable Nvidia with optirun, you have to edit: 

~/anaconda3/share/jupyter/kernels/python3/kernel.json 

to add on the first line: 

 "optirun",

so that it becomes:

"argv": [
  "optirun",


The other json I found was this: ~/anaconda3/pkgs/ipykernel-5.1.4-py37h39e3cac_0/share/jupyter/kernels/python3/ but since the first one worked, I didn't edit this one and all is fine so far.

Also, in case you wonder how to enable the cool diagrams in the notebooks, you first have to install pygraphviz, which took some efforts from my side:

sudo equo install pygraphviz

python3.7 -m pip install graphviz --user  

conda install -c alubbock pygraphviz 

 python3.7 -m pip install pygraphviz --user

And then in the notebook, add:

import graphviz
def gv(s): return graphviz.Source('digraph G{ rankdir="LR"' + s + '; }')

and then you get the cool diagrams.