<commit_before>package exploration

import com.typesafe.scalalogging.Logger
import lift.arithmetic.{ArithExpr, Cst}
import play.api.libs.json.Reads._
import play.api.libs.json._
import play.api.libs.functional.syntax._

case class LocalMemoryRulesSettings(
  addIdForCurrentValueInReduce: Boolean,
  addIdMapLcl: Boolean,
  addIdMapWrg: Boolean,
  addIdAfterReduce: Boolean
)

object LocalMemoryRulesSettings{

  def createDefault = createWithDefaults(None, None, None, None)
  def createWithDefaults(
                        addIdForCurrentValueInReduce: Option[Boolean],
                        addIdMapLcl: Option[Boolean],
                        addIdMapWrg: Option[Boolean],
                        addIdAfterReduce: Option[Boolean]
                        ) = LocalMemoryRulesSettings(
  addIdForCurrentValueInReduce.getOrElse(MemoryMappingRewrite.defaultAddIdforCurrentValueInReduce),
  addIdMapLcl.getOrElse(MemoryMappingRewrite.defaultAddIdMapLcl),
  addIdMapWrg.getOrElse(MemoryMappingRewrite.defaultAddIdMapWrg),
  addIdAfterReduce.getOrElse(MemoryMappingRewrite.defaultAddIdAfterReduce))
}

case class ParameterRewriteSettings(
  exploreNDRange: Boolean,
  sampleNDRange: Int,
  disableNDRangeInjection: Boolean,
  sequential: Boolean,
  generateScala: Boolean
)

object ParameterRewriteSettings {

  def createDefault = createWithDefaults(None, None, None, None, None)
  def createWithDefaults(
                        exploreNDRange: Option[Boolean],
                        sampleNDRange: Option[Int],
                        disableNDRangeInjection: Option[Boolean],
                        sequential: Option[Boolean],
                        generateScala: Option[Boolean]
                        ) = ParameterRewriteSettings(
  exploreNDRange.getOrElse(ParameterRewrite.defaultExploreNDRange),
  sampleNDRange.getOrElse(ParameterRewrite.defaultSampleNDRange),
  disableNDRangeInjection.getOrElse(ParameterRewrite.defaultDisableNDRangeInjection),
  sequential.getOrElse(ParameterRewrite.defaultSequential),
  generateScala.getOrElse(ParameterRewrite.defaultGenerateScala))
}

case class MemoryMappingRewriteSettings(
                                       vectorize: Boolean,
                                       vectorWidth: Int,
                                       sequential: Boolean,
                                       loadBalancing: Boolean,
                                       unrollReduce: Boolean,
                                       global0: Boolean,
                                       global01: Boolean,
                                       global10: Boolean,
                                       global012: Boolean,
                                       global210: Boolean,
                                       group0: Boolean,
                                       group01: Boolean,
                                       group10: Boolean
)

object MemoryMappingRewriteSettings {

  def createDefault = createWithDefaults(None, None, None, None, None, None, None, None, None, None, None, None, None)
  def createWithDefaults(
                        vectorize: Option[Boolean],
                        vectorWidth: Option[Int],
                        sequential: Option[Boolean],
                        loadBalancing: Option[Boolean],
                        unrollReduce: Option[Boolean],
                        global0: Option[Boolean],
                        global01: Option[Boolean],
                        global10: Option[Boolean],
                        global012: Option[Boolean],
                        global210: Option[Boolean],
                        group0: Option[Boolean],
                        group01: Option[Boolean],
                        group10: Option[Boolean]
                        ) = MemoryMappingRewriteSettings(
  vectorize.getOrElse(MemoryMappingRewrite.defaultVectorize),
  vectorWidth.getOrElse(MemoryMappingRewrite.defaultVectorWidth),
  sequential.getOrElse(MemoryMappingRewrite.defaultSequential),
  loadBalancing.getOrElse(MemoryMappingRewrite.defaultLoadBalancing),
  unrollReduce.getOrElse(MemoryMappingRewrite.defaultUnrollReduce),
  global0.getOrElse(MemoryMappingRewrite.defaultGlobal0),
  global01.getOrElse(MemoryMappingRewrite.defaultGlobal01),
  global10.getOrElse(MemoryMappingRewrite.defaultGlobal10),
  global012.getOrElse(MemoryMappingRewrite.defaultGlobal012),
  global210.getOrElse(MemoryMappingRewrite.defaultGlobal210),
  group0.getOrElse(MemoryMappingRewrite.defaultGroup0),
  group01.getOrElse(MemoryMappingRewrite.defaultGroup01),
  group10.getOrElse(MemoryMappingRewrite.defaultGroup10))
}

case class HighLevelRewriteSettings(
  explorationDepth: Int,
  depth: Int,
  distance: Int,
  ruleRepetition: Int,
  vectorWidth: Int,
  sequential: Boolean,
  onlyLower: Boolean,
  oldStringRepresentation: Boolean,
  ruleCollection: String
) {
  override def toString: String =
    s"""HighLevelRewriteSettings:
      |    explorationDepth: $explorationDepth
      |    depth: $depth
      |    distance: $distance
      |    ruleRepetition: $ruleRepetition
      |    vectorWidth: $vectorWidth
      |    sequential: $sequential
      |    onlyLower: $onlyLower
      |    oldStringRepresentation: $oldStringRepresentation
      |    ruleCollection: $ruleCollection
    """.stripMargin
}

object HighLevelRewriteSettings {


  def createDefault = createWithDefaults(None, None, None, None, None, None, None, None, None)
  def createWithDefaults(
                        explorationDepth: Option[Int],
                        depth: Option[Int],
                        distance: Option[Int],
                        ruleRepetition: Option[Int],
                        vectorWidth: Option[Int],
                        sequential: Option[Boolean],
                        onlyLower: Option[Boolean],
                        oldStringRepresentation: Option[Boolean],
                        ruleCollection: Option[String]
                        ) = HighLevelRewriteSettings(
  // priority: 1) command-line args; 2) config-file; 3) default values
  HighLevelRewrite.explorationDepth.value.getOrElse(explorationDepth.getOrElse(HighLevelRewrite.defaultExplorationDepth)),
  HighLevelRewrite.depthFilter.value.getOrElse(depth.getOrElse(HighLevelRewrite.defaultDepthFilter)),
  HighLevelRewrite.distanceFilter.value.getOrElse(distance.getOrElse(HighLevelRewrite.defaultDistanceFilter)),
  HighLevelRewrite.ruleRepetition.value.getOrElse(ruleRepetition.getOrElse(HighLevelRewrite.defaultRuleRepetition)),
  HighLevelRewrite.vectorWidth.value.getOrElse(vectorWidth.getOrElse(HighLevelRewrite.defaultVectorWidth)),
  HighLevelRewrite.sequential.value.getOrElse(sequential.getOrElse(HighLevelRewrite.defaultSequential)),
  HighLevelRewrite.onlyLower.value.getOrElse(onlyLower.getOrElse(HighLevelRewrite.defaultOnlyLower)),
  HighLevelRewrite.oldStringRepresentation.value.getOrElse(oldStringRepresentation.getOrElse(HighLevelRewrite.defaultOldStringRepresentation)),
  HighLevelRewrite.ruleCollection.value.getOrElse(ruleCollection.getOrElse(HighLevelRewrite.defaultRuleCollection)))
}

object SearchParameters {
  // Default input size for all dimensions to use for filtering, if no input combinations provided
  private val default_size = 1024

  // Minimum number of work item per workgroup
  private val min_work_items = 128

  // Maximum number of work item per workgroup
  private val max_work_items = 1024

  // Minimal global grid size
  private val min_grid_size = 4

  // Max amount of private memory allocated (this is not necessarily the number of registers)
  private val max_amount_private_memory = 1024

  // Max static amount of local memory
  private val max_amount_local_memory = 50000

  // Minimum number of workgroups
  private val min_num_workgroups = 8

  // Maximum number of workgroups<commit_msg>Make creating HighLevelRewriteSettings more readable<commit_after>package exploration

import com.typesafe.scalalogging.Logger
import lift.arithmetic.{ArithExpr, Cst}
import org.clapper.argot.{FlagOption, SingleValueOption}
import play.api.libs.json.Reads._
import play.api.libs.json._
import play.api.libs.functional.syntax._

case class LocalMemoryRulesSettings(
  addIdForCurrentValueInReduce: Boolean,
  addIdMapLcl: Boolean,
  addIdMapWrg: Boolean,
  addIdAfterReduce: Boolean
)

object LocalMemoryRulesSettings{

  def createDefault = createWithDefaults(None, None, None, None)
  def createWithDefaults(
                        addIdForCurrentValueInReduce: Option[Boolean],
                        addIdMapLcl: Option[Boolean],
                        addIdMapWrg: Option[Boolean],
                        addIdAfterReduce: Option[Boolean]
                        ) = LocalMemoryRulesSettings(
  addIdForCurrentValueInReduce.getOrElse(MemoryMappingRewrite.defaultAddIdforCurrentValueInReduce),
  addIdMapLcl.getOrElse(MemoryMappingRewrite.defaultAddIdMapLcl),
  addIdMapWrg.getOrElse(MemoryMappingRewrite.defaultAddIdMapWrg),
  addIdAfterReduce.getOrElse(MemoryMappingRewrite.defaultAddIdAfterReduce))
}

case class ParameterRewriteSettings(
  exploreNDRange: Boolean,
  sampleNDRange: Int,
  disableNDRangeInjection: Boolean,
  sequential: Boolean,
  generateScala: Boolean
)

object ParameterRewriteSettings {

  def createDefault = createWithDefaults(None, None, None, None, None)
  def createWithDefaults(
                        exploreNDRange: Option[Boolean],
                        sampleNDRange: Option[Int],
                        disableNDRangeInjection: Option[Boolean],
                        sequential: Option[Boolean],
                        generateScala: Option[Boolean]
                        ) = ParameterRewriteSettings(
  exploreNDRange.getOrElse(ParameterRewrite.defaultExploreNDRange),
  sampleNDRange.getOrElse(ParameterRewrite.defaultSampleNDRange),
  disableNDRangeInjection.getOrElse(ParameterRewrite.defaultDisableNDRangeInjection),
  sequential.getOrElse(ParameterRewrite.defaultSequential),
  generateScala.getOrElse(ParameterRewrite.defaultGenerateScala))
}

case class MemoryMappingRewriteSettings(
                                       vectorize: Boolean,
                                       vectorWidth: Int,
                                       sequential: Boolean,
                                       loadBalancing: Boolean,
                                       unrollReduce: Boolean,
                                       global0: Boolean,
                                       global01: Boolean,
                                       global10: Boolean,
                                       global012: Boolean,
                                       global210: Boolean,
                                       group0: Boolean,
                                       group01: Boolean,
                                       group10: Boolean
)

object MemoryMappingRewriteSettings {

  def createDefault = createWithDefaults(None, None, None, None, None, None, None, None, None, None, None, None, None)
  def createWithDefaults(
                        vectorize: Option[Boolean],
                        vectorWidth: Option[Int],
                        sequential: Option[Boolean],
                        loadBalancing: Option[Boolean],
                        unrollReduce: Option[Boolean],
                        global0: Option[Boolean],
                        global01: Option[Boolean],
                        global10: Option[Boolean],
                        global012: Option[Boolean],
                        global210: Option[Boolean],
                        group0: Option[Boolean],
                        group01: Option[Boolean],
                        group10: Option[Boolean]
                        ) = MemoryMappingRewriteSettings(
  vectorize.getOrElse(MemoryMappingRewrite.defaultVectorize),
  vectorWidth.getOrElse(MemoryMappingRewrite.defaultVectorWidth),
  sequential.getOrElse(MemoryMappingRewrite.defaultSequential),
  loadBalancing.getOrElse(MemoryMappingRewrite.defaultLoadBalancing),
  unrollReduce.getOrElse(MemoryMappingRewrite.defaultUnrollReduce),
  global0.getOrElse(MemoryMappingRewrite.defaultGlobal0),
  global01.getOrElse(MemoryMappingRewrite.defaultGlobal01),
  global10.getOrElse(MemoryMappingRewrite.defaultGlobal10),
  global012.getOrElse(MemoryMappingRewrite.defaultGlobal012),
  global210.getOrElse(MemoryMappingRewrite.defaultGlobal210),
  group0.getOrElse(MemoryMappingRewrite.defaultGroup0),
  group01.getOrElse(MemoryMappingRewrite.defaultGroup01),
  group10.getOrElse(MemoryMappingRewrite.defaultGroup10))
}

case class HighLevelRewriteSettings(
  explorationDepth: Int,
  depth: Int,
  distance: Int,
  ruleRepetition: Int,
  vectorWidth: Int,
  sequential: Boolean,
  onlyLower: Boolean,
  oldStringRepresentation: Boolean,
  ruleCollection: String
) {
  override def toString: String =
    s"""HighLevelRewriteSettings:
      |    explorationDepth: $explorationDepth
      |    depth: $depth
      |    distance: $distance
      |    ruleRepetition: $ruleRepetition
      |    vectorWidth: $vectorWidth
      |    sequential: $sequential
      |    onlyLower: $onlyLower
      |    oldStringRepresentation: $oldStringRepresentation
      |    ruleCollection: $ruleCollection
    """.stripMargin
}

object HighLevelRewriteSettings {

  import HighLevelRewrite._

  def getValue[T](option: SingleValueOption[T], config: Option[T], default: T) =
    option.value.getOrElse(config.getOrElse(default))

  def getValue[T](option: FlagOption[T], config: Option[T], default: T) =
    option.value.getOrElse(config.getOrElse(default))

  def createDefault = createWithDefaults(None, None, None, None, None, None, None, None, None)

  def createWithDefaults(
                        configExplorationDepth: Option[Int],
                        configDepth: Option[Int],
                        configDistance: Option[Int],
                        configRuleRepetition: Option[Int],
                        configVectorWidth: Option[Int],
                        configSequential: Option[Boolean],
                        configOnlyLower: Option[Boolean],
                        configOldStringRepresentation: Option[Boolean],
                        configRuleCollection: Option[String]
                        ) = HighLevelRewriteSettings(
  // priority: 1) command-line args; 2) config-file; 3) default values
  getValue(explorationDepth, configExplorationDepth, defaultExplorationDepth),
  getValue(depthFilter, configDepth, defaultDepthFilter),
  getValue(distanceFilter, configDistance, defaultDistanceFilter),
  getValue(ruleRepetition, configRuleRepetition, defaultRuleRepetition),
  getValue(vectorWidth, configVectorWidth, defaultVectorWidth),
  getValue(sequential, configSequential, defaultSequential),
  getValue(onlyLower, configOnlyLower, defaultOnlyLower),
  getValue(oldStringRepresentation, configOldStringRepresentation, defaultOldStringRepresentation),
  getValue(ruleCollection, configRuleCollection, defaultRuleCollection))
}

object SearchParameters {
  // Default input size for all dimensions to use for filtering, if no input combinations provided
  private val default_size = 1024

  // Minimum number of work item per workgroup
  private val min_work_items = 128

  // Maximum number of work item per workgroup
  private val max_work_items = 1024

  // Minimal global grid size
  private val min_grid_size = 4

  // Max amount of private memory allocated (this is not necessarily the number of registers)
  private val max_amount_private_memory = 1024

  // Max static amount of local memory
  private val max_amount_local_memory = 50000

  // Minimum number of workgroups
  private val min_num_workgroups = 8

  // Maximum number of workgroups
{'fraction_non_alphanumeric': 0.07023794375874794, 'fraction_numerical': 0.011324596004580736, 'mean_word_length': 2.6336107258437353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '668720', 'n_tokens_mistral': 4349, 'n_tokens_neox': 3825, 'n_words': 768}