def test_generateSolutions(useGlobalParameters): with useGlobalParameters(): scriptDir = os.path.dirname(os.path.realpath(__file__)) dataDir = os.path.realpath(os.path.join(scriptDir, "..", "test_data", "unit")) problemTypeFilePath = os.path.join(dataDir, "library_data", "problemType.yaml") hardcodedParametersFilePath = os.path.join(dataDir, "library_data", "hardcodedParameters.yaml") initialSolutionParametersFilePath = os.path.join(dataDir, "library_data", "initialSolutionParameters.yaml") problemType = LibraryIO.readYAML(problemTypeFilePath)["ProblemType"] problemTypeObject = SolutionStructs.ProblemType(problemType) hardcodedParameters = LibraryIO.readYAML(hardcodedParametersFilePath) initialSolutionParameters = LibraryIO.readYAML(initialSolutionParametersFilePath) solutionList = BenchmarkProblems.generateForkedSolutions (problemTypeObject, hardcodedParameters, [initialSolutionParameters]) assert len(solutionList) == 2
def test_WriteClientLibraryFromSolutions(tmpdir): Common.globalParameters["MergeFiles"] = True Common.globalParameters["CodeObjectVersion"] = "V3" Common.globalParameters["YAML"] = True Common.globalParameters["CxxCompiler"] = "hipcc" Common.assignGlobalParameters({}) libraryWorkingPath = tmpdir.mkdir("lib") buildWorkingPath = tmpdir.mkdir("build") scriptDir = os.path.dirname(os.path.realpath(__file__)) dataDir = os.path.realpath( os.path.join(scriptDir, "..", "test_data", "unit")) solutionsFilePath = os.path.join(dataDir, "solutions", "solutions_nn_3.yaml") fileSolutions = LibraryIO.parseSolutionsFile(solutionsFilePath) solutions = fileSolutions[1] Common.setWorkingPath(buildWorkingPath) TensileCreateLibrary.WriteClientLibraryFromSolutions( solutions, libraryWorkingPath) Common.popWorkingPath() tensileLibraryPath = os.path.join(libraryWorkingPath, "library") hsacoFiles = glob.glob(tensileLibraryPath + "/*hsaco") assert (len(hsacoFiles) > 0) coFiles = glob.glob(tensileLibraryPath + "/*TensileLibrary*co") assert (len(coFiles) > 0) tensileYamlFilePath = os.path.join(tensileLibraryPath, "TensileLibrary.yaml") assert os.path.exists(tensileYamlFilePath) == 1 config = None try: stream = open(tensileYamlFilePath, "r") except IOError: mylogger.error("Cannot open file: %s" % tensileYamlFilePath) config = yaml.load(stream, yaml.SafeLoader) stream.close() actualSolutions = config["solutions"] assert (len(actualSolutions) == 3) metadataYamlFilePath = os.path.join(tensileLibraryPath, "metadata.yaml") assert os.path.exists(metadataYamlFilePath) == 1 metadata = None try: stream = open(metadataYamlFilePath, "r") except IOError: mylogger.error("Cannot open file: %s" % metadataYamlFilePath) metadata = yaml.load(stream, yaml.SafeLoader) stream.close() actualProblemType = metadata["ProblemType"] assert (len(actualProblemType) > 0)
def test_integration(useGlobalParameters, builddir, getLogicFileDir, testYamls, mergeFiles, libraryFormat, shortNames, legacyComponents): mergeFiles, shortNames, legacyComponents = str2bool(mergeFiles, shortNames, legacyComponents) if isSkippedTest(testYamls, mergeFiles, libraryFormat, shortNames, legacyComponents): pytest.skip("only run pre_checkin test in certain combo") logicFileDir = os.path.join(getLogicFileDir, testYamls) outputDir = os.path.join(builddir, "lib") with useGlobalParameters(OutputPath=outputDir, WorkingPath=outputDir, MergeFiles=mergeFiles, LibraryFormat=libraryFormat, LegacyComponents=legacyComponents, ShortNames=shortNames, GenerateManifestAndExit=False ): Common.ensurePath(outputDir) createLibraryScript = ClientWriter.getBuildClientLibraryScript(outputDir, logicFileDir) subprocess.run(shlex.split(createLibraryScript), cwd=outputDir, check=True) coList = [] libList = [] coExt = "co" libExt = "yaml" if libraryFormat == "yaml" else "dat" with open(os.path.join(outputDir,"library","TensileManifest.txt"), "r") as f: lines = f.read().split("\n") coList = [line for line in lines if coExt in line] libList = [line for line in lines if libExt in line] logicFiles = [os.path.join(logicFileDir, f) for f in os.listdir(logicFileDir) \ if (os.path.isfile(os.path.join(logicFileDir, f)) and os.path.splitext(f)[1]==".yaml")] clientParametersPaths = [] isaStr = "".join([str(e) for e in Common.globalParameters["CurrentISA"]]) for logicFileName in logicFiles: (scheduleName, _, problemType, _, _, exactLogic, _, newLibrary, archName) = LibraryIO.parseLibraryLogicFile(logicFileName) problemSizes = ProblemSizesMock(random.sample(exactLogic, min(len(exactLogic), 16))) # sample at most 16 problems if isaStr in archName: clientParametersPaths.append(ClientWriter.writeClientConfig( forBenchmark=False, solutions=None, problemSizes=problemSizes, stepName=str(ProblemType(problemType)), stepBaseDir=outputDir, newLibrary=newLibrary, configBase="ClientParameters_%s_%s"%(scheduleName, str(ProblemType(problemType))), codeObjectFiles=coList, tileAwareSelection=False, libraryFile=libList[0])) forBenchmark = False enableTileSelection = False returncode = ClientWriter.runClient(logicFileDir, forBenchmark, enableTileSelection, clientParametersPaths) assert(returncode == 0)
def test_loadSolutions(caplog, useGlobalParameters): with useGlobalParameters(): mylogger.debug("this is a test of debug log") mylogger.info("this is some info") scriptDir = os.path.dirname(os.path.realpath(__file__)) dataDir = os.path.realpath( os.path.join(scriptDir, "..", "test_data", "unit")) solutionsFilePath = os.path.join(dataDir, "solutions", "solutions_nn_3.yaml") fileSolutions = LibraryIO.parseSolutionsFile(solutionsFilePath) solutions = fileSolutions[1] kernels, _, _ = TensileCreateLibrary.generateKernelObjectsFromSolutions( solutions) assert len(solutions) == 3 assert len(kernels) == 3 solutionWriter, _, kernelWriterAssembly, \ _, _ = TensileCreateLibrary.getSolutionAndKernelWriters(solutions, kernels) expectedSolutionName0 = "Cijk_Ailk_Bljk_SB_MT128x128x2_SE_TT8_8_WG16_16_1" expectedSolutionName1 = "Cijk_Ailk_Bljk_SB_MT64x64x2_SE_TT4_4_WG16_16_1" expectedSolutionName2 = "Cijk_Ailk_Bljk_SB_MT64x64x2_SE_TT4_8_WG16_8_1" actualSolutionName0 = solutionWriter.getSolutionName(solutions[0]) actualSolutionName1 = solutionWriter.getSolutionName(solutions[1]) actualSolutionName2 = solutionWriter.getSolutionName(solutions[2]) assert expectedSolutionName0 == actualSolutionName0 assert expectedSolutionName1 == actualSolutionName1 assert expectedSolutionName2 == actualSolutionName2 expectedKernelName0 = "Cijk_Ailk_Bljk_SB_MT128x128x2_SE_K1_TT8_8_WG16_16_1" expectedKernelName1 = "Cijk_Ailk_Bljk_SB_MT64x64x2_SE_K1_TT4_4_WG16_16_1" expectedKernelName2 = "Cijk_Ailk_Bljk_SB_MT64x64x2_SE_K1_TT4_8_WG16_8_1" actualKernelName0 = kernelWriterAssembly.getKernelName(kernels[0]) actualKernelName1 = kernelWriterAssembly.getKernelName(kernels[1]) actualKernelName2 = kernelWriterAssembly.getKernelName(kernels[2]) assert expectedKernelName0 == actualKernelName0 assert expectedKernelName1 == actualKernelName1 assert expectedKernelName2 == actualKernelName2
def test_CreateBenchmarkClientParametersForSizes(tmpdir): Common.globalParameters["CurrentISA"] = (9,0,6) dataWorkingPath = tmpdir.mkdir("Data") configWorkingPath = tmpdir.mkdir("run_configs") scriptDir = os.path.dirname(os.path.realpath(__file__)) dataDir = os.path.realpath(os.path.join(scriptDir, "..", "test_data", "unit")) testDataPath = os.path.join(dataDir, "library_data") libraryPath = os.path.join(testDataPath, "library") metadataFilepath = os.path.join(libraryPath, "metadata.yaml") metadataFile = LibraryIO.readYAML(metadataFilepath) problemTypeDict = metadataFile["ProblemType"] sizes = [{"Exact": [196, 256, 64, 1024]}] problemSizes = SolutionStructs.ProblemSizes(problemTypeDict, sizes) dataFilePath = os.path.join(dataWorkingPath, "results.csv") configFile = os.path.join(configWorkingPath, "ClientParameters.ini") ClientWriter.CreateBenchmarkClientParametersForSizes(testDataPath, problemSizes, dataFilePath, configFile) assert os.path.exists(configFile) == 1