def writeExactLogic(solutionsForSchedule, exactLogic, solutionNames, ptr):
  s = ""
  indent = "  "
  for ruleIdx in range(0, len(exactLogic)):
    rule = exactLogic[ruleIdx]
    problemSize = rule[0]
    solutionIdx = rule[1][0]
    solution = solutionsForSchedule[solutionIdx]
    solutionGFlops = rule[1][1]
    s += indent
    if ruleIdx > 0:
      s += "else "
    s += "if ("
    s += " size%s == %u " % (globalParameters["IndexChars"][0], problemSize[0])
    for i in range(1, len(problemSize)):
      s += "&& size%s == %u " % (globalParameters["IndexChars"][i], \
          problemSize[i])

    a = writeSolutionAssertionChecksForSolution(solution)
    if a != "":
        s+= "&& " + a

    solutionName = solutionNames[solutionIdx]
    if ptr:
      returnValue = solutionName
    else:
      returnValue = "\"%s~\"" % solutionName
    s += ") return %s; // %.0f GFlop/s\n" % (returnValue, solutionGFlops)
  return s
Esempio n. 2
0
def writeExactLogic(schedProbName, problemType, indexOrder,
                    solutionsForSchedule, exactLogic, \
                    solutionNames, ptr):
    s = ""
    indent = "  "
    s += "  ProblemSizes_%s p(" % problemType
    for i in range(0, len(indexOrder)):
        if i != 0: s += ", "
        s += "size%s" % globalParameters["IndexChars"][i]
    s += ");\n"

    s += "  int solutionIdx = find_algorithm_static(p, solutionMapper_%s);\n" \
           % (schedProbName)
    s += "  if (solutionIdx != -1) {\n"
    if ptr:
        s += "    auto checkValue = solutionTable_%s[solutionIdx].functionPtr;\n" % (
            schedProbName)
    else:
        s += "    auto checkValue = solutionTable_%s[solutionIdx].name;\n" % (
            schedProbName)
    s += "    return checkValue;\n"
    s += "  }\n"

    if 0:  # TODO - remove this code, this generates the old if-tree and checks against above
        for ruleIdx in range(0, len(exactLogic)):
            rule = exactLogic[ruleIdx]
            problemSize = rule[0]
            solutionIdx = rule[1][0]
            solution = solutionsForSchedule[solutionIdx]
            solutionGFlops = rule[1][1]
            s += indent
            if ruleIdx > 0:
                s += "else "
            s += "if ("
            s += " size%s == %u " % (globalParameters["IndexChars"][0],
                                     problemSize[0])
            for i in range(1, len(problemSize)):
                s += "&& size%s == %u " % (globalParameters["IndexChars"][i], \
                    problemSize[i])

            a = writeSolutionAssertionChecksForSolution(solution)
            if a != "":
                s += "&& " + a

            solutionName = solutionNames[solutionIdx]
            s += ") {\n"
            if ptr:
                returnValue = solutionName
                s += "    assert(%s == checkValue);\n" % returnValue
            else:
                # why add a trailing ~ here?
                returnValue = "\"%s~\"" % solutionName
                s += "    assert(!strcmp(%s,checkValue));\n" % returnValue

            s += "  return %s;} // %.0f GFlop/s\n" % (returnValue,
                                                      solutionGFlops)
    return s
Esempio n. 3
0
def writeRangeLogicRec(depth, indexOrder, rangeLogic, \
    solutionsForSchedule, solutionNames, problemType, ptr):
    indexChars = globalParameters["IndexChars"]
    indent = "  "
    indent += "  " * depth
    s = ""
    lowestLevel = depth == len(indexOrder) - 1
    numRules = len(rangeLogic)
    for ruleIdx in range(0, numRules):
        rule = rangeLogic[ruleIdx]
        threshold = rule[0]
        if lowestLevel:
            solutionIdx = rule[1]
            solution = solutionsForSchedule[solutionIdx]
            solutionName = solutionNames[solutionIdx]
            if ptr:
                returnValue = solutionName
            else:
                returnValue = "\"%s\"" % solutionName

            a = writeSolutionAssertionChecksForSolution(solution)
            if a != "":
                s += indent + "if (" + a + ")"
                indent += "  "

            if threshold > 0:
                s += "%sif (size%s <= %u) return %s;\n" \
                    % (indent, indexChars[indexOrder[depth]], threshold, returnValue)
            else:
                s += "%sreturn %s;\n" % (indent, returnValue)
        else:
            if threshold > 0:
                s += "%sif (size%s <= %u) {\n" \
                    % (indent, indexChars[indexOrder[depth]], threshold)
            else:
                s += "%s{\n" % (indent)
            s += writeRangeLogicRec(depth+1, indexOrder, rule[1], solutionsForSchedule, solutionNames, \
                problemType, ptr)
            s += "%s}\n" % (indent)
    return s