delete trailing newlines
This commit is contained in:
parent
b4e31f122a
commit
483fa8458d
8
Makefile
8
Makefile
|
@ -1,18 +1,18 @@
|
||||||
#
|
#
|
||||||
# Student makefile for Cache Lab
|
# Student makefile for Cache Lab
|
||||||
#
|
#
|
||||||
CC = gcc
|
CC = gcc
|
||||||
CFLAGS = -g -Wall -Werror -std=c99
|
CFLAGS = -g -Wall -Werror -std=c99
|
||||||
|
|
||||||
all: csim test-trans tracegen
|
all: csim test-trans tracegen
|
||||||
# Generate a handin tar file each time you compile
|
# Generate a handin tar file each time you compile
|
||||||
-tar -cvf ${USER}-handin.tar csim.c trans.c
|
-tar -cvf ${USER}-handin.tar csim.c trans.c
|
||||||
|
|
||||||
csim: csim.c cachelab.c cachelab.h
|
csim: csim.c cachelab.c cachelab.h
|
||||||
$(CC) $(CFLAGS) -o csim csim.c cachelab.c -lm
|
$(CC) $(CFLAGS) -o csim csim.c cachelab.c -lm
|
||||||
|
|
||||||
test-trans: test-trans.c trans.o cachelab.c cachelab.h
|
test-trans: test-trans.c trans.o cachelab.c cachelab.h
|
||||||
$(CC) $(CFLAGS) -o test-trans test-trans.c cachelab.c trans.o
|
$(CC) $(CFLAGS) -o test-trans test-trans.c cachelab.c trans.o
|
||||||
|
|
||||||
tracegen: tracegen.c trans.o cachelab.c
|
tracegen: tracegen.c trans.o cachelab.c
|
||||||
$(CC) $(CFLAGS) -O0 -o tracegen tracegen.c trans.o cachelab.c
|
$(CC) $(CFLAGS) -O0 -o tracegen tracegen.c trans.o cachelab.c
|
||||||
|
|
4
README
4
README
|
@ -1,4 +1,4 @@
|
||||||
This is the handout directory for the CS:APP Cache Lab.
|
This is the handout directory for the CS:APP Cache Lab.
|
||||||
|
|
||||||
************************
|
************************
|
||||||
Running the autograders:
|
Running the autograders:
|
||||||
|
@ -16,7 +16,7 @@ Check the correctness and performance of your transpose functions:
|
||||||
linux> ./test-trans -M 61 -N 67
|
linux> ./test-trans -M 61 -N 67
|
||||||
|
|
||||||
Check everything at once (this is the program that your instructorruns):
|
Check everything at once (this is the program that your instructorruns):
|
||||||
linux> ./driver.py
|
linux> ./driver.py
|
||||||
|
|
||||||
******
|
******
|
||||||
Files:
|
Files:
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* cachelab.h - Prototypes for Cache Lab helper functions
|
* cachelab.h - Prototypes for Cache Lab helper functions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -16,10 +16,10 @@ typedef struct trans_func{
|
||||||
unsigned int num_evictions;
|
unsigned int num_evictions;
|
||||||
} trans_func_t;
|
} trans_func_t;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* printSummary - This function provides a standard way for your cache
|
* printSummary - This function provides a standard way for your cache
|
||||||
* simulator * to display its final hit and miss statistics
|
* simulator * to display its final hit and miss statistics
|
||||||
*/
|
*/
|
||||||
void printSummary(int hits, /* number of hits */
|
void printSummary(int hits, /* number of hits */
|
||||||
int misses, /* number of misses */
|
int misses, /* number of misses */
|
||||||
int evictions); /* number of evictions */
|
int evictions); /* number of evictions */
|
||||||
|
|
34
test-trans.c
34
test-trans.c
|
@ -27,7 +27,7 @@ extern void registerFunctions();
|
||||||
|
|
||||||
/* External variables defined in cachelab-tools.c */
|
/* External variables defined in cachelab-tools.c */
|
||||||
extern trans_func_t func_list[MAX_TRANS_FUNCS];
|
extern trans_func_t func_list[MAX_TRANS_FUNCS];
|
||||||
extern int func_counter;
|
extern int func_counter;
|
||||||
|
|
||||||
/* Globals set on the command line */
|
/* Globals set on the command line */
|
||||||
static int M = 0;
|
static int M = 0;
|
||||||
|
@ -41,7 +41,7 @@ struct results {
|
||||||
};
|
};
|
||||||
static struct results results = {-1, 0, INT_MAX};
|
static struct results results = {-1, 0, INT_MAX};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* eval_perf - Evaluate the performance of the registered transpose functions
|
* eval_perf - Evaluate the performance of the registered transpose functions
|
||||||
*/
|
*/
|
||||||
void eval_perf(unsigned int s, unsigned int E, unsigned int b)
|
void eval_perf(unsigned int s, unsigned int E, unsigned int b)
|
||||||
|
@ -52,11 +52,11 @@ void eval_perf(unsigned int s, unsigned int E, unsigned int b)
|
||||||
char buf[1000], cmd[255];
|
char buf[1000], cmd[255];
|
||||||
char filename[128];
|
char filename[128];
|
||||||
|
|
||||||
registerFunctions();
|
registerFunctions();
|
||||||
|
|
||||||
/* Open the complete trace file */
|
/* Open the complete trace file */
|
||||||
FILE* full_trace_fp;
|
FILE* full_trace_fp;
|
||||||
FILE* part_trace_fp;
|
FILE* part_trace_fp;
|
||||||
|
|
||||||
/* Evaluate the performance of each registered transpose function */
|
/* Evaluate the performance of each registered transpose function */
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ void eval_perf(unsigned int s, unsigned int E, unsigned int b)
|
||||||
sprintf(cmd, "valgrind --tool=lackey --trace-mem=yes --log-fd=1 -v ./tracegen -M %d -N %d -F %d > trace.tmp", M, N,i);
|
sprintf(cmd, "valgrind --tool=lackey --trace-mem=yes --log-fd=1 -v ./tracegen -M %d -N %d -F %d > trace.tmp", M, N,i);
|
||||||
flag=WEXITSTATUS(system(cmd));
|
flag=WEXITSTATUS(system(cmd));
|
||||||
if (0!=flag) {
|
if (0!=flag) {
|
||||||
printf("Validation error at function %d! Run ./tracegen -M %d -N %d -F %d for details.\nSkipping performance evaluation for this function.\n",flag-1,M,N,i);
|
printf("Validation error at function %d! Run ./tracegen -M %d -N %d -F %d for details.\nSkipping performance evaluation for this function.\n",flag-1,M,N,i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,7 @@ void eval_perf(unsigned int s, unsigned int E, unsigned int b)
|
||||||
sprintf(filename, "trace.f%d", i);
|
sprintf(filename, "trace.f%d", i);
|
||||||
part_trace_fp = fopen(filename, "w");
|
part_trace_fp = fopen(filename, "w");
|
||||||
assert(part_trace_fp);
|
assert(part_trace_fp);
|
||||||
|
|
||||||
/* Locate trace corresponding to the trans function */
|
/* Locate trace corresponding to the trans function */
|
||||||
flag = 0;
|
flag = 0;
|
||||||
while (fgets(buf, 1000, full_trace_fp) != NULL) {
|
while (fgets(buf, 1000, full_trace_fp) != NULL) {
|
||||||
|
@ -106,7 +106,7 @@ void eval_perf(unsigned int s, unsigned int E, unsigned int b)
|
||||||
if (buf[0]==' ' && buf[2]==' ' &&
|
if (buf[0]==' ' && buf[2]==' ' &&
|
||||||
(buf[1]=='S' || buf[1]=='M' || buf[1]=='L' )) {
|
(buf[1]=='S' || buf[1]=='M' || buf[1]=='L' )) {
|
||||||
sscanf(buf+3, "%llx,%u", &addr, &len);
|
sscanf(buf+3, "%llx,%u", &addr, &len);
|
||||||
|
|
||||||
/* If start marker found, set flag */
|
/* If start marker found, set flag */
|
||||||
if (addr == marker_start)
|
if (addr == marker_start)
|
||||||
flag = 1;
|
flag = 1;
|
||||||
|
@ -137,10 +137,10 @@ void eval_perf(unsigned int s, unsigned int E, unsigned int b)
|
||||||
/* Run the reference simulator */
|
/* Run the reference simulator */
|
||||||
printf("Step 2: Evaluating performance (s=%d, E=%d, b=%d)\n", s, E, b);
|
printf("Step 2: Evaluating performance (s=%d, E=%d, b=%d)\n", s, E, b);
|
||||||
char cmd[255];
|
char cmd[255];
|
||||||
sprintf(cmd, "./csim-ref -s %u -E %u -b %u -t trace.f%d > /dev/null",
|
sprintf(cmd, "./csim-ref -s %u -E %u -b %u -t trace.f%d > /dev/null",
|
||||||
s, E, b, i);
|
s, E, b, i);
|
||||||
system(cmd);
|
system(cmd);
|
||||||
|
|
||||||
/* Collect results from the reference simulator */
|
/* Collect results from the reference simulator */
|
||||||
FILE* in_fp = fopen(".csim_results","r");
|
FILE* in_fp = fopen(".csim_results","r");
|
||||||
assert(in_fp);
|
assert(in_fp);
|
||||||
|
@ -151,13 +151,13 @@ void eval_perf(unsigned int s, unsigned int E, unsigned int b)
|
||||||
func_list[i].num_evictions = evictions;
|
func_list[i].num_evictions = evictions;
|
||||||
printf("func %u (%s): hits:%u, misses:%u, evictions:%u\n",
|
printf("func %u (%s): hits:%u, misses:%u, evictions:%u\n",
|
||||||
i, func_list[i].description, hits, misses, evictions);
|
i, func_list[i].description, hits, misses, evictions);
|
||||||
|
|
||||||
/* If it is transpose_submit(), record number of misses */
|
/* If it is transpose_submit(), record number of misses */
|
||||||
if (results.funcid == i) {
|
if (results.funcid == i) {
|
||||||
results.misses = misses;
|
results.misses = misses;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -169,7 +169,7 @@ void usage(char *argv[]){
|
||||||
printf(" -h Print this help message.\n");
|
printf(" -h Print this help message.\n");
|
||||||
printf(" -M <rows> Number of matrix rows (max %d)\n", MAXN);
|
printf(" -M <rows> Number of matrix rows (max %d)\n", MAXN);
|
||||||
printf(" -N <cols> Number of matrix columns (max %d)\n", MAXN);
|
printf(" -N <cols> Number of matrix columns (max %d)\n", MAXN);
|
||||||
printf("Example: %s -M 8 -N 8\n", argv[0]);
|
printf("Example: %s -M 8 -N 8\n", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -192,7 +192,7 @@ void sigalrm_handler(int signum){
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* main - Main routine
|
* main - Main routine
|
||||||
*/
|
*/
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
@ -215,7 +215,7 @@ int main(int argc, char* argv[])
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (M == 0 || N == 0) {
|
if (M == 0 || N == 0) {
|
||||||
printf("Error: Missing required argument\n");
|
printf("Error: Missing required argument\n");
|
||||||
usage(argv);
|
usage(argv);
|
||||||
|
@ -244,11 +244,11 @@ int main(int argc, char* argv[])
|
||||||
|
|
||||||
/* Check the performance of the student's transpose function */
|
/* Check the performance of the student's transpose function */
|
||||||
eval_perf(5, 1, 5);
|
eval_perf(5, 1, 5);
|
||||||
|
|
||||||
/* Emit the results for this particular test */
|
/* Emit the results for this particular test */
|
||||||
if (results.funcid == -1) {
|
if (results.funcid == -1) {
|
||||||
printf("\nError: We could not find your transpose_submit() function\n");
|
printf("\nError: We could not find your transpose_submit() function\n");
|
||||||
printf("Error: Please ensure that description field is exactly \"%s\"\n",
|
printf("Error: Please ensure that description field is exactly \"%s\"\n",
|
||||||
SUBMIT_DESCRIPTION);
|
SUBMIT_DESCRIPTION);
|
||||||
printf("\nTEST_TRANS_RESULTS=0:0\n");
|
printf("\nTEST_TRANS_RESULTS=0:0\n");
|
||||||
}
|
}
|
||||||
|
|
16
tracegen.c
16
tracegen.c
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* tracegen.c - Running the binary tracegen with valgrind produces
|
* tracegen.c - Running the binary tracegen with valgrind produces
|
||||||
* a memory trace of all of the registered transpose functions.
|
* a memory trace of all of the registered transpose functions.
|
||||||
*
|
*
|
||||||
* The beginning and end of each registered transpose function's trace
|
* The beginning and end of each registered transpose function's trace
|
||||||
* is indicated by reading from "marker" addresses. These two marker
|
* is indicated by reading from "marker" addresses. These two marker
|
||||||
* addresses are recorded in file for later use.
|
* addresses are recorded in file for later use.
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
/* External variables declared in cachelab.c */
|
/* External variables declared in cachelab.c */
|
||||||
extern trans_func_t func_list[MAX_TRANS_FUNCS];
|
extern trans_func_t func_list[MAX_TRANS_FUNCS];
|
||||||
extern int func_counter;
|
extern int func_counter;
|
||||||
|
|
||||||
/* External function from trans.c */
|
/* External function from trans.c */
|
||||||
extern void registerFunctions();
|
extern void registerFunctions();
|
||||||
|
@ -68,18 +68,18 @@ int main(int argc, char* argv[]){
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Register transpose functions */
|
/* Register transpose functions */
|
||||||
registerFunctions();
|
registerFunctions();
|
||||||
|
|
||||||
/* Fill A with data */
|
/* Fill A with data */
|
||||||
initMatrix(M,N, A, B);
|
initMatrix(M,N, A, B);
|
||||||
|
|
||||||
/* Record marker addresses */
|
/* Record marker addresses */
|
||||||
FILE* marker_fp = fopen(".marker","w");
|
FILE* marker_fp = fopen(".marker","w");
|
||||||
assert(marker_fp);
|
assert(marker_fp);
|
||||||
fprintf(marker_fp, "%llx %llx",
|
fprintf(marker_fp, "%llx %llx",
|
||||||
(unsigned long long int) &MARKER_START,
|
(unsigned long long int) &MARKER_START,
|
||||||
(unsigned long long int) &MARKER_END );
|
(unsigned long long int) &MARKER_END );
|
||||||
fclose(marker_fp);
|
fclose(marker_fp);
|
||||||
|
@ -103,5 +103,3 @@ int main(int argc, char* argv[]){
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
25
trans.c
25
trans.c
|
@ -1,4 +1,4 @@
|
||||||
/*
|
/*
|
||||||
* trans.c - Matrix transpose B = A^T
|
* trans.c - Matrix transpose B = A^T
|
||||||
*
|
*
|
||||||
* Each transpose function must have a prototype of the form:
|
* Each transpose function must have a prototype of the form:
|
||||||
|
@ -6,30 +6,30 @@
|
||||||
*
|
*
|
||||||
* A transpose function is evaluated by counting the number of misses
|
* A transpose function is evaluated by counting the number of misses
|
||||||
* on a 1KB direct mapped cache with a block size of 32 bytes.
|
* on a 1KB direct mapped cache with a block size of 32 bytes.
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "cachelab.h"
|
#include "cachelab.h"
|
||||||
|
|
||||||
int is_transpose(int M, int N, int A[N][M], int B[M][N]);
|
int is_transpose(int M, int N, int A[N][M], int B[M][N]);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* transpose_submit - This is the solution transpose function that you
|
* transpose_submit - This is the solution transpose function that you
|
||||||
* will be graded on for Part B of the assignment. Do not change
|
* will be graded on for Part B of the assignment. Do not change
|
||||||
* the description string "Transpose submission", as the driver
|
* the description string "Transpose submission", as the driver
|
||||||
* searches for that string to identify the transpose function to
|
* searches for that string to identify the transpose function to
|
||||||
* be graded.
|
* be graded.
|
||||||
*/
|
*/
|
||||||
char transpose_submit_desc[] = "Transpose submission";
|
char transpose_submit_desc[] = "Transpose submission";
|
||||||
void transpose_submit(int M, int N, int A[N][M], int B[M][N])
|
void transpose_submit(int M, int N, int A[N][M], int B[M][N])
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* You can define additional transpose functions below. We've defined
|
* You can define additional transpose functions below. We've defined
|
||||||
* a simple one below to help you get started.
|
* a simple one below to help you get started.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* trans - A simple baseline transpose function, not optimized for the cache.
|
* trans - A simple baseline transpose function, not optimized for the cache.
|
||||||
*/
|
*/
|
||||||
char trans_desc[] = "Simple row-wise scan transpose";
|
char trans_desc[] = "Simple row-wise scan transpose";
|
||||||
|
@ -42,7 +42,7 @@ void trans(int M, int N, int A[N][M], int B[M][N])
|
||||||
tmp = A[i][j];
|
tmp = A[i][j];
|
||||||
B[j][i] = tmp;
|
B[j][i] = tmp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,14 +56,14 @@ void trans(int M, int N, int A[N][M], int B[M][N])
|
||||||
void registerFunctions()
|
void registerFunctions()
|
||||||
{
|
{
|
||||||
/* Register your solution function */
|
/* Register your solution function */
|
||||||
registerTransFunction(transpose_submit, transpose_submit_desc);
|
registerTransFunction(transpose_submit, transpose_submit_desc);
|
||||||
|
|
||||||
/* Register any additional transpose functions */
|
/* Register any additional transpose functions */
|
||||||
registerTransFunction(trans, trans_desc);
|
registerTransFunction(trans, trans_desc);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* is_transpose - This helper function checks if B is the transpose of
|
* is_transpose - This helper function checks if B is the transpose of
|
||||||
* A. You can check the correctness of your transpose by calling
|
* A. You can check the correctness of your transpose by calling
|
||||||
* it before returning from the transpose function.
|
* it before returning from the transpose function.
|
||||||
|
@ -81,4 +81,3 @@ int is_transpose(int M, int N, int A[N][M], int B[M][N])
|
||||||
}
|
}
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue