summaryrefslogtreecommitdiff
path: root/scripts/generator
diff options
context:
space:
mode:
authorCNugteren <web@cedricnugteren.nl>2015-09-17 10:14:33 +0200
committerCNugteren <web@cedricnugteren.nl>2015-09-17 10:14:33 +0200
commit6307d2e5db1347112d992b2ef7a6cde9b3441389 (patch)
tree9c77189cf09b09a7bd59af2299047b890f737386 /scripts/generator
parent1c242100266e46cf97227c5506a1c32e51afbd00 (diff)
Added script to generate API interface and implementation automatically
Diffstat (limited to 'scripts/generator')
-rw-r--r--scripts/generator/datatype.py54
-rw-r--r--scripts/generator/generator.py234
-rw-r--r--scripts/generator/routine.py320
3 files changed, 608 insertions, 0 deletions
diff --git a/scripts/generator/datatype.py b/scripts/generator/datatype.py
new file mode 100644
index 00000000..cca3534d
--- /dev/null
+++ b/scripts/generator/datatype.py
@@ -0,0 +1,54 @@
+#!/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
+FLT = "float"
+DBL = "double"
+FLT2 = "float2"
+DBL2 = "double2"
+F2CL = "cl_float2"
+D2CL = "cl_double2"
+
+# Structure holding data-type and precision information
+class DataType():
+ def __init__(self, name, template, scalars, buffertype):
+ 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 # Only used for template types
+
+ # 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"
+
+# ==================================================================================================
diff --git a/scripts/generator/generator.py b/scripts/generator/generator.py
new file mode 100644
index 00000000..699cd9cf
--- /dev/null
+++ b/scripts/generator/generator.py
@@ -0,0 +1,234 @@
+#!/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 script automatically generates the bodies of the following files, creating the full CLBlast
+# API interface and implementation (C, C++, and clBLAS wrapper):
+# clblast.h
+# clblast.cc
+# clblast_c.h
+# clblast_c.cc
+# wrapper_clblas.h
+#
+# ==================================================================================================
+
+# System modules
+import sys
+import os.path
+
+# Local files
+from routine import Routine
+from datatype import DataType, FLT, DBL, FLT2, DBL2, F2CL, D2CL
+
+# ==================================================================================================
+
+# Regular data-types
+S = DataType("S", FLT, [FLT, FLT, FLT, FLT], FLT ) # single (32)
+D = DataType("D", DBL, [DBL, DBL, DBL, DBL], DBL ) # double (64)
+C = DataType("C", FLT2, [FLT2, FLT2, F2CL, F2CL], F2CL) # single-complex (3232)
+Z = DataType("Z", DBL2, [DBL2, DBL2, D2CL, D2CL], D2CL) # double-complex (6464)
+
+# Special cases
+Css = DataType("C", FLT, [FLT, FLT, FLT, FLT], FLT ) # As C, but with constants from S
+Zdd = DataType("Z", DBL, [DBL, DBL, DBL, DBL], DBL ) # As Z, but with constants from D
+Ccs = DataType("C", FLT2+","+FLT, [FLT2, FLT, F2CL, FLT], FLT2) # As C, but with one constant from S
+Zzd = DataType("Z", DBL2+","+DBL, [DBL2, DBL, D2CL, DBL], DBL2) # As Z, but with one constant from D
+
+# C++ template data-types
+T = DataType("typename T", "T", ["T", "T", "T", "T"], "T") # regular routine
+Tc = DataType("typename T", "std::complex<T>,T", ["T", "T", "T", "T"], "std::complex<T>") # for herk
+TU = DataType("typename T, typename U", "T,U", ["T", "U", "T", "U"], "T") # for her2k
+
+# ==================================================================================================
+
+# Populates a list of routines
+routines = [
+[ # Level 1
+ Routine(True, 1, "swap", T, [S,D,C,Z], ["n"], [], [], ["x","y"], [], False, "Swap two vectors"),
+ Routine(True, 1, "scal", T, [S,D,C,Z], ["n"], [], [], ["x"], ["alpha"], False, "Vector scaling"),
+ Routine(True, 1, "copy", T, [S,D,C,Z], ["n"], [], ["x"], ["y"], [], False, "Vector copy"),
+ Routine(True, 1, "axpy", T, [S,D,C,Z], ["n"], [], ["x"], ["y"], ["alpha"], False, "Vector-times-constant plus vector"),
+ Routine(True, 1, "dot", T, [S,D], ["n"], [], ["x","y"], ["dot"], [], True, "Dot product of two vectors"),
+ Routine(True, 1, "dotu", T, [C,Z], ["n"], [], ["x","y"], ["dot"], [], True, "Dot product of two complex vectors"),
+ Routine(True, 1, "dotc", T, [C,Z], ["n"], [], ["x","y"], ["dot"], [], True, "Dot product of two complex vectors, one conjugated"),
+],
+[ # Level 2
+ Routine(True, 2, "gemv", T, [S,D,C,Z], ["m","n"], ["layout","a_transpose"], ["a","x"], ["y"], ["alpha","beta"], False, "Generalized matrix-vector multiplication"),
+ Routine(True, 2, "hemv", T, [C,Z], ["n"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Hermitian matrix-vector multiplication"),
+ Routine(True, 2, "symv", T, [S,D], ["n"], ["layout","triangle"], ["a","x"], ["y"], ["alpha","beta"], False, "Symmetric matrix-vector multiplication"),
+],
+[ # Level 3
+ Routine(True, 3, "gemm", T, [S,D,C,Z], ["m","n","k"], ["layout","a_transpose","b_transpose"], ["a","b"], ["c"], ["alpha","beta"], False, "Generalized matrix-matrix multiplication"),
+ Routine(True, 3, "symm", T, [S,D,C,Z], ["m","n"], ["layout","side","triangle"], ["a","b"], ["c"], ["alpha","beta"], False, "Symmetric matrix-matrix multiplication"),
+ Routine(True, 3, "hemm", T, [C,Z], ["m","n"], ["layout","side","triangle"], ["a","b"], ["c"], ["alpha","beta"], False, "Hermitian matrix-matrix multiplication"),
+ Routine(True, 3, "syrk", T, [S,D,C,Z], ["n","k"], ["layout","triangle","a_transpose"], ["a"], ["c"], ["alpha","beta"], False, "Rank-K update of a symmetric matrix"),
+ Routine(True, 3, "herk", Tc, [Css,Zdd], ["n","k"], ["layout","triangle","a_transpose"], ["a"], ["c"], ["alpha","beta"], False, "Rank-K update of a hermitian matrix"),
+ Routine(True, 3, "syr2k", T, [S,D,C,Z], ["n","k"], ["layout","triangle","ab_transpose"], ["a","b"], ["c"], ["alpha","beta"], False, "Rank-2K update of a symmetric matrix"),
+ Routine(True, 3, "her2k", TU, [Ccs,Zzd], ["n","k"], ["layout","triangle","ab_transpose"], ["a","b"], ["c"], ["alpha","beta"], False, "Rank-2K update of a hermitian matrix"),
+ Routine(True, 3, "trmm", T, [S,D,C,Z], ["m","n"], ["layout","side","triangle","a_transpose","diagonal"], ["a"], ["b"], ["alpha"], False, "Triangular matrix-matrix multiplication"),
+]]
+
+# ==================================================================================================
+
+# Separators for the BLAS levels
+separators = ["""
+// =================================================================================================
+// BLAS level-1 (vector-vector) routines
+// =================================================================================================""",
+"""
+// =================================================================================================
+// BLAS level-2 (matrix-vector) routines
+// =================================================================================================""",
+"""
+// =================================================================================================
+// BLAS level-3 (matrix-matrix) routines
+// ================================================================================================="""]
+
+# ==================================================================================================
+
+# 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)+";\n"
+ return result
+
+# The C++ API implementation (.cc)
+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 event_cpp = Event(*event);\n"
+ result += " auto routine = X"+routine.name+"<"+routine.template.template+">(queue_cpp, event_cpp);\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 = " "*(23 + routine.Length() + len(flavour.template))
+ result += "template StatusCode "+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, 20)+";\n"
+ return result
+
+# The C API implementation (.cc)
+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:
+ result += "\n// Forwards the clBLAS calls for %s\n" % (routine.ShortNames())
+ if routine.NoScalars():
+ result += routine.RoutineHeaderWrapper(routine.template, True, 21)+";\n"
+ for flavour in routine.flavours:
+ indent = " "*(17 + routine.Length())
+ result += routine.RoutineHeaderWrapper(flavour, False, 21)+" {\n"
+ arguments = routine.ArgumentsWrapper(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, n);\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);"
+ result += "\n}\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.cc",
+ path_clblast+"/include/clblast_c.h",
+ path_clblast+"/src/clblast_c.cc",
+ path_clblast+"/test/wrapper_clblas.h",
+]
+header_lines = [84, 44, 80, 24, 22]
+footer_lines = [6, 3, 5, 2, 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()
+ header = original[:header_lines[i]]
+ footer = original[-footer_lines[i]:]
+
+ # Re-writes the body of the file
+ with open(files[i], "w") as f:
+ body = ""
+ for level in [1,2,3]:
+ 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])
+ f.write("".join(header))
+ f.write(body)
+ f.write("".join(footer))
+
+# ==================================================================================================
diff --git a/scripts/generator/routine.py b/scripts/generator/routine.py
new file mode 100644
index 00000000..b2c50e3d
--- /dev/null
+++ b/scripts/generator/routine.py
@@ -0,0 +1,320 @@
+#!/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.
+#
+# ==================================================================================================
+
+# 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 OptionToWrapper(x):
+ return {
+ 'layout': "clblasOrder",
+ 'a_transpose': "clblasTranspose",
+ 'b_transpose': "clblasTranspose",
+ 'ab_transpose': "clblasTranspose",
+ 'side': "clblasSide",
+ 'triangle': "clblasUplo",
+ 'diagonal': "clblasDiag",
+ }[x]
+
+# ==================================================================================================
+
+# Class holding routine-specific information (e.g. name, which arguments, which precisions)
+class Routine():
+ def __init__(self, implemented, level, name, template, flavours, sizes, options,
+ inputs, outputs, scalars, scratch, description):
+ self.implemented = implemented
+ 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
+
+ # 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])
+
+ # ==============================================================================================
+
+ # 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 ["dot"]) 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 ["dot"]) 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):
+ a = ["Buffer<"+self.template.buffertype+">("+name+"_buffer)"]
+ b = [name+"_offset"]
+ c = [name+"_"+self.Postfix(name)] if (name not in ["dot"]) else []
+ return [", ".join(a+b+c)]
+ return []
+
+ # As above but with a static cast for clBLAS wrapper
+ def BufferWrapper(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 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 ["dot"]) else []
+ return [", ".join(a+b+c)]
+ return []
+
+ # ==============================================================================================
+
+ # Retrieves the name of a scalar (alpha/beta)
+ def Scalar(self, name):
+ if (name in self.scalars):
+ return [name]
+ return []
+
+ # Retrieves the use of a scalar (alpha/beta)
+ def ScalarUse(self, name, flavour):
+ if ((name == "alpha") and (name in self.scalars)):
+ return [flavour.UseAlpha()]
+ elif ((name == "beta") and (name in self.scalars)):
+ return [flavour.UseBeta()]
+ return []
+
+ # Retrieves the use of a scalar (alpha/beta)
+ def ScalarUseWrapper(self, name, flavour):
+ if ((name == "alpha") and (name in self.scalars)):
+ return [flavour.UseAlphaCL()]
+ elif ((name == "beta") and (name in self.scalars)):
+ return [flavour.UseBetaCL()]
+ return []
+
+ # Retrieves the definition of a scalar (alpha/beta)
+ def ScalarDef(self, name, flavour):
+ if ((name == "alpha") and (name in self.scalars)):
+ return ["const "+flavour.alpha_cl+" "+name]
+ elif ((name == "beta") and (name in self.scalars)):
+ return ["const "+flavour.beta_cl+" "+name]
+ return []
+
+ # As above, but without 'cl_' prefix
+ def ScalarDefPlain(self, name, flavour):
+ if ((name == "alpha") and (name in self.scalars)):
+ return ["const "+flavour.alpha_cpp+" "+name]
+ elif ((name == "beta") and (name in self.scalars)):
+ return ["const "+flavour.beta_cpp+" "+name]
+ return []
+
+ # Retrieves the type of a scalar (alpha/beta)
+ def ScalarType(self, name, flavour):
+ if ((name == "alpha") and (name in self.scalars)):
+ return ["const "+flavour.alpha_cpp]
+ elif ((name == "beta") and (name in self.scalars)):
+ return ["const "+flavour.beta_cpp]
+ 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 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 OptionsDefWrapper(self):
+ if self.options:
+ definitions = ["const "+OptionToWrapper(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 a combination of all the argument names, with Claduc casts
+ def ArgumentsCladuc(self, flavour, indent):
+ return (self.Options() + self.Sizes() + self.BufferCladuc("dot") +
+ self.Scalar("alpha") +
+ self.BufferCladuc("a") + self.BufferCladuc("b") + self.BufferCladuc("x") +
+ self.Scalar("beta") + self.BufferCladuc("y") + self.BufferCladuc("c"))
+
+ # Retrieves a combination of all the argument names, with CLBlast casts
+ def ArgumentsCast(self, flavour, indent):
+ return (self.OptionsCast(indent) + self.Sizes() + self.Buffer("dot") +
+ self.ScalarUse("alpha", flavour) +
+ self.Buffer("a") + self.Buffer("b") + self.Buffer("x") +
+ self.ScalarUse("beta", flavour) + self.Buffer("y") + self.Buffer("c"))
+
+ # As above, but for the clBLAS wrapper
+ def ArgumentsWrapper(self, flavour):
+ return (self.Options() + self.Sizes() + self.BufferWrapper("dot") +
+ self.ScalarUseWrapper("alpha", flavour) +
+ self.BufferWrapper("a") + self.BufferWrapper("b") + self.BufferWrapper("x") +
+ self.ScalarUseWrapper("beta", flavour) + self.BufferWrapper("y") + self.BufferWrapper("c"))
+
+ # Retrieves a combination of all the argument definitions
+ def ArgumentsDef(self, flavour):
+ return (self.OptionsDef() + self.SizesDef() + self.BufferDef("dot") +
+ self.ScalarDef("alpha", flavour) +
+ self.BufferDef("a") + self.BufferDef("b") + self.BufferDef("x") +
+ self.ScalarDef("beta", flavour) + self.BufferDef("y") + self.BufferDef("c"))
+
+ # As above, but clBLAS wrapper plain datatypes
+ def ArgumentsDefWrapper(self, flavour):
+ return (self.OptionsDefWrapper() + self.SizesDef() + self.BufferDef("dot") +
+ self.ScalarDefPlain("alpha", flavour) +
+ self.BufferDef("a") + self.BufferDef("b") + self.BufferDef("x") +
+ self.ScalarDefPlain("beta", flavour) + self.BufferDef("y") + self.BufferDef("c"))
+
+ # Retrieves a combination of all the argument types
+ def ArgumentsType(self, flavour):
+ return (self.OptionsType() + self.SizesType() + self.BufferType("dot") +
+ self.ScalarType("alpha", flavour) +
+ self.BufferType("a") + self.BufferType("b") + self.BufferType("x") +
+ self.ScalarType("beta", flavour) + self.BufferType("y") + self.BufferType("c"))
+
+
+ # ==============================================================================================
+
+ # Retrieves the C++ templated definition for a routine
+ def RoutineHeaderCPP(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.ArgumentsDef(self.template)])
+ result += ",\n"+indent+"cl_command_queue* queue, cl_event* 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* queue, cl_event* event)"
+ return result
+
+ # As above, but now for C
+ def RoutineHeaderC(self, flavour, spaces):
+ indent = " "*(spaces + self.Length())
+ result = "StatusCode 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 RoutineHeaderWrapper(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.ArgumentsDefWrapper(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
+
+# ==================================================================================================