# Install Tensorflow
## Short way
- Can use GPU with cuda (<10.1) only
`pip install tensorflow`
## Long way
Reference: [Build from source](https://www.tensorflow.org/install/source)
```sh
sudo apt update && sudo apt install bazel-3.1.0
bazel --version
sudo ln -s /usr/bin/bazel-3.1.0 /usr/bin/bazel
```
```sh
git clone https://github.com/tensorflow/tensorflow.git
cd tensorflow
git checkout branch_name # r1.9, r1.10, etc.
```
```./configure```
<details>
<summary>View sample configuration session</summary>
You have bazel 3.0.0 installed.
Please specify the location of python. [Default is /usr/bin/python3]:
```sh
Found possible Python library paths:
/usr/lib/python3/dist-packages
/usr/local/lib/python3.6/dist-packages
Please input the desired Python library path to use. Default is [/usr/lib/python3/dist-packages]
Do you wish to build TensorFlow with OpenCL SYCL support? [y/N]:
No OpenCL SYCL support will be enabled for TensorFlow.
Do you wish to build TensorFlow with ROCm support? [y/N]:
No ROCm support will be enabled for TensorFlow.
Do you wish to build TensorFlow with CUDA support? [y/N]: Y
CUDA support will be enabled for TensorFlow.
Do you wish to build TensorFlow with TensorRT support? [y/N]:
No TensorRT support will be enabled for TensorFlow.
Found CUDA 10.1 in:
/usr/local/cuda-10.1/targets/x86_64-linux/lib
/usr/local/cuda-10.1/targets/x86_64-linux/include
Found cuDNN 7 in:
/usr/lib/x86_64-linux-gnu
/usr/include
Please specify a list of comma-separated CUDA compute capabilities you want to build with.
You can find the compute capability of your device at: https://developer.nvidia.com/cuda-gpus Each capability can be specified as "x.y" or "compute_xy" to include both virtual and binary GPU code, or as "sm_xy" to only include the binary code.
Please note that each additional compute capability significantly increases your build time and binary size, and that TensorFlow only supports compute capabilities >= 3.5 [Default is: 3.5,7.0]: 6.1
Do you want to use clang as CUDA compiler? [y/N]:
nvcc will be used as CUDA compiler.
Please specify which gcc should be used by nvcc as the host compiler. [Default is /usr/bin/gcc]:
Please specify optimization flags to use during compilation when bazel option "--config=opt" is specified [Default is -march=native -Wno-sign-compare]:
Would you like to interactively configure ./WORKSPACE for Android builds? [y/N]:
Not configuring the WORKSPACE for Android builds.
Preconfigured Bazel build configs. You can use any of the below by adding "--config=<>" to your build command. See .bazelrc for more details.
--config=mkl # Build with MKL support.
--config=monolithic # Config for mostly static monolithic build.
--config=ngraph # Build with Intel nGraph support.
--config=numa # Build with NUMA support.
--config=dynamic_kernels # (Experimental) Build kernels into separate shared objects.
--config=v2 # Build TensorFlow 2.x instead of 1.x.
Preconfigured Bazel build configs to DISABLE default on features:
--config=noaws # Disable AWS S3 filesystem support.
--config=nogcp # Disable GCP support.
--config=nohdfs # Disable HDFS support.
--config=nonccl # Disable NVIDIA NCCL support.
Configuration finished
```
</details>
```sh
bazel build //tensorflow/tools/pip_package:build_pip_package
```
## Check GPU if exists
```python=
tf.config.list_physical_devices('GPU')
tf.test.gpu_device_name()
```
## Analysis
I'm able to confirm the following,
- pip install tensorflow supports gpu as well, we no longer need to add "-gpu" like before.
- To use gpu, right now, we can use TF 2.x with cuda-10.1 and lower.
- For cuda-10.2+, we need to [build TF from source](https://www.tensorflow.org/install/source) on our pc.
- Some people from internet and Shivashish san has used symlink to create/link 10.1 from 10.2, but this may not be good for long term.
- In my case, I'm also not able to use gpu with earlier version (i install it using pip install tensorflow-gpu==1.15)

- Now, I'll make model in pytorch, since it is compatible with my pc/cuda-10.2.