Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 85 lines (66 sloc) 1.923 kb
b4e1dfd changed c to cpp
Siddardha G authored
1 #include <iostream>
2 #include <cstdlib>
fa15031 Pavan Kumar Sunkara Added memory get function to check cache
authored
3 #include <cmath>
5649cdc Finished implemeting Cache with Sets and Blocks
SIddardha G authored
4 #include "Access.h"
df42f31 Pavan Kumar Sunkara Initial commit
authored
5
dfc4fc3 Pavan Kumar Sunkara Started classes
authored
6 using namespace std;
df42f31 Pavan Kumar Sunkara Initial commit
authored
7
60e8c2d Pavan Kumar Sunkara Finished cache_unaware
authored
8 // External functions
9 extern void cache_unaware(void);
a9b5e0e Pavan Kumar Sunkara Some small part of cache aware
authored
10 extern void cache_aware(int);
60e8c2d Pavan Kumar Sunkara Finished cache_unaware
authored
11 extern void cache_oblivious(void);
12
12de838 Pavan Kumar Sunkara Finished memory class
authored
13 // Global variable declaration
14 Access* accessor;
60e8c2d Pavan Kumar Sunkara Finished cache_unaware
authored
15 int matrix_n, matrix_m, matrix_p;
16
17 // Function prototype declaration
18 int A(int x, int y);
19 int B(int x, int y);
12de838 Pavan Kumar Sunkara Finished memory class
authored
20
dfc4fc3 Pavan Kumar Sunkara Started classes
authored
21 int main(int argc, char** argv) {
aebb796 Pavan Kumar Sunkara Changed the method of taking INPUT
authored
22 if(argc!=7) {
23 cout << "Usage: " << argv[0] << " <cache_size_inKB> <block_size_inB> <associativity> <matrix_n> <matrix_m> <matrix_p>\n";
b5e64b8 Pavan Kumar Sunkara Started memory
authored
24 return 1;
25 }
26
2f21013 Pavan Kumar Sunkara Now matrices are not square
authored
27 // Reading matrix lengths
aebb796 Pavan Kumar Sunkara Changed the method of taking INPUT
authored
28 matrix_n = atoi(argv[4]);
29 matrix_m = atoi(argv[5]);
30 matrix_p = atoi(argv[6]);
b5e64b8 Pavan Kumar Sunkara Started memory
authored
31
8a94054 Pavan Kumar Sunkara Many changes which are listed below
authored
32 // Initialise accessor
33 accessor = new Access(atoi(argv[1])*1024, atoi(argv[2]), atoi(argv[3]), (matrix_n+matrix_p)*matrix_m);
34
2f21013 Pavan Kumar Sunkara Now matrices are not square
authored
35 // Reading matrices A & B
aebb796 Pavan Kumar Sunkara Changed the method of taking INPUT
authored
36 for(int i=0; i<matrix_n; i++)
37 for(int j=0; j<matrix_m; j++) {
8a94054 Pavan Kumar Sunkara Many changes which are listed below
authored
38 accessor->write(rand());
2f21013 Pavan Kumar Sunkara Now matrices are not square
authored
39 }
aebb796 Pavan Kumar Sunkara Changed the method of taking INPUT
authored
40 for(int i=0; i<matrix_m; i++)
41 for(int j=0; j<matrix_p; j++) {
8a94054 Pavan Kumar Sunkara Many changes which are listed below
authored
42 accessor->write(rand());
12de838 Pavan Kumar Sunkara Finished memory class
authored
43 }
b5e64b8 Pavan Kumar Sunkara Started memory
authored
44
aebb796 Pavan Kumar Sunkara Changed the method of taking INPUT
authored
45 // Starting Ouput
46 cout << "\tCache size: " << argv[1] << " KB" << endl;
47 cout << "\tBlock size: " << argv[2] << " B" << endl;
48 cout << "\tAssociativity: " << argv[3] << endl;
49 cout << endl;
50 cout << "\tMatrix n: " << argv[4] << endl;
51 cout << "\tMatrix m: " << argv[5] << endl;
52 cout << "\tMatrix p: " << argv[6] << endl;
53
60e8c2d Pavan Kumar Sunkara Finished cache_unaware
authored
54 // Cache Unaware matrix multiplication
55 cache_unaware();
4691547 Pavan Kumar Sunkara Cold & Conflict misses done
authored
56 accessor->print((char*)"unaware");
fa15031 Pavan Kumar Sunkara Added memory get function to check cache
authored
57
58 // Restart Cache
59 accessor->restart_cache();
60e8c2d Pavan Kumar Sunkara Finished cache_unaware
authored
60
61 // Cache Aware matrix multiplication
fa15031 Pavan Kumar Sunkara Added memory get function to check cache
authored
62 cache_aware(2);
4691547 Pavan Kumar Sunkara Cold & Conflict misses done
authored
63 accessor->print((char*)"aware");
fa15031 Pavan Kumar Sunkara Added memory get function to check cache
authored
64
65 // Restart Cache
66 accessor->restart_cache();
60e8c2d Pavan Kumar Sunkara Finished cache_unaware
authored
67
8a94054 Pavan Kumar Sunkara Many changes which are listed below
authored
68 // Cache Oblivious matrix multiplicatio
60e8c2d Pavan Kumar Sunkara Finished cache_unaware
authored
69 cache_oblivious();
4691547 Pavan Kumar Sunkara Cold & Conflict misses done
authored
70 accessor->print((char*)"oblivious");
fa2404c Made classes for Set and Block
SIddardha G authored
71
aebb796 Pavan Kumar Sunkara Changed the method of taking INPUT
authored
72 cout << endl;
b5e64b8 Pavan Kumar Sunkara Started memory
authored
73
4691547 Pavan Kumar Sunkara Cold & Conflict misses done
authored
74 delete accessor;
df42f31 Pavan Kumar Sunkara Initial commit
authored
75 return 0;
76 }
60e8c2d Pavan Kumar Sunkara Finished cache_unaware
authored
77
78 int A(int x, int y) {
79 return accessor->get(x*matrix_m+y);
80 }
81
82 int B(int x, int y) {
83 return accessor->get(matrix_n*matrix_m+x*matrix_p+y);
84 }
Something went wrong with that request. Please try again.