brintos

brintos / llvm-project-archived public Read only

0
0
Text · 7.8 KiB · da97a40 Raw
200 lines · python
1import ompdModule2 3 4class ompd_parallel(object):5    def __init__(self, parallel_handle):6        """Initializes an ompd_parallel object with the pointer7        to a handle of a parallel region."""8        self.parallel_handle = parallel_handle9        self.threads = {}10        self.itasks = {}11        self.enclosing_parallel_handle = None12        self.enclosing_parallel = False13        self.task_handle = None14 15    def get_thread_in_parallel(self, thread_num):16        """Obtains thread handles for the threads associated with the17        parallel region specified by parallel_handle."""18        if not thread_num in self.threads:19            thread_handle = ompdModule.call_ompd_get_thread_in_parallel(20                self.parallel_handle, thread_num21            )22            self.threads[thread_num] = ompd_thread(thread_handle)23        return self.threads[thread_num]24 25    def get_enclosing_parallel_handle(self):26        """Obtains a parallel handle for the parallel region enclosing27        the parallel region specified by parallel_handle."""28        if not self.enclosing_parallel_handle:29            self.enclosing_parallel_handle = (30                ompdModule.call_ompd_get_enclosing_parallel_handle(self.parallel_handle)31            )32        return self.enclosing_parallel_handle33 34    def get_enclosing_parallel(self):35        if not self.enclosing_parallel:36            self.enclosing_parallel = ompd_parallel(37                self.get_enclosing_parallel_handle()38            )39        return self.enclosing_parallel40 41    def get_task_in_parallel(self, thread_num):42        """Obtains handles for the implicit tasks associated with the43        parallel region specified by parallel_handle."""44        if not thread_num in self.itasks:45            task_handle = ompdModule.call_ompd_get_task_in_parallel(46                self.parallel_handle, thread_num47            )48            self.itasks[thread_num] = ompd_task(task_handle)49        return self.itasks[thread_num]50 51    def __del__(self):52        """Releases the parallel handle."""53        pass  # let capsule destructors do the job54 55 56class ompd_task(object):57    def __init__(self, task_handle):58        """Initializes a new ompd_task_handle object and sets the attribute59        to the task handle specified."""60        self.task_handle = task_handle61        self.task_parallel_handle = False62        self.generating_task_handle = False63        self.scheduling_task_handle = False64        self.task_parallel = False65        self.generating_task = False66        self.scheduling_task = False67        self.task_frames = None68        self.task_frame_flags = None69 70    def get_task_parallel_handle(self):71        """Obtains a task parallel handle for the parallel region enclosing72        the task region specified."""73        if not self.task_parallel_handle:74            self.task_parallel_handle = ompdModule.call_ompd_get_task_parallel_handle(75                self.task_handle76            )77        return self.task_parallel_handle78 79    def get_task_parallel(self):80        if not self.task_parallel:81            self.task_parallel = ompd_parallel(self.get_task_parallel_handle())82        return self.task_parallel83 84    def get_generating_task_handle(self):85        """Obtains the task handle for the task that created the task specified86        by the task handle."""87        if not self.generating_task_handle:88            self.generating_task_handle = (89                ompdModule.call_ompd_get_generating_task_handle(self.task_handle)90            )91        return self.generating_task_handle92 93    def get_generating_task(self):94        if not self.generating_task:95            self.generating_task = ompd_task(96                ompdModule.call_ompd_get_generating_task_handle(self.task_handle)97            )98        return self.generating_task99 100    def get_scheduling_task_handle(self):101        """Obtains the task handle for the task that scheduled the task specified."""102        if not self.scheduling_task_handle:103            self.scheduling_task_handle = (104                ompdModule.call_ompd_get_scheduling_task_handle(self.task_handle)105            )106        return self.scheduling_task_handle107 108    def get_scheduling_task(self):109        """Returns ompd_task object for the task that scheduled the current task."""110        if not self.scheduling_task:111            self.scheduling_task = ompd_task(self.get_scheduling_task_handle())112        return self.scheduling_task113 114    def get_task_function(self):115        """Returns long with address of function entry point."""116        return ompdModule.call_ompd_get_task_function(self.task_handle)117 118    def get_task_frame_with_flags(self):119        """Returns enter frame address and flag, exit frame address and flag for current task handle."""120        if self.task_frames is None or self.task_frame_flags is None:121            ret_value = ompdModule.call_ompd_get_task_frame(self.task_handle)122            if isinstance(ret_value, tuple):123                self.task_frames = (ret_value[0], ret_value[2])124                self.task_frame_flags = (ret_value[1], ret_value[3])125            else:126                return ret_value127        return (128            self.task_frames[0],129            self.task_frame_flags[0],130            self.task_frames[1],131            self.task_frame_flags[1],132        )133 134    def get_task_frame(self):135        """Returns enter and exit frame address for current task handle."""136        if self.task_frames is None:137            ret_value = ompdModule.call_ompd_get_task_frame(self.task_handle)138            if isinstance(ret_value, tuple):139                self.task_frames = (ret_value[0], ret_value[2])140            else:141                return ret_value142        return self.task_frames143 144    def __del__(self):145        """Releases the task handle."""146        pass  # let capsule destructors do the job147 148 149class ompd_thread(object):150    def __init__(self, thread_handle):151        """Initializes an ompd_thread with the data received from152        GDB."""153        self.thread_handle = thread_handle154        self.parallel_handle = None155        self.task_handle = None156        self.current_task = False157        self.current_parallel = False158        self.thread_id = False159 160    def get_current_parallel_handle(self):161        """Obtains the parallel handle for the parallel region associated with162        the given thread handle."""163        # TODO: invalidate thread objects based on `gdb.event.cont`. This should invalidate all internal state.164        self.parallel_handle = ompdModule.call_ompd_get_curr_parallel_handle(165            self.thread_handle166        )167        return self.parallel_handle168 169    def get_current_parallel(self):170        """Returns parallel object for parallel handle of the parallel region171        associated with the current thread handle."""172        if not self.current_parallel:173            self.current_parallel = ompd_parallel(self.get_current_parallel_handle())174        return self.current_parallel175 176    def get_current_task_handle(self):177        """Obtains the task handle for the current task region of the178        given thread."""179        return ompdModule.call_ompd_get_curr_task_handle(self.thread_handle)180 181    def get_thread_id(self):182        """Obtains the ID for the given thread."""183        if not self.thread_id:184            self.thread_id = ompdModule.call_ompd_get_thread_id(self.thread_handle)185        return self.thread_id186 187    def get_current_task(self):188        """Returns task object for task handle of the current task region."""189        return ompd_task(self.get_current_task_handle())190 191    def get_state(self):192        """Returns tuple with OMPD state (long) and wait_id, in case the thread is in a193        waiting state. Helper function for 'ompd threads' command."""194        (state, wait_id) = ompdModule.call_ompd_get_state(self.thread_handle)195        return (state, wait_id)196 197    def __del__(self):198        """Releases the given thread handle."""199        pass  # let capsule destructors do the job200