This commit is contained in:
Garry Boyer
2007-05-03 15:14:10 +00:00
parent 6fd1a1e0e4
commit e422ef61a4
4 changed files with 255 additions and 141 deletions
+92 -73
View File
@@ -29,14 +29,16 @@ class ArrayInCore {
Element *ptr_;
/** The number of elements in the array. */
index_t size_;
#ifdef DEBUG
/** Number of live items. */
index_t live_;
#endif
public:
#error "This doesn't cover region exclusion"
ArrayInCore() {}
~ArrayInCore() {
delete ptr_;
delete[] ptr_;
DEBUG_ONLY(ptr_ = BIG_BAD_NUMBER);
DEBUG_SAME_INT(live_, 0);
}
@@ -44,82 +46,12 @@ class ArrayInCore {
void Init(index_t size_in) {
ptr_ = new Element[size_];
size_ = size_in;
live_ = 0;
DEBUG_ONLY(live_ = 0);
}
index_t size() const {
return size_;
}
/**
* Efficient sampling from a large array.
*/
void MakeSample(Element *dest_, index_t begin, index_t count,
index_t n) {
DEBUG_BOUNDS(n, size_);
index_t step = count / n;
index_t i_mine = begin;
// TODO: Better sampling algorithm, or cache efficient algorithm
for (index_t i_dest = 0; i_dest < n; i_dest++) {
dest_[i_dest] = ptr_[i_mine];
i_mine += step;
}
}
/**
* Starts reading from a segment of the array.
*
* This assumes that nobody else is writing to the same block
* of memory, or that you are fine with unpredictable store/load
* ordering.
*
* When done, you must call StopRead.
*/
const Element *StartRead(index_t begin, index_t count) {
DEBUG_BOUNDS(begin, size_);
DEBUG_BOUNDS(begin + count, size_ + 1);
DEBUG_ONLY(live_++);
return ptr_ + begin;
}
/**
* Stops reading from a segment of the array.
*
* This will free any resources associated with the returned
* pointer (if necessary).
*/
void StopRead(const Element *ptr, index_t begin, index_t count) {
DEBUG_ASSERT(ptr - ptr_ == begin);
DEBUG_ONLY(live_--);
/* nothing necessary */
}
/**
* Starts writing to a segment of the array.
*
* Exclusive access is required. This returns a pointer that acts as
* an array and can be written to. When you are done, you must call
* StopWrite.
*/
Element *StartWrite(index_t begin, index_t count) {
DEBUG_BOUNDS(begin, size_);
DEBUG_BOUNDS(begin + count, size_ + 1);
DEBUG_ONLY(live_++);
return ptr_ + begin;
}
/**
* Stops writing from a segment of the array.
*
* If necessary, this flushes back any changes and frees up any
* associated resources.
*/
void StopWrite(Element *ptr, index_t begin, index_t count) {
DEBUG_ASSERT(ptr - ptr_ == begin);
DEBUG_ONLY(live_--);
/* nothing necessary */
}
/**
* Starts reading a single element.
@@ -168,6 +100,93 @@ class ArrayInCore {
DEBUG_ONLY(live_--);
/* nothing necessary */
}
void DeclareWritebackRange(index_t start, index_t count) {
}
void DeclareTempRange(index_t start, index_t count) {
}
void FlushWritebackRange(index_t start, index_t count) {
}
};
#endif
#ifdef GRAVEYARD
/**
* Starts reading from a segment of the array.
*
* This assumes that nobody else is writing to the same block
* of memory, or that you are fine with unpredictable store/load
* ordering.
*
* When done, you must call StopRead.
*/
const Element *StartRead(index_t begin, index_t count) {
DEBUG_BOUNDS(begin, size_);
DEBUG_BOUNDS(begin + count, size_ + 1);
DEBUG_ONLY(live_++);
return ptr_ + begin;
}
/**
* Stops reading from a segment of the array.
*
* This will free any resources associated with the returned
* pointer (if necessary).
*/
void StopRead(const Element *ptr, index_t begin, index_t count) {
DEBUG_ASSERT(ptr - ptr_ == begin);
DEBUG_ONLY(live_--);
/* nothing necessary */
}
/**
* Starts writing to a segment of the array.
*
* Exclusive access is required. This returns a pointer that acts as
* an array and can be written to. When you are done, you must call
* StopWrite.
*/
Element *StartWrite(index_t begin, index_t count) {
DEBUG_BOUNDS(begin, size_);
DEBUG_BOUNDS(begin + count, size_ + 1);
DEBUG_ONLY(live_++);
return ptr_ + begin;
}
/**
* Stops writing from a segment of the array.
*
* If necessary, this flushes back any changes and frees up any
* associated resources.
*/
void StopWrite(Element *ptr, index_t begin, index_t count) {
DEBUG_ASSERT(ptr - ptr_ == begin);
DEBUG_ONLY(live_--);
/* nothing necessary */
}
#endif
+51
View File
@@ -0,0 +1,51 @@
template<typename TElement>
class CacheArray {
FORBID_COPY(CacheArray);
public:
typedef TElement Element;
private:
Element *ptr_;
index_t size_;
index_t live_;
public:
CacheArray() {}
~CacheArray() {
delete ptr_;
DEBUG_ONLY(ptr_ = BIG_BAD_NUMBER);
DEBUG_SAME_INT(live_, 0);
}
void Init(index_t size_in) {
}
index_t size() const {
}
const Element *StartRead(index_t element_id) {
}
void StopRead(const Element *ptr, index_t element_id) {
}
Element *StartWrite(index_t element_id) {
}
void StopWrite(Element *ptr, index_t element_id) {
}
void DeclareWritebackRange(index_t start, index_t count) {
}
void DeclareTempRange(index_t start, index_t count) {
}
void FlushWritebackRange(index_t start, index_t count) {
}
};
+112
View File
@@ -0,0 +1,112 @@
#define USE_OT(AClass, visitor) \
public: \
template<typename Visitor> \
friend void TraverseObject(AClass *x, Visitor *v) { \
x->TraverseObject(v); \
} \
\
private: \
template<typename Visitor> \
void TraverseObject_(Visitor *visitor_variable_name) \
#define USE_OT_FULL(AClass, visitor_variable_name) \
public: \
~AClass() { \
OTDestructorVisitor v; \
TraverseObject_(&v); \
} \
\
AClass(const AClass& other) { \
OTCopyConstructorVisitor v(other); \
TraverseObject_(&v); \
} \
\
const AClass& operator = (const AClass& other) { \
OTAssignmentVisitor v(other); \
TraverseObject_(&v); \
} \
\
USE_OT(AClass, visitor)
class OTVisitor {
public:
template<typename T> void Mine(T& x);
template<typename T> void Ptr(T*& x);
template<typename T> void Array(T*& x, int i);
template<typename T> void MallocPtr(T*& x);
template<typename T> void MallocArray(T*& x, int i);
};
template<typename X, typename Visitor>
void TraverseObject(X* x, Visitor* v) {
v->Primitive(*x);
}
class OTDestructorVisitor {
public:
template<typename T> void Primitive(T& x) {}
template<typename T> void Mine(T& x) {
// not necessary for destructors - destructors chain automatically
}
template<typename T> void Ptr(T*& x) {
delete x;
}
template<typename T> void Array(T*& x, int i) {
delete[] x;
}
template<typename T> void MallocPtr(T*& x) {
x->~T(); free(x); DEBUG_POISON_PTR(x);
}
template<typename T> void MallocArray(T*& x, int i) {
mem::DestructAll(x, t); free(x); DEBUG_POISON_PTR(x);
}
};
class OTCopyConstructorVisitor {
public:
template<typename T> void Primitive(T& x) {
*x = *GetPointer(x);
}
template<typename T> void Mine(T& x) {
TraverseObject(x, this);
}
template<typename T> void Ptr(T*& x) {
recursively copy x
}
template<typename T> void Array(T*& x, int i) {
recursively copy x
}
template<typename T> void MallocPtr(T*& x) {
recursively copy x
}
template<typename T> void MallocArray(T*& x, int i) {
recursively copy x
}
};
class OTDestructorVisitor {
void
};
class AClass {
Foo a;
Bar b;
USE_OT(AClass, v) {
v->Mine(a);
v->Mine(b);
}
};
class Vector {
double *d;
index_t len;
USE_OT(Vector, v) {
v->Mine(len);
v->MallocPtr(d, len);
}
};
-68
View File
@@ -515,71 +515,3 @@ class Tkde {
}
};
};
/*
depth first
-> each node has....
-> its mu value (which contains delta)
-> pushdown deltas
void Recurse(Node *q, List *list_old, ValueResults val_old, PruneResults pr_old) {
PrunedResults pr_new;
CoarseResults cr_new;
ValueResults val_new;
List *list_new;
for (r in list_old) {
d_l <- delta(q, r_l)
if (must_explore(d_l, val_old)) {
list_new += r_l
cr_new += d_r
} else {
pr_new += d_r
}
d_r <- delta(q, r_r)
if (must_explore(d_r, val_old)) {
list_new += r_r
cr_new += d_r
} else {
pr_new += d_r
}
}
pr_new += pr_old
val_new = pr_new + cr_new
PrunedResults pr_l, pr_r;
CoarseResults cr_l, cr_r;
ValueResults val_l, val_r;
List *list_l
List *list_r
for (r in list_new) {
d_l <- delta(q_l, r)
if (must_explore(d_l, val_new)) {
list_l += r
cr_l += d_l
} else {
pr_l += d_l
}
d_r <- delta(q_r, r)
if (must_explore(d_r, val_new)) {
list_r += r
cr_r += d_r
} else {
pr_r += d_r
}
}
val_l = pr_l + cr_l;
val_r = pr_r + cr_r;
Split(cr_l + )
}
*/