コード例 #1
0
ファイル: database.py プロジェクト: liuguoyou/CLBlast
def main(argv):

    # Parses the command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "source_folder",
        help="The folder with JSON files to parse to add to the database")
    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)

    # Parses the path arguments
    database_filename = os.path.join(cl_args.clblast_root, "scripts",
                                     "database", "database.json")
    database_best_filename = os.path.join(cl_args.clblast_root, "scripts",
                                          "database", "database_best.json")
    json_files = os.path.join(cl_args.source_folder, "*.json")
    cpp_database_path = os.path.join(cl_args.clblast_root, "src", "database",
                                     "kernels")

    # Checks whether the command-line arguments are valid
    clblast_header = os.path.join(
        cl_args.clblast_root, "include",
        "clblast.h")  # Not used but just for validation
    if not os.path.isfile(clblast_header):
        raise RuntimeError(
            "The path '" + cl_args.clblast_root +
            "' does not point to the root of the CLBlast library")
    if len(glob.glob(json_files)) < 1:
        print("[database] The path '" + cl_args.source_folder +
              "' does not contain any JSON files")

    # Downloads the database if a local copy is not present
    if not os.path.isfile(database_filename):
        io.download_database(database_filename, DATABASE_SERVER_URL)

    # Loads the database from disk
    database = io.load_database(database_filename)

    # Loops over all JSON files in the supplied folder
    for file_json in glob.glob(json_files):

        # Loads the newly imported data
        sys.stdout.write("[database] Processing '" + file_json +
                         "' ")  # No newline printed
        imported_data = io.load_tuning_results(file_json)

        # Fixes the problem that some vendors use multiple different names
        for target in VENDOR_TRANSLATION_TABLE:
            if imported_data["device_vendor"] == target:
                imported_data["device_vendor"] = VENDOR_TRANSLATION_TABLE[
                    target]

        # Adds the new data to the database
        old_size = db.length(database)
        database = db.add_section(database, imported_data)
        new_size = db.length(database)
        print("with " + str(new_size - old_size) +
              " new items")  # Newline printed here

    # Stores the modified database back to disk
    if len(glob.glob(json_files)) >= 1:
        io.save_database(database, database_filename)

    # Retrieves the best performing results
    print("[database] Calculating the best results per device/kernel...")
    database_best_results = bests.get_best_results(database)

    # Determines the defaults for other vendors and per vendor
    print("[database] Calculating the default values...")
    database_defaults = defaults.calculate_defaults(database, cl_args.verbose)
    database_best_results["sections"].extend(database_defaults["sections"])

    # Optionally outputs the database to disk
    if cl_args.verbose:
        io.save_database(database_best_results, database_best_filename)

    # Outputs the database as a C++ database
    print("[database] Producing a C++ database in '" + cpp_database_path +
          "'...")
    clblast.print_cpp_database(database_best_results, cpp_database_path)

    print("[database] All done")
コード例 #2
0
def main(argv):

    # Parses the command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "source_folder",
        help="The folder with JSON files to parse to add to the database")
    parser.add_argument("clblast_root", help="Root of the CLBlast sources")
    parser.add_argument("-r",
                        "--remove_device",
                        type=str,
                        default=None,
                        help="Removes all entries for a specific device")
    parser.add_argument("--add_tuning_parameter",
                        type=str,
                        default=None,
                        help="Adds this parameter to existing entries")
    parser.add_argument("--add_tuning_parameter_for_kernel",
                        type=str,
                        default=None,
                        help="Adds the above parameter for this kernel")
    parser.add_argument(
        "--add_tuning_parameter_value",
        type=int,
        default=0,
        help="Set this value as the default for the above parameter")
    parser.add_argument("-v",
                        "--verbose",
                        action="store_true",
                        help="Increase verbosity of the script")
    cl_args = parser.parse_args(argv)

    # Parses the path arguments
    database_filename = os.path.join(cl_args.clblast_root, "scripts",
                                     "database", "database.json")
    database_best_filename = os.path.join(cl_args.clblast_root, "scripts",
                                          "database", "database_best.json")
    json_files = os.path.join(cl_args.source_folder, "*.json")
    cpp_database_path = os.path.join(cl_args.clblast_root, "src", "database",
                                     "kernels")

    # Checks whether the command-line arguments are valid
    clblast_header = os.path.join(
        cl_args.clblast_root, "include",
        "clblast.h")  # Not used but just for validation
    if not os.path.isfile(clblast_header):
        raise RuntimeError(
            "The path '" + cl_args.clblast_root +
            "' does not point to the root of the CLBlast library")
    if len(glob.glob(json_files)) < 1:
        print("[database] The path '" + cl_args.source_folder +
              "' does not contain any JSON files")

    # Downloads the database if a local copy is not present
    if not os.path.isfile(database_filename):
        io.download_database(database_filename, DATABASE_SERVER_URL)

    # Loads the database from disk
    database = io.load_database(database_filename)

    # Loops over all JSON files in the supplied folder
    for file_json in glob.glob(json_files):
        sys.stdout.write("[database] Processing '" + file_json +
                         "' ")  # No newline printed

        try:
            # Loads the newly imported data
            imported_data = io.load_tuning_results(file_json)

            # Adds the new data to the database
            old_size = db.length(database)
            database = db.add_section(database, imported_data)
            new_size = db.length(database)
            print("with " + str(new_size - old_size) +
                  " new items")  # Newline printed here

        except ValueError:
            print("--- WARNING: invalid file, skipping")

    # Checks for tuning results with mis-matched entries
    remove_mismatched_arguments(database)

    # Stores the modified database back to disk
    if len(glob.glob(json_files)) >= 1:
        io.save_database(database, database_filename)

    # Removes database entries before continuing
    if cl_args.remove_device is not None:
        print("[database] Removing all results for device '%s'" %
              cl_args.remove_device)
        remove_database_entries(database,
                                {"clblast_device_name": cl_args.remove_device})
        #, "kernel_family": "xgemm"})
        io.save_database(database, database_filename)

    # Adds new tuning parameters to existing database entries
    if cl_args.add_tuning_parameter is not None and\
       cl_args.add_tuning_parameter_for_kernel is not None:
        print(
            "[database] Adding tuning parameter: '%s' for kernel '%s' with default %d"
            % (cl_args.add_tuning_parameter,
               cl_args.add_tuning_parameter_for_kernel,
               cl_args.add_tuning_parameter_value))
        add_tuning_parameter(database, cl_args.add_tuning_parameter,
                             cl_args.add_tuning_parameter_for_kernel,
                             cl_args.add_tuning_parameter_value)
        io.save_database(database, database_filename)

    # Retrieves the best performing results
    print("[database] Calculating the best results per device/kernel...")
    database_best_results = bests.get_best_results(database)

    # Determines the defaults for other vendors and per vendor
    print("[database] Calculating the default values...")
    database_defaults = defaults.calculate_defaults(database, cl_args.verbose)
    database_best_results["sections"].extend(database_defaults["sections"])

    # Optionally outputs the database to disk
    if cl_args.verbose:
        io.save_database(database_best_results, database_best_filename)

    # Outputs the database as a C++ database
    print("[database] Producing a C++ database in '" + cpp_database_path +
          "'...")
    clblast.print_cpp_database(database_best_results, cpp_database_path)

    print("[database] All done")
コード例 #3
0
ファイル: database.py プロジェクト: CNugteren/CLBlast
def main(argv):

    # Parses the command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("source_folder", help="The folder with JSON files to parse to add to the database")
    parser.add_argument("clblast_root", help="Root of the CLBlast sources")
    parser.add_argument("-r", "--remove_device", type=str, default=None, help="Removes all entries for a specific device")
    parser.add_argument("--add_tuning_parameter", type=str, default=None, help="Adds this parameter to existing entries")
    parser.add_argument("--add_tuning_parameter_for_kernel", type=str, default=None, help="Adds the above parameter for this kernel")
    parser.add_argument("--add_tuning_parameter_value", type=int, default=0, help="Set this value as the default for the above parameter")
    parser.add_argument("-v", "--verbose", action="store_true", help="Increase verbosity of the script")
    cl_args = parser.parse_args(argv)

    # Parses the path arguments
    database_filename = os.path.join(cl_args.clblast_root, "scripts", "database", "database.json")
    database_best_filename = os.path.join(cl_args.clblast_root, "scripts", "database", "database_best.json")
    json_files = os.path.join(cl_args.source_folder, "*.json")
    cpp_database_path = os.path.join(cl_args.clblast_root, "src", "database", "kernels")

    # Checks whether the command-line arguments are valid
    clblast_header = os.path.join(cl_args.clblast_root, "include", "clblast.h")  # Not used but just for validation
    if not os.path.isfile(clblast_header):
        raise RuntimeError("The path '" + cl_args.clblast_root +
                           "' does not point to the root of the CLBlast library")
    if len(glob.glob(json_files)) < 1:
        print("[database] The path '" + cl_args.source_folder + "' does not contain any JSON files")

    # Downloads the database if a local copy is not present
    if not os.path.isfile(database_filename):
        io.download_database(database_filename, DATABASE_SERVER_URL)

    # Loads the database from disk
    database = io.load_database(database_filename)

    # Loops over all JSON files in the supplied folder
    for file_json in glob.glob(json_files):
        sys.stdout.write("[database] Processing '" + file_json + "' ")  # No newline printed

        try:
            # Loads the newly imported data
            imported_data = io.load_tuning_results(file_json)

            # Adds the new data to the database
            old_size = db.length(database)
            database = db.add_section(database, imported_data)
            new_size = db.length(database)
            print("with " + str(new_size - old_size) + " new items")  # Newline printed here

        except ValueError:
            print("--- WARNING: invalid file, skipping")

    # Checks for tuning results with mis-matched entries
    remove_mismatched_arguments(database)

    # Stores the modified database back to disk
    if len(glob.glob(json_files)) >= 1:
        io.save_database(database, database_filename)

    # Removes database entries before continuing
    if cl_args.remove_device is not None:
        print("[database] Removing all results for device '%s'" % cl_args.remove_device)
        remove_database_entries(database, {"clblast_device_name": cl_args.remove_device})
                                           #, "kernel_family": "xgemm"})
        io.save_database(database, database_filename)

    # Adds new tuning parameters to existing database entries
    if cl_args.add_tuning_parameter is not None and\
       cl_args.add_tuning_parameter_for_kernel is not None:
        print("[database] Adding tuning parameter: '%s' for kernel '%s' with default %d" %
              (cl_args.add_tuning_parameter, cl_args.add_tuning_parameter_for_kernel,
               cl_args.add_tuning_parameter_value))
        add_tuning_parameter(database, cl_args.add_tuning_parameter,
                             cl_args.add_tuning_parameter_for_kernel,
                             cl_args.add_tuning_parameter_value)
        io.save_database(database, database_filename)

    # Retrieves the best performing results
    print("[database] Calculating the best results per device/kernel...")
    database_best_results = bests.get_best_results(database)

    # Determines the defaults for other vendors and per vendor
    print("[database] Calculating the default values...")
    database_defaults = defaults.calculate_defaults(database, cl_args.verbose)
    database_best_results["sections"].extend(database_defaults["sections"])

    # Optionally outputs the database to disk
    if cl_args.verbose:
        io.save_database(database_best_results, database_best_filename)

    # Outputs the database as a C++ database
    print("[database] Producing a C++ database in '" + cpp_database_path + "'...")
    clblast.print_cpp_database(database_best_results, cpp_database_path)

    print("[database] All done")
コード例 #4
0
ファイル: database.py プロジェクト: dividiti/CLBlast
def main(argv):

    # Parses the command-line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("source_folder", help="The folder with JSON files to parse to add to the database")
    parser.add_argument("clblast_root", help="Root of the CLBlast sources")
    parser.add_argument("-r", "--remove_device", type=str, default=None, help="Removes all entries for a specific device")
    parser.add_argument("-v", "--verbose", action="store_true", help="Increase verbosity of the script")
    cl_args = parser.parse_args(argv)

    # Parses the path arguments
    database_filename = os.path.join(cl_args.clblast_root, "scripts", "database", "database.json")
    database_best_filename = os.path.join(cl_args.clblast_root, "scripts", "database", "database_best.json")
    json_files = os.path.join(cl_args.source_folder, "*.json")
    cpp_database_path = os.path.join(cl_args.clblast_root, "src", "database", "kernels")

    # Checks whether the command-line arguments are valid
    clblast_header = os.path.join(cl_args.clblast_root, "include", "clblast.h")  # Not used but just for validation
    if not os.path.isfile(clblast_header):
        raise RuntimeError("The path '" + cl_args.clblast_root + "' does not point to the root of the CLBlast library")
    if len(glob.glob(json_files)) < 1:
        print("[database] The path '" + cl_args.source_folder + "' does not contain any JSON files")

    # Downloads the database if a local copy is not present
    if not os.path.isfile(database_filename):
        io.download_database(database_filename, DATABASE_SERVER_URL)

    # Loads the database from disk
    database = io.load_database(database_filename)

    # Loops over all JSON files in the supplied folder
    for file_json in glob.glob(json_files):

        # Loads the newly imported data
        sys.stdout.write("[database] Processing '" + file_json + "' ")  # No newline printed
        imported_data = io.load_tuning_results(file_json)

        # Fixes the problem that some vendors use multiple different names
        for target in VENDOR_TRANSLATION_TABLE:
            if imported_data["device_vendor"] == target:
                imported_data["device_vendor"] = VENDOR_TRANSLATION_TABLE[target]

        # Adds the new data to the database
        old_size = db.length(database)
        database = db.add_section(database, imported_data)
        new_size = db.length(database)
        print("with " + str(new_size - old_size) + " new items")  # Newline printed here

    # Checks for tuning results with mis-matched entries
    remove_mismatched_arguments(database)

    # Stores the modified database back to disk
    if len(glob.glob(json_files)) >= 1:
        io.save_database(database, database_filename)

    # Removes database entries before continuing
    if cl_args.remove_device is not None:
        print("[database] Removing all results for device '%s'" % cl_args.remove_device)
        remove_database_entries(database, {"device": cl_args.remove_device})
        io.save_database(database, database_filename)

    # Retrieves the best performing results
    print("[database] Calculating the best results per device/kernel...")
    database_best_results = bests.get_best_results(database)

    # Determines the defaults for other vendors and per vendor
    print("[database] Calculating the default values...")
    database_defaults = defaults.calculate_defaults(database, cl_args.verbose)
    database_best_results["sections"].extend(database_defaults["sections"])

    # Optionally outputs the database to disk
    if cl_args.verbose:
        io.save_database(database_best_results, database_best_filename)

    # Outputs the database as a C++ database
    print("[database] Producing a C++ database in '" + cpp_database_path + "'...")
    clblast.print_cpp_database(database_best_results, cpp_database_path)

    print("[database] All done")