Welcome to our new lecture
In this lecture we will talk about
CPU vs GPU
We have seen about CPU in previous lectures
We have seen
What is CPU and what is its function
CPU means
Central Processing Unit
What does it do?
It executes your machine code
It reads it line by line
Let's understand with an example
I have a WhatsApp application
WhatsApp application was written in some high level
language After that
Compiler converted it in machine code When it is converted
in machine code It becomes an executable file
Let me show you
Let's open whiteboard Let me write here
How does an application run?
Let's talk about it
Here I have a WhatsApp application
WhatsApp What does
WhatsApp do?
What did I write it in?
What did engineers write it in?
They wrote it in high level language
Now that high level language can be any language
It can be your C
It can be your C++
It can be your
JavaScript It can be your Python
I wrote an application in high level language
What happens after that?
After that
Our compiler converts this code in machine code
Compiler converted it
When it converts it, an executable file is generated
WhatsApp .exe It happens with every application
WhatsApp.exe Wherever you see this thing
WhatsApp.exe It means it is an executable file
The code you wrote in high level language
High level language means equivalent to English language
Suppose you wrote 10 lines of code
First line is this
Second line is this
So on you wrote 10 lines of code
Now High level language
Corresponding What will happen here?
When compiler converts
What will happen here?
Lines will be generated like this
Up to 10
Whatever you wrote here
It was written in English language
For example, I write
Hash include
You can understand what I wrote
Hash include
But when it is converted
It becomes like this
It becomes a code like this
Similarly Second line
Corresponding machine code
Machine code This code
My CPU executes My CPU executes If there is no error
When I
WhatsApp.exe What do we do?
We click on any icon
Mobile phone icon Desktop icon
When I click on any icon
CPU RAM Generally Block diagram
Hard disk
I made hard disk
HDD Hard disk drive WhatsApp.exe File is here File is here
File When I click on any icon
I have to come to RAM
Where did it come?
Here in RAM When it came here
Which file is this?
It is written in 10101 After that CPU executes it line by
line
This is the work of CPU
CPU does
Computation Whatever complex problems It does
Computation After that it shows the outcome
We also saw
CPU has two units
One unit is ALU
One unit is CU
What does ALU unit do?
ALU unit does Arithmetic and Logical unit
Whatever is related to Arithmetic and Logic
What does it do?
This unit handles it
What does CU do?
CU sees the data transfer
Between two resources
CU sees all these
I understood this much
Problem with CPU is
CPU is general purpose
Here we write
CPU is general purpose
Means You will give it
Any work of computation
It will do it for you
But here the problem is
Graphical Work Let's try to understand
What is the meaning of graphical work?
There are two types of things
One is
Text based
Here I write
Text based
Second is
Graphical representation
Or you can say
This is your
Textual representation
This is your graphical representation
What are the things in graphical representation?
Like If you want to show an image
Or you want to show a photo
If you want to show a photo or image
What are the things in graphical representation?
Which I can see visually
Which eyes look appealing
If you want to show a photo or image
Or you want to show a video
Or you want to show a video game
All these things
Game, video
Or images
You have a lot of graphics in it
A lot of graphics means
In one video
There are a lot of frames
But in frames
A lot of things are running at the same time
Like your tree is cutting leaves
Two people are dancing
One person is going out of the side
Two cars are going out of the front
It's raining
So many things are happening in that video
So I understand what is this
Graphical representation
So where we were talking about graphical representation
Heavy work
Which was related to graphical representation
There CPU was not able to do
Why it was not able to do?
There was a little problem
The problem with CPU is
We have limited cores in CPU
What is the meaning of cores?
If I say
I have two hands
And I can do two things at a time
I will say Two cores
If I have four hands
I can do four things at a time
Four cores
If I have eight hands
And I can do eight things at a time
I will say It is called octa-core
If I have ten hands
I will say deca-core
In this way I understand
Core means hands In computer language I will say I will be
able to do as many things as there are cores
Simultaneously Talking about CPU architecture
Talking about CPU architecture
Like in mobile phone
Like Apple's
Bionic chip
A17, A16
Android processors
Snapdragon MediaTek They have an architecture
As you can see here
We will come to the architecture
In this architecture Some things have been given
Like your house You go to someone
You want to build a house
You go to the architect
You say
I want to use the land
Tell me what can be done
You tell me a requirement
What a kitchen In my house, there are 4 children So each
has own room
You have given them a description
Says these things are required
Tell us
Build a room here
Make a kitchen Make a washroom Make a main entrance
Divide the land
you can see that I have written 4 things in this way.
Now you will see that in these 4 things, what is written
here?
ALU is written 4 times.
That is, I can say this.
Now the processor of my mobile phone comes or
to reduce
score
in
the score.
Thanks for watching.
I am going to explain this diagram to you
Here I have understood that this is my control unit
Here I have written that this is my control unit
And this is my ALU
This is your course
Which will handle your work one by one
Here you will run four applications
This is your efficiency core
This is your cache
Which is your temporary data
Which is related to any application
It comes here and stores it in the cache
This is very fast
This is your dynamic RAM
So this is how we divided it
So I found out that the problem in the CPU was that
The number of cores is less there
And that is the general purpose
So there was no work
There was a general purpose and not a specific purpose
That's why we said that
Some requirements are being fulfilled
What was the requirement
That another chip should be installed
The second thing was that the number of cores is less
What we need is that we have to handle multiple things at
once Simultaneously we have to handle many things So how
will we handle that
We will do that with the help of this
That is, we put a lot of cores in the GPU
For example, you see this green color What happened to all
this
I found out that as soon as a green box is given here
So this is the ALU
So in this way I have a lot of ALU
I understood that this is also done This is also done
Now wherever you see
What will you see
You will see only green color
I found out this
I found out this whole row
This whole row All my things came here like this All my
things came here
After that, as DRAM is given here My DRAM is also given here
What is the rest
If I take out this portion
So you will see two things
There are two things like this
And it is like this
Like my control and cache
It is in the same color
This yellow color that is above
This is your control
The second thing that happened to you What happened to you
How How So I found out that there is a difference in the
architecture of both What is the difference
Here the ALU In my GPU I get to see a lot
But if I look at the other side
I get to see less in the CPU
I found out Now what is the benefit
What is the benefit of being more coarse
The benefit of being more coarse
Because it is able to handle multiple things
Now one thing also comes
It is handling multiple things
Along with one thing
Like thread
Here Let's try to understand
I have four cores here
These four cores can handle my four applications
So here I say
I have a memory
What do I have
I have RAM In this RAM Four applications are running
One application is running here
And one application is running here
So it became one
Let's say three So it is running here
Now this one This application
Whatever space it is taking
To run in memory
What can we do
We can divide it into threads
Divide it like this
In thread T1 This code is written
We have divided this code into all parts
Thread 1
Thread 2
Thread 3
If you ask what is the meaning of thread
It is a piece of code
Which does the same thing
Thread 1, Thread 2, Thread 3
So what will my core do
My core means Let's make a core here
So my first core
Will handle something The second core Will handle my second
application
The third core will handle my Instagram The fourth core
will handle my presentation Now There are threads in every
core
Thread means
Memory is sharing the same
Common But this thread does a piece of code
It runs simultaneously This one is running
This one is running
That means
The code we have
Divide it into small parts
Thread 1 will execute some part
Thread 2 will execute some part
Thread 3 will execute some part
So what will happen
Whatever code you have
It will run quickly
You will see So I understood Now as it is inside
Can we do this thing inside it Because I already have a lot
of code If I use thread inside it
I get to know
It works more Efficiently Better So I understood What is my
CPU
And what is my GPU
I saw CPU I used to use CPU
Then we felt the need of GPU So we brought GPU
Now Let's see
Comparing them
Based on functionality Architecture Parallelism Memory
hierarchy
Programming model
Use cases
Power consumption
Let's see
Is my CPU better
I will not say better
Because use cases are different
Let's see
So Let's start
From functionality
Let's change the pen
First of all Let's talk about CPU
We already know CPU is for general purpose
And GPU is for specific purpose
You will see Same thing here Like what is written
You can read it
CPU reading between the lines
I have shown you
If I talk about CPU
It is clearly written here
CPU Is designed
For general purpose General purpose means It will handle
Your many applications In any way Why we designed GPU?
It should be a chip which can execute all the things
related to graphics and run everything efficiently
I came to know that this is the general purpose and GPU is
the specific purpose
I said yes, it shows only the things related to graphics
So, all your computing tasks which are the general purpose
in nature
What does it do to all of them?
Why CPU is responsible for all of them? Is it only
responsible for general purpose computing tasks?
I said no
Rest of the instructions
In your program, there are many instructions First you have
to do this, second you have to do that
Third you have to do this
So, the responsibility of executing all those instructions
is also on your CPU
So, my CPU
I know that my CPU has two units One is the arithmetic unit
and the other is the logical unit So, my arithmetic
operations or logical operations are easily handled by ALU
unit
So, I came to know this
So, data can also be transferred between two resources
How can data be transferred between two resources? Suppose
I want to send a message to my friend on WhatsApp
So, when I send the message on WhatsApp it will be visible
on the display It will also be visible on my display and
when I type the message
I will type it on a keyboard So, what happens to the
keyboard?
Keyboard becomes a resource and the monitor becomes a
second resource So, what is happening between these two
resources? Data is being transferred and data is being
flowed
So, this thing is also done by CPU And which part of CPU
does it do? It does the CU part, it does the control unit
Then I understood this
Now I understood, I saw this earlier So, what is the
functionality of GPU? What does GPU function?
In the initial design why was GPU designed?
It was designed to render my graphics to show graphics
I used it
I have evolved slowly slowly why i have evolved like
anything like internet like now we are talking about web
3.0 where it started from web 1.0 where static information
was shown after that web 2.0 came where what happened you
came to know that there
is something like dynamic that means you went to youtube
you wrote that Punjabi songs after listening to you they
brought Punjabi songs you are able to interact now web 3.0
will come or it is going on there also you will see things
that will be more advanced
than that so there is a process of evolution in human
beings also there is a process of evolution here also when
gpu came in starting then i know that they brought graphics
to render but what happened slowly slowly when evolution
happened it started handling
parallel processing tasks like it is written here gpu have
evolved to handle parallel processing tasks efficiently
means it will handle parallel processing tasks efficiently
i said how? explain it so i said it does things like what
tasks do i have i said
in one video i have many tasks in that i have to show
leaves falling i have to show rain i have to show my
girlfriend and boyfriend walking i have to show 4 to 5
things then i said now all these tasks will have a
processing then only i will be able to
see so to handle them efficiently gpu evolved slowly so now
in today's time gpu handles easily so here it was written
they excel at performing repetitive if there is any task
which is repetitive like you have to fire a gun in pubg you
are doing the same
thing again and again or you have to do parallel
computation that the bullet which is fired by the gun i
have to run along with it means these two things are
happening together so what happened it is running parallel
simultaneously it is running together
so this thing also is a function of gpu so gpu handles it
easily and what is written in the last making them highly
effective for certain types of workload means whatever
workload i had earlier i was not able to do until gpu was
not there now when gpu
has come and whatever work is done highly effectively
highly effectively whatever your workload is performed by
gpu this is also a function of gpu so i understood what is
the function of gpu and also i understood what is the
function of gpu let's talk
about the second point that both the architectures are very
different how to know that both the architectures are very
different you can see this is the architecture how it is
divided here is the control after that here is the allu in
second section in
third section in fourth section then i came to know here is
the cache one part is done and here is the section
1,2,3,4,5,6,7 total 7 sections are there here 1,2,3,4,5,6,7
8,9,10,11 15,20 after that 2 so if we assume 25 then 25 is
50,75,100 after that
200 and 201 this is divided in 21 so we came to know that
this architecture is different this architecture is
different now you will see like this like this like this
like this like this like this like this like this like this
like this like this like
this like this like this like this like this like this like
this like this
like this like this like this like this like this like this
like this like
this like this like this like this like this like this like
this like this
like this like this like this like this like this like this
like this like this like this like this
and what is this thing? now when so many tasks will be
together then our work will be effective for task so this
thread thing divide in sub-tasks so that parallel sub-tasks
will be executed like rendering graphics and processing
large data set now large
data sets if you want to process it then you divide it in
small chunks and it will be parallel simultaneously same
you do if you want to render graphics render means show
this is the thing so in this case also what happens is that
things are divided in
small sub-tasks so I got to know that there are some
powerful codes in CPU and I can thread those powerful codes
but if you do it in thread then in 100x or 1000x you will
not get such codes so I got to know that there is a lot of
difference in architecture
like we said what we saw here we saw that we have small
specialized cores
I understood specialized cores then I saw specialized cores
in architecture also like this here like this
I got to know many small cores then I saw parallelism let's
compare parallelism can GPU because I have many cores in
parallelism which can work together let's see CPU we get to
see such things or not in GPU we get to see such things we
try to understand
that if we talk about CPU it is made for task switching
designed for task switching and handling multiple threads
efficiently that's why parallelism is like this see here I
have a memory and in this memory two things are running
here it is running whatsapp
here it is running and here in this part it is running
Instagram Instagram these two things are running together
multiple tasks after that task switching happens suppose
upload video where do you go first you go to gallery import
from gallery this is input output till the time
I am getting a file from there till then task switching
happens you do this till then
CPU will execute whatsapp instructions now next handle
multiple threads means in whatsapp multiple threads are
there like I have done here this thread is t1 this thread
is t2 and this is t3 and this is t3 now remember that
memory is shared by common not
like this is your instagram it is using different memory
your whatsapp is using different memory but thread is my
particular task it is executing same memory we have done
only if code of whatsapp was 10 lines we have divided it
into 3 lines and we are
trying to execute all those lines thread 1 will execute 3
lines thread 2 will execute 3 lines thread 3 will execute 3
lines thread 1 will execute 1 line like this I understood
what thread does with the help of thread
I can run multiple tasks efficiently I can run multiple
tasks efficiently I can do variety of tasks simultaneously
in variety of tasks whatsapp is different instagram is
different you can see more graphical things in whatsapp you
can see more textual
things simultaneously you can switch you can see multiple
threads which will work efficiently but one line is very
important
I want to tell you can we highlight it yes we can we say
this line is very important but may not perform as well as
GPUs for massively parallel workload you can do anything
you can use multiple threads but you will not be able to
perform as well as your GPU why you will not be able to
perform because we made GPU specifically for this purpose
that it will handle all
the things related to graphics when it will handle
everything then it is obvious if CPU was doing then why GPU
and if GPU is doing then it is because
CPU was not able to do massively parallel workload
CPU can't do because it does not have so many cores you
have smaller cores which you can see in GPU
I can't see them in GPU but if we talk about GPU its
negative point its negative point is that it can't handle
massively parallel workload but here it is designed for
massive parallelism your negative point is positive point
of GPU and I came to know
that if you want to do massive parallelism then you have to
use GPU you can see parallelism in GPU you can see
parallelism in CPU but you can see parallelism in GPU but
you can't see parallelism in CPU but you can't see
parallelism in CPU it can handle
thousands of threads simultaneously here we understood that
you can see thread concept here also you can see thread
concept in CPU but when it comes to running thousands of
threads at the same time then we can say that it is GPU
because we made it specially
for this purpose so this makes it well suited for what kind
of task like processing image for that task for machine
learning for this purpose or for scientific simulation for
that purpose also it makes it well suited so I came to know
that
I can see parallelism in CPU but what we saw on massive
scale in GPU now let's talk about memory hierarchy now
let's talk about memory hierarchy now let's talk about
memory hierarchy now let's talk about memory hierarchy now
let's talk about memory hierarchy
now let's talk about memory hierarchy now let's talk about
memory hierarchy now let's talk about memory hierarchy now
let's talk about memory hierarchy now let's talk about
memory hierarchy now let's talk about memory hierarchy now
let's talk about memory
hierarchy now let's talk about memory hierarchy now let's
talk about memory hierarchy now let's talk about memory
hierarchy now let's talk about memory hierarchy
I am going to learn CUDA, CUDA is not CUDA, it is C U D A,
then I realized that it is OpenCL, so I have to learn it,
that is, the specialized languages ​​in it are CUDA and
OpenCL, whereas in the CPU, in the programming model, you
get to see C, C++, Python.
Now let's talk about use cases, that when should I use the
CPU, where should I use it, what is the requirement of the
CPU, what is the requirement of the GPU, should I go and
tell him that whoever I am, from whom I will bring the
laptop, that brother,
you do one thing, give dedicated dp, no, why is it not
necessary, I am doing a basic task,
I am doing a basic job, so why do I need it, there is no
need, if I am doing such things, then why do I need it,
here we see use cases, what do we see in use cases, the
first thing is our CPU, in CPU, we saw that it is well
suited for general purpose,
this is what we read in the first point, okay, in the first
point, we also saw that the functionality of the CPU is
that it is a general purpose, but here you get to see the
same thing that general purpose computing, which is your
task, it is well suited
for that, if you feel that brother, what do you have to do
basically, you have to listen to such songs, you have to
edit such documents, you have to play a light game, so
there I will say that brother, do one thing, the CPU will
come, so there you do
not need to take the GPU, the integrated GPU that will come
there, to a large extent, it will solve all your things,
then why do you have to go to take it for no reason, so
after that, let's see here, what is your computing task,
general purpose computing
task, including running operating system, what does your
operating system run, this is the computing task, this
operating system is going to run, who does this, CPU does
it, or office applications, office application means that
your word,
Excel, PowerPoint, these applications, if you want to run
this application normally, then what will you do, you will
simply use it, that brother, you will take the CPU, you
will not go to the GPU, the integrated GPU that will come
to you, you will use
it, and task with complex logic, if there is a task in
which there is a lot of complex logic, what can you do in
that too, that brother, what is the use of this, CPU, so
you will take the CPU, and there you will go to the
integrated GPU, you will not
go to the dedicated GPU, but if you talk here, what is the
use of GPU, when you should take GPU, particularly
effective for graphic rendering, if you want to do graphics
rendering, if you want to do scientific simulation, you
have to do something on machine
learning, you have to do something on video processing, and
you have to do other tasks, in which parallel computation
is happening, so there you will think that my integrated
GPU is not going to work here, so when the integrated GPU
is not going to work,
so there I will automatically go to whom, there I will go
to the dedicated GPU, so I found out what is the use case
of CPU, and what is the use case of GPU, if I talk about
power consumption, so I said that power consumption, when I
have so many codes,
and they will run together, so it is the same thing, if I
tell you that if you do more work, then you will get more
tired, it is the same thing, that is, you have to put more
power, so here our small smaller codes, what they do, they
work, means they
will work efficiently, but what will happen, power
consumption will be more, let's see the power consumption
of CPU, generally designed for power efficiency, and can be
more power aware, that is, there is not much power in it,
they are power aware, they
take care of things on their own, they do not spend so much
power, especially in mobile and battery powered devices,
power efficiency, that is, they are power efficient, they
do not drain much power, they do not use much power, but if
I talk about GPU,
while they can be power hungry, they are very hungry for
power,
GPUs are optimized for performance, you have to get a
performance, the game should run very well, what will you
do, you will use GPU,