[CS61C FA20] Lecture 32.6 - Flynn Taxonomy, SIMD Instructions: Matrix Multiply Example — Transcript
Full transcript
- 0:00[Music]
- 0:10hello
- 0:11and welcome back to our parallelism
- 0:12module
- 0:14so now we know how do seamless
- 0:17extensions work how are they supported
- 0:21by the instruction set architecture are
- 0:24they
- 0:24generally roughly implemented in
- 0:26hardware and how do we use these
- 0:28instructions in
- 0:29assembly and perhaps as in 36
- 0:32and c so let's take a look at one
- 0:36example
- 0:36that puts things together and uses
- 0:40the the similar instructions to perform
- 0:43matrix multiplication so
- 0:47we have seen this matrix multiplication
- 0:48as a motivating example early on this is
- 0:50a really tiny matrix it has
- 0:53you know it is multiplying only two by
- 0:55two matrices
- 0:56two by two square matrices and produces
- 0:58another
- 0:59two by two square matrix but
- 1:02i've circled these elements that we are
- 1:05working with in a little bit different
- 1:07way
- 1:07than i've done it before i
- 1:10do want to highlight here that the
- 1:14way how data is organized in memory
- 1:17matters a lot so be careful about that
- 1:22we're assuming that the data is stored
- 1:26in the column format so
- 1:29in this case a11
- 1:32is next to a21 they are neighbors in the
- 1:36column
- 1:36so they should be stored next to each
- 1:38other in the memory
- 1:40but generally in a larger matrix
- 1:44a11 is not going to be next to
- 1:47a 1 2.
- 1:51okay so
- 1:54let's see what do we need to do in order
- 1:56to
- 1:57perform a basically kind of a half of
- 2:00this or a quarter of a matrix
- 2:01multiplication
- 2:02we'll use elements a 1 1 a 2 1
- 2:062 1 and multiply them in b 1
- 2:091 to get this
- 2:13first two elements in
- 2:16c 1 1 and c 2 1.
- 2:19that's where the parallelism is going to
- 2:21come from
- 2:22so when we are doing matrix
- 2:25multiplication
- 2:26we will first initialize the matrix so
- 2:29we'll set everything to zeros
- 2:31and then we're going to be adding these
- 2:34element-wise products to that running
- 2:36sum
- 2:38so uh in order to implement what i've
- 2:42just said
- 2:43we need to do a couple of steps first we
- 2:46need to
- 2:46load these operands into
- 2:50the xmm registers
- 2:53so if a11 and a21
- 2:57are next to each other this is they're
- 3:00stored in a column order
- 3:01they're going to be read in order
- 3:05and they're going to be stored together
- 3:07as a
- 3:09packed double precision vector
- 3:14now there is another instruction that
- 3:16enables us to essentially
- 3:18read the next operand which by the way
- 3:20are not necessarily
- 3:22stored next to each other because b11 if
- 3:25your b matrix is also stored in a
- 3:27column order these two elements b 1 1
- 3:30and b 1 2
- 3:30are not going to be next to each other
- 3:32so we can
- 3:34read both of those in two separate
- 3:36instructions
- 3:38and make two copies of that there is a
- 3:40separate instruction
- 3:41ssc instruction that does that so we got
- 3:44things where they
- 3:45are supposed to be we can go ahead and
- 3:48multiply them
- 3:49but we're actually going to perform
- 3:51multiply
- 3:53and addition typically these ssc
- 3:56instructions or different kinds of
- 3:58vector instructions support something
- 4:00that is called the fuse multiply add
- 4:02so they do multiplication and addition
- 4:06in one instruction
- 4:10that instruction may take more than one
- 4:12cycle but
- 4:14it's you know like one take to do
- 4:15multiply add
- 4:18so in this case it is spelled out as
- 4:24mm add then with the contents over here
- 4:28of a multiple inside of it so that is
- 4:31essentially these two instructions one
- 4:33after another
- 4:34uh we'll first do parallel
- 4:36multiplication and then do parallel
- 4:38addition
- 4:39in xmm registers so as a result in c1 we
- 4:42are going to
- 4:43have a 1 1 b 1 1
- 4:47and then in the upper part of that
- 4:49register and in the lower part of the
- 4:50register we're going to have a 2 1
- 4:53b 1 1.
- 4:56essentially this part over here
- 5:00and then in
- 5:04c2 we're going to have a11 b12
- 5:08and 2 1 b 1 2.
- 5:11then we continue we get the next
- 5:15few elements of this matrix
- 5:19register a is going to get loaded
- 5:23with the next elements in the array so
- 5:25will be the registers b1 and b2
- 5:27these are all just xmm registers and
- 5:30we turn the crank one more time
- 5:34and we are done our
- 5:37registers destination register c1 and c2
- 5:40contain four elements of our
- 5:44double precision result
- 5:47matrix and that is it
- 5:50that's essentially what is the you know
- 5:52how we can use these
- 5:53simply instructions to perform matrix
- 5:57multiplication
- 5:59multiple elements at a time
- 6:05a code is shown here um i'm not going to
- 6:08walk through it
- 6:09it is reasonably uh straightforward
- 6:14it is shown as an example of using
- 6:16intrinsics
- 6:17in the c code so what you'll find out
- 6:20here is a
- 6:21mix of standard c code with
- 6:24the with the
- 6:28intrinsic declarations and then
- 6:31intrinsic instructions and that's it
- 6:34it's a relatively quick code
- 6:36it is worth walking through it and
- 6:38understanding exactly how does it
- 6:40implement what i've shown in the
- 6:41previous few slides
- 6:45we're almost ready to wrap up our
- 6:47discussion about
- 6:49the sim cindy architectures and
- 6:52their role in parallelism
- 6:56first i want to make a quick remark
- 6:58about risk five we've been talking about
- 7:00risk five so far
- 7:01but we had to switch over to intel
- 7:04x86 extensions um for
- 7:08this module why is that well
- 7:12there are risk five vector extension
- 7:16there is a risk 5 vector extension that
- 7:18is in development is still
- 7:19in the draft it is almost ready to go
- 7:25prime time but
- 7:28we can't have any hardware there is no
- 7:30hardware that supports it so we can't
- 7:31have
- 7:32projects and labs and so on give it a
- 7:34year or two
- 7:35and risk five vector extensions will be
- 7:37there and we can do
- 7:39everything in the risk live world for
- 7:41now we need to
- 7:42patch it up with the intel 686
- 7:46avx and sscs
- 7:52what you'll find out you know please you
- 7:54can take a look
- 7:55if you like into the v extension draft
- 7:57there is a whole bunch of instructions
- 7:59there assumes 512
- 8:01wide vectors
- 8:04in conclusion we have the examined
- 8:08uh flint's taxonomy of parallel
- 8:11architectures and
- 8:12we have paid attention generally in cmd
- 8:14and memdi
- 8:16architectures and actually what we have
- 8:18learned so far
- 8:20are the cmd architectures and
- 8:23we are going to revisit sim the
- 8:24architectures when we take a look at
- 8:26gpus a bit later
- 8:28in the course
- 8:31and in the next few segments we're going
- 8:33to take a look at
- 8:34memdi instructions we'll also examine
- 8:38how this is implemented in case of
- 8:40intel's abx simdi extension
- 8:45and we can see that there is one
- 8:47instruction that can fetch
- 8:48and another instruction will operate on
- 8:51a vector of data
- 8:52or multiple operands simultaneously
- 8:56and we've seen how we can use those how
- 8:58we can directly access those
- 9:00as c intrinsics
- 9:04that is it it's time for a break
- 9:07we'll continue with how do we work
- 9:11with multiple processors in multiple
- 9:14cores
- 9:15see you later
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 32.6 - Flynn Taxonomy, SIMD Instructions: Matrix Multiply Example by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,165 words across 219 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.