[clblas] 35/54: Changing AutoGemm scripts to work with both python2 and python3

Ghislain Vaillant ghisvail-guest at moszumanska.debian.org
Thu Jan 14 20:07:36 UTC 2016


This is an automated email from the git hooks/post-receive script.

ghisvail-guest pushed a commit to branch debian/sid
in repository clblas.

commit 1983aafaf090a8198dbde432d29f42f13bfe6e52
Author: Pavan Yalamanchili <pavan at arrayfire.com>
Date:   Tue Dec 15 19:14:29 2015 -0500

    Changing AutoGemm scripts to work with both python2 and python3
---
 src/library/blas/AutoGemm/AutoGemm.py            |  5 ++-
 src/library/blas/AutoGemm/AutoGemmParameters.py  |  8 ++---
 src/library/blas/AutoGemm/Includes.py            |  4 +--
 src/library/blas/AutoGemm/KernelOpenCL.py        | 23 +++++++------
 src/library/blas/AutoGemm/KernelParameters.py    | 42 ++++++++++++++++--------
 src/library/blas/AutoGemm/KernelSelection.py     | 25 +++++++-------
 src/library/blas/AutoGemm/KernelsToPreCompile.py |  7 ++--
 7 files changed, 63 insertions(+), 51 deletions(-)

diff --git a/src/library/blas/AutoGemm/AutoGemm.py b/src/library/blas/AutoGemm/AutoGemm.py
index 936c001..a8542cb 100644
--- a/src/library/blas/AutoGemm/AutoGemm.py
+++ b/src/library/blas/AutoGemm/AutoGemm.py
@@ -38,13 +38,12 @@ if __name__ == "__main__":
   if args.output:
     Common.setOutputPath(args.output)
   else:
-    print "AutoGemm.py: Warning: No output path specified; default is working directory."
+    print("AutoGemm.py: Warning: No output path specified; default is working directory.")
 
-  print "AutoGemm.py: using OpenCL " + args.clCompilerVersion + " compiler"
+  print("AutoGemm.py: using OpenCL " + args.clCompilerVersion + " compiler")
   Common.setClCompilerVersion(args.clCompilerVersion)
   AutoGemmParameters.setArchitecture(args.architecture)
 
   KernelOpenCL.writeOpenCLKernels()
   KernelSelection.writeKernelSelection()
   Includes.writeIncludes()
-
diff --git a/src/library/blas/AutoGemm/AutoGemmParameters.py b/src/library/blas/AutoGemm/AutoGemmParameters.py
index ee50211..081b1d7 100644
--- a/src/library/blas/AutoGemm/AutoGemmParameters.py
+++ b/src/library/blas/AutoGemm/AutoGemmParameters.py
@@ -127,20 +127,20 @@ def getTilesForPrecision(precision):
     validTiles = sizeData[2]
     # add valid tiles
     for tileParams in validTiles:
-      #print tileParams
+      #print(tileParams)
       tile.workGroupNumRows = tileParams[0]
       tile.workGroupNumCols = tileParams[1]
       tile.microTileNumRows = tileParams[2]
       tile.microTileNumCols = tileParams[3]
       tile.macroTileNumRows = tile.workGroupNumRows*tile.microTileNumRows
       tile.macroTileNumCols = tile.workGroupNumCols*tile.microTileNumCols
-      #print tile.getName()
+      #print(tile.getName())
       for unroll in unrolls[precision]:
         tile.unroll = unroll
         if tile.isValid():
           tiles.append( copy.copy(tile) )
         else:
-          print tile.getName() + " - SKIPPING - "
+          print(tile.getName() + " - SKIPPING - ")
 
     # add fallback tile
     tile.workGroupNumRows = fallbackTile[0]
@@ -154,7 +154,7 @@ def getTilesForPrecision(precision):
       if tile.isValid():
         tiles.append( copy.copy(tile) )
       else:
-        print tile.getName() + " - SKIPPING - "
+        print(tile.getName() + " - SKIPPING - ")
 
   setTiles = set(tiles)
   tiles = list( setTiles )
diff --git a/src/library/blas/AutoGemm/Includes.py b/src/library/blas/AutoGemm/Includes.py
index d525f08..3c8435f 100644
--- a/src/library/blas/AutoGemm/Includes.py
+++ b/src/library/blas/AutoGemm/Includes.py
@@ -425,7 +425,7 @@ class CppKernelEnumeration:
 # Write Includes
 ################################################################################
 def writeIncludes():
-  print "AutoGemm.py: Generating include files."
+  print("AutoGemm.py: Generating include files.")
   if not os.path.exists( Common.getIncludePath() ):
     os.makedirs( Common.getIncludePath() )
 
@@ -490,5 +490,5 @@ if __name__ == "__main__":
   if len(sys.argv) == 2:
     Common.setOutputPath(sys.argv[1])
   else:
-    print "Warning: No output path specified; default is working directory."
+    print("Warning: No output path specified; default is working directory.")
   writeIncludes()
diff --git a/src/library/blas/AutoGemm/KernelOpenCL.py b/src/library/blas/AutoGemm/KernelOpenCL.py
index 7b48746..ccf266f 100644
--- a/src/library/blas/AutoGemm/KernelOpenCL.py
+++ b/src/library/blas/AutoGemm/KernelOpenCL.py
@@ -175,14 +175,14 @@ def makeOpenCLKernelString(kernel):
   kStr += endLine
   kStr += "/* %dx%d micro-tile */%s" % (kernel.microTileNumRows, kernel.microTileNumCols, endLine)
   kStr += "#define MICRO_TILE \\\\" + endLine
-  for a in range(0, kernel.microTileNumRows):
+  for a in range(0, int(kernel.microTileNumRows)):
     kStr += "  rA[%d] = localA[offA + %d*WG_NUM_ROWS]; \\\\%s" % (a, a, endLine)
-  for b in range(0, kernel.microTileNumCols):
+  for b in range(0, int(kernel.microTileNumCols)):
     kStr += "  rB[%d] = localB[offB + %d*WG_NUM_COLS]; \\\\%s" % (b, b, endLine)
   kStr += "  offA += (MACRO_TILE_NUM_ROWS+LOCAL_COL_PAD); \\\\" + endLine
   kStr += "  offB += (MACRO_TILE_NUM_COLS+LOCAL_ROW_PAD); \\\\" + endLine
-  for a in range(0, kernel.microTileNumRows):
-    for b in range(0, kernel.microTileNumCols):
+  for a in range(0, int(kernel.microTileNumRows)):
+    for b in range(0, int(kernel.microTileNumCols)):
       kStr += "  TYPE_MAD(rA[%d],rB[%d],rC[%d][%d]); \\\\%s" % (a, b, a, b, endLine)
   kStr += "  mem_fence(CLK_LOCAL_MEM_FENCE);" + endLine
   kStr += endLine
@@ -372,7 +372,7 @@ def makeOpenCLKernelString(kernel):
     zeroString = "(double2)(0.0, 0.0)"
   else:
     zeroString = "0.0"
-  for a in range(0, numALoads):
+  for a in range(0, int(numALoads)):
     kStr += "    lA[ %d*localAStride ] = " % a
     if kernel.isRowKernel():
       kStr += "( globalARow(%d) >= M) ? %s : " % ( a, zeroString )
@@ -385,7 +385,7 @@ def makeOpenCLKernelString(kernel):
     kStr += "A[ GET_GLOBAL_INDEX_A( globalARow(%d), globalACol(%d) ) ];%s" % (numALoads, numALoads, endLine)
     kStr += "    }" + endLine
 
-  for b in range(0, numBLoads):
+  for b in range(0, int(numBLoads)):
     kStr += "    lB[ %d*localBStride ] = " % b
     if kernel.isColKernel():
       kStr += "( globalBCol(%d) >= N) ? %s : " % ( b, zeroString )
@@ -406,7 +406,7 @@ def makeOpenCLKernelString(kernel):
   # do mads
   kStr += endLine
   kStr += "    /* do mads */" + endLine
-  for u in range(0, kernel.unroll):
+  for u in range(0, int(kernel.unroll)):
     kStr += "    MICRO_TILE" + endLine
 
   ####################################
@@ -444,8 +444,8 @@ def makeOpenCLKernelString(kernel):
   if kernel.precision=="z":
     kStr += "  double type_mad_tmp;" + endLine
 
-  for a in range(0, kernel.microTileNumRows):
-    for b in range(0, kernel.microTileNumCols):
+  for a in range(0, int(kernel.microTileNumRows)):
+    for b in range(0, int(kernel.microTileNumCols)):
       if kernel.isRowKernel():
         kStr += "  if (globalCRow+%d*WG_NUM_ROWS < M)" % a
       if kernel.isColKernel():
@@ -541,7 +541,7 @@ def writeOpenCLKernels():
               cornerKernel.macroTileNumCols = 1
               writeOpenCLKernelToFile(cornerKernel)
               numKernels += 4
-  print "AutoGemm.py: generated %d kernels" % numKernels
+  print("AutoGemm.py: generated %d kernels" % numKernels)
 
 
 
@@ -590,5 +590,4 @@ if __name__ == "__main__":
 
   kernelName = kernel.getName()
   kernelFileName = Common.getKernelSourcePath() + kernelName +"_src.cpp"
-  print "kernel \"%s\" written to %s" % (kernelName, kernelFileName)
-
+  print("kernel \"%s\" written to %s" % (kernelName, kernelFileName))
diff --git a/src/library/blas/AutoGemm/KernelParameters.py b/src/library/blas/AutoGemm/KernelParameters.py
index 058ae19..b797d96 100644
--- a/src/library/blas/AutoGemm/KernelParameters.py
+++ b/src/library/blas/AutoGemm/KernelParameters.py
@@ -44,15 +44,32 @@ class TileParameters:
   def __repr__(self):
     return self.getName()
 
+  def __lt__(self, other):
+    return self.getName() < other.getName()
+
+  def __cmp__(self, other):
+      # Python3 should ignore this method
+      # This is needed for python2 for proper comparison
+    try:
+      return cmp(self.getName(), other.getName())
+    except:
+      self_name = self.getName()
+      other_name = other.getName()
+      if (self_name < other_name):
+        return -1
+      elif (self_name == other_name):
+        return 0
+      else:
+        return 1
 
   def printAttributes(self):
-    print "workGroupNumRows = %d" % self.workGroupNumRows
-    print "workGroupNumCols = %d" % self.workGroupNumCols
-    print "microTileNumRows = %d" % self.microTileNumRows
-    print "microTileNumCols = %d" % self.microTileNumCols
-    print "macroTileNumRows = %d" % self.macroTileNumRows
-    print "macroTileNumCols = %d" % self.macroTileNumCols
-    print "unroll           = %d" % self.unroll
+    print("workGroupNumRows = %d" % self.workGroupNumRows)
+    print("workGroupNumCols = %d" % self.workGroupNumCols)
+    print("microTileNumRows = %d" % self.microTileNumRows)
+    print("microTileNumCols = %d" % self.microTileNumCols)
+    print("macroTileNumRows = %d" % self.macroTileNumRows)
+    print("macroTileNumCols = %d" % self.macroTileNumCols)
+    print("unroll           = %d" % self.unroll)
 
   ##############################################################################
   # Tile - get Multiples
@@ -188,11 +205,11 @@ class NonTileParameters:
     self.beta = -1       # 0, 1
 
   def printAttributes(self):
-    print "precision = " + self.precision
-    print "order     = " + self.order
-    print "transA    = " + self.transA
-    print "transB    = " + self.transB
-    print "beta      = %d" % self.beta
+    print("precision = " + self.precision)
+    print("order     = " + self.order)
+    print("transA    = " + self.transA)
+    print("transB    = " + self.transB)
+    print("beta      = %d" % self.beta)
 
   ##############################################################################
   # NonTile - get Name
@@ -250,4 +267,3 @@ class KernelParameters( NonTileParameters, TileParameters ):
   def getCornerName(self):
     return NonTileParameters.getName(self) \
         + "_" + TileParameters.getCornerName(self)
-
diff --git a/src/library/blas/AutoGemm/KernelSelection.py b/src/library/blas/AutoGemm/KernelSelection.py
index 659ae67..f21ce2e 100644
--- a/src/library/blas/AutoGemm/KernelSelection.py
+++ b/src/library/blas/AutoGemm/KernelSelection.py
@@ -17,10 +17,10 @@ def tileInRange( tileMin, tileMax, rangeMin, rangeMax):
     valid = True
   else:
     valid = False
-  #print "Range [%4ux%4u]: [%4u,%4u] is %s b/c" \
-  #    % (rangeMin, rangeMax, tileMin, tileMax, "valid" if valid else "INVALID" )
-  #print "if ( %i<0 or (%u >= %u and %u>0) and %u <= %u" \
-  #    %( tileMax, tileMax, rangeMax, rangeMax, tileMin, rangeMin )
+  #print("Range [%4ux%4u]: [%4u,%4u] is %s b/c" \
+  #    % (rangeMin, rangeMax, tileMin, tileMax, "valid" if valid else "INVALID" ))
+  #print("if ( %i<0 or (%u >= %u and %u>0) and %u <= %u" \
+  #    %( tileMax, tileMax, rangeMax, rangeMax, tileMin, rangeMin ))
   return valid
 
 
@@ -159,7 +159,7 @@ class KernelSelection:
       ####################################
       # order
       for order in orderList:
-        #print precision + "gemm" + "_" + order
+        #print(precision + "gemm" + "_" + order)
         kernel.order = order
         self.logic += indent(1) + "if (order == " + order + ") {\n"
         transList = transDict[precision]
@@ -167,7 +167,7 @@ class KernelSelection:
         ####################################
         # transA
         for transA in transList:
-          #print precision + "gemm" + "_" + order + "_" + transA
+          #print(precision + "gemm" + "_" + order + "_" + transA)
           kernel.transA = transA
           self.logic += indent(2) + "if (transA == "
           if transA == "N":
@@ -194,7 +194,7 @@ class KernelSelection:
             ####################################
             # beta
             for beta in betaList:
-              #print precision + "gemm" + "_" + order + "_" + transA + "_" + transB + "_B" + str(beta)
+              #print(precision + "gemm" + "_" + order + "_" + transA + "_" + transB + "_B" + str(beta))
               kernel.beta = beta
               self.logic += indent(4) + "if ( "
               if beta == 0:
@@ -212,7 +212,7 @@ class KernelSelection:
                 fallbackTile = sizeEvent[1]
                 validTiles = sizeEvent[2]
                 self.logic += indent(5)+"if ( M*N >= "+str(sizeMin)+"*"+str(sizeMin) + ") {\n"
-                #print precision + "gemm" + "_" + order + "_" + transA + "_" + transB + "_B" + str(beta) + "_" + str(sizeMin) + "->" + str(sizeMax)
+                #print(precision + "gemm" + "_" + order + "_" + transA + "_" + transB + "_B" + str(beta) + "_" + str(sizeMin) + "->" + str(sizeMax))
 
                 ####################################
                 # valid tiles
@@ -234,7 +234,7 @@ class KernelSelection:
                 ####################################
                 # fallback tile - TODO all tiles begin added
                 self.logic += indent(6)+"// fallback tile\n"
-                #print "\nFallback[%i, %i]"%(sizeMin, sizeMax)
+                #print("\nFallback[%i, %i]"%(sizeMin, sizeMax))
                 kernel.workGroupNumRows = fallbackTile[0]
                 kernel.workGroupNumCols = fallbackTile[1]
                 kernel.microTileNumRows = fallbackTile[2]
@@ -387,7 +387,7 @@ class KernelSelectionSpecific:
     self.betaInitialized = False
 
   def newPrecision(self, precision ):
-    #print "KernelSelectionSpecific: " + precision + "gemm"
+    #print("KernelSelectionSpecific: " + precision + "gemm")
     if self.precisionInitialized:
       self.logic += self.zeroIndent+self.tab+self.tab + "}\n" # 2 tabs
       self.logic += self.zeroIndent+self.tab + "}\n" # 1 tab
@@ -621,7 +621,7 @@ class KernelSelectionSpecific:
 # Main
 ################################################################################
 def writeKernelSelection():
-  print "AutoGemm.py: Generating kernel selection."
+  print("AutoGemm.py: Generating kernel selection.")
   if not os.path.exists( Common.getIncludePath() ):
     os.makedirs( Common.getIncludePath() )
 
@@ -680,5 +680,4 @@ if __name__ == "__main__":
     AutoGemmParameters.setArchitecture(sys.argv[2])
     writeKernelSelection()
   else:
-    print "USAGE: python KernelSelection.py output_path architecture"
-
+    print("USAGE: python KernelSelection.py output_path architecture")
diff --git a/src/library/blas/AutoGemm/KernelsToPreCompile.py b/src/library/blas/AutoGemm/KernelsToPreCompile.py
index ff24c50..4495b5b 100644
--- a/src/library/blas/AutoGemm/KernelsToPreCompile.py
+++ b/src/library/blas/AutoGemm/KernelsToPreCompile.py
@@ -9,7 +9,7 @@ import Common
 ################################################################################
 
 def writeOfflineCompilation(args):
-  print "AutoGemm.py: Generating list of kernels to pre-compile."
+  print("AutoGemm.py: Generating list of kernels to pre-compile.")
   if not os.path.exists( Common.getIncludePath() ):
     os.makedirs( Common.getIncludePath() )
 
@@ -57,7 +57,7 @@ def writeOfflineCompilation(args):
   ocFile.write( fileStr )
   ocFile.close()
   count *= 4
-  print "AutoGemm.py: %u kernels will be pre-compiled." % count
+  print("AutoGemm.py: %u kernels will be pre-compiled." % count)
 
 
 ################################################################################
@@ -76,7 +76,7 @@ if __name__ == "__main__":
   if args.output:
     Common.setOutputPath(args.output)
   else:
-    print "Warning: No output path specified; default is working directory."
+    print("Warning: No output path specified; default is working directory.")
 
   # write offline compilation header
   if args.precisions is None:
@@ -88,4 +88,3 @@ if __name__ == "__main__":
   if args.betas is None:
     args.betas = []
   writeOfflineCompilation(args)
-

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/clblas.git



More information about the debian-science-commits mailing list