OpenMP Runtime
tomp_parallel.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2013, Texas Instruments Incorporated - http://www.ti.com/
00003  *   All rights reserved.
00004  *
00005  *  Redistribution and use in source and binary forms, with or without
00006  *  modification, are permitted provided that the following conditions are met:
00007  *      * Redistributions of source code must retain the above copyright
00008  *        notice, this list of conditions and the following disclaimer.
00009  *      * Redistributions in binary form must reproduce the above copyright
00010  *        notice, this list of conditions and the following disclaimer in the
00011  *        documentation and/or other materials provided with the distribution.
00012  *      * Neither the name of Texas Instruments Incorporated nor the
00013  *        names of its contributors may be used to endorse or promote products
00014  *        derived from this software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00035 #ifndef TOMP_PARALLEL_H_
00036 #define TOMP_PARALLEL_H_
00037 
00038 #include "tomp_defs.h"
00039 #include "tomp_init.h"
00040 #include "tomp_util.h"
00041 #include "tomp_qmss.h"
00042 #include "gomp_libgomp.h"
00043 
00045 typedef void (*tomp_OutlinedFunc) (void*);
00046 
00053 typedef struct _tomp_Team
00054 {
00056     unsigned int nthreads;
00057 
00059     tomp_Barrier barrier;
00060 
00062     volatile unsigned int task_count;
00063 
00065     volatile unsigned int curr_task_id;
00066 
00070     struct gomp_work_share dummy_ws;
00071 
00073     volatile unsigned char ordered_release[TOMP_DEVICE_NUM_CORES];
00074 
00075     unsigned int DP;
00076 
00078     tomp_event_t event;
00079 
00081     //  parent team.
00082     struct _tomp_TeamState *prev_ts;
00083 
00084 } tomp_Team;
00085 
00089 typedef struct _tomp_TeamState
00090 {
00092     tomp_Team *team;
00093 
00096     int team_id;
00097 
00099     struct gomp_work_share *work_share;
00100 
00102     struct gomp_work_share *last_work_share;
00103 
00105     unsigned long static_trip;
00106     
00108     tomp_event_t event;
00109 
00111     int level;
00112 
00113 } tomp_TeamState;
00114 
00115 
00117 typedef enum { tomp_TaskStealing_DISABLED = 0, 
00118                tomp_TaskSteaking_ENABLED
00119 } tomp_TaskStealing_e;
00120 
00121 
00128 typedef struct _tomp_Thread
00129 {
00131     tomp_TeamState *ts;
00132 
00134     struct _tomp_Task *current_task;
00135 
00137     tomp_TaskStealing_e task_stealing;
00138 } tomp_Thread;
00139 
00140 
00142 typedef enum { tomp_TaskKind_IMPLICIT = 0, 
00143                tomp_TaskKind_DEFERRED,
00144                tomp_TaskKind_INCLUDED
00145 } tomp_TaskKind_e;
00146 
00147 
00153 typedef struct _tomp_Task
00154 {                    
00156     tomp_OutlinedFunc entry_func;
00157 
00159     void*      arg_buffer;
00160 
00162     tomp_Team *team;
00163 
00165     int teamMember;
00166 
00168     struct _tomp_Task *parent;
00169 
00171     volatile int children_count;
00172 
00174     unsigned short id;
00175 
00177     volatile unsigned char completed_execution;
00178     
00180     unsigned char arg_buffer_in_task;
00181 
00183     unsigned char kind;
00184 
00186     void *tls_block;
00187 
00189     tomp_event_t event;
00190 
00192     struct gomp_task_icv icv;
00193 } tomp_Task;
00194 
00195 
00196 extern tomp_Thread tomp_thread;
00197 extern void*       __TI_tls_currentTP;
00198 extern uint32_t    tomp_threadNum;
00199 
00200 extern tomp_event_t tomp_eventHdlTbl[TOMP_DEVICE_NUM_CORES - 1];
00201 extern tomp_Task*   tomp_taskPtrTbl[TOMP_DEVICE_NUM_CORES - 1];
00202 
00203 extern tomp_Task* tomp_initialTaskForMaster;
00204 extern tomp_Task* tomp_implicitTaskForMaster;
00205 
00206 extern void tomp_eoStartLoopX(tomp_event_t event);
00207 extern void tomp_eoStartTaskX(tomp_event_t event);
00208 
00209 tomp_Team* tomp_initialize_team(unsigned int num_threads);
00210 void tomp_start_team(tomp_Team *ts, void (*fn) (void *), unsigned char *data);
00211 
00212 tomp_TeamState* tomp_alloc_TeamState();
00213 
00221 static inline void tomp_clear_TeamState(tomp_TeamState *ts)
00222 {
00223     ts->team            = NULL;
00224     ts->work_share      = NULL;
00225     ts->last_work_share = NULL;
00226     ts->static_trip     = 0;
00227 }
00228 
00229 
00233 static inline void tomp_taskInit(tomp_Task *task, tomp_TaskKind_e kind, 
00234                                  tomp_Task *parent, tomp_Team *team)
00235 {
00236     task->id                  = 0;
00237     task->kind                = kind;
00238     task->entry_func          = NULL;
00239     task->arg_buffer          = NULL;
00240     task->arg_buffer_in_task  = false;
00241     task->team                = team;
00242     task->teamMember          = (kind == tomp_TaskKind_IMPLICIT) ? 0 : -1;
00243     task->parent              = parent;
00244     task->children_count      = 0;
00245     task->completed_execution = false;
00246     task->icv                 = parent->icv;
00247 }
00248 
00249 extern void tomp_completePendingTasks();
00250 
00251 /* Here's how to access the current copy of the ICVs.  */
00252 
00253 static inline struct gomp_task_icv *gomp_icv (void)
00254 {
00255   return &tomp_thread.current_task->icv;
00256 }
00257 #endif /* TOMP_PARALLEL_H_ */
 All Classes Files Functions Variables Typedefs Enumerations Defines