def readSolutions(filename): try: stream = open(filename, "r") except IOError: printExit("Cannot open file: %s" % filename) solutionStates = yaml.load(stream, yaml.SafeLoader) stream.close() # verify if len(solutionStates) < 2: printExit("len(%s) %u < 2" % (filename, len(solutionStates))) versionString = solutionStates[0]["MinimumRequiredVersion"] if not versionIsCompatible(versionString): printWarning("File \"%s\" version=%s does not match current Tensile version=%s" \ % (filename, versionString, __version__) ) if "ProblemSizes" not in solutionStates[1]: printExit("%s doesn't begin with ProblemSizes" % filename) else: problemSizesConfig = solutionStates[1]["ProblemSizes"] solutions = [] for i in range(2, len(solutionStates)): solutionState = solutionStates[i] solutionObject = Solution(solutionState) solutions.append(solutionObject) problemType = solutions[0]["ProblemType"] problemSizes = ProblemSizes(problemType, problemSizesConfig) return (problemSizes, solutions)
def readLibraryLogicForSchedule(filename): print1("# Reading Library Logic: %s" % (filename)) try: stream = open(filename, "r") except IOError: printExit("Cannot open file: %s" % filename) data = yaml.load(stream, yaml.SafeLoader) stream.close() # verify if len(data) < 6: printExit("len(%s) %u < 7" % (filename, len(data))) # parse out objects versionString = data[0]["MinimumRequiredVersion"] scheduleName = data[1] architectureName = data[2] deviceNames = data[3] problemTypeState = data[4] solutionStates = data[5] indexOrder = data[6] exactLogic = data[7] rangeLogic = data[8] # does version match if not versionIsCompatible(versionString): printWarning("File \"%s\" version=%s does not match Tensile version=%s" \ % (filename, versionString, __version__) ) # unpack problemType problemType = ProblemType(problemTypeState) # unpack solutions solutions = [] for i in range(0, len(solutionStates)): solutionState = solutionStates[i] if solutionState["KernelLanguage"] == "Assembly": isa0 = int(architectureName[3]) isa1 = int(architectureName[4]) isa2 = int(architectureName[5]) solutionState["ISA"] = (isa0, isa1, isa2) else: solutionState["ISA"] = (0, 0, 0) solutionObject = Solution(solutionState) if solutionObject["ProblemType"] != problemType: printExit("ProblemType of file doesn't match solution: %s != %s" \ % (problemType, solutionObject["ProblemType"])) solutions.append(solutionObject) return (scheduleName, deviceNames, problemType, solutions, indexOrder, \ exactLogic, rangeLogic )