def main(argv): # Parses the command-line arguments parser = argparse.ArgumentParser() parser.add_argument("clblast_root", help="Root of the CLBlast sources") parser.add_argument("-v", "--verbose", action="store_true", help="Increase verbosity of the script") cl_args = parser.parse_args(argv) library_root = cl_args.clblast_root # Checks whether the command-line arguments are valid; exists otherwise for f in FILES: if not os.path.isfile(library_root + f): print("[ERROR] The path '" + library_root + "' does not point to the root of the CLBlast library") sys.exit() # Iterates over all regular files to output for i in range(0, len(FILES)): # Stores the header and the footer of the original file with open(library_root + FILES[i]) as f: original = f.readlines() file_header = original[:HEADER_LINES[i]] file_footer = original[-FOOTER_LINES[i]:] # Re-writes the body of the file with open(library_root + FILES[i], "w") as f: body = "" levels = [1, 2, 3] if (i == 4 or i == 5 or i == 6) else [1, 2, 3, 4] for level in levels: if i not in [11]: body += cpp.LEVEL_SEPARATORS[level - 1] + "\n" for routine in ROUTINES[level - 1]: if i == 0: body += cpp.clblast_h(routine) if i == 1: body += cpp.clblast_cc(routine) if i == 2: body += cpp.clblast_c_h(routine) if i == 3: body += cpp.clblast_c_cc(routine) if i == 4: body += cpp.wrapper_clblas(routine) if i == 5: body += cpp.wrapper_cblas(routine) if i == 6: body += cpp.wrapper_cublas(routine) if i == 7: if routine.batched == 0 and routine.name not in [ "convgemm" ]: body += cpp.clblast_netlib_c_h(routine) if i == 8: if routine.batched == 0 and routine.name not in [ "convgemm" ]: body += cpp.clblast_netlib_c_cc(routine) if i == 9: body += cpp.clblast_h(routine, cuda=True) if i == 10: body += cpp.clblast_cc(routine, cuda=True) if i == 11: body += pyclblast.generate_pyx(routine) f.write("".join(file_header)) f.write(body) f.write("".join(file_footer)) # Outputs all the test implementations for level in [1, 2, 3, 4]: for routine in ROUTINES[level - 1]: if routine.has_tests: level_string = cpp.LEVEL_NAMES[level - 1] routine_suffix = "level" + level_string + "/x" + routine.lowercase_name( ) + ".cpp" # Correctness tests filename = library_root + "/test/correctness/routines/" + routine_suffix with open(filename, "w") as f: f.write(cpp.HEADER + "\n") f.write(cpp.correctness_test(routine, level_string)) f.write(cpp.FOOTER) # Performance tests filename = library_root + "/test/performance/routines/" + routine_suffix with open(filename, "w") as f: f.write(cpp.HEADER + "\n") f.write(cpp.performance_test(routine, level_string)) f.write(cpp.FOOTER) # API documentation filename = cl_args.clblast_root + "/doc/api.md" # Stores the header and the footer of the original documentation file with open(filename) as f: original = f.readlines() file_header = original[:HEADER_LINES_DOC] file_footer = original[-FOOTER_LINES_DOC:] # Outputs the API documentation with open(filename, "w") as f: # Outputs the header f.write("".join(file_header)) doc_header = doc.header() f.write(doc_header) # Generates the documentation for each routine for level in [1, 2, 3, 4]: for routine in ROUTINES[level - 1]: if routine.implemented: doc_routine = doc.generate(routine) f.write(doc_routine) # Outputs the footer f.write("".join(file_footer))
def main(argv): # Parses the command-line arguments parser = argparse.ArgumentParser() parser.add_argument("clblast_root", help="Root of the CLBlast sources") parser.add_argument("-v", "--verbose", action="store_true", help="Increase verbosity of the script") cl_args = parser.parse_args(argv) library_root = cl_args.clblast_root # Checks whether the command-line arguments are valid; exists otherwise for f in FILES: if not os.path.isfile(library_root + f): print("[ERROR] The path '" + library_root + "' does not point to the root of the CLBlast library") sys.exit() # Iterates over all regular files to output for i in range(0, len(FILES)): # Stores the header and the footer of the original file with open(library_root + FILES[i]) as f: original = f.readlines() file_header = original[:HEADER_LINES[i]] file_footer = original[-FOOTER_LINES[i]:] # Re-writes the body of the file with open(library_root + FILES[i], "w") as f: body = "" levels = [1, 2, 3] if (i == 4 or i == 5 or i == 6) else [1, 2, 3, 4] for level in levels: if i not in [11]: body += cpp.LEVEL_SEPARATORS[level - 1] + "\n" for routine in ROUTINES[level - 1]: if i == 0: body += cpp.clblast_h(routine) if i == 1: body += cpp.clblast_cc(routine) if i == 2: body += cpp.clblast_c_h(routine) if i == 3: body += cpp.clblast_c_cc(routine) if i == 4: body += cpp.wrapper_clblas(routine) if i == 5: body += cpp.wrapper_cblas(routine) if i == 6: body += cpp.wrapper_cublas(routine) if i == 7: if routine.batched == 0 and routine.name not in ["convgemm"]: body += cpp.clblast_netlib_c_h(routine) if i == 8: if routine.batched == 0 and routine.name not in ["convgemm"]: body += cpp.clblast_netlib_c_cc(routine) if i == 9: body += cpp.clblast_h(routine, cuda=True) if i == 10: body += cpp.clblast_cc(routine, cuda=True) if i == 11: body += pyclblast.generate_pyx(routine) f.write("".join(file_header)) f.write(body) f.write("".join(file_footer)) # Outputs all the test implementations for level in [1, 2, 3, 4]: for routine in ROUTINES[level - 1]: if routine.has_tests: level_string = cpp.LEVEL_NAMES[level - 1] routine_suffix = "level" + level_string + "/x" + routine.lowercase_name() + ".cpp" # Correctness tests filename = library_root + "/test/correctness/routines/" + routine_suffix with open(filename, "w") as f: f.write(cpp.HEADER + "\n") f.write(cpp.correctness_test(routine, level_string)) f.write(cpp.FOOTER) # Performance tests filename = library_root + "/test/performance/routines/" + routine_suffix with open(filename, "w") as f: f.write(cpp.HEADER + "\n") f.write(cpp.performance_test(routine, level_string)) f.write(cpp.FOOTER) # API documentation filename = cl_args.clblast_root + "/doc/api.md" # Stores the header and the footer of the original documentation file with open(filename) as f: original = f.readlines() file_header = original[:HEADER_LINES_DOC] file_footer = original[-FOOTER_LINES_DOC:] # Outputs the API documentation with open(filename, "w") as f: # Outputs the header f.write("".join(file_header)) doc_header = doc.header() f.write(doc_header) # Generates the documentation for each routine for level in [1, 2, 3, 4]: for routine in ROUTINES[level - 1]: if routine.implemented: doc_routine = doc.generate(routine) f.write(doc_routine) # Outputs the footer f.write("".join(file_footer))