Exemple #1
0
    def _add_framework_info(self, framework_obj_list):
        """
        Add framework info into timeline metadata.

        Args:
            framework_obj_list (list): The framework metadata.
        """
        logger.debug('Start adding framework info into timeline...')
        # Get the framework info that will be written into timeline.
        framework_info_dict = {}
        for framework_obj in framework_obj_list:
            op_name = framework_obj[0]
            op_type = framework_obj[1]
            op_full_name = framework_obj[4]
            op_info = framework_obj[5]
            framework_info_dict[op_full_name] = {
                'name': op_name,
                'args': {
                    'type': op_type,
                    'fullname': op_full_name
                }
            }
            framework_info_dict[op_full_name]['args'].update(op_info)

        # Insert framework info into timeline.
        for timeline_item in self._timeline_meta:
            op_full_name = timeline_item.get('name')
            framework_item = framework_info_dict.get(op_full_name)
            if framework_item:
                timeline_item['name'] = framework_item.get('name')
                timeline_item['args'] = framework_item.get('args')

        logger.debug('Finished adding framework info into timeline...')
    def get_proposer(self, proposer_type, *args):
        """
        Get the specified proposer according to the proposer type.

        Args:
            proposer_type (str): The proposer type.
            args (list): The parameters required for the specific proposer class.

        Returns:
            Proposer, the specified proposer instance.

        Examples:
            >>> proposer_type = 'step_trace'
            >>> proposer = ProposerFactory.instance().get_proposer(proposer_type, self.profiling_dir, self.device_id)

        """
        logger.debug("The 'proposer_type' is %s,The 'args' is %s",
                     proposer_type, str(args))
        proposer_instance = None
        sub_name = proposer_type.split('_')
        proposer_class_name = ''.join([name.capitalize() for name in sub_name])
        proposer_class_name += 'Proposer'

        if hasattr(proposer_module, proposer_class_name):
            proposer_instance = getattr(proposer_module,
                                        proposer_class_name)(*args)
        else:
            logger.warning("The proposer class %s does not exist.",
                           proposer_class_name)
        return proposer_instance
Exemple #3
0
    def analyze(self, options=None):
        """
        Get the proposal from proposer.

        Args:
            options (dict): options for proposer analysis.
                - step_trace: include optional parameters for step trace,The dictionary key is iter_interval
                  used to get the analyser options for iteration interval time.

        Returns:
            dict, the proposal from proposer instance,the dictionary key is a language internationalization
            label, and the value is used to format the value in the language internationalization string.

        Examples:
            >>> proposer_type = 'step_trace'
            >>> proposer = ProposerFactory.instance().get_proposer(proposer_type, self.profiling_dir, self.device_id)
            >>> result = proposer.analyze(options)
        """
        logger.info("The StepTraceProposer is running")

        options = get_options(options)
        logger.debug("The StepTraceProposer 'options' is %s", str(options))
        step_trace_condition = options.get("step_trace", {})
        # Get the proposals of iteration interval.
        self._iter_interval_analyze(step_trace_condition)
        return self.__proposal_dict
    def init_timeline(self, all_reduce_info, framework_info):
        """
        Init timeline metadata, adding all collected info.

        Args:
            all_reduce_info (list[list]): The metadata of AllReduce operator.
            framework_info (dict): The framework metadata.
        """
        logger.info('Initiating timeline...')
        timeline_list = self._load_timeline_data()
        self._timeline_summary['op_exe_times'] = len(timeline_list)

        # Add AllReduce info to timeline temp list and sort by start time.
        if all_reduce_info:
            logger.debug('AllReduce info found. Start adding info into timeline...')
            timeline_list.extend(all_reduce_info)
            timeline_list.sort(key=lambda x: float(x[2]))

        # Init a dict for counting the num of streams.
        stream_count_dict = {}
        for timeline in timeline_list:
            self._parse_timeline_data(timeline)
            # Updating the collection of streams.
            if len(timeline) == 4:
                self._update_num_of_streams(timeline, stream_count_dict)

        # Get framework metadata.
        framework_obj_list = framework_info.get('object')
        # The length of list is the number of operators.
        self._timeline_summary['num_of_ops'] = len(framework_obj_list)
        self._add_framework_info(framework_obj_list)
        logger.info('Finished adding info into timeline...')

        # Update timeline summary info
        self._timeline_summary['num_of_streams'] = len(stream_count_dict.keys())
 def get_analyser_result(self, analyser_type, condition=None):
     logger.debug("The Proposer 'analyser_type' is %s, 'options' is %s", str(analyser_type), str(condition))
     analyser_result = {}
     try:
         analyser = AnalyserFactory.instance().get_analyser(analyser_type, self.profiling_path, self.device_id)
         analyser_result = analyser.query(condition)
         logger.debug("The 'analyser_result' is %s, the 'condition' is %s.", str(analyser_result), str(condition))
     except MindInsightException as e:
         logger.warning(e)
     return analyser_result
Exemple #6
0
    def write_timeline(self):
        """Load data according to the parsed profiling files."""
        # Write timeline to file.
        file_size = self.write_timeline_to_json()

        # If the file size is larger than 20MB, open a new file and
        # write the first 20MB content into it.
        if file_size > SIZE_LIMIT:
            logger.debug('File size is larger than 20MB, will be resized...')
            # write to json file for display
            self.write_timeline_to_json_by_limitation()
    def get_proposal(self, options=None):
        """
        Get compose proposals.

        Args:
            options (dict): options for composed proposal.
                - compose_proposal_result: execution results of the already running proposers.
                - step_trace: include optional parameters for step trace,The dictionary key is iter_interval
                  used to get the analyser options for iteration interval time.

        Returns:
            dict, the proposals from multiple different proposers.

        Examples:
            >>> type_list = ['common', 'step_trace']
            >>> condition = {"filter_condition": {'mode': "proc", "proc_name": "iteration_interval"}}
            >>> options = {'step_trace': {"iter_interval": condition}}
            >>> cp = ComposeProposal(self.profiling_dir, self.device_id, type_list)
            >>> result_proposal = cp.get_proposal(options=options)
        """
        logger.info("The ComposeProposal is running")
        options = get_options(options)
        logger.debug("The 'options' is %s", str(options))
        # The flag whether to write category label.
        type_label_flag = options.get("type_label_flag", True)
        compose_proposal_result = OrderedDict()
        logger.debug("The 'compose_proposer_type_list' is %s",
                     str(self.compose_proposer_type_list))
        for proposer_type in self.compose_proposer_type_list:
            proposer = ProposerFactory.instance().get_proposer(
                proposer_type, self.profiling_path, self.device_id)

            if proposer is None:
                continue

            # Write the result of proposals to option for other proposer to get.
            options["compose_proposal_result"] = compose_proposal_result

            result = proposer.analyze(options)
            # Insert category label.
            if result and type_label_flag:
                proposer_type_label = proposer_type + "-type_label"
                # Get the name of the category label, the default is the same as the proposer type.
                type_label_name = options.get(proposer_type_label,
                                              proposer_type)
                # Add postfix to category label name
                type_proposal_label = type_label_name + self.type_label_postfix
                compose_proposal_result[type_proposal_label] = None
                # Merge results to the proposals dictionary.
                compose_proposal_result.update(result)
            elif result and not type_label_flag:
                # Merge results to the proposals dictionary.
                compose_proposal_result.update(result)

        logger.debug("The 'compose_proposal_result' is %s",
                     str(compose_proposal_result))
        return compose_proposal_result
Exemple #8
0
 def _iter_interval_analyze(self, step_trace_condition):
     """Get the proposals of iteration interval."""
     iter_interval_dict = OrderedDict()
     default_iter_interval_lst = [0]
     iter_interval_condition = step_trace_condition.get("iter_interval", {})
     analyser_result = self.get_analyser_result(
         self.__proposer_type, condition=iter_interval_condition)
     iter_interval_length_lst = analyser_result.get("info", {}).get(
         "iteration_interval", default_iter_interval_lst)
     logger.debug("The 'iter_interval_length_lst' is %s",
                  str(iter_interval_length_lst))
     # Check the iter_interval_length_lst.
     if not isinstance(iter_interval_length_lst,
                       list) or not iter_interval_length_lst:
         logger.warning(
             "The 'iter_interval_length_lst' is %s, it is null or not a list",
             str(iter_interval_length_lst))
     else:
         if iter_interval_length_lst[
                 0] > self.__step_trace_iter_interval_threshold:
             iter_interval_dict[self.__iter_interval_label] = [
                 str(self.__step_trace_iter_interval_threshold)
             ]
             self.__proposal_dict.update(iter_interval_dict)