00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef __GNUC__
00029 #pragma interface
00030 #endif
00031
00032 #ifndef _util_group_memregion_h
00033 #define _util_group_memregion_h
00034
00035 #include <list>
00036 #include <vector>
00037 #include <memory>
00038 #include <sys/types.h>
00039
00040 #include <util/group/memory.h>
00041
00042 namespace sc {
00043
00050 class MemoryGrpRegion: public MemoryGrp {
00051 public:
00053 MemoryGrpRegion(const Ref<MemoryGrp>& mem, size_t mem_start, size_t max_size);
00055 MemoryGrpRegion(const Ref<MemoryGrp>& mem, size_t max_size);
00056 ~MemoryGrpRegion();
00057
00058 void set_localsize(size_t);
00059 void* localdata();
00060
00061 void* obtain_readwrite(distsize_t offset, int size);
00062 void* obtain_readonly(distsize_t offset, int size);
00063 void* obtain_writeonly(distsize_t offset, int size);
00064 void release_readonly(void* data, distsize_t offset, int size);
00065 void release_writeonly(void* data, distsize_t offset, int size);
00066 void release_readwrite(void* data, distsize_t offset, int size);
00067
00068
00069
00070
00071
00072 void sum_reduction_on_node(double *data, size_t doffset, int dsize, int node=-1);
00073
00074 void activate();
00075 void deactivate();
00076 void sync();
00077 void catchup();
00078 void* malloc_local(size_t nbytes);
00079 void free_local(void* data);
00080
00082 Ref<MemoryGrp> clone();
00083 void print(std::ostream &o=ExEnv::out0()) const;
00084
00085 private:
00086
00087
00088 static const int only_allow_double_aligned_regions_ = 1;
00089
00090
00091
00092
00093
00094 static const int classdebug_ = 0;
00095 static int classdebug() { return classdebug_; }
00096
00097
00098 void init();
00099
00101 class LocalRegion {
00102 public:
00103 LocalRegion(size_t start, size_t size) : start_(start), size_(size) {}
00104 size_t start() const { return start_; }
00105 size_t size() const { return size_; }
00106 bool operator==(const LocalRegion& other) const {
00107 return start() == other.start() && size() == other.size();
00108 }
00109 bool operator>(const LocalRegion& other) const {
00110 return start() > other.start();
00111 }
00112 private:
00113 size_t start_;
00114 size_t size_;
00115 };
00116 typedef std::list<LocalRegion> LocalRegions;
00117
00118 Ref<MemoryGrp> host_;
00119 LocalRegion reserve_;
00120 std::vector<distsize_t> host_offsets_;
00121
00122 distsize_t offset_to_host_offset(const distsize_t& offset) const;
00123
00125 class HostToRegionsMap {
00126 public:
00127 HostToRegionsMap();
00128 ~HostToRegionsMap();
00129 void insert(const MemoryGrp* host, const LocalRegion& region);
00130 void erase(const MemoryGrp* host, const LocalRegion& region);
00132 size_t find_free(const MemoryGrp* host, size_t sz) const;
00133 private:
00134 const LocalRegions* regions(const MemoryGrp* host) const;
00135 typedef std::map<const MemoryGrp*,LocalRegions*> ImplType;
00136 ImplType impl_;
00137 Ref<ThreadLock> lock_;
00138 };
00139 static HostToRegionsMap map_;
00140
00141 };
00142
00143 }
00144
00145 #endif
00146
00147
00148
00149
00150