[CS61C FA20] Lecture 32.2 - Flynn Taxonomy, SIMD Instructions: Matrix Multiplication — Transcript
Full transcript
- 0:00[Music]
- 0:10hi welcome back to our paralysis module
- 0:13before we introduce the ways how we
- 0:16actually accomplish
- 0:17parallel operation let's try to
- 0:19establish a baseline and our baseline
- 0:21will be some common kernel executed
- 0:24on a sequential machine
- 0:27that we have studied so far by using
- 0:30programming techniques
- 0:32that are familiar to us so let's start
- 0:35with matrix multiplication we have seen
- 0:36matrix multiplication
- 0:38uh to get a matrix c which is a product
- 0:41of two matrices a and b we
- 0:44would walk through over the elements
- 0:48in that matrix c over all the rows
- 0:51and columns to find the elements c
- 0:54i j and they're going to be
- 0:58element-wise products or corresponding
- 1:01rows
- 1:01and columns in matrices a and b so for
- 1:05example to find an element c
- 1:071 1 in this matrix that would be
- 1:11a product of a 1 1 b
- 1:141 1 plus a 1 2
- 1:17b 2 1. when we plug in the numbers for
- 1:20the
- 1:23sample matrix down here that would be
- 1:25equal to
- 1:271 times 1 plus 0 times 2
- 1:30equals to 1. and so on we continue doing
- 1:34that
- 1:35over the all the elements i
- 1:38j in the matrix c when we write a
- 1:41program this is essentially
- 1:43a triple loop we are going to walk over
- 1:47all the elements i j and k
- 1:50in three loops let's take a look at the
- 1:53implementation
- 1:54in a familiar language like python so
- 1:57matrix multiplication in python
- 1:59essentially influence those three loops
- 2:01we go over the
- 2:03coefficients we want coefficients i and
- 2:06j
- 2:07within their range in this case these
- 2:09are square matrices
- 2:10we initialize each of the values
- 2:14for the elements c i j
- 2:18to zero and then we accumulate you know
- 2:21in the inner loop we accumulate
- 2:25a times b from corresponding places
- 2:29in matrices a and b
- 2:33when we try to time that we can find
- 2:36out that the result is fairly
- 2:38independent on the
- 2:39size of the matrix we get about
- 2:435 mega flops
- 2:46what are mega flops well it's a measure
- 2:48of
- 2:49how fast is our computational throughput
- 2:52you'll often hear people referring to
- 2:55megaflops
- 2:56and that stands for millions of floating
- 2:58point operations per second
- 3:00now each of the floating point
- 3:02operations here that we encounter
- 3:05is counted separately so we are going to
- 3:07see a floating point add
- 3:08and a floating point malt so each add
- 3:11and each mult
- 3:12are going to be two separate
- 3:16floating point operations so
- 3:19there is one floating point operation
- 3:22that corresponds to multiplication
- 3:25and one floating point operation that
- 3:28corresponds to addition so
- 3:30this line of code is two flops
- 3:33so um when you take a look at this
- 3:37then therefore since this is a triple
- 3:38loop or square matrices of each other
- 3:41size n
- 3:42so it takes n cubed flops times two
- 3:45because in within each iteration
- 3:48we have two floating point operations
- 3:53now is this fast
- 3:56or slow it's kind of hard to tell i mean
- 3:59we really haven't discussed that
- 4:01so far so let's take a look at a second
- 4:03example let's see how do we implement
- 4:05this
- 4:06in c language well there is not much
- 4:08difference
- 4:09in c we are going to have a scalar
- 4:13which is our sequential uh kind of an
- 4:16operation so here is our djm scalar
- 4:19baseline
- 4:20it's a triple loop element gets in an
- 4:22element gets
- 4:23initialized and we accumulate uh
- 4:28a times b products to it
- 4:32how long does that take to do well you
- 4:35can actually run this experiment
- 4:37there is a standard library time dot h
- 4:39that exists in c
- 4:40that we can invoke and what we can get
- 4:42from that we can get
- 4:44clock so we can get a
- 4:47clock cycle when we start running this
- 4:52matrix multiplication and we can get
- 4:54then
- 4:55clock that corresponds to the end
- 4:58of execution of a problem and if we run
- 5:01the program
- 5:02we call djem as a function in between
- 5:04we're going to get the number of clock
- 5:05cycles
- 5:06that it takes us to execute if we divide
- 5:08that by the number of clocks per second
- 5:11we get the speed of our matrix
- 5:14multiplication
- 5:15so if we repeat that versus python
- 5:18and compare it to python this is what we
- 5:19get and numbers here
- 5:23of how many flops do we get
- 5:26is actually in gigaflops not in
- 5:30megaflops it's in gigaflops so billions
- 5:32of floating point operations per second
- 5:35compared to megaflops that we have seen
- 5:38in with with the python
- 5:42um and
- 5:46we see something kind of surprising this
- 5:49is
- 5:49way faster you know code running in c
- 5:52is way faster than code running in in
- 5:56python it's not just a low light it's
- 5:59like 240 times faster
- 6:01that's crazy
- 6:07yeah you should feel good about yourself
- 6:09now we you know see
- 6:10and you know how to do these things that
- 6:13correspond to performance programming
- 6:15that's a kind of a big deal
- 6:19uh and you can think about you can start
- 6:20appreciating 61c even more than you are
- 6:22appreciating so far
- 6:24because there is no other class that
- 6:25gives you um 240 boost
- 6:29240x boost in in your um
- 6:33performance programming skills
- 6:36there is one another interesting thing
- 6:38here that we see
- 6:40is that the performance in the numbers
- 6:44of gigaflops is
- 6:46constant until we get to a certain size
- 6:49of a
- 6:49matrix and then it drops
- 6:55what do you think where does that come
- 6:56from
- 6:59it has highly likely to do something
- 7:02with the cache size some of these things
- 7:04may not be fitting
- 7:06in the cache some of these matrices may
- 7:08not be fitting in the cache
- 7:12so this is great we improved the
- 7:14performance
- 7:15by 240x but you don't want to stop here
- 7:18we are going to make this matrix
- 7:20multiplication go faster and faster
- 7:23throughout this module so we're going to
- 7:26take a little break
- 7:28and then talk a little bit about how do
- 7:31we
- 7:32classify these different types of
- 7:34parallelism
- 7:36see you after a break
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 32.2 - Flynn Taxonomy, SIMD Instructions: Matrix Multiplication by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,001 words across 177 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.