diff options
author | Cedric Nugteren <web@cedricnugteren.nl> | 2016-06-28 22:32:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-28 22:32:25 +0200 |
commit | 7c13bacf129291e3e295ecb6e833788477085fa0 (patch) | |
tree | d114eeca418444d0b1c70cc9cce983de041235c9 /scripts/generator/routine.py | |
parent | 181eb20bbf15cf11baaf6112b6965050c49dd543 (diff) | |
parent | 577f0ee1179014ece853af39d6f0ff0c87316eb3 (diff) |
Merge pull request #70 from CNugteren/development
Update to version 0.8.0
Diffstat (limited to 'scripts/generator/routine.py')
-rw-r--r-- | scripts/generator/routine.py | 97 |
1 files changed, 82 insertions, 15 deletions
diff --git a/scripts/generator/routine.py b/scripts/generator/routine.py index e5059c61..00883776 100644 --- a/scripts/generator/routine.py +++ b/scripts/generator/routine.py @@ -58,9 +58,9 @@ def OptionToDoc(x): '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 horizontal position of the triangular matrix, either `Side::kLeft` (141) or `Side::kRight` (142).", - 'triangle': "The vertical position of the triangular matrix, either `Triangle::kUpper` (121) or `Triangle::kLower` (122).", - 'diagonal': "The property of the diagonal matrix, either `Diagonal::kNonUnit` (131) for a non-unit values on the diagonal or `Diagonal::kUnit` (132) for a unit values on the diagonal.", + '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] # ================================================================================================== @@ -99,6 +99,18 @@ class Routine(): 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"] @@ -119,6 +131,12 @@ class Routine(): 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": @@ -146,6 +164,17 @@ class Routine(): 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 "" @@ -156,6 +185,16 @@ class Routine(): 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 "" @@ -179,7 +218,7 @@ class Routine(): # 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"] + a = [name+"_buffer()"] b = [name+"_offset"] c = [] if (name in ["x","y"]): @@ -226,7 +265,7 @@ class Routine(): 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+"."] if (name not in self.BuffersWithoutLdInc()) else [] + 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 [] @@ -238,6 +277,12 @@ class Routine(): 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: @@ -248,7 +293,7 @@ class Routine(): return [name] return [] - # Retrieves the use of a scalar (alpha/beta) + # As above, but for the clBLAS wrapper def ScalarUseWrapper(self, name, flavour): if name in self.scalars: if name == "alpha": @@ -258,7 +303,7 @@ class Routine(): return [name] return [] - # Retrieves the use of a scalar for CBLAS (alpha/beta) + # As above, but for the CBLAS wrapper def ScalarUseWrapperC(self, name, flavour): if name in self.scalars: if flavour.IsComplex(name): @@ -321,7 +366,7 @@ class Routine(): # Retrieves the documentation of the sizes def SizesDoc(self): if self.sizes: - definitions = ["`const size_t "+s+"`: Integer size argument." for s in self.sizes] + definitions = ["`const size_t "+s+"`: Integer size argument. This value must be positive." for s in self.sizes] return definitions return [] @@ -371,12 +416,34 @@ class Routine(): # Retrieves the documentation of the options def OptionsDoc(self): if self.options: - definitions = ["`const "+OptionToCLBlast(o)+"`: "+OptionToDoc(o) for o in 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() + @@ -388,7 +455,7 @@ class Routine(): list(chain(*[self.BufferCladuc(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 CLBlast casts + # 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()])) + @@ -434,12 +501,12 @@ class Routine(): # As above, but clBLAS wrapper plain datatypes def ArgumentsDefWrapperCL(self, flavour): return (self.OptionsDefWrapperCL() + self.SizesDef() + - list(chain(*[self.BufferDef(b) for b in self.ScalarBuffersFirst()])) + + list(chain(*[self.BufferDefWrapperCL(b, flavour) for b in self.ScalarBuffersFirst()])) + self.ScalarDefPlain("alpha", flavour) + - list(chain(*[self.BufferDef(b) for b in self.BuffersFirst()])) + + list(chain(*[self.BufferDefWrapperCL(b, flavour) for b in self.BuffersFirst()])) + self.ScalarDefPlain("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.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 @@ -480,7 +547,7 @@ class Routine(): # Retrieves a list of routine requirements for documentation def RequirementsDoc(self): - return [] + return self.requirements # ============================================================================================== |