Sunday, February 12, 2023

CPU & GPU Internel components with explanation

Terminology : 

BIOS (Basic Input/Output System) is the first software that runs when you power on your system, performing an initial pack of diagnostic tests (POST, or Power On Self-Test) to see if there are any issues with the hardware. 
POST is the first step in your hardware's boot sequence. The machine won't continue with the boot sequence if the POST fails.

BIOS contains instructions on controlling various hardware components such as hard disks, keyboards, and display screens.

VBIOS (Video basic input/output system) is the BIOS of a graphics card in a computer. 
                    VBIOS initializes the graphics card at the computer's boot time.

SBIOS (System Management BIOS):

Defines data structures that can be used to read management information produced by the BIOS of a computer. 
SBIOS eliminates the need for the operating system to probe hardware directly to discover what devices are present in the computer

To check SBIOS version cmd:  sudo dmidecode -s bios-version


Kernel installation steps on RPM-based machines (RHEL/Cent OS):
    1. Need to uninstall the existing driver on the machine
    2.  wget <kernel from the given link>
    3. To install the downloaded kernel, you can use any one of the following commands:
            sudo rpm -ivh <downloaded kernel name>
                                        or
            sudo yum install <downloaded kernel name>
    4. Verify kernel is installed properly or not by using the following command:
            rpm -qa | grep <kernel_version>
        
BKC: Best known configuration

Installtion steps for BKC

IOMMU stands for Input-Output Memory Management Unit. It's a hardware component that connects a DMA-capable I/O bus to system memory

IFWI stands for Integrated Firmware Image. It is a combination of firmware components that are programmed into a system's flash or eMMC.

NUMA stands for Non-Uniform Memory Access. It is a computer memory design that allows multiple processors to share memory locally in a multiprocessing system. 
NUMA is used to increase processor speed without increasing the load on the processor bus. It's used in enterprise computing and nearly every industry that calls for high-performance computing (HPC).

UEFI (Unified Extensible Firmware Interface) is a newer standard that replaces the legacy BIOS.
UEFI offers more features and benefits, such as faster boot times, better security, larger disk support, and graphical user interface.


Dynamic Kernel Module Support (DKMS) is a program/framework that enables generating Linux kernel modules whose sources generally reside outside the kernel source tree.  

CMD:  sudo dkms status  -->This  command will give the GPU kernel & OS-kernel (C.P.U)
Ex: 
CMD:  uname -r   --> This  command will give OS kernel only
Ex: 

CMD: /usr/lib/modules/6.x.x-xx-generic/kernel/drivers

This is the OS kernel path where all the drivers (input / tty / Bluetooth / GPU/ PCI ..... ) will be located

What is Swap memory?  and what is the purpose of Swap memory?
  • Swap space (virtual memory) is a designated area on a hard drive that is used as an extension of physical memory (RAM). 
  • When the system's RAM becomes full, inactive pages are moved to the swap space, freeing up RAM for active processes
  • While swap space can help machines with a small amount of RAM, it should not be considered a replacement for more RAM.
How do we check Swap memory in our machine?

   commands to check swap memory: free -h          or     sudo swapon --show
   the output of  free -h  : 
                     total        used        free      shared  buff/cache   available
Mem:           125Gi       9.0Gi       113Gi       112Mi       2.8Gi       115Gi
Swap:           93Gi          0B        93Gi
  
the output of   sudo swapon --show  : 
        
NAME      TYPE       SIZE USED PRIO
/dev/sda3 partition 93.1G   0B   -2

Can we increase the swap memory? Ans: Yes. 

How to increase/ resize swap memory? / How to increase Swap Space in Ubuntu 22.04 LTS Jammy?

Steps to add Swap area in Ubuntu 22.04 LTS Linux

1. Check the current Swap Space

            cmd: sudo swapon -s 

            result: if there is no swap memory means it will not show anything (empty)

                        otherwise shown as below

                Filename                                Type            Size            Used            Priority

                /swapfile                               file            31457276        0               -2

2. Turn off Swap

            cmd: sudo swapoff -a                             Command output shows: Nothing 

3. Create a Swap file on Ubuntu 22.04 to increase the size

   Note: While using the given command keep one thing in mind 40G means, 40GB of space you are about to allocate for Swap       

            cmd: sudo fallocate -l 40G /swapfile        Command output shows: Nothing  

4. Change file permission

            cmd:  sudo chmod 600 /swapfile              Command output shows: Nothing  

5. Mark SWAP space and activate it

            cmd:  sudo mkswap /swapfile

                    mkswap: /swapfile: warning: wiping old swap signature.

                    Setting up swapspace version 1, size = 100 GiB (107374178304 bytes)

                    no label, UUID=0764024e-ac01-4c29-91ab-bb64f7af33a3

            cmd: sudo swapon /swapfile               Command output shows: Nothing 

        Note: After activating, can you check whether the Swap space is added to your system? By using the below cmd.

          cmd: sudo swapon -s     or     free -h

6. Set Ubuntu 22.04 SWAP file as permanent

            cmd:  echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

7. Set swap usage or swappiness

            cmd: sysctl vm.swappiness                  Command output shows:  vm.swappiness = 60

         However, this change is forgotten by the system after a reboot unless the following is entered in the system file /etc/sysctl.conf:

            cmd: sudo nano /etc/sysctl.conf     Command will open a file, at the end of the file add vm.swappiness = 60  then save the file with the help of the options shown there. just check again if your change is saved or not?

       8. Now reload the sysctl configuration file

            cmd: sudo sysctl -p

            cmd: sudo reboot

for any clarification use this link: https://linux.how2shout.com/how-to-increase-swap-space-in-ubuntu-22-04-lts-jammy/#1_Check_current_Swap_Space.


How to avoid hanging issues on our laptops/Personal computers?
 1. Delete unwanted /unnecessary files and folders 📂 in laptops /PCs 💻 

    We have to delete files & folders from 3 locations

              a. Delete files & folders present in the prefetch folder

                  press windows+r  type prefetch press Enter button ==> then try to delete all files & folders  

   b. Delete files & folders present in the temp folder

                  press windows+r  type temp press Enter button ==> then try to delete all files & folders 

   c. Delete files & folders present in the %temp% folder

                  press windows+r  type %temp%  press Enter button  ==> then try to delete all files & folders 

              d. Delete malicious softwares

                              press windows+r  type MRT  press Enter button  ==> click on YES  --> Next --> enable quick scan Radio button, automatically malicious softwares will be removed.


Request: If you find this information useful, please provide your valuable comments.


Dockers and containers

What is docker?

Docker is an environment with its own OS+ user space (related packages & modules) that resides on a bare-metal system and uses system HW/Kernel resources to serve a different purpose.


We must understand 3 environments (Bare metal,  Docker, virtualization)

·        Bare metal is one kind of environment where we test our GPUs directly

·        Docker is one kind of environment that is separated from Bare metal.

       Virtualization is software, that makes computing environments independent of physical infrastructure. In contrast, cloud computing is a service that delivers shared computing resources (software and/or data) on demand via the Internet.

·        If you launch Docker, it has its own user space with all dependent packages and its own OS.

The beauty of the docker concept :


   Docker is platform-independent and can run on any machine regardless of the operating system present.


      Docker is controlled by a kernel space.

·        Kernel sitting very close to the hardware.                                                 

·        If Kernel space/Firmware is broken/crashed, we can’t do anything.

·        Both Bare-metal and Docker have the packages, Except Docker does not have kernel space. Docker will use kernel space which is available on the bare metal.

Docker architecture components & How does docker work? 

Docker architecture comprises 3 main components

1. Docker Client: This is the interface through which users interact. It communicates with the docker daemon.

2. Docker Host: Here, Docker daemon listens for docker API requests and manages various docker objects, including images, containers, networks, and volumes

3. Docker Registry: This is where Docker images are stored. Docker hub, for instance, is a widely used public registry 

       

For operations related to Docker on your machines or servers, such as Docker building, pulling, or running containers, the Docker daemon must be active & running.

Note: Based on OS, you can install & activate the Docker daemon by using the steps below

 Ubuntu 18.04/20.04/22.04/24.04

sudo apt-get -y install apt-transport-https ca-certificates curl  

curl -fsSL https://get.docker.com/ | sh

sudo systemctl start docker → start the Docker daemon:

sudo systemctl status docker → verify it's running or not [ Active: active (running)]

sudo systemctl enable docker → make sure it starts at every server reboot

  Docker & container related commands

sudo docker pull <docker_name_based_on_OS> cmd will pull the specific Docker image into the machine

sudo docker images  ==> cmd will list the available dockers in the present machine

sudo docker rmi  -f  docker_id ==> cmd will delete a single specific docker in the present machine

sudo docker rmi  -f  docker_id_1 docker_id_2 docker_id_3 ==> Will delete multiple dockers

sudo docker ps -a ==> cmd will list the available containers on the present server

sudo docker rm container_id ==> cmd will delete a single specific container present in the machine

sudo docker rm container_id_1 container_id_2 container_id_3 ==> will delete multiple containers

docker system prune -a   ==> It will clear space on your device by doing the following tasks 

     This command will remove: 

            - all stopped containers

            - all networks not used by at least one container

            - all images without at least one container associated with them

            - all build cache


Ø   sudo dmesg: dmesg contains all kernel-related information (loading /unloading, module loading, firmware loading, etc. lot of information).

Ø  sudo dmesg | grep -i error if you search like this, it will give kernel/firmware-related error messages 

Ø  Any kernel-related error & other information you want to see, then you must run sudo dmesg from the home directory,

su sudo dmesg -C  --> It will clear all kernel error messages

Ø  cd /var/log/ èin this folder, the dmesg log file & other kernel log files are present.

èFirmware not loaded/ kernel crashed. All information you can use the command sudo dmesg | grep -i error to see the error messages.


Request: If you find this information useful, please provide your valuable comments.

Friday, November 18, 2022

Technical Info

 

Windows Subsystem for Linux Has Reached v1.0 Stable Release


Windows Subsystem for Linux (WSL) is a tool that lets you run a GNU/Linux environment inside a Windows system without needing a virtual machine or dual-boot.

https://news.itsfoss.com/wsl-stable-available/


Saturday, October 15, 2022

Pytorch framework & Tensorflow Framework

PyTorch and TensorFlow are two of the most popular deep learning frameworks. 

                                                               

PyTorch (Most popular research DL framework*)

  • PyTorch is an open-source ML and DL framework developed by Facebook (Meta) using Python and released to the public in 2016. 
  • Now open source & used by companies such as Tesla, Microsoft, and OpenAI.. etc
  • PyTorch is a low-level API for NLP (natural language processing) and computer vision. It is a more powerful version of Numpy.
  • PyTorch is used by leading tech companies like 
    • Tesla to build the computer vision system for their self-driving vehicles
    • Meta to power the curation and understanding systems for their timelines.
    • Apple to create computationally enhanced photography and even automated weed-killing tractors.

  • What can PyTorch be used for?
          PyTorch allows you to manipulate and process data and write machine learning algorithms using Python code

Deep Learning 
What deep learning is good for



Tensor Explanation from root level

 9    ---> (single number)                            ---> scalar   (0 D Tensor)  (D means Dimensional)

[19, 82] (group of numbers --> Row)        ---> Vector (1D Tensor)

[[9 ,88 ] ,

 [19 ,8]]   (combination of rows & colums) --> Matrix ((2 D Tensor))

3X3  Matrix (Red, Green, and Blue)           ---> 3D Tensor (Ex: Image)

4D or 5D tensor (Videos or large data)

  • Images are first converted into numerical values called tensors. 
  • These tensors are given to a neural network, which processes them using mathematical calculations and generates an output tensor. 
  • This output is then transformed into meaningful information that humans can easily understand.



 CUDA (Compute Unified Device Architecture) is a parallel computing platform and programming model developed by NVIDIA that allows software developers to use a GPU for general-purpose computing, not just graphics.

What CUDA does?

Normally, GPUs were designed mainly for graphics. CUDA lets you use the thousands of GPU cores to perform computational tasks much faster than a CPU for certain workloads.




TensorFlow was developed by Google and released to the public in 2015. Production and research are the main uses of TensorFlow.

Implementation :

https://colab.research.google.com/drive/1B9QKy3FJNbCwSNGXFEUTAhRpxeQAg856




Friday, July 15, 2022

AI ML DL

 




Jenkins: The leading open source automation server, Jenkins provides hundreds of plugins to support building, deploying, and automating any project.



Difference between Private Key and Public Key


KeyPrivate KeyPublic Key
AlgorithmPrivate key is used for both encrypting and decrypting the sensitive data. It is shared between the sender and receiver of encrypted data.Public key is used only for the purpose of encrypting the data.
PerformanceThe private key mechanism is faster.The public key mechanism is slower.
SecrecyThe private key is kept secret and not public to anyone apart from the sender and the receiver.The public key is free to use and the private key is kept secret only.
TypeThe private key mechanism is called "symmetric" because a single key is shared between two parties.The public key mechanism is called "asymmetric" because there are two keys for different purposes.
SharingThe private key is to be shared between two parties.The public key can be used by anyone but the private key is to be shared between two parties only.
TargetsPerformance testing checks the reliability, scalability, and speed of the system.

Thursday, April 7, 2022

Python if-else Interview questions

What are the three main conditional statements in Python?
Answer:        if, elif, and else


. What will be the output of the following Python code?

names_1 = ["Narendra", "Boyina", "raj", "Mahalakshmi"]

if  'Raj' in names_1:

print(1)

else:

print(2)

a) None

b) 1

c) 2

d) Error


Answer: c

Explanation: Python is case sensitive, "if" condition failed because "Raj" is not available in that list, "raj" is available, so else block statement is executed.

========================================================================

A company decided to give a bonus of 5% to the employee if his/her year of service is more than 5 years.
Ask users for their salary and year of service and print the net bonus amount.

Answer:


salary = int(input("Enter salary"))

yos = int(input("Enter year of service"))

if yos>5:

  print "Bonus is",.05*salary

else:

  print "No bonus"

========================================================================

 Accept the kilometers covered  for the rented car and calculate the bill according to the following criteria:

First 10 Km              Rs11/km

Next 90Km               Rs 10/km

After that               Rs9/km

Answer
.

kmc = int(input("Enter the kilometer covered"))

if kmc <=10 :

    amt = kmc * 11

elif kmc > 10 and kmc <= 100:

    amt = 110 + (kmc - 10)*10

elif kmc > 100:

    amt = 1010 + (kmc - 100)*9

print("Total amount to pay is ", amt)

========================================================================



========================================================================

Write a program to calculate the electricity bill (accept the number of units from user) according to the following criteria :

             Unit                                                     Price  

First 100 units                                               no charge

Next 100 units                                              Rs 5 per unit

After 200 units                                             Rs 10 per unit

(For example, if the input unit is 350 then the total bill amount is Rs2000)


logic.

amt=0

numer_units=int(input("Enter number of electric unit"))

if numer_units<=100:

     amt=0

if numer_units>100 and numer_units<=200:

     amt=(numer_units-100)*5

if numer_units>200:

     amt=500+(numer_units-200)*10

print("Amount to pay :",amt)

========================================================================

Accept any city from the user and display a monument of that city.

  City                                 Monument

  Delhi                               Red Fort

  Agra                                Taj Mahal

  Jaipur                              Jal Mahal


 Answer

 

city = input("Enter name of the city")

if city.lower()=="delhi":

    print("Monument name is : Red Fort")

elif city.lower()=="agra":

    print("Monument name is : Taj Mahal")

elif city.lower()=="jaipur":

    print("Monument name is : Jal Mahal")

else:

print("Enter correct name of city")


========================================================================

Write a program to find the largest number out of three, excepted by the user.

 Answer


num1 = int(input("Enter first number"))
num2 = int(input("Enter second number"))
num3 = int(input("Enter third number"))
if num1 > num2 and num1 > num3:
      print("Greatest number is ", num1)
if num2 > num1 and num2 > num3:
      print("Greatest number is ", num2)
if num3 > num2 and num3 > num1:
     print("Greatest number is ", num3)
print("Enter correct name of city")

========================================================================

Accept the following from the user and calculate the percentage of class attended:

a.     Total number of working days

b.     Total number of absent days 

After calculating the percentage show that, If the percentage is less than 75 then the student will not be able to sit in the exam.

 Answer

 

nd = int(input("Enter total number of working days"))

na = int(input("Enter number of days  absent"))

per=(nd-na)/nd*100

print("Your attendance is ",per)

if per <75 :

     print("You are not eligible for exams")

else:

     print("You are eligible for writing exam")

========================================================================


                                Request: Please provide your valuable comments

Python Comprehensions Interview questions - Multiple choice

 1. Suppose list1 = [0.5 * x for x in range(0, 4)], list1 is:

a) [0, 1, 2, 3]

b) [0, 1, 2, 3, 4]

c) [0.0, 0.5, 1.0, 1.5]

d) [0.0, 0.5, 1.0, 1.5, 2.0]


Answer: c

Explanation: Execute in the shell to verify.


2. What will be the output of the following Python code?

names_1 = ["Narendra", "Bhagyasree", "Raj", "Mahalakshmi"]

names_2 = [name.lower() for name in names_1]

 print(names_2[2][0])

a) None

b) R

c) r

d) b


Answer: c

Explanation: List Comprehension is a shorthand for creating new lists.


3. What will be the output of the following Python code?

>>>m = [[x, x + 1, x + 2] for x in range(0, 3)]

a) [[1, 2, 3], [4, 5, 6], [7, 8, 9]]

b) [[0, 1, 2], [1, 2, 3], [2, 3, 4]]

c) [1, 2, 3, 4, 5, 6, 7, 8, 9]

d) [0, 1, 2, 1, 2, 3, 2, 3, 4]


Answer: b

Explanation: Execute in the shell to verify.


4. How many elements are in m?

m = [[x, y] for x in range(0, 4) for y in range(0, 4)]

a) 8

b) 12

c) 16

d) 32


Answer: c

Explanation: Execute in the shell to verify.

 

5. What will be the output of the following Python code?

a=[1,2,3,4]

b=[sum(a[0:x+1]) for x in range(0,len(a))]

print(b)

a) 10

b) [1,3,5,7] 

c) 4

d) [1,3,6,10]


Answer: d

Explanation: The above code returns the cumulative sum of elements in a list


6. What will be the output of the following Python code?

>>>t = (1, 2, 4, 3, 8, 9)

>>>[t[i] for i in range(0, len(t), 2)]

a) Error

b) [1, 2, 4, 3, 8, 9]

c) [1, 4, 8]

d) (1, 4, 8)


Answer: c

Explanation: Execute in the shell to verify.


7. What will be the output of the following Python code?

a={i: i*i for i in range(6)}

print(a)

a) Dictionary comprehension doesn’t exist

b) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25, 6:36}

c) {0: 0, 1: 1, 4: 4, 9: 9, 16: 16, 25: 25}

d) {0: 0, 1: 1, 2: 4, 3: 9, 4: 16, 5: 25}


Answer: d

Explanation: Dictionary comprehension is implemented in the above piece of code.


8. What will be the output of the following Python code?

 a={i: 'A' + str(i) for i in range(5)}

print(a)  

a) An exception is thrown

b) {0: ‘A0’, 1: ‘A1’, 2: ‘A2’, 3: ‘A3’, 4: ‘A4’}

c) {0: ‘A’, 1: ‘A’, 2: ‘A’, 3: ‘A’, 4: ‘A’}

d) {0: ‘0’, 1: ‘1’, 2: ‘2’, 3: ‘3’, 4: ‘4’}


Answer: b 

Explanation: Dictionary comprehension and string concatenation is implemented in the above piece of code.


 What will be the output of the following Python code?

a="hello"

b=list( (x.upper(), len(x))  for x in a)

print(b)

a) [(‘H’, 1), (‘E’, 1), (‘L’, 1), (‘L’, 1), (‘O’, 1)]

b) [(‘HELLO’, 5)]

c) [(‘H’, 5), (‘E’, 5), (‘L’, 5), (‘L’, 5), (‘O’, 5)]

d) Syntax error


Answer: a

Explanation: Variable x iterates over each letter in the string hence the length of each letter is 1.