lab3-handout/trans.c /* * trans.c - Matrix transpose B = A^T * * Each transpose function must have a prototype of the form: * void trans(int M, int N, int A[N][M], int B[M][N]); * * A transpose...

1 answer below »
The password to open the pdf is: CSOSPRING2020%-



lab3-handout/trans.c /* * trans.c - Matrix transpose B = A^T * * Each transpose function must have a prototype of the form: * void trans(int M, int N, int A[N][M], int B[M][N]); * * A transpose function is evaluated by counting the number of misses * on a 1KB direct mapped cache with a block size of 32 bytes. */ #include #include "lab3.h" 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 * will be graded on for Part B of the assignment. Do not change * the description string "Transpose submission", as the driver * searches for that string to identify the transpose function to * be graded. */ char transpose_submit_desc[] = "Transpose submission"; 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 * a simple one below to help you get started. */ /* * trans - A simple baseline transpose function, not optimized for the cache. */ char trans_desc[] = "Simple row-wise scan transpose"; void trans(int M, int N, int A[N][M], int B[M][N]) { int i, j, tmp; for (i = 0; i < n;="" i++)="" {="" for="" (j="0;" j="">< m;="" j++)="" {="" tmp="A[i][j];" b[j][i]="tmp;" }="" }="" }="" *="" *="" registerfunctions="" -="" this="" function="" registers="" your="" transpose="" *="" functions="" with="" the="" driver.="" at="" runtime,="" the="" driver="" will="" *="" evaluate="" each="" of="" the="" registered="" functions="" and="" summarize="" their="" *="" performance.="" this="" is="" a="" handy="" way="" to="" experiment="" with="" different="" *="" transpose="" strategies.="" */="" void="" registerfunctions()="" {="" *="" register="" your="" solution="" function="" */="" registertransfunction(transpose_submit,="" transpose_submit_desc);="" *="" register="" any="" additional="" transpose="" functions="" */="" registertransfunction(trans,="" trans_desc);="" }="" *="" *="" is_transpose="" -="" this="" helper="" function="" checks="" if="" b="" is="" the="" transpose="" of="" *="" a.="" you="" can="" check="" the="" correctness="" of="" your="" transpose="" by="" calling="" *="" it="" before="" returning="" from="" the="" transpose="" function.="" */="" int="" is_transpose(int="" m,="" int="" n,="" int="" a[n][m],="" int="" b[m][n])="" {="" int="" i,="" j;="" for="" (i="0;" i="">< n;="" i++)="" {="" for="" (j="0;" j="">< m;="" ++j)="" {="" if="" (a[i][j]="" !="B[j][i])" {="" return="" 0;="" }="" }="" }="" return="" 1;="" }="" lab3-handout/driver.py="" #!/usr//bin/python="" #="" #="" driver.py="" -="" the="" driver="" tests="" the="" correctness="" of="" the="" student's="" cache="" #="" simulator="" and="" the="" correctness="" and="" performance="" of="" their="" transpose="" #="" function.="" it="" uses="" ./test-csim="" to="" check="" the="" correctness="" of="" the="" #="" simulator="" and="" it="" runs="" ./test-trans="" on="" three="" different="" sized="" #="" matrices="" (32x32,="" 64x64,="" and="" 61x67)="" to="" test="" the="" correctness="" and="" #="" performance="" of="" the="" transpose="" function.="" #="" import="" subprocess;="" import="" re;="" import="" os;="" import="" sys;="" import="" optparse;="" #="" #="" computemissscore="" -="" compute="" the="" score="" depending="" on="" the="" number="" of="" #="" cache="" misses="" #="" def="" computemissscore(miss,="" lower,="" upper,="" full_score):="" if="" miss=""><= lower:="" return="" full_score="" if="" miss="">= upper: return 0 score = (miss - lower) * 1.0 range = (upper- lower) * 1.0 return round((1 - score / range) * full_score, 1) # # main - Main function # def main(): # Configure maxscores here maxscore= {}; maxscore['csim'] = 27 maxscore['transc'] = 1 maxscore['trans32'] = 8 maxscore['trans64'] = 8 maxscore['trans61'] = 10 # Parse the command line arguments p = optparse.OptionParser() p.add_option("-A", action="store_true", dest="autograde", help="emit autoresult string for Autolab"); opts, args = p.parse_args() autograde = opts.autograde # Check the correctness of the cache simulator print "Part A: Testing cache simulator" print "Running ./test-csim" p = subprocess.Popen("./test-csim", shell=True, stdout=subprocess.PIPE) stdout_data = p.communicate()[0] # Emit the output from test-csim stdout_data = re.split('\n', stdout_data) for line in stdout_data: if re.match("TEST_CSIM_RESULTS", line): resultsim = re.findall(r'(\d+)', line) else: print "%s" % (line) # Check the correctness and performance of the transpose function # 32x32 transpose print "Part B: Testing transpose function" print "Running ./test-trans -M 32 -N 32" p = subprocess.Popen("./test-trans -M 32 -N 32 | grep TEST_TRANS_RESULTS", shell=True, stdout=subprocess.PIPE) stdout_data = p.communicate()[0] result32 = re.findall(r'(\d+)', stdout_data) # 64x64 transpose print "Running ./test-trans -M 64 -N 64" p = subprocess.Popen("./test-trans -M 64 -N 64 | grep TEST_TRANS_RESULTS", shell=True, stdout=subprocess.PIPE) stdout_data = p.communicate()[0] result64 = re.findall(r'(\d+)', stdout_data) # 61x67 transpose print "Running ./test-trans -M 61 -N 67" p = subprocess.Popen("./test-trans -M 61 -N 67 | grep TEST_TRANS_RESULTS", shell=True, stdout=subprocess.PIPE) stdout_data = p.communicate()[0] result61 = re.findall(r'(\d+)', stdout_data) # Compute the scores for each step csim_cscore = map(int, resultsim[0:1]) trans_cscore = int(result32[0]) * int(result64[0]) * int(result61[0]); miss32 = int(result32[1]) miss64 = int(result64[1]) miss61 = int(result61[1]) trans32_score = computeMissScore(miss32, 300, 600, maxscore['trans32']) * int(result32[0]) trans64_score = computeMissScore(miss64, 1300, 2000, maxscore['trans64']) * int(result64[0]) trans61_score = computeMissScore(miss61, 2000, 3000, maxscore['trans61']) * int(result61[0]) total_score = csim_cscore[0] + trans32_score + trans64_score + trans61_score # Summarize the results print "\nCache Lab summary:" print "%-22s%8s%10s%12s" % ("", "Points", "Max pts", "Misses") print "%-22s%8.1f%10d" % ("Csim correctness", csim_cscore[0], maxscore['csim']) misses = str(miss32) if miss32 == 2**31-1 : misses = "invalid" print "%-22s%8.1f%10d%12s" % ("Trans perf 32x32", trans32_score, maxscore['trans32'], misses) misses = str(miss64) if miss64 == 2**31-1 : misses = "invalid" print "%-22s%8.1f%10d%12s" % ("Trans perf 64x64", trans64_score, maxscore['trans64'], misses) misses = str(miss61) if miss61 == 2**31-1 : misses = "invalid" print "%-22s%8.1f%10d%12s" % ("Trans perf 61x67", trans61_score, maxscore['trans61'], misses) print "%22s%8.1f%10d" % ("Total points", total_score, maxscore['csim'] + maxscore['trans32'] + maxscore['trans64'] + maxscore['trans61']) # Emit autoresult string for Autolab if called with -A option
Answered Same DayMay 05, 2021

Answer To: lab3-handout/trans.c /* * trans.c - Matrix transpose B = A^T * * Each transpose function must have a...

Ria answered on May 10 2021
157 Votes
screenshots and videos/1.png
screenshots and videos/video1.mp4
screenshots and videos/2.png
screenshots and videos/3.png
screenshots and videos/4.png
screenshots and videos/5.png
screenshots and videos/6.png
screenshots and videos/video2.mp4
vincent-handin.tar
csim.c
// Name: Vincent Caliendo
#include "lab3.h"
#include
#include
#include
#include
//64 bit variable type we will use to hold memory addresses
typedef unsigned long long int memAddress;
//struct used to store and gro
up all the needed parameters of the cache together
struct Parameters {
int s;         //number of set index bits (the number of sets is 2^s)
int S;         //total number of sets (calculated from 2^s)
int E;         //number of lines per set (associativity)
int b;         //number of block bits (the block size is 2^b)
int B;         //block size (calculated from 2^b)
int hits;     //Number of hits
int misses;     //Number of misses
int evicts;     //Number of evictions
int verbose;     //verbosity flag
};
//lines that will be stored in sets
struct setLine{
int uses;
int valid;
unsigned long long tag;
char *block;
};
//a set is made up of lines
struct cacheSet{
struct setLine *lines;
};
//a cache is made up of sets which contain lines
struct Cache{
struct cacheSet *sets;
};
struct Cache build(long long totalSets, int totalLines, int blockSize){
struct Cache newCache;
struct cacheSet set;
struct setLine line;
//allocate memory for the new cache based off of how many total sets it will have
newCache.sets = (struct cacheSet*) malloc(sizeof(struct cacheSet)* totalSets);
for (int i = 0; i < totalSets; i++){
//allocate memory for each line in each set of the new cache
set.lines = (struct setLine*) malloc (sizeof(struct setLine) * totalLines);
//assigns the newly created sets to the cache
newCache.sets[i] = set;
//sets the value of every field in each line to 0 and then assigns them to the sets within the cache
for (int j = 0; j < totalLines; j ++){
line.uses = 0;
line.valid = 0;
line.tag = 0;
set.lines[j] = line;
}
}
return newCache;
}
void printUsage(){
printf("Usafe: /csim-ref [-hv] -s -E -b -t \n");
printf("-h: Optional help flag that prints usage info\n");
printf("-v: Optional verbose flag that displays trace info\n");
printf("-s : Number of set index bits (the number of sets is 2^s)\n");
printf("-E : Associativity (number of lines per set)\n");
printf("-b : Number of block bits (the block size is 2^b)\n");
printf("-t : Name of the valgrind trace to replay\n");
}
//returns the line number of the least recently used line (meaning that it meets the requirements for eviction)
int findLRU(struct cacheSet set, struct Parameters param){
int totalLines = param.E;
int minUses = set.lines[0].uses;
int LRU = 0;
//loop through every line in the set, saving the line number of the line with the least uses
//and its number of uses for comparison with the rest of the set, replacing it if another line
//is found with less uses
for(int i = 0; i < totalLines; i++){
if(set.lines[i].uses < minUses){
LRU = i;
minUses = set.lines[i].uses;
}
}
return LRU;
}
//returns the line number of the most recently used line (meaning that it belongs in the cache)
int findMRU(struct cacheSet set, struct Parameters param){
int totalLines = param.E;
int maxUses = set.lines[0].uses;
int MRU = 0;
//loop through every line in the set, saving the line number of the line with the most uses
//and its number of uses for comparison with the rest of the set, replacing it if another line
//is found with more uses
for(int i = 0; i < totalLines; i++){
if(set.lines[i].uses > maxUses){
MRU = i;
maxUses = set.lines[i].uses;
}
}
return MRU;
}
//Determines if there is a hit
int checkHit(struct setLine line, memAddress address){
return line.tag == address && line.valid;
}
//Determines if a given set is full
int isSetFull(struct cacheSet set, struct Parameters param){
int totalLines = param.E;
for(int i=0;i //if we find an empty line then the set is not full, so return 1
if(set.lines[i].valid == 0){
return 1;
}
}
//no empty lines so the set is full
return 0;
}
//checks whether any lines in a given set are empty and returns the number of
//the empty line if one exists, if there are none then return 0 because therefore the set is full
int anyEmptyLines(struct cacheSet set, struct Parameters param){
int totalLines = param.E;
struct setLine line;
for (int i = 0; i < totalLines; i++){
line = set.lines[i];
//if a line is not valid return its line number
if(line.valid == 0){
return i;
}
}
return 0;
}
struct Parameters Simulation(struct Cache aCache, struct Parameters param, memAddress address){
//calculate the size of the tag by subtracting the
//sum of the number of block bits and the number of sets in the cache from 64
int tagSize = 64-(param.b + param.s);
//calculate the address tag by shifting the address to the right by the sum of the sets and block bits
memAddress addressTag = address >> (param.s +...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here