7474 "pyatf_strategies" : "kernel_tuner.strategies.pyatf_strategies" ,
7575 "hybrid_vndx" : "kernel_tuner.strategies.gen_hybrid_vndx" ,
7676 "adaptive_tabu_greywolf" : "kernel_tuner.strategies.gen_adaptive_tabu_greywolf" ,
77+ "nsga2" : "kernel_tuner.strategies.pymoo_minimize" ,
78+ "nsga3" : "kernel_tuner.strategies.pymoo_minimize" ,
7779}
7880
7981_STRATEGY_PARALLEL = ["brute_force" , "random_sample" , "diff_evo" , "genetic_algorithm" , "pso" , "firefly_algorithm" ]
@@ -460,15 +462,15 @@ def __deepcopy__(self, _):
460462 """Optimization objective to sort results on, consisting of a string
461463 that also occurs in results as a metric or observed quantity, default 'time'.
462464 Please see :ref:`objectives`.""" ,
463- "string " ,
465+ "str | list[str] " ,
464466 ),
465467 ),
466468 (
467469 "objective_higher_is_better" ,
468470 (
469471 """boolean that specifies whether the objective should
470472 be maximized (True) or minimized (False), default False.""" ,
471- "bool" ,
473+ "bool | list[bool] " ,
472474 ),
473475 ),
474476 (
@@ -498,6 +500,7 @@ def __deepcopy__(self, _):
498500 ),
499501 ("metrics" , ("specifies user-defined metrics, please see :ref:`metrics`." , "dict" )),
500502 ("simulation_mode" , ("Simulate an auto-tuning search from an existing cachefile" , "bool" )),
503+ ("seed" , ("""The random seed.""" , "int" )),
501504 ("parallel" , ("Set to `True` or an integer to enable parallel tuning. If set to an integer, this will be the number of parallel workers." , "int|bool" )),
502505 (
503506 "observers" ,
@@ -621,6 +624,8 @@ def tune_kernel(
621624 observers = None ,
622625 objective = None ,
623626 objective_higher_is_better = None ,
627+ objectives = None ,
628+ seed = None ,
624629):
625630 start_overhead_time = perf_counter ()
626631 if log :
@@ -630,8 +635,22 @@ def tune_kernel(
630635
631636 _check_user_input (kernel_name , kernelsource , arguments , block_size_names )
632637
633- # default objective if none is specified
634- objective , objective_higher_is_better = get_objective_defaults (objective , objective_higher_is_better )
638+ if objectives :
639+ if isinstance (objectives , dict ):
640+ objective = list (objectives .keys ())
641+ objective_higher_is_better = list (objectives .values ())
642+ else :
643+ raise ValueError ("objectives should be a dict of (objective, higher_is_better) pairs" )
644+ else :
645+ objective , objective_higher_is_better = get_objective_defaults (objective , objective_higher_is_better )
646+ if isinstance (objective , str ):
647+ objective = [objective ]
648+ if isinstance (objective_higher_is_better , bool ):
649+ objective_higher_is_better = [objective_higher_is_better ]
650+
651+ assert isinstance (objective , list )
652+ assert isinstance (objective_higher_is_better , list )
653+ assert len (objective ) == len (objective_higher_is_better )
635654
636655 # check for forbidden names in tune parameters
637656 util .check_tune_params_list (tune_params , observers , simulation_mode = simulation_mode )
@@ -663,7 +682,6 @@ def tune_kernel(
663682 if "searchspace_construction_options" in strategy_options :
664683 searchspace_construction_options = strategy_options ["searchspace_construction_options" ]
665684
666-
667685 # log the user inputs
668686 logging .debug ("tune_kernel called" )
669687 logging .debug ("kernel_options: %s" , util .get_config_string (kernel_options ))
@@ -776,13 +794,35 @@ def preprocess_cache(filepath):
776794
777795 # finished iterating over search space
778796 if results : # checks if results is not empty
779- best_config = util .get_best_config (results , objective , objective_higher_is_better )
780- # add the best configuration to env
781- env ["best_config" ] = best_config
782- if not device_options .quiet :
783- units = getattr (runner , "units" , None )
784- print ("best performing configuration:" )
785- util .print_config_output (tune_params , best_config , device_options .quiet , metrics , units )
797+ if len (objective ) == 1 :
798+ objective = objective [0 ]
799+ objective_higher_is_better = objective_higher_is_better [0 ]
800+ best_config = util .get_best_config (results , objective , objective_higher_is_better )
801+ # add the best configuration to env
802+ env ['best_config' ] = best_config
803+ if not device_options .quiet :
804+ units = getattr (runner , "units" , None )
805+ keys = list (tune_params .keys ())
806+ keys += [objective ]
807+ if metrics :
808+ keys += list (metrics .keys ())
809+ if not quiet :
810+ print (f"\n BEST PERFORMING CONFIGURATION FOR OBJECTIVE { objective } :" )
811+ print (util .get_config_string (best_config , keys , units ))
812+ else :
813+ pareto_front = util .get_pareto_results (results , objective , objective_higher_is_better )
814+ # add the best configuration to env
815+ env ['best_config' ] = pareto_front
816+ if not device_options .quiet :
817+ units = getattr (runner , "units" , None )
818+ keys = list (tune_params .keys ())
819+ keys += list (objective )
820+ if metrics :
821+ keys += list (metrics .keys ())
822+ if not quiet :
823+ print (f"\n BEST PERFORMING CONFIGURATIONS FOR OBJECTIVES: { objective } :" )
824+ for best_config in pareto_front :
825+ print (util .get_config_string (best_config , keys , units ))
786826 elif not device_options .quiet :
787827 print ("no results to report" )
788828
@@ -797,6 +837,28 @@ def preprocess_cache(filepath):
797837
798838tune_kernel .__doc__ = _tune_kernel_docstring
799839
840+
841+ def tune_cache (
842+ cache_path ,
843+ restrictions = None ,
844+ ** kwargs ,
845+ ):
846+ cache = util .read_cache (cache_path , open_cache = False )
847+ tune_args = util .infer_args_from_cache (cache )
848+ _restrictions = [util .infer_restrictions_from_cache (cache )]
849+
850+ # Add the user provided restrictions
851+ if restrictions :
852+ if isinstance (restrictions , list ):
853+ _restrictions .extend (restrictions )
854+ else :
855+ raise ValueError ("The restrictions must be a list()" )
856+
857+ tune_args .update (kwargs )
858+
859+ return tune_kernel (** tune_args , cache = cache_path , restrictions = _restrictions , simulation_mode = True )
860+
861+
800862_run_kernel_docstring = """Compile and run a single kernel
801863
802864 Compiles and runs a single kernel once, given a specific instance of the kernels tuning parameters.
0 commit comments