diff --git a/fastlib/u/garryb/superpar/array.h b/fastlib/u/garryb/superpar/array.h index 51bd12d549..c2b9cc5390 100644 --- a/fastlib/u/garryb/superpar/array.h +++ b/fastlib/u/garryb/superpar/array.h @@ -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 diff --git a/fastlib/u/garryb/superpar/cache.h b/fastlib/u/garryb/superpar/cache.h new file mode 100644 index 0000000000..087a03a884 --- /dev/null +++ b/fastlib/u/garryb/superpar/cache.h @@ -0,0 +1,51 @@ + + + +template +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) { + } +}; diff --git a/fastlib/u/garryb/superpar/otree.h b/fastlib/u/garryb/superpar/otree.h new file mode 100644 index 0000000000..94b737966d --- /dev/null +++ b/fastlib/u/garryb/superpar/otree.h @@ -0,0 +1,112 @@ + +#define USE_OT(AClass, visitor) \ + public: \ + template \ + friend void TraverseObject(AClass *x, Visitor *v) { \ + x->TraverseObject(v); \ + } \ + \ + private: \ + template \ + 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 void Mine(T& x); + template void Ptr(T*& x); + template void Array(T*& x, int i); + template void MallocPtr(T*& x); + template void MallocArray(T*& x, int i); +}; + +template +void TraverseObject(X* x, Visitor* v) { + v->Primitive(*x); +} + +class OTDestructorVisitor { + public: + template void Primitive(T& x) {} + template void Mine(T& x) { + // not necessary for destructors - destructors chain automatically + } + template void Ptr(T*& x) { + delete x; + } + template void Array(T*& x, int i) { + delete[] x; + } + template void MallocPtr(T*& x) { + x->~T(); free(x); DEBUG_POISON_PTR(x); + } + template void MallocArray(T*& x, int i) { + mem::DestructAll(x, t); free(x); DEBUG_POISON_PTR(x); + } +}; + +class OTCopyConstructorVisitor { + public: + template void Primitive(T& x) { + *x = *GetPointer(x); + } + template void Mine(T& x) { + TraverseObject(x, this); + } + template void Ptr(T*& x) { + recursively copy x + } + template void Array(T*& x, int i) { + recursively copy x + } + template void MallocPtr(T*& x) { + recursively copy x + } + template 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); + } +}; diff --git a/fastlib/u/garryb/superpar/tkde.cc b/fastlib/u/garryb/superpar/tkde.cc index 984c8f3d4c..1a260a110e 100644 --- a/fastlib/u/garryb/superpar/tkde.cc +++ b/fastlib/u/garryb/superpar/tkde.cc @@ -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 + ) -} -*/