Presentation is loading. Please wait.

Presentation is loading. Please wait.

June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 1 CS232: Computer Architecture II Fall 2011 Nvidia Fermi GPU.

Similar presentations


Presentation on theme: "June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 1 CS232: Computer Architecture II Fall 2011 Nvidia Fermi GPU."— Presentation transcript:

1 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 1 CS232: Computer Architecture II Fall 2011 Nvidia Fermi GPU

2 2  Computer architecture is about building and analyzing computer systems  Course web page: http://www.cs.illinois.edu/class/cs232/http://www.cs.illinois.edu/class/cs232/  Piazza  Make sure you have an EWS account: —If you are not an engineering student, contact the TAs! What is computer architecture about? Memory Processor Input/Output Compiler HLLASM

3 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 3 Why should you care?  It is interesting. —How do you make a processor that runs at 3Ghz?  It will help you be a better programmer. —Understanding how your program is translated to assembly code lets you reason about correctness and performance. —Demystify the seemingly arbitrary (e.g., bus errors, segmentation faults )  Many cool jobs require an understanding of computer architecture. —The cutting edge is often pushing computers to their limits. —Supercomputing, games, portable devices, etc.  Computer architecture illustrates many fundamental ideas in computer science —Abstraction, caching, and indirection are CS staples

4 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 4 CS232: Computer Architecture II Fall 2011  Two topics: —Background: Low-level programming in High-level languages Bit-wise operations and shifting —Continuing from section: Memory & Loads/Stores in MIPS Write MIPS programs that use more than just registers

5 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 5 Bit-wise Arithmetic

6 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 6 Low-level Programming in “High-level” Languages  Very often it is necessary to store a large number of very small data items.  Example: A Social Security Number (SSN) registry —Needs to keep track of how which SSNs have already been allocated.  How much space is required?

7 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 7 Storing collections of bits as integers  Store N bits in each N-bit integer, only need 10 9 /N integers —Requires 10 9 /8 bytes = 125MBs of storage (fits on a CD)  Allocate array: int array_size = 1000000000/_____________ unsigned int SSN_registry[array_size];  Want two operations on this array: —check_SSN: returns 1 if SSN is used, 0 otherwise —set_SSN: marks an SSN as used. 01000110011111010111010100101001 11011101011010010001010100101011 10010101111010010101100100100010 10010101010101100101010010110010 10010101000101011001010111111101 00001000010111001100100011110101 01101011101001010001000000101011 SSN #7 SSN #68

8 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 8 check_SSN int check_SSN(unsigned int SSN_registry[], int ssn) { int word_index = ssn / sizeof(int); int word = SSN_registry[word_index]; 01000110011111010111010100101001 11011101011010010001010100101011 10010101111010010101100100100010 10010101010101100101010010110010 10010101000101011001010111111101 00001000010111001100100011110101 01101011101001010001000000101011 10010101000101011001010111111101

9 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 9 check_SSN int check_SSN(unsigned int SSN_registry[], int ssn) { int word_index = ssn / sizeof(int); int word = SSN_registry[word_index]; int bit_offset = ssn % sizeof(int) // % is the remainder operation word = word >> bit_offset; // >> shifts a value “right” (note: zeros are inserted at the left because it is an unsigned int) 01000110011111010111010100101001 11011101011010010001010100101011 10010101111010010101100100100010 10010101010101100101010010110010 10010101000101011001010111111101 00001000010111001100100011110101 01101011101001010001000000101011 10010101000101011001010111111101 000001001010100010101100101011111

10 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 10 check_SSN int check_SSN(unsigned int SSN_registry[], int ssn) { int word_index = ssn / sizeof(int); int word = SSN_registry[word_index]; int bit_offset = ssn % sizeof(int) word = word >> bit_offset; word = (word & 1); // & is the bit-wise logical AND operator return word;(each bit position is considered independently) } 01000110011111010111010100101001 11011101011010010001010100101011 10010101111010010101100100100010 10010101010101100101010010110010 10010101000101011001010111111101 00001000010111001100100011110101 01101011101001010001000000101011 10010101000101011001010111111101 000001001010100010101100101011111 000000000000000000000000000000001 &

11 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 11 set_SSN void set_SSN(unsigned int SSN_registry[], int ssn) { int bit_offset = ssn % sizeof(int) int new_bit = (1 << bit_offset) // “left” shift the 1 to the desired spot (always shifts in 0’s at the right) 01000110011111010111010100101001 11011101011010010001010100101011 10010101111010010101100100100010 10010101010101100101010010110010 10010101000101011001010111111101 00001000010111001100100011110101 01101011101001010001000000101011 000000000000000000000010000000000 000000000000000000000000000000001

12 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 12 set_SSN void set_SSN(unsigned int SSN_registry[], int ssn) { int bit_offset = ssn % sizeof(int) int new_bit = (1 << bit_offset) int word_index = ssn / sizeof(int); int word = SSN_registry[word_index]; 01000110011111010111010100101001 11011101011010010001010100101011 10010101111010010101100100100010 10010101010101100101010010110010 10010101000101011001010111111101 00001000010111001100100011110101 01101011101001010001000000101011 100101010001010110010101111111101 000000000000000000000010000000000 000000000000000000000000000000001

13 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 13 100101010001010110010111111111101 set_SSN void set_SSN(unsigned int SSN_registry[], int ssn) { int bit_offset = ssn % sizeof(int) int new_bit = (1 << bit_offset) int word_index = ssn / sizeof(int); int word = SSN_registry[word_index]; word = word | new_bit; // bit-wise logical OR sets the desired bit 01000110011111010111010100101001 11011101011010010001010100101011 10010101111010010101100100100010 10010101010101100101010010110010 10010101000101011001010111111101 00001000010111001100100011110101 01101011101001010001000000101011 100101010001010110010101111111101 000000000000000000000010000000000 | 000000000000000000000000000000001

14 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 14 100101010001010110010111111111101 set_SSN void set_SSN(unsigned int SSN_registry[], int ssn) { int bit_offset = ssn % sizeof(int) int new_bit = (1 << bit_offset) int word_index = ssn / sizeof(int); int word = SSN_registry[word_index]; word = word | new_bit; SSN_registry[word_index] = word; // write back the word into array } Shorthand for last 3 lines: SSN_registry[word_index] |= new_bit; 01000110011111010111010100101001 11011101011010010001010100101011 10010101111010010101100100100010 10010101010101100101010010110010 10010101000101011001011111111101 00001000010111001100100011110101 01101011101001010001000000101011 100101010001010110010101111111101 000000000000000000000010000000000 | 000000000000000000000000000000001

15 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 15 What you just saw  Storage of a collection of booleans in an integer  Use of bit-wise logical operations to read and write specific bits  Use of shifts to move bits with an integer  This stuff gets used all over the place in real code: —Bitmap graphics —Network packet headers —Operating system tracking free disk blocks

16 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 16 Topic 2: Memory & Loads/Stores in MIPS  Last time, we saw registers and basic arithmetic, ultimately leading to: void main() { int i = 516; int j = i*(i+1)/2; i = i + j; } main: # start of main li $t0, 516 # i = 516 addi $t1, $t0, 1 # i + 1 mul $t1, $t0, $t1 # i * (i + 1) li $t2, 2 div $t1, $t1, $t2 # j = i*(i+1)/2 add $t0, $t0, $t1 # i = i + j jr $ra # return

17 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 17 We need more space!  Registers are fast and convenient, but we have only 32 of them, and each one is just 32-bits wide. —That’s not enough to hold data structures like large arrays. —We also can’t access data elements that are wider than 32 bits.  We need to add some main memory to the system! —RAM is cheaper and denser than registers, so we can add lots of it. —But memory can be significantly slower, so registers should be used whenever possible.

18 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 18 Memory review  Memory sizes are specified much like register files; here is a 2 k x n RAM.  A chip select input CS enables or “disables” the RAM.  ADRS specifies the memory location to access.  WR selects between reading from or writing to the memory. —To read from memory, WR should be set to 0. OUT will be the n-bit value stored at ADRS. —To write to memory, we set WR = 1. DATA is the n-bit value to store in memory. CSWROperation 0xNone 10Read selected address 11Write selected address 2 k  n memory ADRSOUT DATA CS WR n k n

19 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 19 MIPS memory  MIPS memory is byte-addressable, which means that each memory address references an 8-bit quantity.  The (original) MIPS architecture can support up to 32 address lines. —This results in a 2 32 x 8 RAM, which would be 4 GB of memory. —Not all actual MIPS machines will have this much! 2 32  8 memory ADRSOUT DATA CS WR 8 32 8 01234567891011Address 8-bit data

20 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 20 Loading and storing bytes  The MIPS instruction set includes dedicated load and store instructions for accessing memory.  MIPS uses indexed addressing. —The address operand specifies a signed constant and a register. —These values are added to generate the effective address.  The MIPS “load byte” instruction lb transfers one byte of data from main memory to a register. lb $t0, 20($a0)# $t0 = Memory[$a0 + 20]  The “store byte” instruction sb transfers the lowest byte of data from a register into main memory. sb $t0, 20($a0)# Memory[$a0 + 20] = $t0

21 June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 21 Byte loads  Question: if you load a byte (8 bits) into a register (32 bits), what value do those other 24 bits have?


Download ppt "June 7, 2016©2011 Craig Zilles (partly adapted from slides by Howard Huang) 1 CS232: Computer Architecture II Fall 2011 Nvidia Fermi GPU."

Similar presentations


Ads by Google