From 3f8d6a2c812e4bc0e3ebed1b96e00434c4bd61d6 Mon Sep 17 00:00:00 2001 From: tj-sun Date: Fri, 16 Feb 2018 16:26:33 +0000 Subject: [PATCH 1/3] remember instructions sorting between recursions --- loopy/schedule/__init__.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/loopy/schedule/__init__.py b/loopy/schedule/__init__.py index 850f0a61f..448dd6b64 100644 --- a/loopy/schedule/__init__.py +++ b/loopy/schedule/__init__.py @@ -657,7 +657,6 @@ def generate_loop_schedules_internal( sched_state, allow_boost=False, debug=None): # allow_insn is set to False initially and after entering each loop # to give loops containing high-priority instructions a chance. - kernel = sched_state.kernel Fore = kernel.options._fore # noqa Style = kernel.options._style # noqa @@ -776,10 +775,13 @@ def generate_loop_schedules_internal( # schedule generation order. return (insn.priority, len(active_groups & insn.groups), insn.id) - insn_ids_to_try = sorted( - # Non-prescheduled instructions go first. - sched_state.unscheduled_insn_ids - sched_state.prescheduled_insn_ids, - key=insn_sort_key, reverse=True) + if sched_state.insn_ids_to_try is None: + insn_ids_to_try = sorted( + # Non-prescheduled instructions go first. + sched_state.unscheduled_insn_ids - sched_state.prescheduled_insn_ids, + key=insn_sort_key, reverse=True) + else: + insn_ids_to_try = sched_state.insn_ids_to_try insn_ids_to_try.extend( insn_id @@ -910,9 +912,13 @@ def generate_loop_schedules_internal( new_uses_of_boostability.append( (insn.id, orig_have & insn.boostable_into)) + new_insn_ids_to_try = list(insn_ids_to_try) + new_insn_ids_to_try.remove(insn.id) + new_sched_state = sched_state.copy( scheduled_insn_ids=sched_state.scheduled_insn_ids | iid_set, unscheduled_insn_ids=sched_state.unscheduled_insn_ids - iid_set, + insn_ids_to_try=new_insn_ids_to_try, schedule=( sched_state.schedule + (RunInstruction(insn_id=insn.id),)), preschedule=( @@ -928,7 +934,6 @@ def generate_loop_schedules_internal( # Don't be eager about entering/leaving loops--if progress has been # made, revert to top of scheduler and see if more progress can be # made. - for sub_sched in generate_loop_schedules_internal( new_sched_state, allow_boost=rec_allow_boost, debug=debug): @@ -1847,6 +1852,7 @@ def generate_loop_schedules_inner(kernel, debug_args={}): may_schedule_global_barriers=True, preschedule=preschedule, + insn_ids_to_try=None, # ilp and vec are not parallel for the purposes of the scheduler parallel_inames=parallel_inames - ilp_inames - vec_inames, -- GitLab From 039177e90b4e1d59a2861e6e7d9eb77c506682dc Mon Sep 17 00:00:00 2001 From: tj-sun Date: Fri, 16 Feb 2018 19:03:19 +0000 Subject: [PATCH 2/3] invalidate instruction sorting when active group changes --- loopy/schedule/__init__.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/loopy/schedule/__init__.py b/loopy/schedule/__init__.py index 448dd6b64..975671fa4 100644 --- a/loopy/schedule/__init__.py +++ b/loopy/schedule/__init__.py @@ -775,6 +775,7 @@ def generate_loop_schedules_internal( # schedule generation order. return (insn.priority, len(active_groups & insn.groups), insn.id) + # Use previous instruction sorting result if it is available if sched_state.insn_ids_to_try is None: insn_ids_to_try = sorted( # Non-prescheduled instructions go first. @@ -883,6 +884,11 @@ def generate_loop_schedules_internal( if is_ready and debug_mode: print("ready to schedule '%s'" % format_insn(kernel, insn.id)) + # Remove the current instruction from the sorted list of instructions + # to try + new_insn_ids_to_try = list(insn_ids_to_try) + new_insn_ids_to_try.remove(insn.id) + if is_ready and not debug_mode: iid_set = frozenset([insn.id]) @@ -900,6 +906,8 @@ def generate_loop_schedules_internal( else: new_active_group_counts[grp] = ( sched_state.group_insn_counts[grp] - 1) + # invalidate instruction to try when active group changes + new_insn_ids_to_try = None else: new_active_group_counts = sched_state.active_group_counts @@ -912,9 +920,6 @@ def generate_loop_schedules_internal( new_uses_of_boostability.append( (insn.id, orig_have & insn.boostable_into)) - new_insn_ids_to_try = list(insn_ids_to_try) - new_insn_ids_to_try.remove(insn.id) - new_sched_state = sched_state.copy( scheduled_insn_ids=sched_state.scheduled_insn_ids | iid_set, unscheduled_insn_ids=sched_state.unscheduled_insn_ids - iid_set, -- GitLab From 681b4133929c3904a83efa3ecad7c832c3d1df8d Mon Sep 17 00:00:00 2001 From: tj-sun Date: Wed, 28 Feb 2018 08:51:26 +0000 Subject: [PATCH 3/3] invalidate inst_ids_to_try when active group changes --- loopy/schedule/__init__.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/loopy/schedule/__init__.py b/loopy/schedule/__init__.py index 975671fa4..771ba7378 100644 --- a/loopy/schedule/__init__.py +++ b/loopy/schedule/__init__.py @@ -884,11 +884,6 @@ def generate_loop_schedules_internal( if is_ready and debug_mode: print("ready to schedule '%s'" % format_insn(kernel, insn.id)) - # Remove the current instruction from the sorted list of instructions - # to try - new_insn_ids_to_try = list(insn_ids_to_try) - new_insn_ids_to_try.remove(insn.id) - if is_ready and not debug_mode: iid_set = frozenset([insn.id]) @@ -906,14 +901,23 @@ def generate_loop_schedules_internal( else: new_active_group_counts[grp] = ( sched_state.group_insn_counts[grp] - 1) - # invalidate instruction to try when active group changes - new_insn_ids_to_try = None - else: new_active_group_counts = sched_state.active_group_counts # }}} + # {{{ update instruction_ids_to_try + + new_insn_ids_to_try = list(insn_ids_to_try) + new_insn_ids_to_try.remove(insn.id) + + # invalidate instruction_ids_to_try when active group changes + if set(new_active_group_counts.keys()) != set( + sched_state.active_group_counts.keys()): + new_insn_ids_to_try = None + + # }}} + new_uses_of_boostability = [] if allow_boost: if orig_have & insn.boostable_into: -- GitLab