jansel / opentuner

An extensible framework for program autotuning
http://opentuner.org/
MIT License
385 stars 114 forks source link

Use only certain values in a range #99

Open dinhv opened 7 years ago

dinhv commented 7 years ago

Is there a way to choose only certain values in a given range? For example manipulator.add_parameter(IntegerParameter('Kb', 1, 72)) manipulator.add_parameter(IntegerParameter('Mb', 72, 144))

and the run function

    def run(self, desired_result, input, limit):
          cfg = desired_result.configuration.data
          mb = cfg['Mb']
          kb = cfg['Kb']

Let's assume that the current configuration is mb = cfg['Mb']=80. For kb = cfg['Kb'] the constraint is mb % kb == 0 so valid values for kb would be (1,2,4,5,8,10,16,20,40,80). Which function from the IntegerParameter class do I have to overwrite for this constraint? The existing examples are working only for continuous ranges.

jbosboom commented 7 years ago

OpenTuner is not a constraint solver, so those kinds of dependencies between parameter values are not directly expressible. Suppose a hill-climb technique suggests increasing Mb by 5 and Kb by 3. What should OpenTuner do to preserve the constraint? You can usually redesign your parameter space to eliminate these dependencies, though.

In this case, I'd leave the Kb parameter as it is and interpret (in run) an Mb_mult parameter as a multiplier on the value of Kb, with the product clamped to the range 72, 144. If it's important that mb take its full range even when Kb is 1, then Mb_mult would range from 1 to 72; if not, you could try a smaller range. You could also try letting both parameters vary freely over their range, and then "rounding" Kb to the nearest divisor of Mb. Both of these parameterizations still allow hill climbers to say 'this number should get bigger', even if they don't change by the exact amount the hill climber asked for.

By the way, if these are your only parameters, your space is only 5184 configurations large, so you may be able to exhaustively search the space if your trials are reasonably fast and/or can run in parallel.