├── week_3 ├── lab │ ├── exercise_04 │ │ ├── test-input.txt │ │ ├── interactive_hello.c │ │ └── makefile │ ├── lab-01.pdf │ ├── exercise_03 │ │ ├── makefile │ │ └── ll_equal.c │ ├── exercise_01 │ │ ├── makefile │ │ └── eccentric.c │ ├── exercise_05 │ │ ├── makefile │ │ └── ll_cycle.c │ └── README.MD ├── homework │ ├── homework-01.pdf │ └── README.MD ├── project │ ├── project-02.pdf │ └── README.MD ├── section │ ├── section-02.pdf │ ├── int_stack │ │ ├── int-stack.h │ │ ├── main.c │ │ ├── makefile │ │ └── int-stack.c │ ├── int_linked_list │ │ ├── int-linked-list.h │ │ ├── makefile │ │ ├── main.c │ │ └── int-linked-list.c │ └── README.MD └── README.MD ├── week_6 ├── README.MD └── lab │ ├── lab-04.pdf │ ├── README.MD │ ├── discrete_fn.s │ └── megalistmanips.s ├── week_10 ├── README.MD └── research │ ├── README.MD │ └── dgemm │ ├── makefile │ ├── dgemm.h │ ├── main.c │ └── dgemm.c ├── week_14 ├── README.MD └── section │ ├── section-13.pdf │ └── README.MD ├── week_2 ├── lab │ ├── lab-00.pdf │ └── README.MD ├── project │ ├── project-01.pdf │ └── README.MD ├── section │ ├── section-01.pdf │ └── README.MD └── README.MD ├── week_4 ├── lab │ ├── lab-02.pdf │ ├── README.MD │ ├── exercise_02 │ │ ├── makefile │ │ └── lfsr.c │ └── exercise_01 │ │ ├── makefile │ │ └── bit_ops.c ├── README.MD └── section │ ├── section-03.pdf │ └── README.MD ├── week_5 ├── lab │ ├── lab-03.pdf │ ├── factorial.s │ ├── README.MD │ └── list_map.s ├── README.MD └── section │ ├── section-04.pdf │ └── README.MD ├── week_9 ├── lab │ ├── lab-07.pdf │ ├── exercise_02 │ │ ├── makefile │ │ └── matrix-multiply.c │ ├── README.MD │ └── exercise_03 │ │ ├── makefile │ │ └── matrix-transpose.c ├── README.MD └── section │ ├── section-08.pdf │ └── README.MD ├── week_12 ├── lab │ ├── lab-10.pdf │ ├── exercise_03_04 │ │ ├── makefile │ │ ├── sorted.c │ │ ├── randomized.c │ │ └── common.h │ └── README.MD ├── README.MD └── section │ ├── section-11.pdf │ ├── exercise_1 │ ├── vector-product.h │ ├── makefile │ ├── main.c │ └── vector-product.c │ └── README.MD ├── week_13 ├── lab │ ├── lab-11.pdf │ ├── README.MD │ ├── makefile │ ├── v-add.c │ └── dot-p.c ├── README.MD └── section │ ├── section-12.pdf │ └── README.MD ├── week_1 ├── README.MD ├── homework │ ├── homework-00.pdf │ └── README.MD └── section │ ├── section-00.pdf │ └── README.MD ├── week_15 ├── README.MD ├── project │ ├── project-05.pdf │ └── README.MD └── section │ ├── section-14.pdf │ └── README.MD ├── .gitmodules ├── .gitignore └── README.MD /week_3/lab/exercise_04/test-input.txt: -------------------------------------------------------------------------------- 1 | Kirill -------------------------------------------------------------------------------- /week_6/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [lab](./lab/README.MD) -------------------------------------------------------------------------------- /week_10/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [research](./research/README.MD) -------------------------------------------------------------------------------- /week_14/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) -------------------------------------------------------------------------------- /week_2/lab/lab-00.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_2/lab/lab-00.pdf -------------------------------------------------------------------------------- /week_3/lab/lab-01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_3/lab/lab-01.pdf -------------------------------------------------------------------------------- /week_4/lab/lab-02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_4/lab/lab-02.pdf -------------------------------------------------------------------------------- /week_5/lab/lab-03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_5/lab/lab-03.pdf -------------------------------------------------------------------------------- /week_6/lab/lab-04.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_6/lab/lab-04.pdf -------------------------------------------------------------------------------- /week_9/lab/lab-07.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_9/lab/lab-07.pdf -------------------------------------------------------------------------------- /week_12/lab/lab-10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_12/lab/lab-10.pdf -------------------------------------------------------------------------------- /week_13/lab/lab-11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_13/lab/lab-11.pdf -------------------------------------------------------------------------------- /week_4/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) 4 | * [lab](./lab/README.MD) -------------------------------------------------------------------------------- /week_5/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) 4 | * [lab](./lab/README.MD) -------------------------------------------------------------------------------- /week_9/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) 4 | * [lab](./lab/README.MD) -------------------------------------------------------------------------------- /week_12/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) 4 | * [lab](./lab/README.MD) -------------------------------------------------------------------------------- /week_13/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) 4 | * [lab](./lab/README.MD) -------------------------------------------------------------------------------- /week_1/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [homework](./homework/README.MD) 4 | * [section](./section/README.MD) -------------------------------------------------------------------------------- /week_1/homework/homework-00.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_1/homework/homework-00.pdf -------------------------------------------------------------------------------- /week_1/section/section-00.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_1/section/section-00.pdf -------------------------------------------------------------------------------- /week_12/section/section-11.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_12/section/section-11.pdf -------------------------------------------------------------------------------- /week_13/section/section-12.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_13/section/section-12.pdf -------------------------------------------------------------------------------- /week_14/section/section-13.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_14/section/section-13.pdf -------------------------------------------------------------------------------- /week_15/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) 4 | * [project](./project/README.MD) -------------------------------------------------------------------------------- /week_15/project/project-05.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_15/project/project-05.pdf -------------------------------------------------------------------------------- /week_15/section/section-14.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_15/section/section-14.pdf -------------------------------------------------------------------------------- /week_2/project/project-01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_2/project/project-01.pdf -------------------------------------------------------------------------------- /week_2/section/section-01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_2/section/section-01.pdf -------------------------------------------------------------------------------- /week_3/homework/homework-01.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_3/homework/homework-01.pdf -------------------------------------------------------------------------------- /week_3/project/project-02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_3/project/project-02.pdf -------------------------------------------------------------------------------- /week_3/section/section-02.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_3/section/section-02.pdf -------------------------------------------------------------------------------- /week_4/section/section-03.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_4/section/section-03.pdf -------------------------------------------------------------------------------- /week_5/section/section-04.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_5/section/section-04.pdf -------------------------------------------------------------------------------- /week_9/section/section-08.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/moki/cs61c/HEAD/week_9/section/section-08.pdf -------------------------------------------------------------------------------- /week_2/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) 4 | * [lab](./lab/README.MD) 5 | * [project](./project/README.MD) -------------------------------------------------------------------------------- /week_3/README.MD: -------------------------------------------------------------------------------- 1 | ## Material 2 | 3 | * [section](./section/README.MD) 4 | * [homework](./homework/README.MD) 5 | * [lab](./lab/README.MD) 6 | * [project](./project/README.MD) -------------------------------------------------------------------------------- /week_2/project/README.MD: -------------------------------------------------------------------------------- 1 | ## Project - 01 2 | 3 | ### Description 4 | 5 | [project-01.pdf](./project-01.pdf) 6 | 7 | ### 8 | 9 | Code located in the git submodule at 10 | 11 | ``` 12 | ./philphix/ 13 | ``` -------------------------------------------------------------------------------- /week_3/project/README.MD: -------------------------------------------------------------------------------- 1 | ## Project - 02 2 | 3 | ### Description 4 | 5 | [project-02.pdf](./project-02.pdf) 6 | 7 | ### 8 | 9 | Code located in the git submodule at 10 | 11 | ``` 12 | ./riscv-is-emu/ 13 | ``` -------------------------------------------------------------------------------- /week_15/project/README.MD: -------------------------------------------------------------------------------- 1 | ## Project - 05 2 | 3 | ### Description 4 | 5 | [project-05.pdf](./project-05.pdf) 6 | 7 | Code located in the git submodule at 8 | 9 | ``` 10 | ./cs61c-sp18-ml-classifier-cache/ 11 | ``` 12 | -------------------------------------------------------------------------------- /week_6/lab/README.MD: -------------------------------------------------------------------------------- 1 | ## Lab 04 2 | 3 | RISC-V Functions and Pointers 4 | 5 | ``` 6 | ./lab-04.pdf 7 | ``` 8 | 9 | ## Exercise 1: Debugging megalistmanips.s 10 | 11 | ``` 12 | megalistmanips.s - TODO 13 | ``` 14 | 15 | ## Exercise 2: Write a function without branches 16 | 17 | ``` 18 | discrete_fn.s 19 | ``` 20 | -------------------------------------------------------------------------------- /week_10/research/README.MD: -------------------------------------------------------------------------------- 1 | ## Research - DGEMM 2 | 3 | DGEMM stands for Double precision, GEneral Matrix Multiply. 4 | 5 | Let's code up naive algorithm, and improve it incrementally, to investigate ways of parrallel optimization and achieve the best possible performance. 6 | 7 | ``` 8 | cd dgemm 9 | make test 10 | ``` 11 | -------------------------------------------------------------------------------- /week_4/lab/README.MD: -------------------------------------------------------------------------------- 1 | ## Lab 02 2 | 3 | Advanced C and Memory Management 4 | 5 | ``` 6 | ./lab-02.pdf 7 | ``` 8 | 9 | ## Exercise 1: Bit Operations 10 | 11 | ``` 12 | cd exercise_01/ 13 | make test 14 | ``` 15 | 16 | ## Exercise 2: Linear feedback shift register 17 | 18 | ``` 19 | cd exercise_02/ 20 | make test 21 | ``` 22 | -------------------------------------------------------------------------------- /week_12/lab/exercise_03_04/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | C_FLAGS=--std=c99 3 | 4 | all: randomized sorted 5 | 6 | clean: 7 | rm -f randomized sorted > /dev/null 2>&1 8 | 9 | sorted: sorted.c common.h 10 | $(CC) $(C_FLAGS) sorted.c -o sorted 11 | 12 | randomized: randomized.c common.h 13 | $(CC) $(C_FLAGS) randomized.c -o randomized 14 | -------------------------------------------------------------------------------- /week_12/section/exercise_1/vector-product.h: -------------------------------------------------------------------------------- 1 | #ifndef VECTOR_PRODUCT_H 2 | 3 | #define VECTOR_PRODUCT_H 4 | 5 | #include 6 | #include 7 | 8 | extern int64_t vector_product_naive(size_t length, int32_t *vector); 9 | 10 | extern int64_t vector_product_vectorized(size_t length, int32_t *vector); 11 | 12 | #endif -------------------------------------------------------------------------------- /week_4/lab/exercise_02/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -g3 -Wno-pointer-arith 3 | 4 | all: lfsr.out 5 | 6 | lfsr.out: lfsr.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | lfsr.o: lfsr.c 10 | 11 | test: all 12 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./lfsr.out 13 | make clean 14 | 15 | clean: 16 | $(RM) lfsr.out *.o vgcore.* -------------------------------------------------------------------------------- /week_9/lab/exercise_02/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -O3 -Wno-pointer-arith 3 | 4 | all: matrix-multiply.out 5 | 6 | matrix-multiply.out: matrix-multiply.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | matrix-multiply.o: matrix-multiply.c 10 | 11 | test: all 12 | ./matrix-multiply.out 13 | make clean 14 | 15 | clean: 16 | $(RM) matrix-multiply.out *.o vgcore.* -------------------------------------------------------------------------------- /week_4/lab/exercise_01/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -g3 -Wno-pointer-arith 3 | 4 | all: bit_ops.out 5 | 6 | bit_ops.out: bit_ops.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | bit_ops.o: bit_ops.c 10 | 11 | test: all 12 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./bit_ops.out 13 | make clean 14 | 15 | clean: 16 | $(RM) bit_ops.out *.o vgcore.* -------------------------------------------------------------------------------- /week_3/lab/exercise_03/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -g3 -Wno-pointer-arith 3 | 4 | all: ll_equal.out 5 | 6 | ll_equal.out: ll_equal.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | ll_equal.o: ll_equal.c 10 | 11 | test: all 12 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./ll_equal.out 13 | make clean 14 | 15 | clean: 16 | $(RM) ll_equal.out *.o vgcore.* -------------------------------------------------------------------------------- /week_3/lab/exercise_01/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -g3 -Wno-pointer-arith 3 | 4 | all: eccentric.out 5 | 6 | eccentric.out: eccentric.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | eccentric.o: eccentric.c 10 | 11 | test: all 12 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./eccentric.out 13 | make clean 14 | 15 | clean: 16 | $(RM) eccentric.out *.o vgcore.* -------------------------------------------------------------------------------- /week_3/lab/exercise_04/interactive_hello.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define MAX_LEN 80 4 | 5 | int main (int argc, char *argv[]) { 6 | char a_word[MAX_LEN]; 7 | 8 | printf ("What's your name?\n"); 9 | 10 | fgets (a_word, MAX_LEN, stdin); 11 | printf("Hey, %sI just really wanted to say hello to you.\n", a_word); 12 | printf("I hope you have a wonderful day.\n"); 13 | 14 | return 0; 15 | } -------------------------------------------------------------------------------- /week_3/section/int_stack/int-stack.h: -------------------------------------------------------------------------------- 1 | #ifndef INT_STACK_H 2 | #define INT_STACK_H 3 | 4 | #include 5 | #include 6 | 7 | typedef struct int_stack int_stack_t; 8 | 9 | int_stack_t *int_stack_constructor(); 10 | 11 | void int_stack_push(int_stack_t *stack, int entry); 12 | 13 | int int_stack_pop(int_stack_t *stack); 14 | 15 | void int_stack_destructor(int_stack_t *stack); 16 | 17 | #endif -------------------------------------------------------------------------------- /week_10/research/dgemm/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -O3 -mavx2 -Wno-pointer-arith 3 | 4 | all: dgemm.out 5 | 6 | dgemm.out: main.o dgemm.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | main.o: main.c dgemm.h 10 | dgemm.o: dgemm.c dgemm.h 11 | 12 | test: all 13 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./dgemm.out 14 | make clean 15 | 16 | clean: 17 | $(RM) dgemm.out *.o vgcore.* -------------------------------------------------------------------------------- /week_3/section/int_linked_list/int-linked-list.h: -------------------------------------------------------------------------------- 1 | #ifndef INT_LINKED_LIST_H 2 | #define INT_LINKED_LIST_H 3 | 4 | #include 5 | 6 | typedef struct int_linked_list ill_t; 7 | 8 | ill_t *ill_constructor(void); 9 | 10 | void ill_insert_front(ill_t *list, int entry); 11 | 12 | int ill_delete_front(ill_t *list); 13 | 14 | void ill_destructor(ill_t *list); 15 | 16 | unsigned char ill_is_empty(ill_t *list); 17 | 18 | #endif -------------------------------------------------------------------------------- /week_10/research/dgemm/dgemm.h: -------------------------------------------------------------------------------- 1 | #ifndef DGEMM 2 | #define DGEMM 3 | 4 | #include 5 | #include 6 | 7 | extern void scalar_dgemm(double *a, double *b, double *c, size_t n); 8 | 9 | extern void avx_dgemm(double *a, double *b, double *c, size_t n); 10 | 11 | extern void avx_unroll_dgemm(double *a, double *b, double *c, size_t n); 12 | 13 | void avx_unroll_blocked_dgemm(double *a, double *b, double *c, size_t n); 14 | 15 | #endif -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "week_2/project/philphix"] 2 | path = week_2/project/philphix 3 | url = git@gitlab.com:moki.codes/cs61c-sp18-philphix.git 4 | [submodule "week_3/project/riscv-is-emu"] 5 | path = week_3/project/riscv-is-emu 6 | url = git@gitlab.com:moki.codes/cs61c-sp18-riscv-is-emu.git 7 | [submodule "week_15/project/cs61c-sp18-ml-classifier-cache"] 8 | path = week_15/project/cs61c-sp18-ml-classifier-cache 9 | url = git@gitlab.com:moki.codes/cs61c-sp18-ml-classifier-cache.git 10 | -------------------------------------------------------------------------------- /week_3/lab/exercise_05/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -g3 -Wno-pointer-arith 3 | 4 | all: ll_cycle.out 5 | 6 | ll_cycle.out: ll_cycle.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | ll_cycle.o: ll_cycle.c 10 | 11 | test: all 12 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./ll_cycle.out 13 | make clean 14 | 15 | debug: all 16 | gdb -q -ex 'set args < test-input.txt' ./ll_cycle.out 17 | make clean 18 | 19 | clean: 20 | $(RM) ll_cycle.out *.o vgcore.* .gdb_* -------------------------------------------------------------------------------- /week_3/section/int_stack/main.c: -------------------------------------------------------------------------------- 1 | #include "int-stack.h" 2 | 3 | #include 4 | 5 | int main(int argc, char **argv) { 6 | int i; 7 | printf("int stack hello\n"); 8 | 9 | int_stack_t *stack = int_stack_constructor(); 10 | 11 | // push 10 elements 12 | for (i = 0; i < 10; i++) 13 | int_stack_push(stack, i); 14 | 15 | // pop 10 elements 16 | for (i = 0; i < 10; i++) 17 | printf("%d ", int_stack_pop(stack)); 18 | 19 | putchar('\n'); 20 | 21 | int_stack_destructor(stack); 22 | } -------------------------------------------------------------------------------- /week_3/section/int_linked_list/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -g3 -Wno-pointer-arith 3 | 4 | all: int-linked-list.out 5 | 6 | int-linked-list.out: main.o int-linked-list.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | main.o: main.c int-linked-list.h 10 | int-linked-list.o: int-linked-list.c int-linked-list.h 11 | 12 | test: clean all 13 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./int-linked-list.out 14 | 15 | clean: 16 | $(RM) main int-linked-list.out *.o vgcore.* -------------------------------------------------------------------------------- /week_12/section/exercise_1/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -O3 -mavx2 -freorder-blocks -Wno-pointer-arith 3 | 4 | all: vector-product.out 5 | 6 | vector-product.out: main.o vector-product.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | main.o: main.c vector-product.h 10 | vector-product.o: vector-product.c vector-product.h 11 | 12 | test: all 13 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./vector-product.out 14 | make clean 15 | 16 | clean: 17 | $(RM) vector-product.out *.o vgcore.* -------------------------------------------------------------------------------- /week_13/lab/README.MD: -------------------------------------------------------------------------------- 1 | ## Lab 11 2 | 3 | Thread-Level Parallelism with OpenMP 4 | 5 | ``` 6 | ./lab-11.pdf 7 | ``` 8 | 9 | ## Exercise 1: Vector Addition 10 | 11 | ``` 12 | look at: 13 | 14 | void v_add_optimized_chunks(double* x, double* y, double* z) 15 | 16 | make test-v-add 17 | ``` 18 | 19 | ## Exercise 2: Dot Product 20 | 21 | ``` 22 | look at: 23 | 24 | double dotp_manual_optimized(double* x, double* y) 25 | 26 | double dotp_reduction_optimized(double* x, double* y) 27 | 28 | make test-dot-p 29 | ``` 30 | -------------------------------------------------------------------------------- /week_3/section/int_stack/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -g3 -Wno-pointer-arith 3 | 4 | all: int-stack.out 5 | 6 | int-stack.out: main.o int-stack.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | main.o: main.c int-stack.h 10 | int-stack.o: int-stack.c int-stack.h 11 | 12 | test: clean all 13 | @echo -e "\e[1;37m" 14 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./int-stack.out 15 | @echo -e "\e[0m" 16 | 17 | clean: 18 | @echo -e "\e[1;34m" 19 | $(RM) main int-stack.out *.o vgcore.* 20 | @echo -e "\e[0m" -------------------------------------------------------------------------------- /week_3/lab/README.MD: -------------------------------------------------------------------------------- 1 | ## Lab 01 2 | C Pointers and GDB 3 | 4 | ``` 5 | ./lab-01.pdf 6 | ``` 7 | 8 | ## Exercise 1: Simple C Program 9 | 10 | ``` 11 | cd exercise_01/ 12 | make test 13 | ``` 14 | 15 | ## Exercise 3: Debugging a buggy C program with GDB 16 | 17 | ``` 18 | cd exercise_03/ 19 | make test 20 | ``` 21 | 22 | ## Exercise 4: "Debugging" a C program that requires user input 23 | 24 | ``` 25 | cd exercise_04/ 26 | make debug 27 | ``` 28 | 29 | ## Exercise 5: Pointers and Structures in C 30 | 31 | ``` 32 | cd exercise_05/ 33 | make test 34 | ``` -------------------------------------------------------------------------------- /week_3/lab/exercise_04/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -g3 -Wno-pointer-arith 3 | 4 | all: interactive_hello.out 5 | 6 | interactive_hello.out: interactive_hello.o 7 | $(CC) $(CFLAGS) -o $@ $^ 8 | 9 | interactive_hello.o: interactive_hello.c 10 | 11 | test: all 12 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./interactive_hello.out 13 | make clean 14 | 15 | debug: all 16 | gdb -q -ex 'set args < test-input.txt' ./interactive_hello.out 17 | make clean 18 | 19 | clean: 20 | $(RM) interactive_hello.out *.o vgcore.* .gdb_* -------------------------------------------------------------------------------- /week_5/lab/factorial.s: -------------------------------------------------------------------------------- 1 | .data 2 | n: .word 7 3 | 4 | .text 5 | main: 6 | la t0, n 7 | lw a0, 0(t0) 8 | jal ra, factorial 9 | 10 | addi a1, a0, 0 11 | addi a0, x0, 1 12 | ecall # Print Result 13 | 14 | addi a0, x0, 10 15 | ecall # Exit 16 | 17 | factorial: beq a0, x0, r1 18 | addi t0, x0, 1 19 | beq a0, t0, r1 20 | 21 | addi t1, x0, 2 22 | 23 | loop: mul t0, t1, t0 24 | 25 | beq t1, a0, exit 26 | addi t1, t1, 1 27 | j loop 28 | 29 | exit: add a0, t0, x0 30 | ret 31 | 32 | r1: addi a0, x0, 1 33 | ret -------------------------------------------------------------------------------- /week_13/lab/makefile: -------------------------------------------------------------------------------- 1 | CC=gcc 2 | CFLAGS=-std=c99 -Wall -pedantic -O3 -fopenmp -pthread -mavx2 -Wno-pointer-arith 3 | 4 | all: v-add.o dot-p.o 5 | 6 | v-add.o: v-add.c 7 | $(CC) $(CFLAGS) v-add.c -o v-add.out 8 | 9 | test-v-add: v-add.o 10 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./v-add.out 11 | make clean 12 | 13 | dot-p.o: dot-p.c 14 | $(CC) $(CFLAGS) dot-p.c -o dot-p.out 15 | 16 | test-dot-p: dot-p.o 17 | valgrind --tool=memcheck --leak-check=yes --track-origins=yes ./dot-p.out 18 | make clean 19 | 20 | clean: 21 | $(RM) v-add.out dot-p.out *.o vgcore.* -------------------------------------------------------------------------------- /week_12/section/exercise_1/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "vector-product.h" 4 | 5 | static size_t vector_length = 8; 6 | 7 | int main(int argc, char **argv) { 8 | int32_t vector[vector_length]; 9 | int64_t product; 10 | 11 | for (size_t i = 0; i < vector_length; ++i) vector[i] = i + 1; 12 | 13 | printf("products of the vector:\n"); 14 | for (size_t i = 0; i < vector_length; ++i) printf("%d ", vector[i]); 15 | putchar('\n'); 16 | 17 | product = vector_product_naive(vector_length, vector); 18 | printf("sequential: %ld\n", product); 19 | 20 | product = vector_product_vectorized(vector_length, vector); 21 | printf("vector extensions: %ld\n", product); 22 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Prerequisites 2 | *.d 3 | 4 | # Object files 5 | *.o 6 | *.ko 7 | *.obj 8 | *.elf 9 | 10 | # Linker output 11 | *.ilk 12 | *.map 13 | *.exp 14 | 15 | # Precompiled Headers 16 | *.gch 17 | *.pch 18 | 19 | # Libraries 20 | *.lib 21 | *.a 22 | *.la 23 | *.lo 24 | 25 | # Shared objects (inc. Windows DLLs) 26 | *.dll 27 | *.so 28 | *.so.* 29 | *.dylib 30 | 31 | # Executables 32 | *.exe 33 | *.out 34 | *.app 35 | *.i*86 36 | *.x86_64 37 | *.hex 38 | 39 | # Debug files 40 | *.dSYM/ 41 | *.su 42 | *.idb 43 | *.pdb 44 | 45 | # Kernel Module Compile Results 46 | *.mod* 47 | *.cmd 48 | .tmp_versions/ 49 | modules.order 50 | Module.symvers 51 | Mkfile.old 52 | dkms.conf 53 | 54 | # vscode 55 | .vscode 56 | -------------------------------------------------------------------------------- /week_12/lab/README.MD: -------------------------------------------------------------------------------- 1 | ## Lab 10 2 | 3 | SIMD Intrinsics and loop-unrolling 4 | 5 | ``` 6 | ./lab-10.pdf 7 | ``` 8 | 9 | ## Exercise 1: Familiarize Yourself with the SIMD Functions 10 | 11 | ``` 12 | Four floating point divisions in single precision (i.e. float): 13 | __m128 _mm_mul_ps (__m128 a, __m128 b) 14 | 15 | Sixteen max operations over signed 8-bit integers (i.e. char): 16 | __m128i _mm_max_epi8 (__m128i a, __m128i b) 17 | 18 | Arithmetic shift right of eight signed 16-bit integers (i.e. short): 19 | __m128i _mm_srai_epi16 (__m128i a, int imm8) 20 | 21 | ``` 22 | 23 | ## Exercise 3: Writing SIMD Code 24 | ## Exercise 4: Loop Unrolling 25 | 26 | ``` 27 | cd exercise_03 28 | make 29 | ./randomized 30 | ``` 31 | -------------------------------------------------------------------------------- /week_3/section/int_linked_list/main.c: -------------------------------------------------------------------------------- 1 | #include "int-linked-list.h" 2 | #include 3 | 4 | int main(int argc, char **argv) { 5 | int i; 6 | 7 | ill_t *list = ill_constructor(); 8 | if (!list) exit(EXIT_FAILURE); 9 | 10 | // insert 10 elements into list 11 | for (i = 0; i < 10; i++) 12 | ill_insert_front(list, i); 13 | 14 | // delete/pop while not empty 15 | while (!ill_is_empty(list)) 16 | printf("%d ", ill_delete_front(list)); 17 | 18 | putchar('\n'); 19 | 20 | ill_destructor(list); 21 | 22 | list = ill_constructor(); 23 | if (!list) exit(EXIT_FAILURE); 24 | 25 | // insert 10 elements into list 26 | for (i = 0; i < 30; i++) 27 | ill_insert_front(list, i); 28 | 29 | ill_destructor(list); 30 | 31 | return 0; 32 | } -------------------------------------------------------------------------------- /week_3/lab/exercise_03/ll_equal.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | typedef struct node { 4 | int val; 5 | struct node* next; 6 | } node; 7 | 8 | int ll_equal(const node* a, const node* b) { 9 | while (a && b) { 10 | if (a->val != b->val) 11 | return 0; 12 | a = a->next; 13 | b = b->next; 14 | } 15 | 16 | return a == b; 17 | } 18 | 19 | int main(int argc, char** argv) { 20 | int i; 21 | node nodes[10]; 22 | 23 | for (i=0; i<10; i++) { 24 | nodes[i].val = 0; 25 | nodes[i].next = NULL; 26 | } 27 | 28 | nodes[0].next = &nodes[1]; 29 | nodes[1].next = &nodes[2]; 30 | nodes[2].next = &nodes[3]; 31 | 32 | printf("equal test 1 result = %d\n", ll_equal(&nodes[0], &nodes[0])); 33 | printf("equal test 2 result = %d\n", ll_equal(&nodes[0], &nodes[2])); 34 | 35 | return 0; 36 | } 37 | -------------------------------------------------------------------------------- /week_12/section/exercise_1/vector-product.c: -------------------------------------------------------------------------------- 1 | #include "vector-product.h" 2 | 3 | int64_t vector_product_naive(size_t length, int32_t *vector) { 4 | int64_t product; 5 | size_t i; 6 | 7 | for (i = 0, product = 1; i < length; ++i) { 8 | product *= vector[i]; 9 | } 10 | 11 | return product; 12 | } 13 | 14 | int64_t vector_product_vectorized(size_t length, int32_t *vector) { 15 | __m128i product = _mm_set1_epi32(1); 16 | int32_t last[4]; 17 | size_t i; 18 | 19 | for (i = 0; i < length / 16; i += 4) { 20 | product = _mm_mullo_epi32( 21 | product, 22 | _mm_loadu_si128((__m128i *) (vector + i)) 23 | ); 24 | } 25 | 26 | _mm_storeu_si128((__m128i *) last, product); 27 | 28 | for (i = length/16; i < length; ++i) last[0] *= vector[i]; 29 | 30 | for (i = 1; i < 4; ++i) last[0] *= last[i]; 31 | 32 | return last[0]; 33 | } -------------------------------------------------------------------------------- /week_12/lab/exercise_03_04/sorted.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "common.h" 5 | 6 | /* ***DON'T MODIFY THIS FILE! ONLY MODIFY COMMON.H!*** */ 7 | 8 | int main(int argc, char* argv[]) { 9 | printf("Let's generate a randomized array.\n"); 10 | unsigned int vals[NUM_ELEMS]; 11 | for(unsigned int i = 0; i < NUM_ELEMS; i++) vals[i] = rand() % 256; 12 | 13 | printf("Now let's sort it.\n"); 14 | qsort(vals, NUM_ELEMS, sizeof(int), int_comparator); 15 | 16 | printf("Starting sorted sum.\n"); 17 | printf("Sum: %lld\n", sum(vals)); 18 | 19 | printf("Starting sorted unrolled sum.\n"); 20 | printf("Sum: %lld\n", sum_unrolled(vals)); 21 | 22 | printf("Starting sorted SIMD sum.\n"); 23 | printf("Sum: %lld\n", sum_simd(vals)); 24 | 25 | printf("Starting sorted SIMD unrolled sum.\n"); 26 | printf("Sum: %lld\n", sum_simd_unrolled(vals)); 27 | } 28 | -------------------------------------------------------------------------------- /week_3/lab/exercise_01/eccentric.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | /* Only change any of these 4 values */ 4 | #define V0 3 5 | #define V1 3 6 | #define V2 1 7 | #define V3 3 8 | 9 | int main(void) { 10 | int a; 11 | char *s; 12 | 13 | printf("Berkeley eccentrics:\n====================\n"); 14 | 15 | for(a=0; a