• Main Page
  • Related Pages
  • Modules
  • Data Structures
  • Files
  • File List
  • Globals

sst/elements/portals4_sm/trig_cpu/trig_cpu.h

00001 // Copyright 2009-2010 Sandia Corporation. Under the terms
00002 // of Contract DE-AC04-94AL85000 with Sandia Corporation, the U.S.
00003 // Government retains certain rights in this software.
00004 // 
00005 // Copyright (c) 2009-2010, Sandia Corporation
00006 // All rights reserved.
00007 // 
00008 // This file is part of the SST software package. For license
00009 // information, see the LICENSE file in the top level directory of the
00010 // distribution.
00011 
00012 
00013 #ifndef COMPONENTS_TRIG_CPU_TRIG_CPU_H
00014 #define COMPONENTS_TRIG_CPU_TRIG_CPU_H
00015 
00016 #include <string>
00017 #include <list>
00018 #include <set>
00019 #include <queue>
00020 #include <vector>
00021 #include <cstdlib>
00022 #include <stdlib.h>
00023 
00024 #include <sst/core/component.h>
00025 #include <sst/core/event.h>
00026 #include <sst/core/link.h>
00027 #include <sst/core/timeConverter.h>
00028 
00029 #include "sst/elements/portals4_sm/trig_nic/trig_nic_event.h"
00030 #include "portals.h"
00031 
00032 using namespace SST;
00033 
00034 class portals;
00035 class application;
00036 class barrier_action;
00037 
00038 struct posted_recv {
00039     int handle;
00040     int src;
00041     void* buffer;
00042 
00043     posted_recv(int handle, int src, void* buffer) {
00044         this->handle = handle;
00045         this->src = src;
00046         this->buffer = buffer;
00047     }
00048 };
00049 
00050 struct unex_msg {
00051     uint8_t* data;
00052     int src;
00053     int length;
00054 
00055     unex_msg(uint8_t* data, int src, int length) {
00056         this->data = data;
00057         this->src = src;
00058         this->length = length;
00059     }
00060 };
00061 
00062 class ptl_nic_event : public Event {
00063 public:
00064     ptl_nic_event(ptl_int_nic_op_t* op) : Event() {
00065         operation = op;
00066     }
00067     ptl_nic_event() : Event() {}
00068 
00069     ptl_int_nic_op_t* operation;
00070 };
00071 
00072 class trig_cpu : public Component {
00073 public:
00074     friend class portals;
00075   
00076     trig_cpu(ComponentId_t id, Params_t& params);
00077     int Setup();
00078     int Finish();
00079 
00080     void send(int dest, uint64_t data);
00081     bool recv(int src, uint64_t* buf, int& handle);
00082 
00083     void isend(int dest, void* data, int length);
00084     bool irecv(int src, void* buf, int& handle);
00085 
00086     bool process_pending_msg();
00087     bool waitall();
00088     bool waitall(int size, int* src);
00089 
00090     int calcXPosition( int node );
00091     int calcYPosition( int node );
00092     int calcZPosition( int node );
00093     int calcNodeID(int x, int y, int z);
00094 
00095     int getMyId(void) { return my_id; }
00096     int getNumNodes(void) { return num_nodes; }
00097 
00098     void addBusyTime(const char* time)
00099     {
00100         busy += defaultTimeBase->convertFromCoreTime(registerTimeBase(time, false)->getFactor());
00101     }
00102 
00103     portals* getPortalsHandle(void) { return ptl; }
00104     int getRadix(void) { return radix; }
00105     int getMessageSize(void) { return msg_size; }
00106     int getChunkSize(void) { return chunk_size; }
00107 
00108 private:
00109     trig_cpu();                      // Don't implement
00110     trig_cpu(const trig_cpu& c);     // Don't implement
00111     void operator=(trig_cpu const&); // Don't implement
00112 
00113     void initPortals(void);
00114 
00115     // This is essentially the clock function, but it is fully event
00116     // driven
00117     void event_handler(Event* ev);
00118 
00119     // Next handle messages from the NIC.  The first for nonportals
00120     // the second for portals
00121     void processEvent( Event* e );
00122     void processEventPortals( Event* e );
00123 
00124     // This is for the ptl_link, which will be going away
00125     void ptlNICHandler( Event* e );
00126 //     bool event_portals(Event* e);
00127 
00128     // Hooked to nic_timing_link.  This is used to throttle the
00129     // bandwidth and model contention on the link to the NIC
00130     void event_nic_timing(Event* e);
00131     void event_dma_return(Event *e);
00132     void event_pio_delay(Event* e);
00133     
00134     void wakeUp();
00135 
00136 
00137     bool writeToNIC(trig_nic_event* ev);
00138     void returnCredits(int num);
00139     void setTimingParams(int set);
00140     
00141     // Base state
00142     int my_id;
00143     int num_nodes;
00144     int state;
00145     int top_state;
00146     int x_size;
00147     int y_size;
00148     int z_size;
00149     int count;
00150     int latency;
00151 
00152     
00153     portals* ptl;
00154     int radix;
00155     int msg_size;
00156     int chunk_size;
00157     bool enable_coalescing;
00158     bool enable_putv;
00159     
00160     // State needed by send/recv/wait
00161     uint64_t msg_rate_delay;
00162     uint64_t busy;
00163     int outstanding_msg;
00164     int recv_handle;
00165     std::list<posted_recv*> posted_recv_q;
00166     std::set<int> outstanding_recv;
00167     std::queue<trig_nic_event*> pending_msg;
00168     std::list<unex_msg*> unex_msg_q;
00169 
00170     bool waiting;
00171     SimTime_t wait_start_time;
00172 
00173     bool blocking;
00174     int nic_credits;
00175     trig_nic_event* blocked_event;
00176     int blocked_busy;
00177   
00178     bool pio_in_progress;
00179     bool use_portals;
00180 
00181     int timing_set;
00182     int delay_host_pio_write;
00183     int delay_sfence;
00184     int delay_bus_xfer;
00185     int latency_dma_mem_access;
00186     int added_pio_latency;
00187     int recv_overhead;
00188     
00189     // Noise variables
00190     SimTime_t noise_interval;
00191     SimTime_t noise_duration;
00192     SimTime_t noise_count;
00193     int noise_runs;
00194     int current_run;
00195     bool do_noise;
00196     
00197     Params_t    params;
00198     Link*       nic;
00199     Link*       self;
00200     Link*       ptl_link;
00201     Link*       nic_timing_link;
00202     bool        nic_timing_wakeup_scheduled;
00203     Link*       dma_return_link;
00204     Link*       pio_delay_link;
00205     int         dma_return_count;
00206 
00207   std::string frequency;
00208 
00209     application *app;
00210 
00211     // Buffers to hold data going to NIC.  Need these to properly
00212     // model contention and to properly throttle bandwidth
00213     std::queue<trig_nic_event*> wc_buffers;
00214     int wc_buffers_max;
00215     std::queue<trig_nic_event*> dma_buffers;
00216     
00217 public:
00218     static barrier_action* barrier_act;
00219     
00220     static void
00221         addTimeToStats(SimTime_t time);
00222 //     { 
00223 //         barrier_act->addTimeToStats(time); 
00224 //      if ( time < min ) min = time;
00225 //      if ( time > max ) max = time;
00226 //      total_time += time; 
00227 //      total_num++;
00228 //     }
00229 
00230 //     static void
00231 //     addTimeToOverallStats(SimTime_t time)
00232 //     {
00233 //         if ( time < overall_min ) overall_min = time;
00234 //         if ( time > overall_max ) overall_max = time;
00235 //         overall_total_time += time;
00236 //         overall_total_num++;
00237 //     }
00238 
00239 //     static void
00240 //     resetStats()
00241 //     {
00242 //         min = 0xffffffff;
00243 //         max = 0;
00244 //         total_time = 0;
00245 //         total_num = 0;
00246 //     }
00247 
00248 //     static void
00249 //     printStats()
00250 //     {
00251 //         printf("Max time: %lu ns\n", (unsigned long) max);
00252 //         printf("Min time: %lu ns\n", (unsigned long) min);
00253 //         printf("Avg time: %lu ns\n", (unsigned long) (total_time/total_num));
00254 //         printf("Total num: %d\n", total_num);
00255 //         fflush(NULL);
00256 //     }
00257 
00258 //     static void
00259 //     printOverallStats()
00260 //     {
00261 //         printf("Overall Max time: %lu ns\n", (unsigned long) overall_max);
00262 //         printf("Overall Min time: %lu ns\n", (unsigned long) overall_min);
00263 //         printf("Overall Avg time: %lu ns\n", (unsigned long) (overall_total_time/overall_total_num));
00264 //         printf("Overall Total num: %d\n", overall_total_num);
00265 //         fflush(NULL);
00266 //     }
00267 
00268     static int
00269     getRand(int max)
00270     {
00271         if (!rand_init) {
00272             srand(0);
00273             rand_init = true;
00274         }
00275         if ( max == 0 ) return 0;
00276         return rand() % max;
00277     }
00278 
00279 //     static void
00280 //     addWakeUp(Link* link)
00281 //     {
00282 //         wake_up[current_link++] = link;
00283 //     }
00284 
00285 //     static void
00286 //     setTotalNodes(int total)
00287 //     {
00288 //         if ( wake_up == NULL ) wake_up = new Link*[total];
00289 //         total_nodes = total;
00290 //     }
00291 
00292 //     static void
00293 //     resetBarrier()
00294 //     {
00295 //         num_remaining = total_nodes;
00296 //     }
00297 
00298     static void
00299     barrier();
00300 //     {
00301 //         num_remaining--;
00302 //         if ( num_remaining == 0 ) {
00303 //             // Everyone has entered barrier, wake everyone up to start
00304 //             // over
00305 //             for ( int i = 0; i < total_nodes; i++ ) {
00306 //                 wake_up[i]->Send(10,NULL);
00307 //             }
00308 //             resetBarrier();
00309 //             printStats();
00310 //             addTimeToOverallStats(max);
00311 //             resetStats();
00312 //         }
00313 //     }
00314 
00315     void start_noise_section() {
00316         do_noise = true;
00317     }
00318     
00319     void end_noise_section() {
00320         do_noise = false;
00321     }
00322 private:
00323 //     static SimTime_t min;
00324 //     static SimTime_t max;
00325 //     static SimTime_t total_time;
00326 //     static int total_num;
00327 
00328 //     static SimTime_t overall_min;
00329 //     static SimTime_t overall_max;
00330 //     static SimTime_t overall_total_time;
00331 //     static int overall_total_num;
00332 
00333     static bool rand_init;
00334 
00335     // Infrastructure for doing more than one allreduce in a single
00336     // simulation
00337 //     static Link** wake_up;
00338 //     static int current_link;
00339 //     static int total_nodes;
00340 //     static int num_remaining;
00341 };
00342 
00343 #endif // COMPONENTS_TRIG_CPU_TRIG_CPU_H

Generated on Fri Oct 22 2010 11:02:25 for SST by  doxygen 1.7.1