summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-x[-rw-r--r--]scripts/database/database.py355
-rw-r--r--scripts/database/database/__init__.py0
-rw-r--r--scripts/database/database/bests.py58
-rw-r--r--scripts/database/database/clblast.py155
-rw-r--r--scripts/database/database/db.py64
-rw-r--r--scripts/database/database/defaults.py180
-rw-r--r--scripts/database/database/io.py60
-rw-r--r--scripts/generator/datatype.py70
-rw-r--r--scripts/generator/generator.py664
-rw-r--r--scripts/generator/generator/__init__.py0
-rw-r--r--scripts/generator/generator/convert.py69
-rw-r--r--scripts/generator/generator/cpp.py257
-rw-r--r--scripts/generator/generator/datatype.py92
-rw-r--r--scripts/generator/generator/doc.py57
-rw-r--r--scripts/generator/generator/routine.py552
-rw-r--r--scripts/generator/routine.py603
16 files changed, 1775 insertions, 1461 deletions
diff --git a/scripts/database/database.py b/scripts/database/database.py
index 49bc1801..f758a2b7 100644..100755
--- a/scripts/database/database.py
+++ b/scripts/database/database.py
@@ -1,325 +1,104 @@
#!/usr/bin/env python
-# ==================================================================================================
-# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
-# project loosely follows the Google C++ styleguide and uses a max-width of 100 characters per line.
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
#
# Author(s):
# Cedric Nugteren <www.cedricnugteren.nl>
-#
-# ==================================================================================================
-# System modules
import sys
import os.path
import glob
-import re
-import json
-try:
- from urllib.request import urlopen # Python 3
-except ImportError:
- from urllib2 import urlopen # Python 2
+import argparse
-# Additional modules
-import pandas as pd
+import database.io as io
+import database.db as db
+import database.clblast as clblast
+import database.bests as bests
+import database.defaults as defaults
# Server storing a copy of the database
-DATABASE_SERVER_URL = "http://www.cedricnugteren.nl/tuning/clblast.db"
-
-# Constants
-VENDOR_DEFAULT = "default"
-DEVICETYPE_DEFAULT = "All"
-DEVICENAME_DEFAULT = "default"
-
-# Attributes
-DEVICETYPE_ATTRIBUTES = ["device_vendor", "device_type"]
-DEVICE_ATTRIBUTES = ["device", "device_core_clock", "device_compute_units"]
-KERNEL_ATTRIBUTES = ["precision", "kernel_family"]
-ARGUMENT_ATTRIBUTES = ["arg_m", "arg_n", "arg_k", "arg_alpha", "arg_beta"]
-ATTRIBUTES = DEVICE_ATTRIBUTES + DEVICETYPE_ATTRIBUTES + KERNEL_ATTRIBUTES + ARGUMENT_ATTRIBUTES
+DATABASE_SERVER_URL = "http://www.cedricnugteren.nl/tuning/clblast.json"
# OpenCL vendor names and their short name
-VENDOR_NAMES = { "device_vendor": {
+VENDOR_TRANSLATION_TABLE = {
"GenuineIntel": "Intel",
"Intel(R) Corporation": "Intel",
"Advanced Micro Devices, Inc.": "AMD",
"NVIDIA Corporation": "NVIDIA",
-}}
-
-# Pandas options
-pd.set_option('display.width', 1000)
-
-# ==================================================================================================
-# Database operations
-# ==================================================================================================
-
-# Downloads the database and save it to disk
-def DownloadDatabase(filename):
- print("## Downloading database from '"+DATABASE_SERVER_URL+"'...")
- df = urlopen(DATABASE_SERVER_URL)
- output = open(file_db,'wb')
- output.write(df.read())
- output.close()
-
-# Loads the database from disk
-def LoadDatabase(filename):
- return pd.read_pickle(filename)
-
-# Saves the database to disk
-def SaveDatabase(df, filename):
- df.to_pickle(filename)
-
-# Loads JSON data from file
-def ImportDataFromFile(filename):
- with open(filename) as f:
- data = json.load(f)
- json_data = pd.DataFrame(data)
- df = pd.io.json.json_normalize(json_data["results"])
- for attribute in ATTRIBUTES:
- if attribute == "kernel_family":
- df[attribute] = re.sub(r'_\d+', '', data[attribute])
- elif attribute in data:
- df[attribute] = data[attribute]
- else:
- df[attribute] = 0
- return df
-
-# Returns the row-wise concatenation of two dataframes
-def ConcatenateData(df1, df2):
- return pd.concat([df1, df2])
-
-# Removes duplicates from a dataframe
-def RemoveDuplicates(df):
- return df.drop_duplicates()
-
-# database = database[(database["device"] != "AMD Radeon R9 M370X Compute Engine") | (database["kernel_family"] != "xgemm") | (database["precision"] != "32")]
-def RemoveEntriesByDevice(df, devicename):
- return df[df["device"] != devicename]
-
-def RemoveEntriesByKernelFamily(df, familyname):
- return df[df["kernel_family"] != familyname]
-
-def GetEntriesByField(df, field, value):
- return df[df[field] == value]
-
-# Example usage:
-# df = UpdateDatabase(df, (df["kernel_family"] == "xdot") & (df["arg_n"] == "67108864"), "arg_n", "2097152")
-def UpdateDatabase(df, condition, field, value):
- df.loc[condition, field] = value
- return df
-
-# Fixes the problem that some vendors use multiple different names
-def SanitizeVendorNames(df):
- df = df.replace(VENDOR_NAMES)
- return df
-
-# Retrieves the results with the lowest execution times
-def GetBestResults(df):
- dfbest = pd.DataFrame()
- grouped = df.groupby(ATTRIBUTES+["kernel"])
- for name, dfgroup in grouped:
- besttime = dfgroup["time"].min()
- bestcase = dfgroup[dfgroup["time"] == besttime].iloc[0]
- dfbest = dfbest.append(bestcase, ignore_index=True)
- return dfbest
-
-# Sets defaults for devices of the same type/vendor based on the smallest values of all know
-# entries. The average might be better for performance but some parameters might not be supported
-# on other devices.
-def CalculateDefaults(df):
- dfdefault = pd.DataFrame()
-
- # Defaults per type/vendor
- groups = df.groupby(DEVICETYPE_ATTRIBUTES+KERNEL_ATTRIBUTES+ARGUMENT_ATTRIBUTES+["kernel"])
- for name, dfgroup in groups:
- default_values = dfgroup.min(axis=0)
- default_values["device"] = DEVICENAME_DEFAULT
- default_values["device_compute_units"] = 0
- default_values["device_core_clock"] = 0
- default_values["time"] = 0.0
- dfdefault = dfdefault.append(default_values, ignore_index=True)
-
- # Checks for mis-matched arguments
- groups = dfdefault.groupby(DEVICETYPE_ATTRIBUTES+KERNEL_ATTRIBUTES+["kernel"])
- for name, dfgroup in groups:
- if len(dfgroup) != 1:
- description = dfgroup["kernel"].min() + " " + dfgroup["device_vendor"].min()
- print("[WARNING] Entries for a single kernel with multiple argument values: " + description)
-
- # Defaults in general
- groups = df.groupby(KERNEL_ATTRIBUTES+ARGUMENT_ATTRIBUTES+["kernel"])
- for name, dfgroup in groups:
- default_values = dfgroup.min(axis=0)
- default_values["device_vendor"] = VENDOR_DEFAULT
- default_values["device_type"] = DEVICETYPE_DEFAULT
- default_values["device"] = DEVICENAME_DEFAULT
- default_values["device_compute_units"] = 0
- default_values["device_core_clock"] = 0
- default_values["time"] = 0.0
- dfdefault = dfdefault.append(default_values, ignore_index=True)
-
- # Database with both types of defaults only
- return dfdefault
-
-# ==================================================================================================
-# C++ header generation
-# ==================================================================================================
-
-# The C++ header
-def GetHeader(family):
- return("""
-// =================================================================================================
-// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
-// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
-// width of 100 characters per line.
-//
-// Author(s):
-// Database generator <database.py>
-//
-// This file populates the database with best-found tuning parameters for the '%s' kernels.
-//
-// =================================================================================================
-
-namespace clblast {
-// ================================================================================================="""
- % family.title())
-
-# The C++ footer
-def GetFooter():
- return("\n} // namespace clblast\n")
-
-# The start of a new C++ precision entry
-def GetPrecision(family, precision):
- precisionstring = ""
- if precision == "16":
- precisionstring = "Half"
- elif precision == "32":
- precisionstring = "Single"
- elif precision == "64":
- precisionstring = "Double"
- elif precision == "3232":
- precisionstring = "ComplexSingle"
- elif precision == "6464":
- precisionstring = "ComplexDouble"
- else:
- print("[ERROR] Unknown precision")
- sys.exit()
- return("\n\nconst Database::DatabaseEntry Database::%s%s = {\n \"%s\", Precision::k%s, {\n"
- % (family.title(), precisionstring, family.title(), precisionstring))
-
-# The C++ device type and vendor
-def GetDeviceVendor(vendor, devtype):
- if vendor == VENDOR_DEFAULT and devtype == DEVICETYPE_DEFAULT:
- return(" { // Default\n kDeviceType%s, \"%s\", {\n" % (devtype, vendor))
- return(" { // %s %ss\n kDeviceType%s, \"%s\", {\n" % (vendor, devtype, devtype[0].upper() + devtype[1:], vendor))
-
-# Prints the data to a C++ database
-def PrintData(df, outputdir):
-
- # Iterates over the kernel families: creates a new file per family
- for family, dffamily in df.groupby(["kernel_family"]):
- dffamily = dffamily.dropna(axis=1, how='all')
- f = open(os.path.join(outputdir, family+'.hpp'), 'w+')
- f.write(GetHeader(family))
-
- # Loops over the different entries for this family and prints their headers
- for precision, dfprecision in dffamily.groupby(["precision"]):
- f.write(GetPrecision(family, precision))
- for vendor, dfvendor in dfprecision.groupby(["device_vendor"]):
- for devtype, dfdevtype in dfvendor.groupby(["device_type"]):
- f.write(GetDeviceVendor(vendor, devtype))
- for device, dfdevice in dfdevtype.groupby(["device"]):
- devicename = "\"%s\"," % device
- f.write(" { %-50s { " % devicename)
+}
- # Collects the paramaters for this case and prints them
- parameters = []
- for kernel, dfkernel in dfdevice.groupby(["kernel"]):
- dfkernel = dfkernel.dropna(axis=1)
- col_names = [col for col in list(dfkernel) if col.startswith('parameters.') and col != "parameters.PRECISION"]
- parameters += ["{\"%s\",%d}" % (p.replace("parameters.",""), dfkernel[p].iloc[0]) for p in col_names]
- f.write(", ".join(parameters))
- f.write(" } },\n")
- # Prints the footers
- f.write(" }\n },\n")
- f.write(" }\n};\n\n// =================================================================================================")
- f.write(GetFooter())
+def main(argv):
-# ==================================================================================================
-# Command-line arguments parsing and verification
-# ==================================================================================================
+ # 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)
-# Checks for the number of command-line arguments
-if len(sys.argv) != 3:
- print("[ERROR] Usage: database.py <folder_with_json_files> <root_of_clblast>")
- sys.exit()
+ # 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")
-# Parses the command-line arguments
-path_json = sys.argv[1]
-path_clblast = sys.argv[2]
-file_db = os.path.join(path_clblast, "scripts", "database", "database.db")
-glob_json = os.path.join(path_json, "*.json")
+ # 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")
-# Checks whether the command-line arguments are valid; exists otherwise
-clblast_h = os.path.join(path_clblast, "include", "clblast.h") # Not used but just for validation
-if not os.path.isfile(clblast_h):
- print("[ERROR] The path '"+path_clblast+"' does not point to the root of the CLBlast library")
- sys.exit()
-if len(glob.glob(glob_json)) < 1:
- print("## The path '"+path_json+"' 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)
-# ==================================================================================================
-# The main body of the script
-# ==================================================================================================
+ # Loads the database from disk
+ database = io.load_database(database_filename)
-# Downloads the database if a local copy is not present
-db_exists = os.path.isfile(file_db)
-if not db_exists:
- DownloadDatabase(file_db)
+ # Loops over all JSON files in the supplied folder
+ for file_json in glob.glob(json_files):
-# Loads the database from disk
-print("## Loading the database from disk...")
-database = LoadDatabase(file_db)
+ # Loads the newly imported data
+ sys.stdout.write("[database] Processing '" + file_json + "' ") # No newline printed
+ imported_data = io.load_tuning_results(file_json)
-# Loops over all JSON files in the supplied folder
-for file_json in glob.glob(glob_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]
- # Loads the newly imported data
- sys.stdout.write("## Processing '"+file_json+"' ")
- imported_data = ImportDataFromFile(file_json)
- imported_data = SanitizeVendorNames(imported_data)
+ # 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
- # Adds the new data to the database
- old_size = len(database.index)
- database = ConcatenateData(database, imported_data)
- database = RemoveDuplicates(database)
- new_size = len(database.index)
- print("with "+str(new_size-old_size)+" new items")
+ # Stores the modified database back to disk
+ if len(glob.glob(json_files)) >= 1:
+ io.save_database(database, database_filename)
-# Stores the modified database back to disk
-if len(glob.glob(glob_json)) >= 1:
- print("## Storing the database to disk...")
- SaveDatabase(database, file_db)
+ # Retrieves the best performing results
+ print("[database] Calculating the best results per device/kernel...")
+ database_best_results = bests.get_best_results(database)
-# Optional: update the database here. Default is disabled, code below is just an example
-if False:
- database = UpdateDatabase(database, ((database["kernel"] == "CopyMatrixFast") & (database["precision"] == "3232")), "arg_alpha", "2+0.5i")
- SaveDatabase(database, file_db)
+ # 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"])
-# Retrieves the best performing results
-print("## Calculating the best results per device/kernel...")
-bests = GetBestResults(database)
+ # Optionally outputs the database to disk
+ if cl_args.verbose:
+ io.save_database(database_best_results, database_best_filename)
-# Determines the defaults for other vendors and per vendor
-defaults = CalculateDefaults(bests)
-bests = ConcatenateData(bests, defaults)
+ # 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)
-# Outputs the data as a C++ database
-path_cpp_database = os.path.join(path_clblast, "src", "database", "kernels")
-print("## Producing a C++ database in '"+path_cpp_database+"'...")
-PrintData(bests, path_cpp_database)
+ print("[database] All done")
-print("## All done")
-# ==================================================================================================
+if __name__ == '__main__':
+ main(sys.argv[1:])
diff --git a/scripts/database/database/__init__.py b/scripts/database/database/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/scripts/database/database/__init__.py
diff --git a/scripts/database/database/bests.py b/scripts/database/database/bests.py
new file mode 100644
index 00000000..c924efde
--- /dev/null
+++ b/scripts/database/database/bests.py
@@ -0,0 +1,58 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+import sys
+
+
+def get_best_results(database):
+ """Retrieves the results with the lowest execution times"""
+ sections_best = []
+ for section in database["sections"]:
+ section_best = {}
+
+ # Stores all the section's meta data
+ for attribute in section.keys():
+ if attribute != "results":
+ section_best[attribute] = section[attribute]
+
+ # Find the best result
+ parameters_best = None
+ time_best = sys.float_info.max
+ for result in section["results"]:
+ if result["time"] < time_best:
+ time_best = result["time"]
+ parameters_best = result["parameters"]
+
+ # Stores the best result
+ section_best["results"] = [{"time": time_best, "parameters": parameters_best}]
+ sections_best.append(section_best)
+
+ return {"sections": sections_best}
+
+
+def get_relative_bests(name, common_results, common_parameters, verbose=False):
+ """Retrieves the parameters with the relative best execution time over different devices"""
+
+ # Helper function
+ def argmax(iterable):
+ return max(enumerate(iterable), key=lambda x: x[1])[0]
+
+ # Computes the sum of the execution times over the different devices
+ performance_sums = []
+ for parameters in common_parameters:
+ performance_sum = sum([r["relative_performance"] for r in common_results if r["parameters"] == parameters])
+ performance_sums.append(performance_sum)
+
+ # Retrieves the entry with the highest performance
+ best_index = argmax(performance_sums)
+ best_performance = performance_sums[best_index]
+ best_parameters = common_parameters[best_index]
+
+ # Completed, report and return the results
+ if verbose:
+ print("[database] " + str(name) + " with performance " + str(best_performance))
+ return best_parameters
diff --git a/scripts/database/database/clblast.py b/scripts/database/database/clblast.py
new file mode 100644
index 00000000..8190f225
--- /dev/null
+++ b/scripts/database/database/clblast.py
@@ -0,0 +1,155 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+import os
+
+# Constants from the C++ code
+VENDOR_DEFAULT = "default"
+DEVICE_TYPE_DEFAULT = "All"
+DEVICE_NAME_DEFAULT = "default"
+
+# List of attributes
+DEVICE_TYPE_ATTRIBUTES = ["device_vendor", "device_type"]
+DEVICE_ATTRIBUTES = ["device", "device_core_clock", "device_compute_units"]
+KERNEL_ATTRIBUTES = ["precision", "kernel_family"]
+ARGUMENT_ATTRIBUTES = ["arg_m", "arg_n", "arg_k", "arg_alpha", "arg_beta"]
+ATTRIBUTES = DEVICE_ATTRIBUTES + DEVICE_TYPE_ATTRIBUTES + KERNEL_ATTRIBUTES + ARGUMENT_ATTRIBUTES
+GROUP_ATTRIBUTES = DEVICE_TYPE_ATTRIBUTES + KERNEL_ATTRIBUTES + ["kernel"] + ARGUMENT_ATTRIBUTES
+
+
+def precision_to_string(precision):
+ """Translates a precision number (represented as Python string) into a descriptive string"""
+ if precision == "16":
+ return "Half"
+ elif precision == "32":
+ return "Single"
+ elif precision == "64":
+ return "Double"
+ elif precision == "3232":
+ return "ComplexSingle"
+ elif precision == "6464":
+ return "ComplexDouble"
+ else:
+ raise("Unknown precision: " + precision)
+
+
+def get_cpp_separator():
+ """Retrieves a C++ comment separator"""
+ return "// ================================================================================================="
+
+
+def get_cpp_header(family):
+ """Retrieves the C++ header"""
+ return ("\n" + get_cpp_separator() + """
+// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
+// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
+// width of 100 characters per line.
+//
+// Author(s):
+// Database generator <database.py>
+//
+// This file populates the database with best-found tuning parameters for the '%s' kernels.
+//\n"""
+ % family.title() + get_cpp_separator() + "\n\nnamespace clblast {\n" + get_cpp_separator())
+
+
+def get_cpp_footer():
+ """Retrieves the C++ footer"""
+ return "\n} // namespace clblast\n"
+
+
+def get_cpp_precision(family, precision):
+ """Retrieves the C++ code for the start of a new precision"""
+ precision_string = precision_to_string(precision)
+ camelcase_name = family.title().replace("_", "")
+ return("\n\nconst Database::DatabaseEntry Database::%s%s = {\n \"%s\", Precision::k%s, {\n"
+ % (camelcase_name, precision_string, camelcase_name, precision_string))
+
+
+def get_cpp_device_vendor(vendor, device_type):
+ """Retrieves the C++ code for the (default) vendor and device type"""
+ if vendor == VENDOR_DEFAULT and device_type == DEVICE_TYPE_DEFAULT:
+ return " { // Default\n kDeviceType%s, \"%s\", {\n" % (device_type, vendor)
+ device_type_caps = device_type[0].upper() + device_type[1:]
+ return " { // %s %ss\n kDeviceType%s, \"%s\", {\n" % (vendor, device_type, device_type_caps, vendor)
+
+
+def print_cpp_database(database, output_dir):
+ """Outputs the database as C++ code"""
+
+ # Iterates over the kernel families
+ kernel_families = sorted(set([s["kernel_family"] for s in database["sections"]]))
+ for family_name in kernel_families:
+ family_database = [s for s in database["sections"] if s["kernel_family"] == family_name]
+
+ # Opens a new file for each kernel family
+ full_path = os.path.join(output_dir, family_name + ".hpp")
+ with open(full_path, 'w+') as f:
+ f.write(get_cpp_header(family_name))
+
+ # Loops over the different precision (e.g. 16, 32, 3232, 64, 6464)
+ precisions = sorted(set([s["precision"] for s in database["sections"]])) # Based on full database
+ for precision in precisions:
+ precision_database = [s for s in family_database if s["precision"] == precision]
+ f.write(get_cpp_precision(family_name, precision))
+
+ # In case there is nothing found at all (e.g. 16-bit): continue as if this was a precision of 32 but
+ # with the defaults only
+ if len(precision_database) == 0:
+ print("[database] No results found for %s:%s, retrieving defaults from %s:32" %
+ (family_name, precision, family_name))
+ precision_database = [s for s in family_database if s["precision"] == "32"
+ and s["device_vendor"] == VENDOR_DEFAULT
+ and s["device_type"] == DEVICE_TYPE_DEFAULT
+ and s["device"] == DEVICE_NAME_DEFAULT]
+
+ # Loops over device vendors (e.g. AMD)
+ device_vendors = sorted(set([s["device_vendor"] for s in precision_database]))
+ for vendor in device_vendors:
+ vendor_database = [s for s in precision_database if s["device_vendor"] == vendor]
+
+ # Loops over device types (e.g. GPU)
+ device_types = sorted(set([s["device_type"] for s in vendor_database]))
+ for device_type in device_types:
+ type_database = [s for s in vendor_database if s["device_type"] == device_type]
+ f.write(get_cpp_device_vendor(vendor, device_type))
+
+ # Loops over every device of this vendor-type combination
+ devices = sorted(set([s["device"] for s in type_database]))
+ for device_name in devices:
+ device_database = [s for s in type_database if s["device"] == device_name]
+ device_name_quoted = "\"%s\"," % device_name
+ device_name_cpp = " { %-50s { " % device_name_quoted
+ f.write(device_name_cpp)
+
+ # Collects the parameters for this entry
+ parameters = []
+ kernels = sorted(set([s["kernel"] for s in device_database]))
+ for kernel in kernels:
+ kernel_database = [s for s in device_database if s["kernel"] == kernel]
+
+ assert len(kernel_database) == 1
+ results = kernel_database[0]["results"]
+
+ assert len(results) == 1
+ new_parameters = results[0]["parameters"]
+ for parameter_name in sorted(new_parameters):
+ parameter_value = new_parameters[parameter_name]
+ parameters.append("{\"" + parameter_name + "\"," + str(parameter_value) + "}")
+
+ # Prints the entry
+ f.write(", ".join(parameters))
+ f.write(" } },\n")
+
+ # Prints the vendor-type combination footer
+ f.write(" }\n },\n")
+
+ # Prints the precision footer
+ f.write(" }\n};\n\n" + get_cpp_separator())
+
+ # Prints the file footer
+ f.write(get_cpp_footer())
diff --git a/scripts/database/database/db.py b/scripts/database/database/db.py
new file mode 100644
index 00000000..94948b1a
--- /dev/null
+++ b/scripts/database/database/db.py
@@ -0,0 +1,64 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+import clblast
+
+
+def length(database):
+ """Computes the total number of tuning entries"""
+ num_tuning_entries = 0
+ for section in database["sections"]:
+ num_tuning_entries += len(section["results"])
+ return num_tuning_entries
+
+
+def add_section(database, new_section):
+ """Adds a new section to the database"""
+ for old_section in database["sections"]:
+
+ # Verify whether the sections match
+ equal = True
+ for attribute in new_section.keys():
+ if attribute != "results":
+ if attribute not in old_section or new_section[attribute] != old_section[attribute]:
+ equal = False
+ break
+
+ # They match: append the new section's results to the corresponding entry in the database and return
+ if equal:
+ old_section["results"] = combine_results(old_section["results"], new_section["results"])
+ return database
+
+ # No match found: append the whole new section to the database
+ database["sections"].append(new_section)
+ return database
+
+
+def combine_results(old_results, new_results):
+ """Adds new results to the results JSON list"""
+ for new_result in new_results:
+ old_results = combine_result(old_results, new_result)
+ return old_results
+
+
+def combine_result(old_results, new_result):
+ """Adds a new result to the results JSON list; filters for duplicate entries and saves the best performing one"""
+
+ # Loops over all existing results to test for already existing entries with these parameters
+ for old_result in old_results:
+
+ # Verify whether the results match
+ equal = new_result["parameters"] == old_result["parameters"]
+
+ # They match: keep only the one with the minimum execution time
+ if equal:
+ old_result["time"] = min(old_result["time"], new_result["time"])
+ return old_results
+
+ # No match found: append a new result
+ old_results.append(new_result)
+ return old_results
diff --git a/scripts/database/database/defaults.py b/scripts/database/database/defaults.py
new file mode 100644
index 00000000..00405908
--- /dev/null
+++ b/scripts/database/database/defaults.py
@@ -0,0 +1,180 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+
+import clblast
+import bests
+
+
+def set_default_device(section):
+ """Sets the device name and parameters to some default values"""
+ section["device"] = clblast.DEVICE_NAME_DEFAULT
+ section["device_compute_units"] = 0
+ section["device_core_clock"] = 0
+ return section
+
+
+def set_identifiers(database, group_by_attributes, identifier_name):
+ """Sets a group-identifier based on a given set of attributes. Modifies the database but also returns a list of
+ unique identifiers."""
+ identifiers = []
+ for section in database["sections"]:
+ identifier = []
+ for attribute in group_by_attributes:
+ if attribute in section:
+ identifier.append(section[attribute])
+ section[identifier_name] = ";".join(identifier)
+ identifiers.append(section[identifier_name])
+ return sorted(set(identifiers))
+
+
+def remove_identifiers(database, identifier_name):
+ """Removes an identifier from all sections in the database"""
+ for section in database["sections"]:
+ section.pop(identifier_name, None)
+
+
+def get_groups_by_identifier(database, group_identifiers, identifier_name):
+ """Returns a list of (group, group_identifier) tuples based a previously made grouping"""
+ groups = []
+ for group_identifier in group_identifiers:
+
+ # Get all sections in this group
+ group = []
+ for section in database["sections"]:
+ if section[identifier_name] == group_identifier:
+ group.append(section)
+
+ groups.append((group, group_identifier))
+ return groups
+
+
+def calculate_defaults(database, verbose):
+ """Sets defaults for devices of the same type/vendor"""
+
+ # Groups the database by kernel, vendor and device type (e.g. AMD GPU)
+ group_identifiers = set_identifiers(database, clblast.GROUP_ATTRIBUTES, "group_identifier")
+ groups = get_groups_by_identifier(database, group_identifiers, "group_identifier")
+
+ # Loops over all groups
+ default_sections = {"sections": []}
+ for group, group_identifier in groups:
+
+ # Computes the best parameters
+ default_parameters = get_common_best_parameters(group, group_identifier, verbose)
+
+ # Stores all the section's data
+ assert len(group) > 0
+ default_section = {}
+ for attribute in group[0].keys():
+ if attribute != "results" and attribute != "group_identifier":
+ default_section[attribute] = group[0][attribute]
+ default_section = set_default_device(default_section)
+ default_section["results"] = [{"time": 0.0, "parameters": default_parameters}]
+ default_sections["sections"].append(default_section)
+
+ # Groups the database by kernel, vendor and device type (e.g. AMD GPU) - but not by arguments! This is to check for
+ # mis-matched arguments.
+ attributes = clblast.DEVICE_TYPE_ATTRIBUTES + clblast.KERNEL_ATTRIBUTES + ["kernel"]
+ group_identifiers = set_identifiers(default_sections, attributes, "temp_identifier")
+ groups = get_groups_by_identifier(default_sections, group_identifiers, "temp_identifier")
+ for group, group_identifier in groups:
+ if len(group) != 1:
+ print("[ERROR] Entries for a single kernel with multiple argument values: " + str(group_identifier))
+ assert len(group) == 1
+ remove_identifiers(default_sections, "temp_identifier")
+
+ # Groups the database by kernel only
+ group_identifiers = set_identifiers(database, clblast.KERNEL_ATTRIBUTES + ["kernel"], "group_identifier")
+ groups = get_groups_by_identifier(database, group_identifiers, "group_identifier")
+
+ # Loops over all groups
+ for group, group_identifier in groups:
+
+ # Computes the best parameters
+ default_parameters = get_common_best_parameters(group, group_identifier, verbose)
+
+ # Stores all the section's data
+ assert len(group) > 0
+ default_section = {}
+ for attribute in group[0].keys():
+ if attribute != "results" and attribute != "group_identifier":
+ default_section[attribute] = group[0][attribute]
+ default_section = set_default_device(default_section)
+ default_section["device_vendor"] = clblast.VENDOR_DEFAULT
+ default_section["device_type"] = clblast.DEVICE_TYPE_DEFAULT
+ default_section["results"] = [{"time": 0.0, "parameters": default_parameters}]
+ default_sections["sections"].append(default_section)
+
+ # Database with both types of defaults only
+ return default_sections
+
+
+def get_smallest_best_parameters(group):
+ """Sets defaults based on the smallest values of all known entries. The average might be better for performance but
+ some parameters might not be supported on other devices."""
+
+ # Counts the number of devices in this group
+ assert len(group) > 0
+
+ # Find the smallest values of the parameters
+ min_parameters = {}
+ for section in group:
+ assert len(section["results"]) > 0
+ minimum_time = min([result["time"] for result in section["results"]])
+ for result in section["results"]:
+ if result["time"] == minimum_time:
+ for parameter in result["parameters"]:
+ if parameter in min_parameters:
+ min_parameters[parameter] = min(min_parameters[parameter], result["parameters"][parameter])
+ else:
+ min_parameters[parameter] = result["parameters"][parameter]
+
+ return min_parameters
+
+
+def get_common_best_parameters(group, group_identifier, verbose):
+ """Sets defaults based on the best values of entries supported by all devices. This might cause a problem in case
+ not every device was tuned with the same parameters. In that case it falls back to the above method to retrieve
+ the smallest best execution time"""
+
+ # Counts the number of devices in this group
+ num_devices = len(group)
+ assert num_devices > 0
+
+ # Inserts the relative execution times into the database
+ for section in group:
+ assert len(section["results"]) > 0
+ minimum_time = min([result["time"] for result in section["results"]])
+ for result in section["results"]:
+ result["relative_performance"] = minimum_time / result["time"]
+
+ # Determine which parameters are available for all devices
+ common_parameters = [result["parameters"] for result in group[0]["results"]] # Parameters of the first section
+ for i in range(1, num_devices):
+ section_parameters = [result["parameters"] for result in group[i]["results"]]
+ common_parameters = [p for p in section_parameters if p in common_parameters] # Intersection of the parameters
+
+ # Fall back to another method in case there are no shared entries at all across devices
+ if len(common_parameters) == 0:
+ if verbose:
+ print("[database] No common kernels for: " + str(group_identifier) + " with devices: %d " % num_devices)
+ smallest_best_parameters = get_smallest_best_parameters(group)
+ if verbose:
+ print("[database] " + str(group_identifier))
+ return smallest_best_parameters
+
+ # Removes entries with parameters which are not common
+ common_results = []
+ for section in group:
+ for result in section["results"]:
+ if result["parameters"] in common_parameters:
+ common_results.append(result)
+
+ # Retrieves the entries with the highest relative performance
+ relative_best_parameters = bests.get_relative_bests(group_identifier, common_results, common_parameters, verbose)
+ return relative_best_parameters
diff --git a/scripts/database/database/io.py b/scripts/database/database/io.py
new file mode 100644
index 00000000..d14f1297
--- /dev/null
+++ b/scripts/database/database/io.py
@@ -0,0 +1,60 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+import re
+import json
+
+try:
+ from urllib.request import urlopen # Python 3
+except ImportError:
+ from urllib2 import urlopen # Python 2
+
+
+def download_database(filename, database_url):
+ """Downloads a database and saves it to disk"""
+ print("[database] Downloading database from '" + database_url + "'...")
+ database = urlopen(database_url)
+ with open(filename, "wb") as f:
+ f.write(database.read())
+
+
+def load_database(filename):
+ """Loads a database from disk"""
+ print("[database] Loading database from '" + filename + "'")
+ with open(filename) as f:
+ return json.load(f)
+
+
+def save_database(database, filename):
+ """Saves a database to disk"""
+ print("[database] Saving database to '" + filename + "'")
+ with open(filename, "wb") as f:
+ json.dump(database, f, sort_keys=True, indent=4)
+
+
+def load_tuning_results(filename):
+ """Loads JSON data from file and pre-processes it"""
+ with open(filename) as f:
+ json_data = json.load(f)
+
+ # Removes the numbering following the kernel family name
+ json_data["kernel_family"] = re.sub(r'_\d+', '', json_data["kernel_family"])
+
+ # Adds the kernel name to the section instead of to the individual results
+ assert len(json_data["results"]) > 0
+ json_data["kernel"] = json_data["results"][0]["kernel"]
+ for result in json_data["results"]:
+ assert json_data["kernel"] == result["kernel"]
+ result.pop("kernel", None)
+
+ # Removes the 'PRECISION' parameter from the individual results: it is redundant
+ for result in json_data["results"]:
+ assert json_data["precision"] == str(result["parameters"]["PRECISION"])
+ result["parameters"].pop("PRECISION", None)
+
+ # All done
+ return json_data
diff --git a/scripts/generator/datatype.py b/scripts/generator/datatype.py
deleted file mode 100644
index 5bff95d1..00000000
--- a/scripts/generator/datatype.py
+++ /dev/null
@@ -1,70 +0,0 @@
-#!/usr/bin/env python
-
-# ==================================================================================================
-# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
-# project loosely follows the Google C++ styleguide and uses a max-width of 100 characters per line.
-#
-# Author(s):
-# Cedric Nugteren <www.cedricnugteren.nl>
-#
-# This file contains the 'DataType' class, used in the generator script to generate the CLBlast API
-# interface and implementation.
-#
-# ==================================================================================================
-
-# Short-hands for data-types
-HLF = "half"
-FLT = "float"
-DBL = "double"
-FLT2 = "float2"
-DBL2 = "double2"
-
-HCL = "cl_half"
-F2CL = "cl_float2"
-D2CL = "cl_double2"
-
-# Structure holding data-type and precision information
-class DataType():
- def __init__(self, precision_name, name, template, scalars, buffertype):
- self.precision_name = precision_name
- self.name = name
- self.template = template
- self.alpha_cpp = scalars[0]
- self.beta_cpp = scalars[1]
- self.alpha_cl = scalars[2]
- self.beta_cl = scalars[3]
- self.buffertype = buffertype
-
- # Outputs the name of the data-type (alpha/beta), possibly transforming into the right type
- def UseAlpha(self):
- if self.alpha_cpp in [FLT2, DBL2]:
- return self.alpha_cpp+"{alpha.s[0], alpha.s[1]}"
- return "alpha"
- def UseBeta(self):
- if self.beta_cpp in [FLT2, DBL2]:
- return self.beta_cpp+"{beta.s[0], beta.s[1]}"
- return "beta"
-
- # As above, but the transformation is in the opposite direction
- def UseAlphaCL(self):
- if self.alpha_cpp in [FLT2, DBL2]:
- return self.alpha_cl+"{{alpha.real(), alpha.imag()}}"
- return "alpha"
- def UseBetaCL(self):
- if self.beta_cpp in [FLT2, DBL2]:
- return self.beta_cl+"{{beta.real(), beta.imag()}}"
- return "beta"
-
- # Returns the template as used in the correctness/performance tests
- def TestTemplate(self):
- if self.buffertype != self.beta_cpp:
- return "<"+self.buffertype+","+self.beta_cpp+">, "+self.buffertype+", "+self.beta_cpp
- return "<"+self.buffertype+">, "+self.buffertype+", "+self.beta_cpp
-
- # Current scalar is complex
- def IsComplex(self, scalar):
- return ((scalar == "alpha" and self.alpha_cpp in [FLT2, DBL2]) or
- (scalar == "beta" and self.beta_cpp in [FLT2, DBL2]))
-
-
-# ==================================================================================================
diff --git a/scripts/generator/generator.py b/scripts/generator/generator.py
index cf01f79e..d82b13a6 100644
--- a/scripts/generator/generator.py
+++ b/scripts/generator/generator.py
@@ -1,14 +1,13 @@
#!/usr/bin/env python
-# ==================================================================================================
-# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
-# project loosely follows the Google C++ styleguide and uses a max-width of 100 characters per line.
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
#
# Author(s):
# Cedric Nugteren <www.cedricnugteren.nl>
#
-# This script automatically generates the bodies of the following files, creating the full CLBlast
-# API interface and implementation (C, C++, and reference BLAS wrappers):
+# This script automatically generates the bodies of the following files, creating the full CLBlast API interface and
+# implementation (C, C++, and reference BLAS wrappers):
# clblast.h
# clblast.cpp
# clblast_c.h
@@ -19,45 +18,20 @@
# test/correctness/routines/levelX/xYYYY.cpp
# test/performance/routines/levelX/xYYYY.cpp
# It also produces the API documentation found in doc/clblast.md
-#
-# ==================================================================================================
-# System modules
+
import sys
import os.path
+import argparse
-# Local files
-from routine import Routine
-from datatype import DataType, HLF, FLT, DBL, FLT2, DBL2, HCL, F2CL, D2CL
+import generator.cpp as cpp
+import generator.doc as doc
+from generator.routine import Routine
+from generator.datatype import H, S, D, C, Z, Sc, Dz, iH, iS, iD, iC, iZ, Css, Zdd, Ccs, Zzd, T, Tc, TU
-# ==================================================================================================
-# Regular data-types
-H = DataType("H", "H", HLF, [HLF, HLF, HCL, HCL], HLF ) # half (16)
-S = DataType("S", "S", FLT, [FLT, FLT, FLT, FLT], FLT ) # single (32)
-D = DataType("D", "D", DBL, [DBL, DBL, DBL, DBL], DBL ) # double (64)
-C = DataType("C", "C", FLT2, [FLT2, FLT2, F2CL, F2CL], FLT2) # single-complex (3232)
-Z = DataType("Z", "Z", DBL2, [DBL2, DBL2, D2CL, D2CL], DBL2) # double-complex (6464)
-
-# Special cases
-Sc = DataType("C", "Sc", FLT2, [FLT2, FLT2, FLT2, FLT2], FLT2) # As C, but with real output
-Dz = DataType("Z", "Dz", DBL2, [DBL2, DBL2, DBL2, DBL2], DBL2) # As Z, but with real output
-iH = DataType("H", "iH", HLF, [HLF, HLF, HLF, HLF], HLF ) # As H, but with integer output
-iS = DataType("S", "iS", FLT, [FLT, FLT, FLT, FLT], FLT ) # As S, but with integer output
-iD = DataType("D", "iD", DBL, [DBL, DBL, DBL, DBL], DBL ) # As D, but with integer output
-iC = DataType("C", "iC", FLT2, [FLT2, FLT2, F2CL, F2CL], FLT2) # As C, but with integer output
-iZ = DataType("Z", "iZ", DBL2, [DBL2, DBL2, D2CL, D2CL], DBL2) # As Z, but with integer output
-Css = DataType("C", "C", FLT, [FLT, FLT, FLT, FLT], FLT2) # As C, but with constants from S
-Zdd = DataType("Z", "Z", DBL, [DBL, DBL, DBL, DBL], DBL2) # As Z, but with constants from D
-Ccs = DataType("C", "C", FLT2+","+FLT, [FLT2, FLT, F2CL, FLT], FLT2) # As C, but with one constant from S
-Zzd = DataType("Z", "Z", DBL2+","+DBL, [DBL2, DBL, D2CL, DBL], DBL2) # As Z, but with one constant from D
-
-# C++ template data-types
-T = DataType("T", "typename T", "T", ["T", "T", "T", "T"], "T") # regular routine
-Tc = DataType("Tc", "typename T", "std::complex<T>,T", ["T", "T", "T", "T"], "std::complex<T>") # for herk
-TU = DataType("TU", "typename T, typename U", "T,U", ["T", "U", "T", "U"], "T") # for her2k
-
-# ==================================================================================================
+HEADER_LINES = [96, 73, 97, 22, 29, 41]
+FOOTER_LINES = [17, 75, 19, 14, 6, 6]
# Different possibilities for requirements
ald_m = "The value of `a_ld` must be at least `m`."
@@ -77,472 +51,162 @@ cld_n = "The value of `c_ld` must be at least `n`."
# ==================================================================================================
# Populates a list of routines
-routines = [
-[ # Level 1: vector-vector
- Routine(False, True, "1", "rotg", T, [S,D], [], [], [], ["sa","sb","sc","ss"], [], "", "Generate givens plane rotation", "", []),
- Routine(False, True, "1", "rotmg", T, [S,D], [], [], ["sy1"], ["sd1","sd2","sx1","sparam"], [], "", "Generate modified givens plane rotation", "", []),
- Routine(False, True, "1", "rot", T, [S,D], ["n"], [], [], ["x","y"], ["cos","sin"], "", "Apply givens plane rotation", "", []),
- Routine(False, True, "1", "rotm", T, [S,D], ["n"], [], [], ["x","y","sparam"], [], "", "Apply modified givens plane rotation", "", []),
- Routine(True, True, "1", "swap", T, [S,D,C,Z,H], ["n"], [], [], ["x","y"], [], "", "Swap two vectors", "Interchanges _n_ elements of vectors _x_ and _y_.", []),
- Routine(True, True, "1", "scal", T, [S,D,C,Z,H], ["n"], [], [], ["x"], ["alpha"], "", "Vector scaling", "Multiplies _n_ elements of vector _x_ by a scalar constant _alpha_.", []),
- Routine(True, True, "1", "copy", T, [S,D,C,Z,H], ["n"], [], ["x"], ["y"], [], "", "Vector copy", "Copies the contents of vector _x_ into vector _y_.", []),
- Routine(True, True, "1", "axpy", T, [S,D,C,Z,H], ["n"], [], ["x"], ["y"], ["alpha"], "", "Vector-times-constant plus vector", "Performs the operation _y = alpha * x + y_, in which _x_ and _y_ are vectors and _alpha_ is a scalar constant.", []),
- Routine(True, True, "1", "dot", T, [S,D,H], ["n"], [], ["x","y"], ["dot"], [], "n", "Dot product of two vectors", "Multiplies _n_ elements of the vectors _x_ and _y_ element-wise and accumulates the results. The sum is stored in the _dot_ buffer.", []),
- Routine(True, True, "1", "dotu", T, [C,Z], ["n"], [], ["x","y"], ["dot"], [], "n", "Dot product of two complex vectors", "See the regular xDOT routine.", []),
- Routine(True, True, "1", "dotc", T, [C,Z], ["n"], [], ["x","y"], ["dot"], [], "n", "Dot product of two complex vectors, one conjugated", "See the regular xDOT routine.", []),
- Routine(True, True, "1", "nrm2", T, [S,D,Sc,Dz,H], ["n"], [], ["x"], ["nrm2"], [], "2*n", "Euclidian norm of a vector", "Accumulates the square of _n_ elements in the _x_ vector and takes the square root. The resulting L2 norm is stored in the _nrm2_ buffer.", []),
- Routine(True, True, "1", "asum", T, [S,D,Sc,Dz,H], ["n"], [], ["x"], ["asum"], [], "n", "Absolute sum of values in a vector", "Accumulates the absolute value of _n_ elements in the _x_ vector. The results are stored in the _asum_ buffer.", []),
- Routine(True, False, "1", "sum", T, [S,D,Sc,Dz,H], ["n"], [], ["x"], ["sum"], [], "n", "Sum of values in a vector (non-BLAS function)", "Accumulates the values of _n_ elements in the _x_ vector. The results are stored in the _sum_ buffer. This routine is the non-absolute version of the xASUM BLAS routine.", []),
- Routine(True, True, "1", "amax", T, [iS,iD,iC,iZ,iH], ["n"], [], ["x"], ["imax"], [], "2*n", "Index of absolute maximum value in a vector", "Finds the index of the maximum of the absolute values in the _x_ vector. The resulting integer index is stored in the _imax_ buffer.", []),
- Routine(True, False, "1", "max", T, [iS,iD,iC,iZ,iH], ["n"], [], ["x"], ["imax"], [], "2*n", "Index of maximum value in a vector (non-BLAS function)", "Finds the index of the maximum of the values in the _x_ vector. The resulting integer index is stored in the _imax_ buffer. This routine is the non-absolute version of the IxAMAX BLAS routine.", []),
- Routine(True, False, "1", "min", T, [iS,iD,iC,iZ,iH], ["n"], [], ["x"], ["imin"], [], "2*n", "Index of minimum value in a vector (non-BLAS function)", "Finds the index of the minimum of the values in the _x_ vector. The resulting integer index is stored in the _imin_ buffer. This routine is the non-absolute minimum version of the IxAMAX BLAS routine.", []),
+ROUTINES = [
+[ # Level 1: vector-vector
+ Routine(False, True, "1", "rotg", T, [S,D], [], [], [], ["sa","sb","sc","ss"], [], "", "Generate givens plane rotation", "", []),
+ Routine(False, True, "1", "rotmg", T, [S,D], [], [], ["sy1"], ["sd1","sd2","sx1","sparam"], [], "", "Generate modified givens plane rotation", "", []),
+ Routine(False, True, "1", "rot", T, [S,D], ["n"], [], [], ["x","y"], ["cos","sin"], "", "Apply givens plane rotation", "", []),
+ Routine(False, True, "1", "rotm", T, [S,D], ["n"], [], [], ["x","y","sparam"], [], "", "Apply modified givens plane rotation", "", []),
+ Routine(True, True, "1", "swap", T, [S,D,C,Z,H], ["n"], [], [], ["x","y"], [], "", "Swap two vectors", "Interchanges _n_ elements of vectors _x_ and _y_.", []),
+ Routine(True, True, "1", "scal", T, [S,D,C,Z,H], ["n"], [], [], ["x"], ["alpha"], "", "Vector scaling", "Multiplies _n_ elements of vector _x_ by a scalar constant _alpha_.", []),
+ Routine(True, True, "1", "copy", T, [S,D,C,Z,H], ["n"], [], ["x"], ["y"], [], "", "Vector copy", "Copies the contents of vector _x_ into vector _y_.", []),
+ Routine(True, True, "1", "axpy", T, [S,D,C,Z,H], ["n"], [], ["x"], ["y"], ["alpha"], "", "Vector-times-constant plus vector", "Performs the operation _y = alpha * x + y_, in which _x_ and _y_ are vectors and _alpha_ is a scalar constant.", []),
+ Routine(True, True, "1", "dot", T, [S,D,H], ["n"], [], ["x","y"], ["dot"], [], "n", "Dot product of two vectors", "Multiplies _n_ elements of the vectors _x_ and _y_ element-wise and accumulates the results. The sum is stored in the _dot_ buffer.", []),
+ Routine(True, True, "1", "dotu", T, [C,Z], ["n"], [], ["x","y"], ["dot"], [], "n", "Dot product of two complex vectors", "See the regular xDOT routine.", []),
+ Routine(True, True, "1", "dotc", T, [C,Z], ["n"], [], ["x","y"], ["dot"], [], "n", "Dot product of two complex vectors, one conjugated", "See the regular xDOT routine.", []),
+ Routine(True, True, "1", "nrm2", T, [S,D,Sc,Dz,H], ["n"], [], ["x"], ["nrm2"], [], "2*n", "Euclidian norm of a vector", "Accumulates the square of _n_ elements in the _x_ vector and takes the square root. The resulting L2 norm is stored in the _nrm2_ buffer.", []),
+ Routine(True, True, "1", "asum", T, [S,D,Sc,Dz,H], ["n"], [], ["x"], ["asum"], [], "n", "Absolute sum of values in a vector", "Accumulates the absolute value of _n_ elements in the _x_ vector. The results are stored in the _asum_ buffer.", []),
+ Routine(True, False, "1", "sum", T, [S,D,Sc,Dz,H], ["n"], [], ["x"], ["sum"], [], "n", "Sum of values in a vector (non-BLAS function)", "Accumulates the values of _n_ elements in the _x_ vector. The results are stored in the _sum_ buffer. This routine is the non-absolute version of the xASUM BLAS routine.", []),
+ Routine(True, True, "1", "amax", T, [iS,iD,iC,iZ,iH], ["n"], [], ["x"], ["imax"], [], "2*n", "Index of absolute maximum value in a vector", "Finds the index of the maximum of the absolute values in the _x_ vector. The resulting integer index is stored in the _imax_ buffer.", []),
+ Routine(True, False, "1", "max", T, [iS,iD,iC,iZ,iH], ["n"], [], ["x"], ["imax"], [], "2*n", "Index of maximum value in a vector (non-BLAS function)", "Finds the index of the maximum of the values in the _x_ vector. The resulting integer index is stored in the _imax_ buffer. This routine is the non-absolute version of the IxAMAX BLAS routine.", []),
+ Routine(True, False, "1", "min", T, [iS,iD,iC,iZ,iH], ["n"], [], ["x"], ["imin"], [], "2*n", "Index of minimum value in a vector (non-BLAS function)", "Finds the index of the minimum of the values in the _x_ vector. The resulting integer index is stored in the _imin_ buffer. This routine is the non-absolute minimum version of the IxAMAX BLAS routine.", []),
],
-[ # Level 2: matrix-vector
- Routine(True, True, "2a", "gemv", T, [S,D,C,Z,H], ["m","n"], ["layout","a_transpose"], ["a","x"], ["y"], ["alpha","beta"], "", "General matrix-vector multiplication", "Performs the operation _y = alpha * A * x + beta * y_, in which _x_ is an input vector, _y_ is an input and output vector, _A_ is an input matrix, and _alpha_ and _beta_ are scalars. The matrix _A_ can optionally be transposed before performing the operation.", [ald_m]),
- Routine(True, True, "2a", "gbmv", T, [S,D,C,Z,H], ["m","n","kl","ku"], ["layout","a_transpose"], ["a","x"], ["y"], ["alpha","beta"], "", "General banded matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is banded instead.", [ald_kl_ku_one]),
- Routine(True, True, "2a", "hemv", T, [C,Z], ["n"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], "", "Hermitian matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is an Hermitian matrix instead.", [ald_n]),
- Routine(True, True, "2a", "hbmv", T, [C,Z], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], "", "Hermitian banded matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is an Hermitian banded matrix instead.", [ald_k_one]),
- Routine(True, True, "2a", "hpmv", T, [C,Z], ["n"], ["layout","triangle"], ["ap","x"], ["y"], ["alpha","beta"], "", "Hermitian packed matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is an Hermitian packed matrix instead and represented as _AP_.", []),
- Routine(True, True, "2a", "symv", T, [S,D,H], ["n"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], "", "Symmetric matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is symmetric instead.", [ald_n]),
- Routine(True, True, "2a", "sbmv", T, [S,D,H], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], "", "Symmetric banded matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is symmetric and banded instead.", [ald_k_one]),
- Routine(True, True, "2a", "spmv", T, [S,D,H], ["n"], ["layout","triangle"], ["ap","x"], ["y"], ["alpha","beta"], "", "Symmetric packed matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is a symmetric packed matrix instead and represented as _AP_.", []),
- Routine(True, True, "2a", "trmv", T, [S,D,C,Z,H], ["n"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], "n", "Triangular matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is triangular instead.", [ald_n]),
- Routine(True, True, "2a", "tbmv", T, [S,D,C,Z,H], ["n","k"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], "n", "Triangular banded matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is triangular and banded instead.", [ald_k_one]),
- Routine(True, True, "2a", "tpmv", T, [S,D,C,Z,H], ["n"], ["layout","triangle","a_transpose","diagonal"], ["ap"], ["x"], [], "n", "Triangular packed matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is a triangular packed matrix instead and repreented as _AP_.", []),
- Routine(False, True, "2a", "trsv", T, [S,D,C,Z], ["n"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], "", "Solves a triangular system of equations", "", []),
- Routine(False, True, "2a", "tbsv", T, [S,D,C,Z], ["n","k"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], "", "Solves a banded triangular system of equations", "", [ald_k_one]),
- Routine(False, True, "2a", "tpsv", T, [S,D,C,Z], ["n"], ["layout","triangle","a_transpose","diagonal"], ["ap"], ["x"], [], "", "Solves a packed triangular system of equations", "", []),
+[ # Level 2: matrix-vector
+ Routine(True, True, "2a", "gemv", T, [S,D,C,Z,H], ["m","n"], ["layout","a_transpose"], ["a","x"], ["y"], ["alpha","beta"], "", "General matrix-vector multiplication", "Performs the operation _y = alpha * A * x + beta * y_, in which _x_ is an input vector, _y_ is an input and output vector, _A_ is an input matrix, and _alpha_ and _beta_ are scalars. The matrix _A_ can optionally be transposed before performing the operation.", [ald_m]),
+ Routine(True, True, "2a", "gbmv", T, [S,D,C,Z,H], ["m","n","kl","ku"], ["layout","a_transpose"], ["a","x"], ["y"], ["alpha","beta"], "", "General banded matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is banded instead.", [ald_kl_ku_one]),
+ Routine(True, True, "2a", "hemv", T, [C,Z], ["n"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], "", "Hermitian matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is an Hermitian matrix instead.", [ald_n]),
+ Routine(True, True, "2a", "hbmv", T, [C,Z], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], "", "Hermitian banded matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is an Hermitian banded matrix instead.", [ald_k_one]),
+ Routine(True, True, "2a", "hpmv", T, [C,Z], ["n"], ["layout","triangle"], ["ap","x"], ["y"], ["alpha","beta"], "", "Hermitian packed matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is an Hermitian packed matrix instead and represented as _AP_.", []),
+ Routine(True, True, "2a", "symv", T, [S,D,H], ["n"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], "", "Symmetric matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is symmetric instead.", [ald_n]),
+ Routine(True, True, "2a", "sbmv", T, [S,D,H], ["n","k"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], "", "Symmetric banded matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is symmetric and banded instead.", [ald_k_one]),
+ Routine(True, True, "2a", "spmv", T, [S,D,H], ["n"], ["layout","triangle"], ["ap","x"], ["y"], ["alpha","beta"], "", "Symmetric packed matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is a symmetric packed matrix instead and represented as _AP_.", []),
+ Routine(True, True, "2a", "trmv", T, [S,D,C,Z,H], ["n"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], "n", "Triangular matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is triangular instead.", [ald_n]),
+ Routine(True, True, "2a", "tbmv", T, [S,D,C,Z,H], ["n","k"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], "n", "Triangular banded matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is triangular and banded instead.", [ald_k_one]),
+ Routine(True, True, "2a", "tpmv", T, [S,D,C,Z,H], ["n"], ["layout","triangle","a_transpose","diagonal"], ["ap"], ["x"], [], "n", "Triangular packed matrix-vector multiplication", "Same operation as xGEMV, but matrix _A_ is a triangular packed matrix instead and repreented as _AP_.", []),
+ Routine(False, True, "2a", "trsv", T, [S,D,C,Z], ["n"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], "", "Solves a triangular system of equations", "", []),
+ Routine(False, True, "2a", "tbsv", T, [S,D,C,Z], ["n","k"], ["layout","triangle","a_transpose","diagonal"], ["a"], ["x"], [], "", "Solves a banded triangular system of equations", "", [ald_k_one]),
+ Routine(False, True, "2a", "tpsv", T, [S,D,C,Z], ["n"], ["layout","triangle","a_transpose","diagonal"], ["ap"], ["x"], [], "", "Solves a packed triangular system of equations", "", []),
# Level 2: matrix update
- Routine(True, True, "2b", "ger", T, [S,D,H], ["m","n"], ["layout"], ["x","y"], ["a"], ["alpha"], "", "General rank-1 matrix update", "Performs the operation _A = alpha * x * y^T + A_, in which _x_ is an input vector, _y^T_ is the transpose of the input vector _y_, _A_ is the matrix to be updated, and _alpha_ is a scalar value.", [ald_m]),
- Routine(True, True, "2b", "geru", T, [C,Z], ["m","n"], ["layout"], ["x","y"], ["a"], ["alpha"], "", "General rank-1 complex matrix update", "Same operation as xGER, but with complex data-types.", [ald_m]),
- Routine(True, True, "2b", "gerc", T, [C,Z], ["m","n"], ["layout"], ["x","y"], ["a"], ["alpha"], "", "General rank-1 complex conjugated matrix update", "Same operation as xGERU, but the update is done based on the complex conjugate of the input vectors.", [ald_m]),
- Routine(True, True, "2b", "her", Tc, [Css,Zdd], ["n"], ["layout","triangle"], ["x"], ["a"], ["alpha"], "", "Hermitian rank-1 matrix update", "Performs the operation _A = alpha * x * x^T + A_, in which x is an input vector, x^T is the transpose of this vector, _A_ is the triangular Hermetian matrix to be updated, and alpha is a scalar value.", [ald_n]),
- Routine(True, True, "2b", "hpr", Tc, [Css,Zdd], ["n"], ["layout","triangle"], ["x"], ["ap"], ["alpha"], "", "Hermitian packed rank-1 matrix update", "Same operation as xHER, but matrix _A_ is an Hermitian packed matrix instead and represented as _AP_.", []),
- Routine(True, True, "2b", "her2", T, [C,Z], ["n"], ["layout","triangle"], ["x","y"], ["a"], ["alpha"], "", "Hermitian rank-2 matrix update", "Performs the operation _A = alpha * x * y^T + conj(alpha) * y * x^T + A_, in which _x_ is an input vector and _x^T_ its transpose, _y_ is an input vector and _y^T_ its transpose, _A_ is the triangular Hermetian matrix to be updated, _alpha_ is a scalar value and _conj(alpha)_ its complex conjugate.", [ald_n]),
- Routine(True, True, "2b", "hpr2", T, [C,Z], ["n"], ["layout","triangle"], ["x","y"], ["ap"], ["alpha"], "", "Hermitian packed rank-2 matrix update", "Same operation as xHER2, but matrix _A_ is an Hermitian packed matrix instead and represented as _AP_.", []),
- Routine(True, True, "2b", "syr", T, [S,D,H], ["n"], ["layout","triangle"], ["x"], ["a"], ["alpha"], "", "Symmetric rank-1 matrix update", "Same operation as xHER, but matrix A is a symmetric matrix instead.", [ald_n]),
- Routine(True, True, "2b", "spr", T, [S,D,H], ["n"], ["layout","triangle"], ["x"], ["ap"], ["alpha"], "", "Symmetric packed rank-1 matrix update", "Same operation as xSPR, but matrix _A_ is a symmetric packed matrix instead and represented as _AP_.", []),
- Routine(True, True, "2b", "syr2", T, [S,D,H], ["n"], ["layout","triangle"], ["x","y"], ["a"], ["alpha"], "", "Symmetric rank-2 matrix update", "Same operation as xHER2, but matrix _A_ is a symmetric matrix instead.", [ald_n]),
- Routine(True, True, "2b", "spr2", T, [S,D,H], ["n"], ["layout","triangle"], ["x","y"], ["ap"], ["alpha"], "", "Symmetric packed rank-2 matrix update", "Same operation as xSPR2, but matrix _A_ is a symmetric packed matrix instead and represented as _AP_.", []),
+ Routine(True, True, "2b", "ger", T, [S,D,H], ["m","n"], ["layout"], ["x","y"], ["a"], ["alpha"], "", "General rank-1 matrix update", "Performs the operation _A = alpha * x * y^T + A_, in which _x_ is an input vector, _y^T_ is the transpose of the input vector _y_, _A_ is the matrix to be updated, and _alpha_ is a scalar value.", [ald_m]),
+ Routine(True, True, "2b", "geru", T, [C,Z], ["m","n"], ["layout"], ["x","y"], ["a"], ["alpha"], "", "General rank-1 complex matrix update", "Same operation as xGER, but with complex data-types.", [ald_m]),
+ Routine(True, True, "2b", "gerc", T, [C,Z], ["m","n"], ["layout"], ["x","y"], ["a"], ["alpha"], "", "General rank-1 complex conjugated matrix update", "Same operation as xGERU, but the update is done based on the complex conjugate of the input vectors.", [ald_m]),
+ Routine(True, True, "2b", "her", Tc, [Css,Zdd], ["n"], ["layout","triangle"], ["x"], ["a"], ["alpha"], "", "Hermitian rank-1 matrix update", "Performs the operation _A = alpha * x * x^T + A_, in which x is an input vector, x^T is the transpose of this vector, _A_ is the triangular Hermetian matrix to be updated, and alpha is a scalar value.", [ald_n]),
+ Routine(True, True, "2b", "hpr", Tc, [Css,Zdd], ["n"], ["layout","triangle"], ["x"], ["ap"], ["alpha"], "", "Hermitian packed rank-1 matrix update", "Same operation as xHER, but matrix _A_ is an Hermitian packed matrix instead and represented as _AP_.", []),
+ Routine(True, True, "2b", "her2", T, [C,Z], ["n"], ["layout","triangle"], ["x","y"], ["a"], ["alpha"], "", "Hermitian rank-2 matrix update", "Performs the operation _A = alpha * x * y^T + conj(alpha) * y * x^T + A_, in which _x_ is an input vector and _x^T_ its transpose, _y_ is an input vector and _y^T_ its transpose, _A_ is the triangular Hermetian matrix to be updated, _alpha_ is a scalar value and _conj(alpha)_ its complex conjugate.", [ald_n]),
+ Routine(True, True, "2b", "hpr2", T, [C,Z], ["n"], ["layout","triangle"], ["x","y"], ["ap"], ["alpha"], "", "Hermitian packed rank-2 matrix update", "Same operation as xHER2, but matrix _A_ is an Hermitian packed matrix instead and represented as _AP_.", []),
+ Routine(True, True, "2b", "syr", T, [S,D,H], ["n"], ["layout","triangle"], ["x"], ["a"], ["alpha"], "", "Symmetric rank-1 matrix update", "Same operation as xHER, but matrix A is a symmetric matrix instead.", [ald_n]),
+ Routine(True, True, "2b", "spr", T, [S,D,H], ["n"], ["layout","triangle"], ["x"], ["ap"], ["alpha"], "", "Symmetric packed rank-1 matrix update", "Same operation as xSPR, but matrix _A_ is a symmetric packed matrix instead and represented as _AP_.", []),
+ Routine(True, True, "2b", "syr2", T, [S,D,H], ["n"], ["layout","triangle"], ["x","y"], ["a"], ["alpha"], "", "Symmetric rank-2 matrix update", "Same operation as xHER2, but matrix _A_ is a symmetric matrix instead.", [ald_n]),
+ Routine(True, True, "2b", "spr2", T, [S,D,H], ["n"], ["layout","triangle"], ["x","y"], ["ap"], ["alpha"], "", "Symmetric packed rank-2 matrix update", "Same operation as xSPR2, but matrix _A_ is a symmetric packed matrix instead and represented as _AP_.", []),
],
-[ # Level 3: matrix-matrix
- Routine(True, True, "3", "gemm", T, [S,D,C,Z,H], ["m","n","k"], ["layout","a_transpose","b_transpose"], ["a","b"], ["c"], ["alpha","beta"], "", "General matrix-matrix multiplication", "Performs the matrix product _C = alpha * A * B + beta * C_, in which _A_ (_m_ by _k_) and _B_ (_k_ by _n_) are two general rectangular input matrices, _C_ (_m_ by _n_) is the matrix to be updated, and _alpha_ and _beta_ are scalar values. The matrices _A_ and/or _B_ can optionally be transposed before performing the operation.", [ald_transa_m_k, bld_transb_k_n, cld_m]),
- Routine(True, True, "3", "symm", T, [S,D,C,Z,H], ["m","n"], ["layout","side","triangle"], ["a","b"], ["c"], ["alpha","beta"], "", "Symmetric matrix-matrix multiplication", "Same operation as xGEMM, but _A_ is symmetric instead. In case of `side == kLeft`, _A_ is a symmetric _m_ by _m_ matrix and _C = alpha * A * B + beta * C_ is performed. Otherwise, in case of `side == kRight`, _A_ is a symmtric _n_ by _n_ matrix and _C = alpha * B * A + beta * C_ is performed.", [ald_side_m_n, bld_m, cld_m]),
- Routine(True, True, "3", "hemm", T, [C,Z], ["m","n"], ["layout","side","triangle"], ["a","b"], ["c"], ["alpha","beta"], "", "Hermitian matrix-matrix multiplication", "Same operation as xSYMM, but _A_ is an Hermitian matrix instead.", [ald_side_m_n, bld_m, cld_m]),
- Routine(True, True, "3", "syrk", T, [S,D,C,Z,H], ["n","k"], ["layout","triangle","a_transpose"], ["a"], ["c"], ["alpha","beta"], "", "Rank-K update of a symmetric matrix", "Performs the matrix product _C = alpha * A * A^T + beta * C_ or _C = alpha * A^T * A + beta * C_, in which _A_ is a general matrix and _A^T_ is its transpose, _C_ (_n_ by _n_) is the symmetric matrix to be updated, and _alpha_ and _beta_ are scalar values.", [ald_trans_n_k, cld_m]),
- Routine(True, True, "3", "herk", Tc, [Css,Zdd], ["n","k"], ["layout","triangle","a_transpose"], ["a"], ["c"], ["alpha","beta"], "", "Rank-K update of a hermitian matrix", "Same operation as xSYRK, but _C_ is an Hermitian matrix instead.", [ald_trans_n_k, cld_m]),
- Routine(True, True, "3", "syr2k", T, [S,D,C,Z,H], ["n","k"], ["layout","triangle","ab_transpose"], ["a","b"], ["c"], ["alpha","beta"], "", "Rank-2K update of a symmetric matrix", "Performs the matrix product _C = alpha * A * B^T + alpha * B * A^T + beta * C_ or _C = alpha * A^T * B + alpha * B^T * A + beta * C_, in which _A_ and _B_ are general matrices and _A^T_ and _B^T_ are their transposed versions, _C_ (_n_ by _n_) is the symmetric matrix to be updated, and _alpha_ and _beta_ are scalar values.", [ald_trans_n_k, bld_trans_n_k, cld_n]),
- Routine(True, True, "3", "her2k", TU, [Ccs,Zzd], ["n","k"], ["layout","triangle","ab_transpose"], ["a","b"], ["c"], ["alpha","beta"], "", "Rank-2K update of a hermitian matrix", "Same operation as xSYR2K, but _C_ is an Hermitian matrix instead.", [ald_trans_n_k, bld_trans_n_k, cld_n]),
- Routine(True, True, "3", "trmm", T, [S,D,C,Z,H], ["m","n"], ["layout","side","triangle","a_transpose","diagonal"], ["a"], ["b"], ["alpha"], "", "Triangular matrix-matrix multiplication", "Performs the matrix product _B = alpha * A * B_ or _B = alpha * B * A_, in which _A_ is a unit or non-unit triangular matrix, _B_ (_m_ by _n_) is the general matrix to be updated, and _alpha_ is a scalar value.", [ald_side_m_n, bld_m]),
- Routine(False, True, "3", "trsm", T, [S,D,C,Z,H], ["m","n"], ["layout","side","triangle","a_transpose","diagonal"], ["a"], ["b"], ["alpha"], "", "Solves a triangular system of equations", "", []),
+[ # Level 3: matrix-matrix
+ Routine(True, True, "3", "gemm", T, [S,D,C,Z,H], ["m","n","k"], ["layout","a_transpose","b_transpose"], ["a","b"], ["c"], ["alpha","beta"], "", "General matrix-matrix multiplication", "Performs the matrix product _C = alpha * A * B + beta * C_, in which _A_ (_m_ by _k_) and _B_ (_k_ by _n_) are two general rectangular input matrices, _C_ (_m_ by _n_) is the matrix to be updated, and _alpha_ and _beta_ are scalar values. The matrices _A_ and/or _B_ can optionally be transposed before performing the operation.", [ald_transa_m_k, bld_transb_k_n, cld_m]),
+ Routine(True, True, "3", "symm", T, [S,D,C,Z,H], ["m","n"], ["layout","side","triangle"], ["a","b"], ["c"], ["alpha","beta"], "", "Symmetric matrix-matrix multiplication", "Same operation as xGEMM, but _A_ is symmetric instead. In case of `side == kLeft`, _A_ is a symmetric _m_ by _m_ matrix and _C = alpha * A * B + beta * C_ is performed. Otherwise, in case of `side == kRight`, _A_ is a symmtric _n_ by _n_ matrix and _C = alpha * B * A + beta * C_ is performed.", [ald_side_m_n, bld_m, cld_m]),
+ Routine(True, True, "3", "hemm", T, [C,Z], ["m","n"], ["layout","side","triangle"], ["a","b"], ["c"], ["alpha","beta"], "", "Hermitian matrix-matrix multiplication", "Same operation as xSYMM, but _A_ is an Hermitian matrix instead.", [ald_side_m_n, bld_m, cld_m]),
+ Routine(True, True, "3", "syrk", T, [S,D,C,Z,H], ["n","k"], ["layout","triangle","a_transpose"], ["a"], ["c"], ["alpha","beta"], "", "Rank-K update of a symmetric matrix", "Performs the matrix product _C = alpha * A * A^T + beta * C_ or _C = alpha * A^T * A + beta * C_, in which _A_ is a general matrix and _A^T_ is its transpose, _C_ (_n_ by _n_) is the symmetric matrix to be updated, and _alpha_ and _beta_ are scalar values.", [ald_trans_n_k, cld_m]),
+ Routine(True, True, "3", "herk", Tc, [Css,Zdd], ["n","k"], ["layout","triangle","a_transpose"], ["a"], ["c"], ["alpha","beta"], "", "Rank-K update of a hermitian matrix", "Same operation as xSYRK, but _C_ is an Hermitian matrix instead.", [ald_trans_n_k, cld_m]),
+ Routine(True, True, "3", "syr2k", T, [S,D,C,Z,H], ["n","k"], ["layout","triangle","ab_transpose"], ["a","b"], ["c"], ["alpha","beta"], "", "Rank-2K update of a symmetric matrix", "Performs the matrix product _C = alpha * A * B^T + alpha * B * A^T + beta * C_ or _C = alpha * A^T * B + alpha * B^T * A + beta * C_, in which _A_ and _B_ are general matrices and _A^T_ and _B^T_ are their transposed versions, _C_ (_n_ by _n_) is the symmetric matrix to be updated, and _alpha_ and _beta_ are scalar values.", [ald_trans_n_k, bld_trans_n_k, cld_n]),
+ Routine(True, True, "3", "her2k", TU, [Ccs,Zzd], ["n","k"], ["layout","triangle","ab_transpose"], ["a","b"], ["c"], ["alpha","beta"], "", "Rank-2K update of a hermitian matrix", "Same operation as xSYR2K, but _C_ is an Hermitian matrix instead.", [ald_trans_n_k, bld_trans_n_k, cld_n]),
+ Routine(True, True, "3", "trmm", T, [S,D,C,Z,H], ["m","n"], ["layout","side","triangle","a_transpose","diagonal"], ["a"], ["b"], ["alpha"], "", "Triangular matrix-matrix multiplication", "Performs the matrix product _B = alpha * A * B_ or _B = alpha * B * A_, in which _A_ is a unit or non-unit triangular matrix, _B_ (_m_ by _n_) is the general matrix to be updated, and _alpha_ is a scalar value.", [ald_side_m_n, bld_m]),
+ Routine(False, True, "3", "trsm", T, [S,D,C,Z,H], ["m","n"], ["layout","side","triangle","a_transpose","diagonal"], ["a"], ["b"], ["alpha"], "", "Solves a triangular system of equations", "", []),
],
-[ # Level X: extra routines (not part of BLAS)
- Routine(True, True, "x", "omatcopy", T, [S,D,C,Z,H], ["m","n"], ["layout","a_transpose"], ["a"], ["b"], ["alpha"], "", "Scaling and out-place transpose/copy (non-BLAS function)", "Performs scaling and out-of-place transposition/copying of matrices according to _B = alpha*op(A)_, in which _A_ is an input matrix (_m_ rows by _n_ columns), _B_ an output matrix, and _alpha_ a scalar value. The operation _op_ can be a normal matrix copy, a transposition or a conjugate transposition.", [ald_m, bld_n]),
+[ # Level X: extra routines (not part of BLAS)
+ Routine(True, True, "x", "omatcopy", T, [S,D,C,Z,H], ["m","n"], ["layout","a_transpose"], ["a"], ["b"], ["alpha"], "", "Scaling and out-place transpose/copy (non-BLAS function)", "Performs scaling and out-of-place transposition/copying of matrices according to _B = alpha*op(A)_, in which _A_ is an input matrix (_m_ rows by _n_ columns), _B_ an output matrix, and _alpha_ a scalar value. The operation _op_ can be a normal matrix copy, a transposition or a conjugate transposition.", [ald_m, bld_n]),
]]
-# ==================================================================================================
-# Translates an option name to a CLBlast data-type
-def PrecisionToFullName(x):
- return {
- 'H': "Half",
- 'S': "Single",
- 'D': "Double",
- 'C': "ComplexSingle",
- 'Z': "ComplexDouble",
- }[x]
-
-# ==================================================================================================
-
-# Separators for the BLAS levels
-separators = ["""
-// =================================================================================================
-// BLAS level-1 (vector-vector) routines
-// =================================================================================================""",
-"""
-// =================================================================================================
-// BLAS level-2 (matrix-vector) routines
-// =================================================================================================""",
-"""
-// =================================================================================================
-// BLAS level-3 (matrix-matrix) routines
-// =================================================================================================""",
-"""
-// =================================================================================================
-// Extra non-BLAS routines (level-X)
-// ================================================================================================="""]
-
-# Names of the level sub-folders
-levelnames = ["1", "2", "3", "x"]
-
-# Main header/footer for source files
-header = """
-// =================================================================================================
-// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
-// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
-// width of 100 characters per line.
-//
-// Author(s):
-// Cedric Nugteren <www.cedricnugteren.nl>
-//
-// =================================================================================================
-"""
-footer = """
-// =================================================================================================
-"""
-
-# ==================================================================================================
-
-# The C++ API header (.h)
-def clblast_h(routines):
- result = ""
- for routine in routines:
- result += "\n// "+routine.description+": "+routine.ShortNames()+"\n"
- result += routine.RoutineHeaderCPP(12, " = nullptr")+";\n"
- return result
-
-# The C++ API implementation (.cpp)
-def clblast_cc(routines):
- result = ""
- for routine in routines:
- indent1 = " "*(20 + routine.Length())
- result += "\n// "+routine.description+": "+routine.ShortNames()+"\n"
- if routine.implemented:
- result += routine.RoutineHeaderCPP(12, "")+" {\n"
- result += " auto queue_cpp = Queue(*queue);\n"
- result += " auto routine = X"+routine.name+"<"+routine.template.template+">(queue_cpp, event);\n"
- result += " auto status = routine.SetUp();\n"
- result += " if (status != StatusCode::kSuccess) { return status; }\n"
- result += " return routine.Do"+routine.name.capitalize()+"("
- result += (",\n"+indent1).join([a for a in routine.ArgumentsCladuc(routine.template, indent1)])
- result += ");\n"
- else:
- result += routine.RoutineHeaderTypeCPP(12)+" {\n"
- result += " return StatusCode::kNotImplemented;\n"
- result += "}\n"
- for flavour in routine.flavours:
- indent2 = " "*(34 + routine.Length() + len(flavour.template))
- result += "template StatusCode PUBLIC_API "+routine.name.capitalize()+"<"+flavour.template+">("
- result += (",\n"+indent2).join([a for a in routine.ArgumentsType(flavour)])
- result += ",\n"+indent2+"cl_command_queue*, cl_event*);\n"
- return result
-
-# ==================================================================================================
-
-# The C API header (.h)
-def clblast_c_h(routines):
- result = ""
- for routine in routines:
- result += "\n// "+routine.description+": "+routine.ShortNames()+"\n"
- for flavour in routine.flavours:
- result += routine.RoutineHeaderC(flavour, 31, " PUBLIC_API")+";\n"
- return result
-
-# The C API implementation (.cpp)
-def clblast_c_cc(routines):
- result = ""
- for routine in routines:
- result += "\n// "+routine.name.upper()+"\n"
- for flavour in routine.flavours:
- template = "<"+flavour.template+">" if routine.NoScalars() else ""
- indent = " "*(26 + routine.Length() + len(template))
- result += routine.RoutineHeaderC(flavour, 20, "")+" {\n"
- result += " auto status = clblast::"+routine.name.capitalize()+template+"("
- result += (",\n"+indent).join([a for a in routine.ArgumentsCast(flavour, indent)])
- result += ",\n"+indent+"queue, event);"
- result += "\n return static_cast<StatusCode>(status);\n}\n"
- return result
-
-# ==================================================================================================
-
-# The wrapper to the reference clBLAS routines (for performance/correctness testing)
-def wrapper_clblas(routines):
- result = ""
- for routine in routines:
- if routine.has_tests:
- result += "\n// Forwards the clBLAS calls for %s\n" % (routine.ShortNamesTested())
- if routine.NoScalars():
- result += routine.RoutineHeaderWrapperCL(routine.template, True, 21)+";\n"
- for flavour in routine.flavours:
- result += routine.RoutineHeaderWrapperCL(flavour, False, 21)+" {\n"
-
- # There is a version available in clBLAS
- if flavour.precision_name in ["S","D","C","Z"]:
- indent = " "*(17 + routine.Length())
- arguments = routine.ArgumentsWrapperCL(flavour)
- if routine.scratch:
- result += " auto queue = Queue(queues[0]);\n"
- result += " auto context = queue.GetContext();\n"
- result += " auto scratch_buffer = Buffer<"+flavour.template+">(context, "+routine.scratch+");\n"
- arguments += ["scratch_buffer()"]
- result += " return clblas"+flavour.name+routine.name+"("
- result += (",\n"+indent).join([a for a in arguments])
- result += ",\n"+indent+"num_queues, queues, num_wait_events, wait_events, events);"
-
- # There is no clBLAS available, forward the call to one of the available functions
- else: # Half-precision
- indent = " "*(24 + routine.Length())
-
- # Convert to float (note: also integer buffers are stored as half/float)
- for buf in routine.inputs + routine.outputs:
- result += " auto "+buf+"_buffer_bis = HalfToFloatBuffer("+buf+"_buffer, queues[0]);\n"
-
- # Call the float routine
- result += " auto status = clblasX"+routine.name+"("
- result += (",\n"+indent).join([a for a in routine.ArgumentsHalf()])
- result += ",\n"+indent+"num_queues, queues, num_wait_events, wait_events, events);"
- result += "\n"
-
- # Convert back to half
- for buf in routine.outputs:
- result += " FloatToHalfBuffer("+buf+"_buffer, "+buf+"_buffer_bis, queues[0]);\n"
- result += " return status;"
-
- # Complete
- result += "\n}\n"
- return result
-
-# The wrapper to the reference CBLAS routines (for performance/correctness testing)
-def wrapper_cblas(routines):
- result = ""
- for routine in routines:
- if routine.has_tests:
- result += "\n// Forwards the Netlib BLAS calls for %s\n" % (routine.ShortNamesTested())
- for flavour in routine.flavours:
- result += routine.RoutineHeaderWrapperC(flavour, False, 12)+" {\n"
-
- # There is a version available in CBLAS
- if flavour.precision_name in ["S","D","C","Z"]:
- indent = " "*(10 + routine.Length())
- arguments = routine.ArgumentsWrapperC(flavour)
- # Complex scalars
- for scalar in routine.scalars:
- if flavour.IsComplex(scalar):
- result += " const auto "+scalar+"_array = std::vector<"+flavour.buffertype[:-1]+">{"+scalar+".real(), "+scalar+".imag()};\n"
-
- # Special case for scalar outputs
- assignment = ""
- postfix = ""
- endofline = ""
- extra_argument = ""
- for output_buffer in routine.outputs:
- if output_buffer in routine.ScalarBuffersFirst():
- if flavour in [C,Z]:
- postfix += "_sub"
- indent += " "
- extra_argument += ",\n"+indent+"reinterpret_cast<return_pointer_"+flavour.buffertype[:-1]+">(&"+output_buffer+"_buffer["+output_buffer+"_offset])"
- elif output_buffer in routine.IndexBuffers():
- assignment = "((int*)&"+output_buffer+"_buffer[0])["+output_buffer+"_offset] = "
- indent += " "*len(assignment)
- else:
- assignment = output_buffer+"_buffer["+output_buffer+"_offset]"
- if (flavour.name in ["Sc","Dz"]):
- assignment = assignment+".real("
- endofline += ")"
- else:
- assignment = assignment+" = "
- indent += " "*len(assignment)
-
- result += " "+assignment+"cblas_"+flavour.name.lower()+routine.name+postfix+"("
- result += (",\n"+indent).join([a for a in arguments])
- result += extra_argument+endofline+");\n"
-
- # There is no CBLAS available, forward the call to one of the available functions
- else: # Half-precision
- indent = " "*(9 + routine.Length())
-
- # Convert to float (note: also integer buffers are stored as half/float)
- for buf in routine.inputs + routine.outputs:
- result += " auto "+buf+"_buffer_bis = HalfToFloatBuffer("+buf+"_buffer);\n"
-
- # Call the float routine
- result += " cblasX"+routine.name+"("
- result += (",\n"+indent).join([a for a in routine.ArgumentsHalf()])
- result += ");\n"
-
- # Convert back to half
- for buf in routine.outputs:
- result += " FloatToHalfBuffer("+buf+"_buffer, "+buf+"_buffer_bis);\n"
-
- # Complete
- result += "}\n"
- return result
-
-# ==================================================================================================
-
-# Checks for the number of command-line arguments
-if len(sys.argv) != 2:
- print "[ERROR] Usage: generator.py <root_of_clblast>"
- sys.exit()
-
-# Parses the command-line arguments
-path_clblast = sys.argv[1]
-files = [
- path_clblast+"/include/clblast.h",
- path_clblast+"/src/clblast.cpp",
- path_clblast+"/include/clblast_c.h",
- path_clblast+"/src/clblast_c.cpp",
- path_clblast+"/test/wrapper_clblas.hpp",
- path_clblast+"/test/wrapper_cblas.hpp",
-]
-header_lines = [84, 74, 93, 22, 29, 41]
-footer_lines = [17, 75, 19, 14, 6, 6]
-
-# Checks whether the command-line arguments are valid; exists otherwise
-for f in files:
- if not os.path.isfile(f):
- print "[ERROR] The path '"+path_clblast+"' does not point to the root of the CLBlast library"
- sys.exit()
-
-# ==================================================================================================
-
-# Iterates over all files to output
-for i in xrange(0,len(files)):
-
- # Stores the header and the footer of the original file
- with open(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(files[i], "w") as f:
- body = ""
- levels = [1,2,3] if (i == 4 or i == 5) else [1,2,3,4]
- for level in levels:
- body += separators[level-1]+"\n"
- if i == 0:
- body += clblast_h(routines[level-1])
- if i == 1:
- body += clblast_cc(routines[level-1])
- if i == 2:
- body += clblast_c_h(routines[level-1])
- if i == 3:
- body += clblast_c_cc(routines[level-1])
- if i == 4:
- body += wrapper_clblas(routines[level-1])
- if i == 5:
- body += wrapper_cblas(routines[level-1])
- f.write("".join(file_header))
- f.write(body)
- f.write("".join(file_footer))
-
-# ==================================================================================================
-
-# Outputs all the correctness-test implementations
-for level in [1,2,3,4]:
- for routine in routines[level-1]:
- if routine.has_tests:
- filename = path_clblast+"/test/correctness/routines/level"+levelnames[level-1]+"/x"+routine.name+".cpp"
- with open(filename, "w") as f:
- body = ""
- body += "#include \"test/correctness/testblas.hpp\"\n"
- body += "#include \"test/routines/level"+levelnames[level-1]+"/x"+routine.name+".hpp\"\n\n"
- body += "// Shortcuts to the clblast namespace\n"
- body += "using float2 = clblast::float2;\n"
- body += "using double2 = clblast::double2;\n\n"
- body += "// Main function (not within the clblast namespace)\n"
- body += "int main(int argc, char *argv[]) {\n"
- body += " auto errors = size_t{0};\n"
- not_first = "false"
- for flavour in routine.flavours:
- body += " errors += clblast::RunTests<clblast::TestX"+routine.name+flavour.TestTemplate()
- body += ">(argc, argv, "+not_first+", \""+flavour.name+routine.name.upper()+"\");\n"
- not_first = "true"
- body += " if (errors > 0) { return 1; } else { return 0; }\n"
- body += "}\n"
- f.write(header+"\n")
- f.write(body)
- f.write(footer)
-
-# Outputs all the performance-test implementations
-for level in [1,2,3,4]:
- for routine in routines[level-1]:
- if routine.has_tests:
- filename = path_clblast+"/test/performance/routines/level"+levelnames[level-1]+"/x"+routine.name+".cpp"
- with open(filename, "w") as f:
- body = ""
- body += "#include \"test/performance/client.hpp\"\n"
- body += "#include \"test/routines/level"+levelnames[level-1]+"/x"+routine.name+".hpp\"\n\n"
- body += "// Shortcuts to the clblast namespace\n"
- body += "using float2 = clblast::float2;\n"
- body += "using double2 = clblast::double2;\n\n"
- body += "// Main function (not within the clblast namespace)\n"
- body += "int main(int argc, char *argv[]) {\n"
- default = PrecisionToFullName(routine.flavours[0].precision_name)
- body += " switch(clblast::GetPrecision(argc, argv, clblast::Precision::k"+default+")) {\n"
- for precision in ["H","S","D","C","Z"]:
- body += " case clblast::Precision::k"+PrecisionToFullName(precision)+":"
- found = False
- for flavour in routine.flavours:
- if flavour.precision_name == precision:
- body += "\n clblast::RunClient<clblast::TestX"+routine.name+flavour.TestTemplate()
- body += ">(argc, argv); break;\n"
- found = True
- if not found:
- body += " throw std::runtime_error(\"Unsupported precision mode\");\n"
- body += " }\n"
- body += " return 0;\n"
- body += "}\n"
- f.write(header+"\n")
- f.write(body)
- f.write(footer)
-
-# ==================================================================================================
-
-# Outputs the API documentation
-filename = path_clblast+"/doc/clblast.md"
-with open(filename, "w") as f:
-
- # Outputs the header
- f.write("CLBlast: API reference\n")
- f.write("================\n")
- f.write("\n\n")
-
- # Loops over the routines
- for level in [1,2,3,4]:
- for routine in routines[level-1]:
- if routine.implemented:
-
- # Routine header
- f.write("x"+routine.name.upper()+": "+routine.description+"\n")
- f.write("-------------\n")
- f.write("\n")
- f.write(routine.details+"\n")
- f.write("\n")
-
- # Routine API
- f.write("C++ API:\n")
- f.write("```\n")
- f.write(routine.RoutineHeaderCPP(12, "")+"\n")
- f.write("```\n")
- f.write("\n")
- f.write("C API:\n")
- f.write("```\n")
- for flavour in routine.flavours:
- f.write(routine.RoutineHeaderC(flavour, 20, "")+"\n")
- f.write("```\n")
- f.write("\n")
-
- # Routine arguments
- f.write("Arguments to "+routine.name.upper()+":\n")
- f.write("\n")
- for argument in routine.ArgumentsDoc():
- f.write("* "+argument+"\n")
- f.write("* `cl_command_queue* queue`: Pointer to an OpenCL command queue associated with a context and device to execute the routine on.\n")
- f.write("* `cl_event* event`: Pointer to an OpenCL event to be able to wait for completion of the routine's OpenCL kernel(s). This is an optional argument.\n")
- f.write("\n")
-
- # Routine requirements
- if len(routine.RequirementsDoc()) > 0:
- f.write("Requirements for "+routine.name.upper()+":\n")
- f.write("\n")
- for requirement in routine.RequirementsDoc():
- f.write("* "+requirement+"\n")
- f.write("\n")
-
- # Routine footer
- f.write("\n\n")
-
-
-# ==================================================================================================
+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
+
+ # Sets all the files the output
+ files = [
+ library_root + "/include/clblast.h",
+ library_root + "/src/clblast.cpp",
+ library_root + "/include/clblast_c.h",
+ library_root + "/src/clblast_c.cpp",
+ library_root + "/test/wrapper_clblas.hpp",
+ library_root + "/test/wrapper_cblas.hpp",
+ ]
+
+ # Checks whether the command-line arguments are valid; exists otherwise
+ for f in files:
+ if not os.path.isfile(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(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(files[i], "w") as f:
+ body = ""
+ levels = [1, 2, 3] if (i == 4 or i == 5) else [1, 2, 3, 4]
+ for level in levels:
+ 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)
+ 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.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)
+
+ # Outputs the API documentation
+ filename = cl_args.clblast_root + "/doc/clblast.md"
+ with open(filename, "w") as f:
+
+ # Outputs the 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)
+
+if __name__ == '__main__':
+ main(sys.argv[1:])
diff --git a/scripts/generator/generator/__init__.py b/scripts/generator/generator/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/scripts/generator/generator/__init__.py
diff --git a/scripts/generator/generator/convert.py b/scripts/generator/generator/convert.py
new file mode 100644
index 00000000..c0309ec3
--- /dev/null
+++ b/scripts/generator/generator/convert.py
@@ -0,0 +1,69 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+
+def precision_to_full_name(x):
+ """Translates an option name to a CLBlast data-type"""
+ return {
+ 'H': "Half",
+ 'S': "Single",
+ 'D': "Double",
+ 'C': "ComplexSingle",
+ 'Z': "ComplexDouble",
+ }[x]
+
+
+def option_to_clblast(x):
+ """Translates an option name to a CLBlast data-type"""
+ return {
+ 'layout': "Layout",
+ 'a_transpose': "Transpose",
+ 'b_transpose': "Transpose",
+ 'ab_transpose': "Transpose",
+ 'side': "Side",
+ 'triangle': "Triangle",
+ 'diagonal': "Diagonal",
+ }[x]
+
+
+def option_to_clblas(x):
+ """As above, but for clBLAS data-types"""
+ return {
+ 'layout': "clblasOrder",
+ 'a_transpose': "clblasTranspose",
+ 'b_transpose': "clblasTranspose",
+ 'ab_transpose': "clblasTranspose",
+ 'side': "clblasSide",
+ 'triangle': "clblasUplo",
+ 'diagonal': "clblasDiag",
+ }[x]
+
+
+def option_to_cblas(x):
+ """As above, but for CBLAS data-types"""
+ return {
+ 'layout': "CBLAS_ORDER",
+ 'a_transpose': "CBLAS_TRANSPOSE",
+ 'b_transpose': "CBLAS_TRANSPOSE",
+ 'ab_transpose': "CBLAS_TRANSPOSE",
+ 'side': "CBLAS_SIDE",
+ 'triangle': "CBLAS_UPLO",
+ 'diagonal': "CBLAS_DIAG",
+ }[x]
+
+
+def option_to_documentation(x):
+ """Translates an option name to a documentation string"""
+ return {
+ 'layout': "Data-layout of the matrices, either `Layout::kRowMajor` (101) for row-major layout or `Layout::kColMajor` (102) for column-major data-layout.",
+ 'a_transpose': "Transposing the input matrix A, either `Transpose::kNo` (111), `Transpose::kYes` (112), or `Transpose::kConjugate` (113) for a complex-conjugate transpose.",
+ 'b_transpose': "Transposing the input matrix B, either `Transpose::kNo` (111), `Transpose::kYes` (112), or `Transpose::kConjugate` (113) for a complex-conjugate transpose.",
+ 'ab_transpose': "Transposing the packed input matrix AP, either `Transpose::kNo` (111), `Transpose::kYes` (112), or `Transpose::kConjugate` (113) for a complex-conjugate transpose.",
+ 'side': "The position of the triangular matrix in the operation, either on the `Side::kLeft` (141) or `Side::kRight` (142).",
+ 'triangle': "The part of the array of the triangular matrix to be used, either `Triangle::kUpper` (121) or `Triangle::kLower` (122).",
+ 'diagonal': "The property of the diagonal matrix, either `Diagonal::kNonUnit` (131) for non-unit values on the diagonal or `Diagonal::kUnit` (132) for unit values on the diagonal.",
+ }[x]
diff --git a/scripts/generator/generator/cpp.py b/scripts/generator/generator/cpp.py
new file mode 100644
index 00000000..427eb180
--- /dev/null
+++ b/scripts/generator/generator/cpp.py
@@ -0,0 +1,257 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+import generator.datatype as datatype
+import generator.convert as convert
+
+
+NL = "\n"
+SEPARATOR = "// ================================================================================================="
+
+# Separators for the BLAS levels
+LEVEL_SEPARATORS = [
+ NL + SEPARATOR + NL + "// BLAS level-1 (vector-vector) routines" + NL + SEPARATOR,
+ NL + SEPARATOR + NL + "// BLAS level-2 (matrix-vector) routines" + NL + SEPARATOR,
+ NL + SEPARATOR + NL + "// BLAS level-3 (matrix-matrix) routines" + NL + SEPARATOR,
+ NL + SEPARATOR + NL + "// Extra non-BLAS routines (level-X)" + NL + SEPARATOR
+]
+
+# Names of the level sub-folders
+LEVEL_NAMES = ["1", "2", "3", "x"]
+
+# Main header/footer for source files
+FOOTER = NL + SEPARATOR + NL
+HEADER = NL + SEPARATOR + """
+// This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
+// project loosely follows the Google C++ styleguide and uses a tab-size of two spaces and a max-
+// width of 100 characters per line.
+//
+// Author(s):
+// Cedric Nugteren <www.cedricnugteren.nl>
+//
+""" + SEPARATOR + NL
+
+
+def clblast_h(routine):
+ """The C++ API header (.h)"""
+ result = NL + "// " + routine.description + ": " + routine.short_names() + NL
+ result += routine.routine_header_cpp(12, " = nullptr") + ";" + NL
+ return result
+
+
+def clblast_cc(routine):
+ """The C++ API implementation (.cpp)"""
+ indent1 = " " * (20 + routine.length())
+ result = NL + "// " + routine.description + ": " + routine.short_names() + NL
+ if routine.implemented:
+ result += routine.routine_header_cpp(12, "") + " {" + NL
+ result += " auto queue_cpp = Queue(*queue);" + NL
+ result += " auto routine = X" + routine.name + "<" + routine.template.template + ">(queue_cpp, event);" + NL
+ result += " auto status = routine.SetUp();" + NL
+ result += " if (status != StatusCode::kSuccess) { return status; }" + NL
+ result += " return routine.Do" + routine.name.capitalize() + "("
+ result += ("," + NL + indent1).join([a for a in routine.arguments_clcudaapi()])
+ result += ");" + NL
+ else:
+ result += routine.routine_header_type_cpp(12) + " {" + NL
+ result += " return StatusCode::kNotImplemented;" + NL
+ result += "}" + NL
+ for flavour in routine.flavours:
+ indent2 = " " * (34 + routine.length() + len(flavour.template))
+ result += "template StatusCode PUBLIC_API " + routine.name.capitalize() + "<" + flavour.template + ">("
+ result += ("," + NL + indent2).join([a for a in routine.arguments_type(flavour)])
+ result += "," + NL + indent2 + "cl_command_queue*, cl_event*);" + NL
+ return result
+
+
+def clblast_c_h(routine):
+ """The C API header (.h)"""
+ result = NL + "// " + routine.description + ": " + routine.short_names() + NL
+ for flavour in routine.flavours:
+ result += routine.routine_header_c(flavour, 31, " PUBLIC_API") + ";" + NL
+ return result
+
+
+def clblast_c_cc(routine):
+ """The C API implementation (.cpp)"""
+ result = NL + "// " + routine.name.upper() + NL
+ for flavour in routine.flavours:
+ template = "<" + flavour.template + ">" if routine.no_scalars() else ""
+ indent = " " * (26 + routine.length() + len(template))
+ result += routine.routine_header_c(flavour, 20, "") + " {" + NL
+ result += " auto status = clblast::" + routine.name.capitalize() + template + "("
+ result += ("," + NL + indent).join([a for a in routine.arguments_cast(flavour, indent)])
+ result += "," + NL + indent + "queue, event);"
+ result += NL + " return static_cast<StatusCode>(status);" + NL + "}" + NL
+ return result
+
+
+def wrapper_clblas(routine):
+ """The wrapper to the reference clBLAS routines (for performance/correctness testing)"""
+ result = ""
+ if routine.has_tests:
+ result += NL + "// Forwards the clBLAS calls for %s" % routine.short_names_tested() + NL
+ if routine.no_scalars():
+ result += routine.routine_header_wrapper_clblas(routine.template, True, 21) + ";" + NL
+ for flavour in routine.flavours:
+ result += routine.routine_header_wrapper_clblas(flavour, False, 21) + " {" + NL
+
+ # There is a version available in clBLAS
+ if flavour.precision_name in ["S", "D", "C", "Z"]:
+ indent = " " * (17 + routine.length())
+ arguments = routine.arguments_wrapper_clblas(flavour)
+ if routine.scratch:
+ result += " auto queue = Queue(queues[0]);" + NL
+ result += " auto context = queue.GetContext();" + NL
+ result += " auto scratch_buffer = Buffer<" + flavour.template + ">"
+ result += "(context, " + routine.scratch + ");" + NL
+ arguments += ["scratch_buffer()"]
+ result += " return clblas" + flavour.name + routine.name + "("
+ result += ("," + NL + indent).join([a for a in arguments])
+ result += "," + NL + indent + "num_queues, queues, num_wait_events, wait_events, events);"
+
+ # There is no clBLAS available, forward the call to one of the available functions
+ else: # Half-precision
+ indent = " " * (24 + routine.length())
+
+ # Convert to float (note: also integer buffers are stored as half/float)
+ for buf in routine.inputs + routine.outputs:
+ result += " auto " + buf + "_buffer_bis = HalfToFloatBuffer(" + buf + "_buffer, queues[0]);" + NL
+
+ # Call the float routine
+ result += " auto status = clblasX" + routine.name + "("
+ result += ("," + NL + indent).join([a for a in routine.arguments_half()])
+ result += "," + NL + indent + "num_queues, queues, num_wait_events, wait_events, events);"
+ result += NL
+
+ # Convert back to half
+ for buf in routine.outputs:
+ result += " FloatToHalfBuffer(" + buf + "_buffer, " + buf + "_buffer_bis, queues[0]);" + NL
+ result += " return status;"
+
+ # Complete
+ result += NL + "}" + NL
+ return result
+
+
+def wrapper_cblas(routine):
+ """The wrapper to the reference CBLAS routines (for performance/correctness testing)"""
+ result = ""
+ if routine.has_tests:
+ result += NL + "// Forwards the Netlib BLAS calls for %s" % routine.short_names_tested() + NL
+ for flavour in routine.flavours:
+ result += routine.routine_header_wrapper_cblas(flavour, 12) + " {" + NL
+
+ # There is a version available in CBLAS
+ if flavour.precision_name in ["S", "D", "C", "Z"]:
+ indent = " " * (10 + routine.length())
+ arguments = routine.arguments_wrapper_cblas(flavour)
+
+ # Complex scalars
+ for scalar in routine.scalars:
+ if flavour.is_complex(scalar):
+ result += " const auto " + scalar + "_array = std::vector<" + flavour.buffer_type[:-1] + ">"
+ result += "{" + scalar + ".real(), " + scalar + ".imag()};" + NL
+
+ # Special case for scalar outputs
+ assignment = ""
+ postfix = ""
+ end_of_line = ""
+ extra_argument = ""
+ for output_buffer in routine.outputs:
+ if output_buffer in routine.scalar_buffers_first():
+ if flavour in [datatype.C, datatype.Z]:
+ postfix += "_sub"
+ indent += " "
+ extra_argument += "," + NL + indent
+ extra_argument += "reinterpret_cast<return_pointer_" + flavour.buffer_type[:-1] + ">"
+ extra_argument += "(&" + output_buffer + "_buffer[" + output_buffer + "_offset])"
+ elif output_buffer in routine.index_buffers():
+ assignment = "((int*)&" + output_buffer + "_buffer[0])[" + output_buffer + "_offset] = "
+ indent += " " * len(assignment)
+ else:
+ assignment = output_buffer + "_buffer[" + output_buffer + "_offset]"
+ if flavour.name in ["Sc", "Dz"]:
+ assignment += ".real("
+ end_of_line += ")"
+ else:
+ assignment += " = "
+ indent += " " * len(assignment)
+
+ result += " " + assignment + "cblas_" + flavour.name.lower() + routine.name + postfix + "("
+ result += ("," + NL + indent).join([a for a in arguments])
+ result += extra_argument + end_of_line + ");" + NL
+
+ # There is no CBLAS available, forward the call to one of the available functions
+ else: # Half-precision
+ indent = " " * (9 + routine.length())
+
+ # Convert to float (note: also integer buffers are stored as half/float)
+ for buf in routine.inputs + routine.outputs:
+ result += " auto " + buf + "_buffer_bis = HalfToFloatBuffer(" + buf + "_buffer);" + NL
+
+ # Call the float routine
+ result += " cblasX" + routine.name + "("
+ result += ("," + NL + indent).join([a for a in routine.arguments_half()])
+ result += ");" + NL
+
+ # Convert back to half
+ for buf in routine.outputs:
+ result += " FloatToHalfBuffer(" + buf + "_buffer, " + buf + "_buffer_bis);" + NL
+
+ # Complete
+ result += "}" + NL
+ return result
+
+
+def performance_test(routine, level_string):
+ """Generates the body of a performance test for a specific routine"""
+ result = ""
+ result += "#include \"test/performance/client.hpp\"" + NL
+ result += "#include \"test/routines/level" + level_string + "/x" + routine.name + ".hpp\"" + NL + NL
+ result += "// Shortcuts to the clblast namespace" + NL
+ result += "using float2 = clblast::float2;" + NL
+ result += "using double2 = clblast::double2;" + NL + NL
+ result += "// Main function (not within the clblast namespace)" + NL
+ result += "int main(int argc, char *argv[]) {" + NL
+ default = convert.precision_to_full_name(routine.flavours[0].precision_name)
+ result += " switch(clblast::GetPrecision(argc, argv, clblast::Precision::k" + default + ")) {" + NL
+ for precision in ["H", "S", "D", "C", "Z"]:
+ result += " case clblast::Precision::k" + convert.precision_to_full_name(precision) + ":"
+ found = False
+ for flavour in routine.flavours:
+ if flavour.precision_name == precision:
+ result += NL + " clblast::RunClient<clblast::TestX" + routine.name + flavour.test_template()
+ result += ">(argc, argv); break;" + NL
+ found = True
+ if not found:
+ result += " throw std::runtime_error(\"Unsupported precision mode\");" + NL
+ result += " }" + NL
+ result += " return 0;" + NL
+ result += "}" + NL
+ return result
+
+
+def correctness_test(routine, level_string):
+ """Generates the body of a correctness test for a specific routine"""
+ result = ""
+ result += "#include \"test/correctness/testblas.hpp\"" + NL
+ result += "#include \"test/routines/level" + level_string + "/x" + routine.name + ".hpp\"" + NL + NL
+ result += "// Shortcuts to the clblast namespace" + NL
+ result += "using float2 = clblast::float2;" + NL
+ result += "using double2 = clblast::double2;" + NL + NL
+ result += "// Main function (not within the clblast namespace)" + NL
+ result += "int main(int argc, char *argv[]) {" + NL
+ result += " auto errors = size_t{0};" + NL
+ not_first = "false"
+ for flavour in routine.flavours:
+ result += " errors += clblast::RunTests<clblast::TestX" + routine.name + flavour.test_template()
+ result += ">(argc, argv, " + not_first + ", \"" + flavour.name + routine.name.upper() + "\");" + NL
+ not_first = "true"
+ result += " if (errors > 0) { return 1; } else { return 0; }" + NL
+ result += "}" + NL
+ return result
diff --git a/scripts/generator/generator/datatype.py b/scripts/generator/generator/datatype.py
new file mode 100644
index 00000000..9a6c6c02
--- /dev/null
+++ b/scripts/generator/generator/datatype.py
@@ -0,0 +1,92 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+
+# Short-hands for data-types
+D_HALF = "half"
+D_FLOAT = "float"
+D_DOUBLE = "double"
+D_FLOAT2 = "float2"
+D_DOUBLE2 = "double2"
+D_HALF_OPENCL = "cl_half"
+D_FLOAT2_OPENCL = "cl_float2"
+D_DOUBLE2_OPENCL = "cl_double2"
+
+
+class DataType:
+ """Class holding data-type and precision information"""
+
+ def __init__(self, precision_name, name, template, scalars, buffer_type):
+ self.precision_name = precision_name
+ self.name = name
+ self.template = template
+ self.alpha_cpp = scalars[0]
+ self.beta_cpp = scalars[1]
+ self.alpha_cl = scalars[2]
+ self.beta_cl = scalars[3]
+ self.buffer_type = buffer_type
+
+ def use_alpha(self):
+ """Outputs the name of the data-type (alpha/beta), possibly transforming into the right type"""
+ if self.alpha_cpp in [D_FLOAT2, D_DOUBLE2]:
+ return self.alpha_cpp + "{alpha.s[0], alpha.s[1]}"
+ return "alpha"
+
+ def use_beta(self):
+ """As above, but for beta instead of alpha"""
+ if self.beta_cpp in [D_FLOAT2, D_DOUBLE2]:
+ return self.beta_cpp + "{beta.s[0], beta.s[1]}"
+ return "beta"
+
+ def use_alpha_opencl(self):
+ """As above, but the transformation is in the opposite direction"""
+ if self.alpha_cpp in [D_FLOAT2, D_DOUBLE2]:
+ return self.alpha_cl + "{{alpha.real(), alpha.imag()}}"
+ return "alpha"
+
+ def use_beta_opencl(self):
+ """As above, but for beta instead of alpha"""
+ if self.beta_cpp in [D_FLOAT2, D_DOUBLE2]:
+ return self.beta_cl + "{{beta.real(), beta.imag()}}"
+ return "beta"
+
+ def test_template(self):
+ """Returns the template as used in the correctness/performance tests"""
+ if self.buffer_type != self.beta_cpp:
+ return "<" + self.buffer_type + "," + self.beta_cpp + ">, " + self.buffer_type + ", " + self.beta_cpp
+ return "<" + self.buffer_type + ">, " + self.buffer_type + ", " + self.beta_cpp
+
+ def is_complex(self, scalar):
+ """Current scalar is complex"""
+ return ((scalar == "alpha" and self.alpha_cpp in [D_FLOAT2, D_DOUBLE2]) or
+ (scalar == "beta" and self.beta_cpp in [D_FLOAT2, D_DOUBLE2]))
+
+
+# Regular data-types
+H = DataType("H", "H", D_HALF, [D_HALF] * 2 + [D_HALF_OPENCL] * 2, D_HALF) # half (16)
+S = DataType("S", "S", D_FLOAT, [D_FLOAT] * 4, D_FLOAT) # single (32)
+D = DataType("D", "D", D_DOUBLE, [D_DOUBLE] * 4, D_DOUBLE) # double (64)
+C = DataType("C", "C", D_FLOAT2, [D_FLOAT2] * 2 + [D_FLOAT2_OPENCL] * 2, D_FLOAT2) # single-complex (3232)
+Z = DataType("Z", "Z", D_DOUBLE2, [D_DOUBLE2] * 2 + [D_DOUBLE2_OPENCL] * 2, D_DOUBLE2) # double-complex (6464)
+
+# Special cases
+Sc = DataType("C", "Sc", D_FLOAT2, [D_FLOAT2] * 4, D_FLOAT2) # As C, but with real output
+Dz = DataType("Z", "Dz", D_DOUBLE2, [D_DOUBLE2] * 4, D_DOUBLE2) # As Z, but with real output
+iH = DataType("H", "iH", D_HALF, [D_HALF] * 4, D_HALF) # As H, but with integer output
+iS = DataType("S", "iS", D_FLOAT, [D_FLOAT] * 4, D_FLOAT) # As S, but with integer output
+iD = DataType("D", "iD", D_DOUBLE, [D_DOUBLE] * 4, D_DOUBLE) # As D, but with integer output
+iC = DataType("C", "iC", D_FLOAT2, [D_FLOAT2] * 2 + [D_FLOAT2_OPENCL] * 2, D_FLOAT2) # As C, but with integer output
+iZ = DataType("Z", "iZ", D_DOUBLE2, [D_DOUBLE2] * 2 + [D_DOUBLE2_OPENCL] * 2, D_DOUBLE2) # As Z, but with int output
+Css = DataType("C", "C", D_FLOAT, [D_FLOAT, D_FLOAT, D_FLOAT, D_FLOAT], D_FLOAT2) # As C, but with constants from S
+Zdd = DataType("Z", "Z", D_DOUBLE, [D_DOUBLE] * 4, D_DOUBLE2) # As Z, but with constants from D
+Ccs = DataType("C", "C", D_FLOAT2 + "," + D_FLOAT, [D_FLOAT2, D_FLOAT, D_FLOAT2_OPENCL, D_FLOAT], D_FLOAT2) # As C, but with one constant from S
+Zzd = DataType("Z", "Z", D_DOUBLE2 + "," + D_DOUBLE, [D_DOUBLE2, D_DOUBLE, D_DOUBLE2_OPENCL, D_DOUBLE], D_DOUBLE2) # As Z, but with one constant from D
+
+# C++ template data-types
+T = DataType("T", "typename T", "T", ["T", "T", "T", "T"], "T") # regular routine
+Tc = DataType("Tc", "typename T", "std::complex<T>,T", ["T", "T", "T", "T"], "std::complex<T>") # for herk
+TU = DataType("TU", "typename T, typename U", "T,U", ["T", "U", "T", "U"], "T") # for her2k
diff --git a/scripts/generator/generator/doc.py b/scripts/generator/generator/doc.py
new file mode 100644
index 00000000..8657ed0d
--- /dev/null
+++ b/scripts/generator/generator/doc.py
@@ -0,0 +1,57 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+NL = "\n"
+
+
+def header():
+ """Generates the header for the API documentation"""
+ result = "CLBlast: API reference" + NL
+ result += "================" + NL + NL + NL
+ return result
+
+
+def generate(routine):
+ """Generates the API documentation for a given routine"""
+ result = ""
+
+ # Routine header
+ result += "x" + routine.name.upper() + ": " + routine.description + NL
+ result += "-------------" + NL + NL
+ result += routine.details + NL + NL
+
+ # Routine API
+ result += "C++ API:" + NL
+ result += "```" + NL
+ result += routine.routine_header_cpp(12, "") + NL
+ result += "```" + NL + NL
+ result += "C API:" + NL
+ result += "```" + NL
+ for flavour in routine.flavours:
+ result += routine.routine_header_c(flavour, 20, "") + NL
+ result += "```" + NL + NL
+
+ # Routine arguments
+ result += "Arguments to " + routine.name.upper() + ":" + NL + NL
+ for argument in routine.arguments_doc():
+ result += "* " + argument + NL
+ result += "* `cl_command_queue* queue`: "
+ result += "Pointer to an OpenCL command queue associated with a context and device to execute the routine on." + NL
+ result += "* `cl_event* event`: "
+ result += "Pointer to an OpenCL event to be able to wait for completion of the routine's OpenCL kernel(s). "
+ result += "This is an optional argument." + NL + NL
+
+ # Routine requirements
+ if len(routine.requirements_doc()) > 0:
+ result += "Requirements for " + routine.name.upper() + ":" + NL + NL
+ for requirement in routine.requirements_doc():
+ result += "* " + requirement + NL
+ result += NL
+
+ # Routine footer
+ result += NL + NL
+ return result
diff --git a/scripts/generator/generator/routine.py b/scripts/generator/generator/routine.py
new file mode 100644
index 00000000..a4e682c2
--- /dev/null
+++ b/scripts/generator/generator/routine.py
@@ -0,0 +1,552 @@
+
+# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This file follows the
+# PEP8 Python style guide and uses a max-width of 120 characters per line.
+#
+# Author(s):
+# Cedric Nugteren <www.cedricnugteren.nl>
+
+from itertools import chain
+
+import generator.convert as convert
+
+
+class Routine:
+ """Class holding routine-specific information (e.g. name, which arguments, which precisions)"""
+ def __init__(self, implemented, has_tests, level, name, template, flavours, sizes, options,
+ inputs, outputs, scalars, scratch, description, details, requirements):
+ self.implemented = implemented
+ self.has_tests = has_tests
+ self.level = level
+ self.name = name
+ self.template = template
+ self.flavours = flavours
+ self.sizes = sizes
+ self.options = options
+ self.inputs = inputs
+ self.outputs = outputs
+ self.scalars = scalars
+ self.scratch = scratch # Scratch buffer (e.g. for xDOT)
+ self.description = description
+ self.details = details
+ self.requirements = requirements
+
+ @staticmethod
+ def scalar_buffers_first():
+ """List of scalar buffers"""
+ return ["dot", "nrm2", "asum", "sum", "imax", "imin"]
+
+ @staticmethod
+ def scalar_buffers_second():
+ """List of scalar buffers"""
+ return ["sa", "sb", "sc", "ss", "sd1", "sd2", "sx1", "sy1", "sparam"]
+
+ @staticmethod
+ def other_scalars():
+ """List of scalars other than alpha and beta"""
+ return ["cos", "sin"]
+
+ @staticmethod
+ def index_buffers():
+ """List of buffers with unsigned int type"""
+ return ["imax", "imin"]
+
+ @staticmethod
+ def postfix(name):
+ """Retrieves the postfix for a buffer"""
+ return "inc" if (name in ["x", "y"]) else "ld"
+
+ @staticmethod
+ def buffers_vector():
+ """Distinguish between vectors and matrices"""
+ return ["x", "y"]
+
+ @staticmethod
+ def buffers_matrix():
+ """Distinguish between vectors and matrices"""
+ return ["a", "b", "c", "ap"]
+
+ def non_index_inputs(self):
+ """Lists of input/output buffers not index (integer)"""
+ buffers = self.inputs[:] # make a copy
+ for i in self.index_buffers():
+ if i in buffers:
+ buffers.remove(i)
+ return buffers
+
+ def non_index_outputs(self):
+ """Lists of input/output buffers not index (integer)"""
+ buffers = self.outputs[:] # make a copy
+ for i in self.index_buffers():
+ if i in buffers:
+ buffers.remove(i)
+ return buffers
+
+ def buffers_without_ld_inc(self):
+ """List of buffers without 'inc' or 'ld'"""
+ return self.scalar_buffers_first() + self.scalar_buffers_second() + ["ap"]
+
+ def length(self):
+ """Retrieves the number of characters in the routine's name"""
+ return len(self.name)
+
+ def no_scalars(self):
+ """Determines whether or not this routine has scalar arguments (alpha/beta)"""
+ return self.scalars == []
+
+ def short_names(self):
+ """Returns the upper-case names of these routines (all flavours)"""
+ return "/".join([f.name + self.name.upper() for f in self.flavours])
+
+ def short_names_tested(self):
+ """As above, but excludes some"""
+ names = [f.name + self.name.upper() for f in self.flavours]
+ if "H" + self.name.upper() in names:
+ names.remove("H" + self.name.upper())
+ return "/".join(names)
+
+ def buffers_first(self):
+ """Determines which buffers go first (between alpha and beta) and which ones go after"""
+ if self.level == "2b":
+ return ["x", "y"]
+ return ["ap", "a", "b", "x"]
+
+ def buffers_second(self):
+ if self.level == "2b":
+ return ["ap", "a", "b", "c"]
+ return ["y", "c"]
+
+ def buffer(self, name):
+ """Retrieves a variable name for a specific input/output vector/matrix (e.g. 'x')"""
+ if name in self.inputs or name in self.outputs:
+ a = [name + "_buffer"]
+ b = [name + "_offset"]
+ c = [name + "_" + self.postfix(name)] if (name not in self.buffers_without_ld_inc()) else []
+ return [", ".join(a + b + c)]
+ return []
+
+ def buffer_bis(self, name):
+ """As above but with a '_bis' suffix for the buffer name"""
+ if name in self.inputs or name in self.outputs:
+ a = [name + "_buffer_bis"]
+ b = [name + "_offset"]
+ c = [name + "_" + self.postfix(name)] if name not in self.buffers_without_ld_inc() else []
+ return [", ".join(a + b + c)]
+ return []
+
+ def buffer_def(self, name):
+ """As above but with data-types"""
+ prefix = "const " if name in self.inputs else ""
+ if name in self.inputs or name in self.outputs:
+ a = [prefix + "cl_mem " + name + "_buffer"]
+ b = ["const size_t " + name + "_offset"]
+ c = ["const size_t " + name + "_" + self.postfix(name)] if name not in self.buffers_without_ld_inc() else []
+ return [", ".join(a + b + c)]
+ return []
+
+ def buffer_def_wrapper_cl(self, name, flavour):
+ """As above but with data-types"""
+ prefix = "const " if name in self.inputs else ""
+ if name in self.inputs or name in self.outputs:
+ a = [prefix + "Buffer<" + flavour.buffer_type + ">& " + name + "_buffer"]
+ b = ["const size_t " + name + "_offset"]
+ c = ["const size_t " + name + "_" + self.postfix(name)] if name not in self.buffers_without_ld_inc() else []
+ return [", ".join(a + b + c)]
+ return []
+
+ def buffer_def_vector(self, name, flavour):
+ """As above but as vectors"""
+ prefix = "const " if name in self.inputs else ""
+ if name in self.inputs or name in self.outputs:
+ a = [prefix + "std::vector<" + flavour.buffer_type + ">& " + name + "_buffer"]
+ b = ["const size_t " + name + "_offset"]
+ c = ["const size_t " + name + "_" + self.postfix(name)] if name not in self.buffers_without_ld_inc() else []
+ return [", ".join(a + b + c)]
+ return []
+
+ def buffer_clcudaapi(self, name):
+ """As above but with CLCudaAPI buffers"""
+ if name in self.inputs or name in self.outputs:
+ buffer_type = "unsigned int" if (name in self.index_buffers()) else self.template.buffer_type
+ a = ["Buffer<" + buffer_type + ">(" + name + "_buffer)"]
+ b = [name + "_offset"]
+ c = [name + "_" + self.postfix(name)] if (name not in self.buffers_without_ld_inc()) else []
+ return [", ".join(a + b + c)]
+ return []
+
+ def buffer_wrapper_clblas(self, name):
+ """As above but with a static cast for clBLAS wrapper"""
+ if name in self.inputs or name in self.outputs:
+ a = [name + "_buffer()"]
+ b = [name + "_offset"]
+ c = []
+ if name in ["x", "y"]:
+ c = ["static_cast<int>(" + name + "_" + self.postfix(name) + ")"]
+ elif name in ["a", "b", "c"]:
+ c = [name + "_" + self.postfix(name)]
+ return [", ".join(a + b + c)]
+ return []
+
+ def buffer_wrapper_cblas(self, name, flavour):
+ """As above but with a static cast for CBLAS wrapper"""
+ prefix = "const " if name in self.inputs else ""
+ if name in self.inputs or name in self.outputs:
+ if name == "sy1":
+ a = [name + "_buffer[" + name + "_offset]"]
+ elif flavour.precision_name in ["C", "Z"]:
+ a = ["reinterpret_cast<" + prefix + flavour.buffer_type[:-1] + "*>" +
+ "(&" + name + "_buffer[" + name + "_offset])"]
+ else:
+ a = ["&" + name + "_buffer[" + name + "_offset]"]
+ c = []
+ if name in ["x", "y"]:
+ c = ["static_cast<int>(" + name + "_" + self.postfix(name) + ")"]
+ elif name in ["a", "b", "c"]:
+ c = [name + "_" + self.postfix(name)]
+ return [", ".join(a + c)]
+ return []
+
+ def buffer_type(self, name):
+ """As above, but only data-types"""
+ prefix = "const " if (name in self.inputs) else ""
+ if (name in self.inputs) or (name in self.outputs):
+ a = [prefix + "cl_mem"]
+ b = ["const size_t"]
+ c = ["const size_t"] if (name not in self.buffers_without_ld_inc()) else []
+ return [", ".join(a + b + c)]
+ return []
+
+ def buffer_doc(self, name):
+ """Retrieves the documentation of the buffers"""
+ prefix = "const " if (name in self.inputs) else ""
+ inout = "input" if (name in self.inputs) else "output"
+ if (name in self.inputs) or (name in self.outputs):
+ math_name = name.upper() + " matrix" if (name in self.buffers_matrix()) else name + " vector"
+ inc_ld_description = "Leading dimension " if (name in self.buffers_matrix()) else "Stride/increment "
+ a = ["`" + prefix + "cl_mem " + name + "_buffer`: OpenCL buffer to store the " + inout + " " + math_name + "."]
+ b = ["`const size_t " + name + "_offset`: The offset in elements from the start of the " + inout + " " + math_name + "."]
+ if name not in self.buffers_without_ld_inc():
+ c = ["`const size_t " + name + "_" + self.postfix(name) + "`: " +
+ inc_ld_description + "of the " + inout + " " + math_name + ". This value must be greater than 0."]
+ else:
+ c = []
+ return a + b + c
+ return []
+
+ def scalar(self, name):
+ """Retrieves the name of a scalar (alpha/beta)"""
+ if name in self.scalars:
+ return [name]
+ return []
+
+ def scalar_half_to_float(self, name):
+ """As above, but converts from float to half"""
+ if name in self.scalars:
+ return ["HalfToFloat(" + name + ")"]
+ return []
+
+ def scalar_use(self, name, flavour):
+ """Retrieves the use of a scalar (alpha/beta)"""
+ if name in self.scalars:
+ if name == "alpha":
+ return [flavour.use_alpha()]
+ elif name == "beta":
+ return [flavour.use_beta()]
+ return [name]
+ return []
+
+ def scalar_use_wrapper(self, name, flavour):
+ """As above, but for the clBLAS wrapper"""
+ if name in self.scalars:
+ if name == "alpha":
+ return [flavour.use_alpha_opencl()]
+ elif name == "beta":
+ return [flavour.use_beta_opencl()]
+ return [name]
+ return []
+
+ def scalar_use_wrapper_cblas(self, name, flavour):
+ """As above, but for the CBLAS wrapper"""
+ if name in self.scalars:
+ if flavour.is_complex(name):
+ return [name + "_array.data()"]
+ return [name]
+ return []
+
+ def scalar_def(self, name, flavour):
+ """Retrieves the definition of a scalar (alpha/beta)"""
+ if name in self.scalars:
+ if name == "alpha":
+ return ["const " + flavour.alpha_cl + " " + name]
+ return ["const " + flavour.beta_cl + " " + name]
+ return []
+
+ def scalar_def_plain(self, name, flavour):
+ """As above, but without 'cl_' prefix"""
+ if name in self.scalars:
+ if name == "alpha":
+ return ["const " + flavour.alpha_cpp + " " + name]
+ return ["const " + flavour.beta_cpp + " " + name]
+ return []
+
+ def scalar_type(self, name, flavour):
+ """Retrieves the type of a scalar (alpha/beta)"""
+ if name in self.scalars:
+ if name == "alpha":
+ return ["const " + flavour.alpha_cpp]
+ return ["const " + flavour.beta_cpp]
+ return []
+
+ def scalar_doc(self, name):
+ """Retrieves the documentation of a scalar"""
+ if name in self.scalars:
+ if name == "alpha":
+ return ["`const " + self.template.alpha_cpp + " " + name + "`: Input scalar constant."]
+ return ["`const " + self.template.beta_cpp + " " + name + "`: Input scalar constant."]
+ return []
+
+ def sizes_list(self):
+ """Retrieves a list of comma-separated sizes (m, n, k)"""
+ if self.sizes:
+ return [", ".join([s for s in self.sizes])]
+ return []
+
+ def sizes_def(self):
+ """Retrieves the definition of the sizes (m,n,k)"""
+ if self.sizes:
+ return [", ".join(["const size_t " + s for s in self.sizes])]
+ return []
+
+ def sizes_type(self):
+ """Retrieves the types of the sizes (m,n,k)"""
+ if self.sizes:
+ return [", ".join(["const size_t" for s in self.sizes])]
+ return []
+
+ def sizes_doc(self):
+ """# Retrieves the documentation of the sizes"""
+ if self.sizes:
+ definitions = ["`const size_t " + s + "`: Integer size argument. This value must be positive." for s in self.sizes]
+ return definitions
+ return []
+
+ def options_list(self):
+ """Retrieves a list of options"""
+ if self.options:
+ return [", ".join(self.options)]
+ return []
+
+ def options_cast(self, indent):
+ """As above, but now casted to CLBlast data-types"""
+ if self.options:
+ options = ["static_cast<clblast::" + convert.option_to_clblast(o) + ">(" + o + ")" for o in self.options]
+ return [(",\n" + indent).join(options)]
+ return []
+
+ def options_def(self):
+ """Retrieves the definitions of the options (layout, transpose, side, etc.)"""
+ if self.options:
+ definitions = ["const " + convert.option_to_clblast(o) + " " + o for o in self.options]
+ return [", ".join(definitions)]
+ return []
+
+ def options_def_wrapper_clblas(self):
+ """As above, but now using clBLAS data-types"""
+ if self.options:
+ definitions = ["const " + convert.option_to_clblas(o) + " " + o for o in self.options]
+ return [", ".join(definitions)]
+ return []
+
+ def options_def_wrapper_cblas(self):
+ """As above, but now using CBLAS data-types"""
+ if self.options:
+ definitions = ["const " + convert.option_to_cblas(o) + " " + o for o in self.options]
+ return [", ".join(definitions)]
+ return []
+
+ def options_type(self):
+ """Retrieves the types of the options (layout, transpose, side, etc.)"""
+ if self.options:
+ definitions = ["const " + convert.option_to_clblast(o) for o in self.options]
+ return [", ".join(definitions)]
+ return []
+
+ def options_doc(self):
+ """Retrieves the documentation of the options"""
+ if self.options:
+ definitions = ["`const " + convert.option_to_clblast(o) + " " + o + "`: " + convert.option_to_documentation(o) for o in self.options]
+ return definitions
+ return []
+
+ def arguments(self):
+ """Retrieves a combination of all the argument names (no types)"""
+ return (self.options_list() + self.sizes_list() +
+ list(chain(*[self.buffer(b) for b in self.scalar_buffers_first()])) +
+ self.scalar("alpha") +
+ list(chain(*[self.buffer(b) for b in self.buffers_first()])) +
+ self.scalar("beta") +
+ list(chain(*[self.buffer(b) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer(b) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar(s) for s in self.other_scalars()])))
+
+ def arguments_half(self):
+ """As above, but with conversions from half to float"""
+ return (self.options_list() + self.sizes_list() +
+ list(chain(*[self.buffer_bis(b) for b in self.scalar_buffers_first()])) +
+ self.scalar_half_to_float("alpha") +
+ list(chain(*[self.buffer_bis(b) for b in self.buffers_first()])) +
+ self.scalar_half_to_float("beta") +
+ list(chain(*[self.buffer_bis(b) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_bis(b) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar(s) for s in self.other_scalars()])))
+
+ def arguments_clcudaapi(self):
+ """Retrieves a combination of all the argument names, with CLCudaAPI casts"""
+ return (self.options_list() + self.sizes_list() +
+ list(chain(*[self.buffer_clcudaapi(b) for b in self.scalar_buffers_first()])) +
+ self.scalar("alpha") +
+ list(chain(*[self.buffer_clcudaapi(b) for b in self.buffers_first()])) +
+ self.scalar("beta") +
+ list(chain(*[self.buffer_clcudaapi(b) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_clcudaapi(b) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar(s) for s in self.other_scalars()])))
+
+ def arguments_cast(self, flavour, indent):
+ """As above, but with CLBlast casts"""
+ return (self.options_cast(indent) + self.sizes_list() +
+ list(chain(*[self.buffer(b) for b in self.scalar_buffers_first()])) +
+ self.scalar_use("alpha", flavour) +
+ list(chain(*[self.buffer(b) for b in self.buffers_first()])) +
+ self.scalar_use("beta", flavour) +
+ list(chain(*[self.buffer(b) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer(b) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar_use(s, flavour) for s in self.other_scalars()])))
+
+ def arguments_wrapper_clblas(self, flavour):
+ """As above, but for the clBLAS wrapper"""
+ return (self.options_list() + self.sizes_list() +
+ list(chain(*[self.buffer_wrapper_clblas(b) for b in self.scalar_buffers_first()])) +
+ self.scalar_use_wrapper("alpha", flavour) +
+ list(chain(*[self.buffer_wrapper_clblas(b) for b in self.buffers_first()])) +
+ self.scalar_use_wrapper("beta", flavour) +
+ list(chain(*[self.buffer_wrapper_clblas(b) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_wrapper_clblas(b) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar_use_wrapper(s, flavour) for s in self.other_scalars()])))
+
+ def arguments_wrapper_cblas(self, flavour):
+ """As above, but for the CBLAS wrapper"""
+ return (self.options_list() + self.sizes_list() +
+ self.scalar_use_wrapper_cblas("alpha", flavour) +
+ list(chain(*[self.buffer_wrapper_cblas(b, flavour) for b in self.buffers_first()])) +
+ self.scalar_use_wrapper_cblas("beta", flavour) +
+ list(chain(*[self.buffer_wrapper_cblas(b, flavour) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_wrapper_cblas(b, flavour) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar_use_wrapper_cblas(s, flavour) for s in self.other_scalars()])))
+
+ def arguments_def(self, flavour):
+ """Retrieves a combination of all the argument definitions"""
+ return (self.options_def() + self.sizes_def() +
+ list(chain(*[self.buffer_def(b) for b in self.scalar_buffers_first()])) +
+ self.scalar_def("alpha", flavour) +
+ list(chain(*[self.buffer_def(b) for b in self.buffers_first()])) +
+ self.scalar_def("beta", flavour) +
+ list(chain(*[self.buffer_def(b) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_def(b) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar_def(s, flavour) for s in self.other_scalars()])))
+
+ def arguments_def_wrapper_clblas(self, flavour):
+ """As above, but clBLAS wrapper plain data-types"""
+ return (self.options_def_wrapper_clblas() + self.sizes_def() +
+ list(chain(*[self.buffer_def_wrapper_cl(b, flavour) for b in self.scalar_buffers_first()])) +
+ self.scalar_def_plain("alpha", flavour) +
+ list(chain(*[self.buffer_def_wrapper_cl(b, flavour) for b in self.buffers_first()])) +
+ self.scalar_def_plain("beta", flavour) +
+ list(chain(*[self.buffer_def_wrapper_cl(b, flavour) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_def_wrapper_cl(b, flavour) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar_def_plain(s, flavour) for s in self.other_scalars()])))
+
+ def arguments_def_wrapper_cblas(self, flavour):
+ """As above, but CBLAS wrapper plain data-types"""
+ return (self.options_def_wrapper_cblas() + self.sizes_def() +
+ list(chain(*[self.buffer_def_vector(b, flavour) for b in self.scalar_buffers_first()])) +
+ self.scalar_def_plain("alpha", flavour) +
+ list(chain(*[self.buffer_def_vector(b, flavour) for b in self.buffers_first()])) +
+ self.scalar_def_plain("beta", flavour) +
+ list(chain(*[self.buffer_def_vector(b, flavour) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_def_vector(b, flavour) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar_def_plain(s, flavour) for s in self.other_scalars()])))
+
+ def arguments_type(self, flavour):
+ """Retrieves a combination of all the argument types"""
+ return (self.options_type() + self.sizes_type() +
+ list(chain(*[self.buffer_type(b) for b in self.scalar_buffers_first()])) +
+ self.scalar_type("alpha", flavour) +
+ list(chain(*[self.buffer_type(b) for b in self.buffers_first()])) +
+ self.scalar_type("beta", flavour) +
+ list(chain(*[self.buffer_type(b) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_type(b) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar_type(s, flavour) for s in self.other_scalars()])))
+
+ def arguments_doc(self):
+ """Retrieves a combination of all the argument types"""
+ return (self.options_doc() + self.sizes_doc() +
+ list(chain(*[self.buffer_doc(b) for b in self.scalar_buffers_first()])) +
+ list(chain(*[self.buffer_doc(b) for b in self.scalar_buffers_first()])) +
+ self.scalar_doc("alpha") +
+ list(chain(*[self.buffer_doc(b) for b in self.buffers_first()])) +
+ self.scalar_doc("beta") +
+ list(chain(*[self.buffer_doc(b) for b in self.buffers_second()])) +
+ list(chain(*[self.buffer_doc(b) for b in self.scalar_buffers_second()])) +
+ list(chain(*[self.scalar_doc(s) for s in self.other_scalars()])))
+
+ def requirements_doc(self):
+ """Retrieves a list of routine requirements for documentation"""
+ return self.requirements
+
+ def routine_header_cpp(self, spaces, default_event):
+ """Retrieves the C++ templated definition for a routine"""
+ indent = " " * (spaces + self.length())
+ result = "template <" + self.template.name + ">\n"
+ result += "StatusCode " + self.name.capitalize() + "("
+ result += (",\n" + indent).join([a for a in self.arguments_def(self.template)])
+ result += ",\n" + indent + "cl_command_queue* queue, cl_event* event" + default_event + ")"
+ return result
+
+ def routine_header_type_cpp(self, spaces):
+ """As above, but now without variable names"""
+ indent = " " * (spaces + self.length())
+ result = "template <" + self.template.name + ">\n"
+ result += "StatusCode " + self.name.capitalize() + "("
+ result += (",\n" + indent).join([a for a in self.arguments_type(self.template)])
+ result += ",\n" + indent + "cl_command_queue*, cl_event*)"
+ return result
+
+ def routine_header_c(self, flavour, spaces, extra_qualifier):
+ """As above, but now for C"""
+ indent = " " * (spaces + self.length())
+ result = "StatusCode" + extra_qualifier + " CLBlast" + flavour.name + self.name + "("
+ result += (",\n" + indent).join([a for a in self.arguments_def(flavour)])
+ result += ",\n" + indent + "cl_command_queue* queue, cl_event* event)"
+ return result
+
+ def routine_header_wrapper_clblas(self, flavour, def_only, spaces):
+ """As above, but now for the clBLAS wrapper"""
+ template = "<" + flavour.template + ">" if self.no_scalars() and not def_only else ""
+ indent = " " * (spaces + self.length() + len(template))
+ result = ""
+ if self.no_scalars():
+ result += "template <"
+ if def_only:
+ result += flavour.name
+ result += ">\n"
+ result += "clblasStatus clblasX" + self.name + template + "("
+ result += (",\n" + indent).join([a for a in self.arguments_def_wrapper_clblas(flavour)])
+ result += ",\n" + indent + "cl_uint num_queues, cl_command_queue *queues"
+ result += ",\n" + indent + "cl_uint num_wait_events, const cl_event *wait_events, cl_event *events)"
+ return result
+
+ def routine_header_wrapper_cblas(self, flavour, spaces):
+ """As above, but now for the CBLAS wrapper"""
+ indent = " " * (spaces + self.length())
+ result = "void cblasX" + self.name + "("
+ result += (",\n" + indent).join([a for a in self.arguments_def_wrapper_cblas(flavour)]) + ")"
+ return result
diff --git a/scripts/generator/routine.py b/scripts/generator/routine.py
deleted file mode 100644
index 00883776..00000000
--- a/scripts/generator/routine.py
+++ /dev/null
@@ -1,603 +0,0 @@
-#!/usr/bin/env python
-
-# ==================================================================================================
-# This file is part of the CLBlast project. The project is licensed under Apache Version 2.0. This
-# project loosely follows the Google C++ styleguide and uses a max-width of 100 characters per line.
-#
-# Author(s):
-# Cedric Nugteren <www.cedricnugteren.nl>
-#
-# This file contains the 'Routine' class, used in the generator script to generate the CLBlast API
-# interface and implementation.
-#
-# ==================================================================================================
-
-# System modules
-from itertools import chain
-
-# Translates an option name to a CLBlast data-type
-def OptionToCLBlast(x):
- return {
- 'layout': "Layout",
- 'a_transpose': "Transpose",
- 'b_transpose': "Transpose",
- 'ab_transpose': "Transpose",
- 'side': "Side",
- 'triangle': "Triangle",
- 'diagonal': "Diagonal",
- }[x]
-
-# As above, but for clBLAS data-types
-def OptionToWrapperCL(x):
- return {
- 'layout': "clblasOrder",
- 'a_transpose': "clblasTranspose",
- 'b_transpose': "clblasTranspose",
- 'ab_transpose': "clblasTranspose",
- 'side': "clblasSide",
- 'triangle': "clblasUplo",
- 'diagonal': "clblasDiag",
- }[x]
-
-# As above, but for CBLAS data-types
-def OptionToWrapperC(x):
- return {
- 'layout': "CBLAS_ORDER",
- 'a_transpose': "CBLAS_TRANSPOSE",
- 'b_transpose': "CBLAS_TRANSPOSE",
- 'ab_transpose': "CBLAS_TRANSPOSE",
- 'side': "CBLAS_SIDE",
- 'triangle': "CBLAS_UPLO",
- 'diagonal': "CBLAS_DIAG",
- }[x]
-
-# Translates an option name to a documentation string
-def OptionToDoc(x):
- return {
- 'layout': "Data-layout of the matrices, either `Layout::kRowMajor` (101) for row-major layout or `Layout::kColMajor` (102) for column-major data-layout.",
- 'a_transpose': "Transposing the input matrix A, either `Transpose::kNo` (111), `Transpose::kYes` (112), or `Transpose::kConjugate` (113) for a complex-conjugate transpose.",
- 'b_transpose': "Transposing the input matrix B, either `Transpose::kNo` (111), `Transpose::kYes` (112), or `Transpose::kConjugate` (113) for a complex-conjugate transpose.",
- 'ab_transpose': "Transposing the packed input matrix AP, either `Transpose::kNo` (111), `Transpose::kYes` (112), or `Transpose::kConjugate` (113) for a complex-conjugate transpose.",
- 'side': "The position of the triangular matrix in the operation, either on the `Side::kLeft` (141) or `Side::kRight` (142).",
- 'triangle': "The part of the array of the triangular matrix to be used, either `Triangle::kUpper` (121) or `Triangle::kLower` (122).",
- 'diagonal': "The property of the diagonal matrix, either `Diagonal::kNonUnit` (131) for non-unit values on the diagonal or `Diagonal::kUnit` (132) for unit values on the diagonal.",
- }[x]
-
-# ==================================================================================================
-
-# Class holding routine-specific information (e.g. name, which arguments, which precisions)
-class Routine():
- def __init__(self, implemented, has_tests, level, name, template, flavours, sizes, options,
- inputs, outputs, scalars, scratch, description, details, requirements):
- self.implemented = implemented
- self.has_tests = has_tests
- self.level = level
- self.name = name
- self.template = template
- self.flavours = flavours
- self.sizes = sizes
- self.options = options
- self.inputs = inputs
- self.outputs = outputs
- self.scalars = scalars
- self.scratch = scratch # Scratch buffer (e.g. for xDOT)
- self.description = description
- self.details = details
- self.requirements = requirements
-
- # List of scalar buffers
- def ScalarBuffersFirst(self):
- return ["dot","nrm2","asum","sum","imax","imin"]
- def ScalarBuffersSecond(self):
- return ["sa","sb","sc","ss","sd1","sd2","sx1","sy1","sparam"]
-
- # List of scalars other than alpha and beta
- def OtherScalars(self):
- return ["cos","sin"]
-
- # List of buffers with unsigned int type
- def IndexBuffers(self):
- return ["imax","imin"]
-
- # Lists of input/output buffers not index (integer)
- def NonIndexInputs(self):
- buffers = self.inputs[:] # make a copy
- for i in self.IndexBuffers():
- if i in buffers: buffers.remove(i)
- return buffers
- def NonIndexOutputs(self):
- buffers = self.outputs[:] # make a copy
- for i in self.IndexBuffers():
- if i in buffers: buffers.remove(i)
- return buffers
-
- # List of buffers without 'inc' or 'ld'
- def BuffersWithoutLdInc(self):
- return self.ScalarBuffersFirst() + self.ScalarBuffersSecond() + ["ap"]
-
- # Retrieves the number of characters in the routine's name
- def Length(self):
- return len(self.name)
-
- # Retrieves the postfix for a buffer
- def Postfix(self, name):
- return "inc" if (name in ["x","y"]) else "ld"
-
- # Determines whether or not this routine has scalar arguments (alpha/beta)
- def NoScalars(self):
- return self.scalars == []
-
- # Returns the upper-case names of these routines (all flavours)
- def ShortNames(self):
- return "/".join([f.name+self.name.upper() for f in self.flavours])
-
- # As above, but excludes some
- def ShortNamesTested(self):
- names = [f.name+self.name.upper() for f in self.flavours]
- if "H"+self.name.upper() in names: names.remove("H"+self.name.upper())
- return "/".join(names)
-
- # Determines which buffers go first (between alpha and beta) and which ones go after
- def BuffersFirst(self):
- if self.level == "2b":
- return ["x","y"]
- return ["ap","a","b","x"]
- def BuffersSecond(self):
- if self.level == "2b":
- return ["ap","a","b","c"]
- return ["y","c"]
-
- # Distinguish between vectors and matrices
- def BuffersVector(self):
- return ["x","y"]
- def BuffersMatrix(self):
- return ["a","b","c","ap"]
-
- # ==============================================================================================
-
- # Retrieves a variable name for a specific input/output vector/matrix (e.g. 'x')
- def Buffer(self, name):
- if (name in self.inputs) or (name in self.outputs):
- a = [name+"_buffer"]
- b = [name+"_offset"]
- c = [name+"_"+self.Postfix(name)] if (name not in self.BuffersWithoutLdInc()) else []
- return [", ".join(a+b+c)]
- return []
-
- # As above but with a '_bis' suffix for the buffer name
- def BufferBis(self, name):
- #if (name in self.IndexBuffers()):
- # return self.Buffer(name)
- if (name in self.inputs) or (name in self.outputs):
- a = [name+"_buffer_bis"]
- b = [name+"_offset"]
- c = [name+"_"+self.Postfix(name)] if (name not in self.BuffersWithoutLdInc()) else []
- return [", ".join(a+b+c)]
- return []
-
- # As above but with data-types
- def BufferDef(self, name):
- prefix = "const " if (name in self.inputs) else ""
- if (name in self.inputs) or (name in self.outputs):
- a = [prefix+"cl_mem "+name+"_buffer"]
- b = ["const size_t "+name+"_offset"]
- c = ["const size_t "+name+"_"+self.Postfix(name)] if (name not in self.BuffersWithoutLdInc()) else []
- return [", ".join(a+b+c)]
- return []
-
- # As above but with data-types
- def BufferDefWrapperCL(self, name, flavour):
- prefix = "const " if (name in self.inputs) else ""
- if (name in self.inputs) or (name in self.outputs):
- a = [prefix+"Buffer<"+flavour.buffertype+">& "+name+"_buffer"]
- b = ["const size_t "+name+"_offset"]
- c = ["const size_t "+name+"_"+self.Postfix(name)] if (name not in self.BuffersWithoutLdInc()) else []
- return [", ".join(a+b+c)]
- return []
-
- # As above but as vectors
- def BufferDefVector(self, name, flavour):
- prefix = "const " if (name in self.inputs) else ""
- if (name in self.inputs) or (name in self.outputs):
- a = [prefix+"std::vector<"+flavour.buffertype+">& "+name+"_buffer"]
- b = ["const size_t "+name+"_offset"]
- c = ["const size_t "+name+"_"+self.Postfix(name)] if (name not in self.BuffersWithoutLdInc()) else []
- return [", ".join(a+b+c)]
- return []
-
- # As above but with Claduc buffers
- def BufferCladuc(self, name):
- if (name in self.inputs) or (name in self.outputs):
- buffertype = "unsigned int" if (name in self.IndexBuffers()) else self.template.buffertype
- a = ["Buffer<"+buffertype+">("+name+"_buffer)"]
- b = [name+"_offset"]
- c = [name+"_"+self.Postfix(name)] if (name not in self.BuffersWithoutLdInc()) else []
- return [", ".join(a+b+c)]
- return []
-
- # As above but with a static cast for clBLAS wrapper
- def BufferWrapperCL(self, name):
- if (name in self.inputs) or (name in self.outputs):
- a = [name+"_buffer()"]
- b = [name+"_offset"]
- c = []
- if (name in ["x","y"]):
- c = ["static_cast<int>("+name+"_"+self.Postfix(name)+")"]
- elif (name in ["a","b","c"]):
- c = [name+"_"+self.Postfix(name)]
- return [", ".join(a+b+c)]
- return []
-
- # As above but with a static cast for CBLAS wrapper
- def BufferWrapperC(self, name, flavour):
- prefix = "const " if (name in self.inputs) else ""
- if (name in self.inputs) or (name in self.outputs):
- if name == "sy1":
- a = [name+"_buffer["+name+"_offset]"]
- elif flavour.precision_name in ["C","Z"]:
- a = ["reinterpret_cast<"+prefix+flavour.buffertype[:-1]+"*>(&"+name+"_buffer["+name+"_offset])"]
- else:
- a = ["&"+name+"_buffer["+name+"_offset]"]
- c = []
- if (name in ["x","y"]):
- c = ["static_cast<int>("+name+"_"+self.Postfix(name)+")"]
- elif (name in ["a","b","c"]):
- c = [name+"_"+self.Postfix(name)]
- return [", ".join(a+c)]
- return []
-
- # As above, but only data-types
- def BufferType(self, name):
- prefix = "const " if (name in self.inputs) else ""
- if (name in self.inputs) or (name in self.outputs):
- a = [prefix+"cl_mem"]
- b = ["const size_t"]
- c = ["const size_t"] if (name not in self.BuffersWithoutLdInc()) else []
- return [", ".join(a+b+c)]
- return []
-
- # Retrieves the documentation of the buffers
- def BufferDoc(self, name):
- prefix = "const " if (name in self.inputs) else ""
- inout = "input" if (name in self.inputs) else "output"
- if (name in self.inputs) or (name in self.outputs):
- math_name = name.upper()+" matrix" if (name in self.BuffersMatrix()) else name+" vector"
- incld_description = "Leading dimension " if (name in self.BuffersMatrix()) else "Stride/increment "
- a = ["`"+prefix+"cl_mem "+name+"_buffer`: OpenCL buffer to store the "+inout+" "+math_name+"."]
- b = ["`const size_t "+name+"_offset`: The offset in elements from the start of the "+inout+" "+math_name+"."]
- c = ["`const size_t "+name+"_"+self.Postfix(name)+"`: "+incld_description+"of the "+inout+" "+math_name+". This value must be greater than 0."] if (name not in self.BuffersWithoutLdInc()) else []
- return a+b+c
- return []
-
- # ==============================================================================================
-
- # Retrieves the name of a scalar (alpha/beta)
- def Scalar(self, name):
- if (name in self.scalars):
- return [name]
- return []
-
- # As above, but converts from float to half
- def ScalarHalfToFloat(self, name):
- if name in self.scalars:
- return ["HalfToFloat("+name+")"]
- return []
-
- # Retrieves the use of a scalar (alpha/beta)
- def ScalarUse(self, name, flavour):
- if name in self.scalars:
- if name == "alpha":
- return [flavour.UseAlpha()]
- elif name == "beta":
- return [flavour.UseBeta()]
- return [name]
- return []
-
- # As above, but for the clBLAS wrapper
- def ScalarUseWrapper(self, name, flavour):
- if name in self.scalars:
- if name == "alpha":
- return [flavour.UseAlphaCL()]
- elif name == "beta":
- return [flavour.UseBetaCL()]
- return [name]
- return []
-
- # As above, but for the CBLAS wrapper
- def ScalarUseWrapperC(self, name, flavour):
- if name in self.scalars:
- if flavour.IsComplex(name):
- return [name+"_array.data()"]
- return [name]
- return []
-
- # Retrieves the definition of a scalar (alpha/beta)
- def ScalarDef(self, name, flavour):
- if name in self.scalars:
- if name == "alpha":
- return ["const "+flavour.alpha_cl+" "+name]
- return ["const "+flavour.beta_cl+" "+name]
- return []
-
- # As above, but without 'cl_' prefix
- def ScalarDefPlain(self, name, flavour):
- if name in self.scalars:
- if name == "alpha":
- return ["const "+flavour.alpha_cpp+" "+name]
- return ["const "+flavour.beta_cpp+" "+name]
- return []
-
- # Retrieves the type of a scalar (alpha/beta)
- def ScalarType(self, name, flavour):
- if name in self.scalars:
- if name == "alpha":
- return ["const "+flavour.alpha_cpp]
- return ["const "+flavour.beta_cpp]
- return []
-
- # Retrieves the documentation of a scalar
- def ScalarDoc(self, name):
- if name in self.scalars:
- if name == "alpha":
- return ["`const "+self.template.alpha_cpp+" "+name+"`: Input scalar constant."]
- return ["`const "+self.template.beta_cpp+" "+name+"`: Input scalar constant."]
- return []
-
- # ==============================================================================================
-
- # Retrieves a list of comma-separated sizes (m, n, k)
- def Sizes(self):
- if self.sizes:
- return [", ".join([s for s in self.sizes])]
- return []
-
- # Retrieves the definition of the sizes (m,n,k)
- def SizesDef(self):
- if self.sizes:
- return [", ".join(["const size_t "+s for s in self.sizes])]
- return []
-
- # Retrieves the types of the sizes (m,n,k)
- def SizesType(self):
- if self.sizes:
- return [", ".join(["const size_t" for s in self.sizes])]
- return []
-
- # Retrieves the documentation of the sizes
- def SizesDoc(self):
- if self.sizes:
- definitions = ["`const size_t "+s+"`: Integer size argument. This value must be positive." for s in self.sizes]
- return definitions
- return []
-
- # ==============================================================================================
-
- # Retrieves a list of options
- def Options(self):
- if self.options:
- return [", ".join(self.options)]
- return []
-
- # As above, but now casted to CLBlast data-types
- def OptionsCast(self, indent):
- if self.options:
- options = ["static_cast<clblast::"+OptionToCLBlast(o)+">("+o+")" for o in self.options]
- return [(",\n"+indent).join(options)]
- return []
-
- # Retrieves the definitions of the options (layout, transpose, side, etc.)
- def OptionsDef(self):
- if self.options:
- definitions = ["const "+OptionToCLBlast(o)+" "+o for o in self.options]
- return [", ".join(definitions)]
- return []
-
- # As above, but now using clBLAS data-types
- def OptionsDefWrapperCL(self):
- if self.options:
- definitions = ["const "+OptionToWrapperCL(o)+" "+o for o in self.options]
- return [", ".join(definitions)]
- return []
-
- # As above, but now using CBLAS data-types
- def OptionsDefWrapperC(self):
- if self.options:
- definitions = ["const "+OptionToWrapperC(o)+" "+o for o in self.options]
- return [", ".join(definitions)]
- return []
-
- # Retrieves the types of the options (layout, transpose, side, etc.)
- def OptionsType(self):
- if self.options:
- definitions = ["const "+OptionToCLBlast(o) for o in self.options]
- return [", ".join(definitions)]
- return []
-
- # Retrieves the documentation of the options
- def OptionsDoc(self):
- if self.options:
- definitions = ["`const "+OptionToCLBlast(o)+" "+o+"`: "+OptionToDoc(o) for o in self.options]
- return definitions
- return []
-
- # ==============================================================================================
-
- # Retrieves a combination of all the argument names (no types)
- def Arguments(self):
- return (self.Options() + self.Sizes() +
- list(chain(*[self.Buffer(b) for b in self.ScalarBuffersFirst()])) +
- self.Scalar("alpha") +
- list(chain(*[self.Buffer(b) for b in self.BuffersFirst()])) +
- self.Scalar("beta") +
- list(chain(*[self.Buffer(b) for b in self.BuffersSecond()])) +
- list(chain(*[self.Buffer(b) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.Scalar(s) for s in self.OtherScalars()])))
-
- # As above, but with conversions from half to float
- def ArgumentsHalf(self):
- return (self.Options() + self.Sizes() +
- list(chain(*[self.BufferBis(b) for b in self.ScalarBuffersFirst()])) +
- self.ScalarHalfToFloat("alpha") +
- list(chain(*[self.BufferBis(b) for b in self.BuffersFirst()])) +
- self.ScalarHalfToFloat("beta") +
- list(chain(*[self.BufferBis(b) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferBis(b) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.Scalar(s) for s in self.OtherScalars()])))
-
- # Retrieves a combination of all the argument names, with Claduc casts
- def ArgumentsCladuc(self, flavour, indent):
- return (self.Options() + self.Sizes() +
- list(chain(*[self.BufferCladuc(b) for b in self.ScalarBuffersFirst()])) +
- self.Scalar("alpha") +
- list(chain(*[self.BufferCladuc(b) for b in self.BuffersFirst()])) +
- self.Scalar("beta") +
- list(chain(*[self.BufferCladuc(b) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferCladuc(b) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.Scalar(s) for s in self.OtherScalars()])))
-
- # As above, but with CLBlast casts
- def ArgumentsCast(self, flavour, indent):
- return (self.OptionsCast(indent) + self.Sizes() +
- list(chain(*[self.Buffer(b) for b in self.ScalarBuffersFirst()])) +
- self.ScalarUse("alpha", flavour) +
- list(chain(*[self.Buffer(b) for b in self.BuffersFirst()])) +
- self.ScalarUse("beta", flavour) +
- list(chain(*[self.Buffer(b) for b in self.BuffersSecond()])) +
- list(chain(*[self.Buffer(b) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.ScalarUse(s, flavour) for s in self.OtherScalars()])))
-
- # As above, but for the clBLAS wrapper
- def ArgumentsWrapperCL(self, flavour):
- return (self.Options() + self.Sizes() +
- list(chain(*[self.BufferWrapperCL(b) for b in self.ScalarBuffersFirst()])) +
- self.ScalarUseWrapper("alpha", flavour) +
- list(chain(*[self.BufferWrapperCL(b) for b in self.BuffersFirst()])) +
- self.ScalarUseWrapper("beta", flavour) +
- list(chain(*[self.BufferWrapperCL(b) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferWrapperCL(b) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.ScalarUseWrapper(s, flavour) for s in self.OtherScalars()])))
-
- # As above, but for the CBLAS wrapper
- def ArgumentsWrapperC(self, flavour):
- return (self.Options() + self.Sizes() +
- self.ScalarUseWrapperC("alpha", flavour) +
- list(chain(*[self.BufferWrapperC(b, flavour) for b in self.BuffersFirst()])) +
- self.ScalarUseWrapperC("beta", flavour) +
- list(chain(*[self.BufferWrapperC(b, flavour) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferWrapperC(b, flavour) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.ScalarUseWrapperC(s, flavour) for s in self.OtherScalars()])))
-
- # Retrieves a combination of all the argument definitions
- def ArgumentsDef(self, flavour):
- return (self.OptionsDef() + self.SizesDef() +
- list(chain(*[self.BufferDef(b) for b in self.ScalarBuffersFirst()])) +
- self.ScalarDef("alpha", flavour) +
- list(chain(*[self.BufferDef(b) for b in self.BuffersFirst()])) +
- self.ScalarDef("beta", flavour) +
- list(chain(*[self.BufferDef(b) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferDef(b) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.ScalarDef(s, flavour) for s in self.OtherScalars()])))
-
- # As above, but clBLAS wrapper plain datatypes
- def ArgumentsDefWrapperCL(self, flavour):
- return (self.OptionsDefWrapperCL() + self.SizesDef() +
- list(chain(*[self.BufferDefWrapperCL(b, flavour) for b in self.ScalarBuffersFirst()])) +
- self.ScalarDefPlain("alpha", flavour) +
- list(chain(*[self.BufferDefWrapperCL(b, flavour) for b in self.BuffersFirst()])) +
- self.ScalarDefPlain("beta", flavour) +
- list(chain(*[self.BufferDefWrapperCL(b, flavour) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferDefWrapperCL(b, flavour) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.ScalarDefPlain(s, flavour) for s in self.OtherScalars()])))
-
- # As above, but CBLAS wrapper plain datatypes
- def ArgumentsDefWrapperC(self, flavour):
- return (self.OptionsDefWrapperC() + self.SizesDef() +
- list(chain(*[self.BufferDefVector(b, flavour) for b in self.ScalarBuffersFirst()])) +
- self.ScalarDefPlain("alpha", flavour) +
- list(chain(*[self.BufferDefVector(b, flavour) for b in self.BuffersFirst()])) +
- self.ScalarDefPlain("beta", flavour) +
- list(chain(*[self.BufferDefVector(b, flavour) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferDefVector(b, flavour) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.ScalarDefPlain(s, flavour) for s in self.OtherScalars()])))
-
- # Retrieves a combination of all the argument types
- def ArgumentsType(self, flavour):
- return (self.OptionsType() + self.SizesType() +
- list(chain(*[self.BufferType(b) for b in self.ScalarBuffersFirst()])) +
- self.ScalarType("alpha", flavour) +
- list(chain(*[self.BufferType(b) for b in self.BuffersFirst()])) +
- self.ScalarType("beta", flavour) +
- list(chain(*[self.BufferType(b) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferType(b) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.ScalarType(s, flavour) for s in self.OtherScalars()])))
-
- # Retrieves a combination of all the argument types
- def ArgumentsDoc(self):
- return (self.OptionsDoc() + self.SizesDoc() +
- list(chain(*[self.BufferDoc(b) for b in self.ScalarBuffersFirst()])) +
- list(chain(*[self.BufferDoc(b) for b in self.ScalarBuffersFirst()])) +
- self.ScalarDoc("alpha") +
- list(chain(*[self.BufferDoc(b) for b in self.BuffersFirst()])) +
- self.ScalarDoc("beta") +
- list(chain(*[self.BufferDoc(b) for b in self.BuffersSecond()])) +
- list(chain(*[self.BufferDoc(b) for b in self.ScalarBuffersSecond()])) +
- list(chain(*[self.ScalarDoc(s) for s in self.OtherScalars()])))
-
- # ==============================================================================================
-
- # Retrieves a list of routine requirements for documentation
- def RequirementsDoc(self):
- return self.requirements
-
- # ==============================================================================================
-
- # Retrieves the C++ templated definition for a routine
- def RoutineHeaderCPP(self, spaces, default_event):
- indent = " "*(spaces + self.Length())
- result = "template <"+self.template.name+">\n"
- result += "StatusCode "+self.name.capitalize()+"("
- result += (",\n"+indent).join([a for a in self.ArgumentsDef(self.template)])
- result += ",\n"+indent+"cl_command_queue* queue, cl_event* event"+default_event+")"
- return result
-
- # As above, but now without variable names
- def RoutineHeaderTypeCPP(self, spaces):
- indent = " "*(spaces + self.Length())
- result = "template <"+self.template.name+">\n"
- result += "StatusCode "+self.name.capitalize()+"("
- result += (",\n"+indent).join([a for a in self.ArgumentsType(self.template)])
- result += ",\n"+indent+"cl_command_queue*, cl_event*)"
- return result
-
- # As above, but now for C
- def RoutineHeaderC(self, flavour, spaces, extra_qualifier):
- indent = " "*(spaces + self.Length())
- result = "StatusCode"+extra_qualifier+" CLBlast"+flavour.name+self.name+"("
- result += (",\n"+indent).join([a for a in self.ArgumentsDef(flavour)])
- result += ",\n"+indent+"cl_command_queue* queue, cl_event* event)"
- return result
-
- # As above, but now for the clBLAS wrapper
- def RoutineHeaderWrapperCL(self, flavour, def_only, spaces):
- template = "<"+flavour.template+">" if self.NoScalars() and not def_only else ""
- indent = " "*(spaces + self.Length() + len(template))
- result = ""
- if self.NoScalars():
- result += "template <"
- if def_only:
- result += flavour.name
- result += ">\n"
- result += "clblasStatus clblasX"+self.name+template+"("
- result += (",\n"+indent).join([a for a in self.ArgumentsDefWrapperCL(flavour)])
- result += ",\n"+indent+"cl_uint num_queues, cl_command_queue *queues"
- result += ",\n"+indent+"cl_uint num_wait_events, const cl_event *wait_events, cl_event *events)"
- return result
-
- # As above, but now for the CBLAS wrapper
- def RoutineHeaderWrapperC(self, flavour, def_only, spaces):
- indent = " "*(spaces + self.Length())
- result = "void cblasX"+self.name+"("
- result += (",\n"+indent).join([a for a in self.ArgumentsDefWrapperC(flavour)])+")"
- return result
-
-# ==================================================================================================