Beispiel #1
0
 def check(self, conf):
     try:
         con = sobstitute(self.__constrain, conf)
         ret = eval(con)
         if not ret:
             print "Failed to satisfy constrain: {0}".format(con)
     except KeyError, err:
         # print ("Warning: invariant '{0}' couldn't be checked"
         #        "for the current configuration.").format(self.__constrain)
         return True
 def check(self, conf):
     try:
         con = sobstitute(self.__constrain, conf)
         ret = eval(con)
         if not ret:
             print "Failed to satisfy constrain: {0}".format(con)
     except KeyError, err:
         # print ("Warning: invariant '{0}' couldn't be checked"
         #        "for the current configuration.").format(self.__constrain)
         return True
Beispiel #3
0
    def WriteBack(self, def_vals, data, final_out_file, elaborate):

        if elaborate is None:
            return

        self.__sync.acquire()
        data = [x for x in data if x is not None]
        data = [x for x in data if len(x)]
        # we remove the empty elements

        file_name = sobstitute(elaborate.out_file_name.currValue(), self)
        in_file_format = elaborate.in_file_format

        res = {}
        res['MIN'] = [0] * len(in_file_format)
        res['MAX'] = [0] * len(in_file_format)
        res['AVG'] = [0] * len(in_file_format)
        res['STD'] = [0] * len(in_file_format)

        if len(data):
            data_ex = zip(*data)
            for i in range(len(in_file_format)):
                res['AVG'][i] = avg(data_ex[i])
                res['MIN'][i] = min(data_ex[i])
                res['MAX'][i] = max(data_ex[i])

            for i in range(len(in_file_format)):
                res['STD'][i] = std(data_ex[i], res['AVG'][i])

            # print "MINS: " + str(res['MIN'])
            # print "MAXS: " + str(res['MAX'])
            # print "AVG : " + str(res['AVG'])
            # print "STD : " + str(res['STD'])

        vals = []
        for param in elaborate.out_file_format:
            if param in self.__parameters.keys():
                vals.append(toStr(self.__parameters[param].currValue()))
            elif (param.startswith('AVG(') or param.startswith('STD(')
                  or param.startswith('MIN(')
                  or param.startswith('MAX(')) and param.endswith(')'):
                param_name = param[4:-1]
                assert param_name in in_file_format.values
                vals.append(
                    toStr(res[param[:3]][in_file_format.values.index(
                        param_name)]))

        self.__speedup = -1
        idx = elaborate.speedup_idx.currValue()
        if def_vals:
            if def_vals['AVG'][idx] != 0 and res['AVG'][idx] != 0:
                assert (idx > 0 or idx < 0)
                if idx < 0:
                    idx = (-idx) - 1
                    self.__speedup = res['AVG'][idx] / def_vals['AVG'][idx]
                else:
                    idx -= 1
                    self.__speedup = def_vals['AVG'][idx] / res['AVG'][idx]

            vals.append(toStr(self.__speedup))

        open(file_name, 'a').write(",".join(vals) + "\n")

        print "\n{0}".format(80 * "*")
        if res['AVG'][idx] == 0:
            print "* Configuration failed to execute! "
        else:
            print "* Average values: \n*\t%s" % ", ".join(
                map(lambda x: "{0:.3f}".format(x), res['AVG']))
            if self.__speedup != -1:
                print "* Speedup: \n*\t{0:.5f}".format(self.__speedup)
        print "{0}".format(80 * "*")

        self.__sync.notify()
        self.__sync.release()
        return res
    def WriteBack(self, def_vals, data, final_out_file, elaborate):

        if elaborate is None:
            return

        self.__sync.acquire()
        data = [x for x in data if x is not None]
        data = [x for x in data if len(x)]
        # we remove the empty elements

        file_name = sobstitute(elaborate.out_file_name.currValue(), self)
        in_file_format = elaborate.in_file_format

        res = {}
        res["MIN"] = [0] * len(in_file_format)
        res["MAX"] = [0] * len(in_file_format)
        res["AVG"] = [0] * len(in_file_format)
        res["STD"] = [0] * len(in_file_format)

        if len(data):
            data_ex = zip(*data)
            for i in range(len(in_file_format)):
                res["AVG"][i] = avg(data_ex[i])
                res["MIN"][i] = min(data_ex[i])
                res["MAX"][i] = max(data_ex[i])

            for i in range(len(in_file_format)):
                res["STD"][i] = std(data_ex[i], res["AVG"][i])

            # print "MINS: " + str(res['MIN'])
            # print "MAXS: " + str(res['MAX'])
            # print "AVG : " + str(res['AVG'])
            # print "STD : " + str(res['STD'])

        vals = []
        for param in elaborate.out_file_format:
            if param in self.__parameters.keys():
                vals.append(toStr(self.__parameters[param].currValue()))
            elif (
                param.startswith("AVG(")
                or param.startswith("STD(")
                or param.startswith("MIN(")
                or param.startswith("MAX(")
            ) and param.endswith(")"):
                param_name = param[4:-1]
                assert param_name in in_file_format.values
                vals.append(toStr(res[param[:3]][in_file_format.values.index(param_name)]))

        self.__speedup = -1
        idx = elaborate.speedup_idx.currValue()
        if def_vals:
            if def_vals["AVG"][idx] != 0 and res["AVG"][idx] != 0:
                assert idx > 0 or idx < 0
                if idx < 0:
                    idx = (-idx) - 1
                    self.__speedup = res["AVG"][idx] / def_vals["AVG"][idx]
                else:
                    idx -= 1
                    self.__speedup = def_vals["AVG"][idx] / res["AVG"][idx]

            vals.append(toStr(self.__speedup))

        open(file_name, "a").write(",".join(vals) + "\n")

        print "\n{0}".format(80 * "*")
        if res["AVG"][idx] == 0:
            print "* Configuration failed to execute! "
        else:
            print "* Average values: \n*\t%s" % ", ".join(map(lambda x: "{0:.3f}".format(x), res["AVG"]))
            if self.__speedup != -1:
                print "* Speedup: \n*\t{0:.5f}".format(self.__speedup)
        print "{0}".format(80 * "*")

        self.__sync.notify()
        self.__sync.release()
        return res