Permalink
Browse files

Merge remote-tracking branch 'origin/master'

Conflicts:
	access.cpp
	access.h
	main.cpp
	matrix/oblivious.cpp
  • Loading branch information...
2 parents a9b5e0e + ea2ba6a commit 549cc4e7b5a970a9856c2d86d6036637b2bd6fa1 @pksunkara committed Aug 21, 2011
Showing with 107 additions and 18 deletions.
  1. +3 −0 .gitignore
  2. +1 −1 Makefile
  3. +2 −1 access.cpp
  4. +2 −2 access.h
  5. +9 −0 block.cpp
  6. +10 −0 block.h
  7. +8 −3 cache.cpp
  8. +7 −4 cache.h
  9. +4 −6 main.cpp
  10. +22 −1 matrix/oblivious.cpp
  11. +21 −0 set.cpp
  12. +18 −0 set.h
View
3 .gitignore 100644 → 100755
@@ -1,2 +1,5 @@
sim
*.o
+Debug
+.cproject
+.project
View
@@ -4,7 +4,7 @@ RM= rm -rf
all: sim
-sim: access.o cache.o memory.o matrix/aware.o matrix/unaware.o matrix/oblivious.o main.cpp
+sim: access.o cache.o memory.o set.o block.o matrix/aware.o matrix/unaware.o matrix/oblivious.o main.cpp
$(CC) $(CFLAGS) $^ -o $@
%.o: %.c
View
@@ -4,8 +4,9 @@
using namespace std;
-Access::Access(int memory_size) {
+Access::Access(int cache_size, int block_size, int set_size, int memory_size) {
this->memory = new Memory(memory_size);
+ this->cache = new Cache(cache_size, block_size, set_size);
}
void Access::write(int value) {
View
@@ -6,7 +6,7 @@
class Access {
public:
- Access(int memory_size);
+ Access(int cache_size, int block_size, int set_size, int memory_size);
void write(int value);
void set(int addr, int value);
@@ -15,8 +15,8 @@ class Access {
~Access(void);
private:
- int matrix_n;
Memory* memory;
+ Cache* cache;
};
#endif
View
@@ -0,0 +1,9 @@
+#include "Block.h"
+
+Block::Block(int block_size) {
+
+}
+
+Block::~Block() {
+ // TODO Auto-generated destructor stub
+}
View
10 block.h
@@ -0,0 +1,10 @@
+#ifndef BLOCK_H_
+#define BLOCK_H_
+
+class Block {
+public:
+ Block(int block_size);
+ ~Block();
+};
+
+#endif /* BLOCK_H_ */
View
@@ -4,18 +4,23 @@
using namespace std;
-Cache::Cache(int cache_size, int block_size, int assoc) {
+Cache::Cache(int cache_size, int block_size, int set_size) {
this->hits = 0;
this->misses = 0;
// Cache size is given in KB
this->cache_size = cache_size*1024;
+
// Block size is given in B
this->block_size = block_size;
- this->assoc = assoc;
+ this->set_size = set_size;
+ this->set_n = this->cache_size / (this->set_size * this->block_size);
//TODO: Introduce blocks later
- this->memory = new int(this->cache_size/4);
+ for( int i=0; i<set_n; i++) {
+ this->memory[i] = new Set(this->set_size, this->block_size);
+ }
+
}
int Cache::get_hits(void) {
View
11 cache.h
@@ -1,24 +1,27 @@
#ifndef CACHE_H
#define CACHE_H
+#include "set.h"
+
class Cache {
public:
- Cache(int cache_size, int block_size, int assoc);
+ Cache(int cache_size, int block_size, int set_size);
int get_hits(void);
int get_misses(void);
~Cache(void);
private:
- int* memory;
-
int cache_size;
int block_size;
- int assoc;
+ int set_size;
+ int set_n;
int hits;
int misses;
+
+ Set** memory;
};
#endif
View
@@ -1,10 +1,7 @@
#include <iostream>
-#include <cstdio>
#include <cstdlib>
#include <fstream>
#include "access.h"
-#include "cache.h"
-#include "memory.h"
using namespace std;
@@ -23,7 +20,7 @@ int B(int x, int y);
int main(int argc, char** argv) {
if(argc!=5) {
- printf("Usage: %s <cache_size_inKB> <block_size_inB> <associativity> <memory_size_inKB>\n", argv[0]);
+ cout << "Usage: " << argv[0] << "<cache_size_inKB> <block_size_inB> <associativity> <memory_size_inKB>\n";
return 1;
}
@@ -40,8 +37,8 @@ int main(int argc, char** argv) {
return 1;
}
- // Initalize accessor
- accessor = new Access(atoi(argv[4]));
+ // Initialise accessor
+ accessor = new Access(atoi(argv[1]), atoi(argv[2]), atoi(argv[3]), atoi(argv[4]));
// Reading matrix lengths
inFile >> matrix_n >> matrix_m >> matrix_p;
@@ -72,6 +69,7 @@ int main(int argc, char** argv) {
cout << "Cache Oblivious:" << endl;
cache_oblivious();
cout << endl << "\tCache Statistics:" << endl << endl;
+
// Closing files
inFile.close();
View
@@ -9,4 +9,25 @@ extern int matrix_n, matrix_m, matrix_p;
extern int A(int, int);
extern int B(int, int);
-void cache_oblivious(void) {}
+void cache_oblivious(void) {
+ int i, j, k;
+ recur_func(matrix_n, matrix_m, matrix_p, 0, 0, 0, 0);
+}
+
+void recur_func(int n, int m, int p, int a1, int a2, int b1, int b2){
+ if((n==1) && (m==1) && (p==1)){
+ cout << A(a1, a2)*B(b1, b2) << endl;
+ return;
+ }
+
+ if((n >= m) && (n >= p)) {
+ recur_func(n/2, m, p, a1, a2, b1, b2);
+ recur_func((n - n/2), m, p, a1+n/2, a2, b1, b2);
+ } else if((m >= n) && (m >= p)) {
+ recur_func(n, m/2, p, a1, a2, b1, b2);
+ recur_func(n, (m-m/2), p, a1, a2+m/2, b1+m/2, b2);
+ } else if((p >= m) && (p >= n)) {
+ recur_func(n, m, p/2, a1, a2, b1, b2);
+ recur_func(n, m, (p-p/2), a1, a2, b1, b2+p/2);
+ }
+}
View
21 set.cpp
@@ -0,0 +1,21 @@
+/*
+ * Set.cpp
+ *
+ * Created on: 21-Aug-2011
+ * Author: gsiddardha
+ */
+
+#include "Set.h"
+
+Set::Set(int set_size, int block_size) {
+ this->set_size = set_size;
+ this->block_size = block_size;
+
+ for(int i=0; i<set_size; i++) {
+ this->block[i] = new Block(block_size);
+ }
+}
+
+Set::~Set() {
+ // TODO Auto-generated destructor stub
+}
View
18 set.h
@@ -0,0 +1,18 @@
+#ifndef SET_H_
+#define SET_H_
+
+#include "block.h"
+
+class Set {
+public:
+ Set();
+ ~Set();
+
+private:
+ int set_size;
+ int block_size;
+
+ Block** blocks;
+};
+
+#endif /* SET_H_ */

0 comments on commit 549cc4e

Please sign in to comment.