Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Sunday, November 10, 2019

Window's subLinux (WSL)

https://www.tegakari.net/en/2020/08/windows-subsystem-for-linux-2wsl2_vol1/

I. Install WSL on Windows

https://docs.microsoft.com/en-us/windows/wsl/install-win10
There are 2 versions: Comparing WSL 2 and WSL 1. Should use WSL 2 for better performance.

a. Prepare
# Enable both the Windows Subsystem for Linux and the Virtual Machine Platform optional components.
Open PowerShell as an admin and run the following script: (After the script is complete, you need to reboot your machine, since this enables new Windows features.)
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart
dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

# Download & Install the Linux kernel update package
# Set WSL 2 as your default version: in Powershell
wsl --set-default-version 2

b. Installing WSL: 
# using Microsoft Store
go to: https://aka.ms/wslstore
and intsall a Linux shell
# not use Microsoft Store 
https://docs.microsoft.com/en-us/windows/wsl/install-manual
download: Ubuntu_2004.2020.424.0_x64.appx
in powerShell: Add-AppxPackage .\Ubuntu_2004.2020.424.0_x64.appx


c. Create a Unix Account
Open up a Command Prompt and run the following command:  > bash 

d. Location
on Window 10, "~home/user" directory locates at : 
## for WSL1
%localappdata%\lxss\home\{username}
C:\Users\{user}\AppData\Local\lxss\{username}
## for WSL2
\\wsl$\Ubuntu-20.04\home\{username}

## Hard drives: cd  /mnt/d/work/



II. Work on WSL

# Login root as default
open cmd:   ubuntu config --default-user root

# Update Ubuntu: sudo apt update && apt upgrade

# delete folder/file
sudo -r -f \folder

# install GCC
sudo apt-get install gcc-10 g++-10 gfortran-10

# install python
# check:   python --version
## set isntall python3 as default (similar for python2, )
sudo apt install python-is-python3 python-dev python3-dev

1. Insall Modules
sudo apt-get install tcl environment-modules

2. install cuda
2a. Install NVIDIA driver for WSL2
https://docs.nvidia.com/cuda/wsl-user-guide/index.html
460.20_gameready_win10-dch_64bit_international.exe

Note: Do not install any Linux display driver in WSL. The Windows Display Driver will install both the regular driver components for native Windows and for WSL support.

2b. Install cuda-toolkit for WSL2
https://docs.nvidia.com/cuda/wsl-user-guide/index.html
# Launch Ubuntu terminal

# First, set up the CUDA network repository. 

sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo sh -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
sudo apt-get update
# Now install CUDA. Note that for WSL 2, you should use the cuda-toolkit-<version>
#(Do not choose the cuda, cuda-11-0, or cuda-drivers meta-packages under WSL 2)
sudo apt-get install -y cuda-toolkit-11-0
#test  (path: \\wsl$\Ubuntu-20.04\usr\local\cuda-11.1)
nvcc --version # cuda version

NOTE: gpu works with Window Insider Prebuild 20236 -->
        


3. OpenMPI + gcc +gpu
cd wSourceCode
tar xvf openmpi-4.1.0rc3.tar.gz
cd openmpi-4.1.0rc3
mkdir buildGCC-cuda && cd buildGCC-cuda
##
export myCUDA=/usr/local/cuda-11.0
../configure CC=gcc CXX=g++ FC=gfortran F77=gfortran \
--with-sge --without-verbs --without-ucx --with-cuda=${myCUDA} \
--prefix=/opt/app/openmpi/4.1.0-gcc9.3-cuda11
make
sudo make install

## use,
export PATH=/opt/app/openmpi/4.1.0-gcc9.3-cuda11/bin:$PATH
export LD_LIBRARY_PATH=/opt/app/openmpi/4.1.0-gcc9.3-cuda11/lib:$LD_LIBRARY_PATH

## make Module files (\\wsl$\Ubuntu-20.04\home\tha\1moduleFiles)
# module use /home/tha/1moduleFiles
set topdir /opt/app/openmpi/4.1.0-gcc9.3-cuda11 prepend-path PATH $topdir/bin prepend-path LD_LIBRARY_PATH $topdir/lib prepend-path INCLUDE $topdir/include prepend-path PKG_CONFIG_PATH $topdir/lib/pkgconfig # this is required

4. Compile lammps
### we have GTX 1060 with Pascal architecture
sudo apt install zlib1g-dev ocl-icd-opencl-dev  pkg-config
sudo apt-get install libblas-dev liblapack-dev libgsl-dev   #for plumed
##
git clone --branch master https://github.com/lammps/lammps.git lammps_master
cd lammps_master
git pull origin master
mkdir build-gpu && cd build-gpu

##
module load cmake-3.18.3
module load ompi/4.1.0-gcc9.3-cuda11
module load cuda-11.2
#--
export PATH=$PATH:/opt/app/openmpi/4.1.0-gcc9.3-cuda11/bin
export CC=mpicc
export CXX=mpic++
export FORTRAN=mpifort
cmake ../cmake -C ../cmake/presets/all_on.cmake \
-DLAMMPS_EXCEPTIONS=yes -DBUILD_MPI=yes -DBUILD_OMP=yes -DLAMMPS_MACHINE=mpi \
-DPKG_USER-OMP=yes -DPKG_USER-INTEL=no -DPKG_KOKKOS=yes \
 -DPKG_GPU=yes -DGPU_API=cuda -D GPU_ARCH=sm_61 \
-DPKG_USER-SMD=yes -DDOWNLOAD_EIGEN3=yes -DDOWNLOAD_VORO=yes \
-DPKG_KIM=no -DDOWNLOAD_KIM=no -DPKG_LATTE=no -DPKG_MSCG=no -DPKG_USER-ATC=no -DPKG_USER-MESONT=no  \
-DPKG_USER-ADIOS=no -DPKG_USER-NETCDF=no -DPKG_USER-QUIP=no -DPKG_USER-SCAFACOS=no \
-DPKG_USER-VTK=no -DPKG_USER-H5MD=no \
-DPKG_USER-PLUMED=yes -DDOWNLOAD_PLUMED=yes \
-DCMAKE_C_COMPILER=mpicc -DCMAKE_CXX_COMPILER=mpic++ -DCMAKE_Fortran_COMPILER=mpifort \
-DCMAKE_INSTALL_PREFIX=/opt/app/lammps/master-gpu
make -j 8
sudo make install
####################
-DGPU_API=cuda -D GPU_ARCH=sm_61



III. Install Anaconda on WSL:

    wget https://repo.continuum.io/archive/Anaconda3-2019.07-Linux-x86_64.sh
  • Run installation :  bash Anaconda3-2019.07-Linux-x86_64.sh
  • Update conda (optional):   conda update conda

Manually add the Anaconda bin folder to your PATH:

1. open file  "~/.bashrc"  (note: use Vim in Linux, donot open using Windows explorer)
(C:\Users\thang\AppData\Local\Packages\CanonicalGroupLimited.UbuntuonWindows_79rhkp1fndgsc\LocalState\rootfs\home\tha)

2. added :      export PATH=/home/tha/anaconda3/bin:$PATH

Test the installed python:


  • open Sub_Linux_Prompt, and type: which python

/home/tha/anaconda3/bin/python

II. Install Xeus-cling Kernel for Jupyter notebook on Window's subLinux (WSL)

3. Install Xeus-cling

- Assume Conda is installed
open Sub_Linux_Prompt, and type:         conda install xeus-cling notebook -c QuantStack -c conda-forge
Update xeus-cling (optional):    conda upate xeus-cling

4. set the BROWSER for WSL:

add the following command to the bottom of my ~/.bashrc file.

vim .bashrc 

export BROWSER='/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'


NOTE: open .bashrc file using Windows may cause "permission error" on next launch. To solve it, type:
sudo chmod -R 777 /home/thang/.bashrc

5. Using:

  • open "Sub_Linux_Prompt" from an "arbitrary folder": Shift + Right Click and selecting the Open Linux shell here 
  • type: jupyter notebook
  • copy the last URL in Sub_Linux_Prompt to IE

Ref.:
https://github.com/QuantStack/xeus-cling/blob/master/README.md
https://libinruan.github.io/2018/11/06/Install-Jupyter-s-C-kernel-on-Windows-Subsystem-for-Linux/
https://gist.github.com/kauffmanes/5e74916617f9993bc3479f401dfec7da
https://www.howtoforge.com/vim-basics

Monday, March 5, 2018

Install Nvidia CUDA-9.1 environment on Ubuntu WinBash

1. Install NVIDIA Graphics Driver

Determine the latest version of Nvidia driver available for your graphics card
Detecting NVIDIA card model
lspci -vnn | grep VGA
Visit the graphics drivers PPA homepage here and determine the latest versions of Nvidia drivers available
Remove Previous Installations (Important)
Search what packages from nvidia you have installed.
dpkg -l | grep -i nvidia
except the package nvidia-common all other packages should be purged.
sudo apt-get remove --purge nvidia-*
sudo apt-get autoremove
sudo reboot
Update gcc-6 g++6
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-6 g++-6
sudo ln -s /usr/bin/gcc-6 /usr/bin/gcc -f
sudo ln -s /usr/bin/g++-6 /usr/bin/g++ -f
checking
gcc -v
Add the graphics drivers PPA
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update

Install
sudo apt-get install nvidia-390 nvidia-390-dev
sudo reboot
lsmod | grep nvidia
or
nvidia-smi
If there is no output, then your installation has probably failed. It is also possible that the driver is not available in your system's driver database. You can run the following command to check if your system is running on the open source driver nouveau. If the output is negative for nouveau, then all is well with your installation.
lsmod | grep nouveau

Prevent automatic updates that might break the drivers
sudo apt-mark hold nvidia-390


2. Install CUDA

Preparation for installing of CUDA 9 + SDK
We install a number of build/dev packages which we require later:
sudo apt-get install g++ freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libglu1-mesa libglu1-mesa-dev
We notice that the default gcc/g++ version on 17.10 is 7.2.0 (Ubuntu 7.2.0-8ubuntu3) :
gcc -v
CUDA 9 requires gcc 6. Thus, we install it and set the corresponding sym-links:
sudo apt install gcc-6
sudo apt install g++-6
sudo ln -s /usr/bin/gcc-6 /usr/local/cuda/bin/gcc
sudo ln -s /usr/bin/g++-6 /usr/local/cuda/bin/g++
Note that the default gcc version is still 7.2; can be checked by running gcc -v again.
Installation of CUDA 9 + SDK
Download a version of CUDA 9, such as
wget https://developer.nvidia.com/compute/cuda/9.0/Prod/local_installers/cuda_9.0.176_384.81_linux-run
Make the downloaded file executable and run it using sudo:
chmod +x cuda_9.1.85_387.26_linux.run 
sudo ./cuda_cuda_9.1.85_387.26_linux.run --override
We install CUDA with the following configurations:
You are attempting to install on an unsupported configuration. Do you wish to continue?
y
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 384.81?
n
Install the CUDA 9.0 Toolkit?
y
Enter Toolkit Location
[default location]
Do you want to install a symbolic link at /usr/local/cuda?
y
Install the CUDA 9.0 Samples?
y
Enter CUDA Samples Location
[default location]
Test the CUDA 9 installation using the SDK
Build your favorite CUDA sample and run it:
cd ~/NVIDIA_CUDA-9.0_Samples/5_Simulations/smokeParticles
make
../../bin/x86_64/linux/release/smokeParticles 
After the installation finishes, configure runtime library.
sudo bash -c "echo /usr/local/cuda/lib64/ > /etc/ld.so.conf.d/cuda.conf"
sudo ldconfig
It is also recommended for Ubuntu users to append string /usr/local/cuda/bin to system file /etc/environments so that nvcc will be included in $PATH. This will take effect after reboot.

Install cuDNN

The recommended way for installing cuDNN is to first copy the tgz file to /usr/local and then extract it, and then remove the tgz file if necessary. This method will preserve symbolic links. At last, execute sudo ldconfig to update the shared library cache.

** References:
1) How can I install CUDA 9 on Ubuntu 17.10
2) Install NVIDIA Driver and CUDA on Ubuntu / CentOS / Fedora Linux OS
3) Install Nvidia CUDA-7.5 environment in CentOS 6
4) Things to know when installing NVIDIA drivers
5) Install the latest NVIDIA driver on Linux
6) GTX 1070 on Ubuntu 16.04 with Cuda 8.0 and Theano