コード例 #1
0
ファイル: Includes.py プロジェクト: ache7/clBLAS
def writeIncludes():
  print "AutoGemm.py: Generating include files."
  if not os.path.exists( Common.getIncludePath() ):
    os.makedirs( Common.getIncludePath() )

  kernelSourceIncludes     = KernelSourceIncludes()
  kernelBinaryIncludes     = KernelBinaryIncludes()
  clKernelIncludes         = ClKernelIncludes()
  kernelSourceBuildOptions = KernelSourceBuildOptions()
  kernelBinaryBuildOptions = KernelBinaryBuildOptions()
  cppKernelEnumeration     = CppKernelEnumeration()


  # for each precision
  kernel = KernelParameters.KernelParameters()
  for precision in AutoGemmParameters.precisions:
    kernel.precision = precision
    cppKernelEnumeration.newPrecision(precision)

    # valid tiles for this precision
    tiles = AutoGemmParameters.getTilesForPrecision(precision)

    # add tiles for this precision to Cpp
    for tile in tiles:
      cppKernelEnumeration.addTile(tile)

    # for non tile parameters
    for order in AutoGemmParameters.orders:
      kernel.order = order
      for transA in AutoGemmParameters.transposes[precision]:
        kernel.transA = transA
        for transB in AutoGemmParameters.transposes[precision]:
          kernel.transB = transB
          for beta in AutoGemmParameters.betas:
            kernel.beta = beta

            # add this nonTile combo for this precision to Cpp
            cppKernelEnumeration.addNonTile(kernel)

            # for tile parameters
            for tile in tiles:
              kernel.useTile(tile)
              kernelSourceIncludes.addKernel(kernel)
              kernelBinaryIncludes.addKernel(kernel)
              kernelSourceBuildOptions.addKernel(kernel)
              kernelBinaryBuildOptions.addKernel(kernel)
              clKernelIncludes.addKernel(kernel)
              cppKernelEnumeration.addKernel(kernel)

  # save written files
  kernelSourceIncludes.writeToFile()
  kernelBinaryIncludes.writeToFile()
  clKernelIncludes.writeToFile()
  kernelSourceBuildOptions.writeToFile()
  kernelBinaryBuildOptions.writeToFile()
  cppKernelEnumeration.writeToFile()
コード例 #2
0
ファイル: KernelsToPreCompile.py プロジェクト: zwets/clBLAS
def writeOfflineCompilation(args):
    print("AutoGemm.py: Generating list of kernels to pre-compile.")
    if not os.path.exists(Common.getIncludePath()):
        os.makedirs(Common.getIncludePath())

    ocFileName = Common.getIncludePath() + "AutoGemmKernelsToPreCompile.h"
    ocFile = open(ocFileName, "w")
    ocFile.write(Common.getAutoGemmHeader())

    fileStr = "\n/*precision, order, transA, transB, beta, tileNumRows, tileNumCols, unroll*/\n"
    fileStr += "\nunsigned int gemmPreCompile[][8] = {\n"

    count = 0
    for precision in args.precisions:
        ocFile.write(fileStr)
        fileStr = ""
        validTiles = AutoGemmParameters.getTilesForPrecision(precision)
        for order in args.orders:
            for transpose in args.transposes:
                transA = transpose[0]
                transB = transpose[1]
                if (transA == "C" or transB == "C") and (precision == "s"
                                                         or precision == "d"):
                    # real precision doesn't have conjugate transpose
                    continue
                for beta in args.betas:
                    for tile in validTiles:
                        # print combination
                        kernelStr = "  { %1u, %1u, %1u, %1u, %1u, %3u, %3u, %2u },\n" \
                            % (
                            Common.precisionInt[precision],
                            Common.orderInt[order],
                            Common.transposeInt[transA],
                            Common.transposeInt[transB],
                            beta,
                            tile.macroTileNumRows,
                            tile.macroTileNumCols,
                            tile.unroll
                            )
                        fileStr += kernelStr
                        #print kernelStr
                        count += 1
    if count is 0:
        fileStr += "  { %1u, %1u, %1u, %1u, %1u, %3u, %3u, %2u },\n" \
            % ( 0, 0, 0, 0, 0, 0, 0, 0 )
    fileStr += "};\n"
    fileStr += "unsigned int gemmPreCompileNum = " + str(count) + ";\n"
    ocFile.write(fileStr)
    ocFile.close()
    count *= 4
    print("AutoGemm.py: %u kernels will be pre-compiled." % count)
コード例 #3
0
def writeOfflineCompilation(args):
  print("AutoGemm.py: Generating list of kernels to pre-compile.")
  if not os.path.exists( Common.getIncludePath() ):
    os.makedirs( Common.getIncludePath() )

  ocFileName = Common.getIncludePath() + "AutoGemmKernelsToPreCompile.h"
  ocFile = open(ocFileName, "w")
  ocFile.write( Common.getAutoGemmHeader() )

  fileStr = "\n/*precision, order, transA, transB, beta, tileNumRows, tileNumCols, unroll*/\n"
  fileStr += "\nunsigned int gemmPreCompile[][8] = {\n"

  count = 0
  for precision in args.precisions:
    ocFile.write( fileStr )
    fileStr = ""
    validTiles = AutoGemmParameters.getTilesForPrecision(precision)
    for order in args.orders:
      for transpose in args.transposes:
        transA = transpose[0]
        transB = transpose[1]
        if (transA=="C" or transB=="C") and (precision=="s" or precision=="d"):
          # real precision doesn't have conjugate transpose
          continue
        for beta in args.betas:
          for tile in validTiles:
            # print combination
            kernelStr = "  { %1u, %1u, %1u, %1u, %1u, %3u, %3u, %2u },\n" \
                % (
                Common.precisionInt[precision],
                Common.orderInt[order],
                Common.transposeInt[transA],
                Common.transposeInt[transB],
                beta,
                tile.macroTileNumRows,
                tile.macroTileNumCols,
                tile.unroll
                )
            fileStr += kernelStr
            #print kernelStr
            count+=1
  if count is 0:
    fileStr += "  { %1u, %1u, %1u, %1u, %1u, %3u, %3u, %2u },\n" \
        % ( 0, 0, 0, 0, 0, 0, 0, 0 )
  fileStr += "};\n"
  fileStr += "unsigned int gemmPreCompileNum = " + str(count) + ";\n"
  ocFile.write( fileStr )
  ocFile.close()
  count *= 4
  print("AutoGemm.py: %u kernels will be pre-compiled." % count)
コード例 #4
0
def writeKernelSelection():
    print("AutoGemm.py: Generating kernel selection.")
    if not os.path.exists(Common.getIncludePath()):
        os.makedirs(Common.getIncludePath())

    ########################################
    # kernel selection specific
    kss = KernelSelectionSpecific()

    # for each precision
    kernel = KernelParameters.KernelParameters()
    for precision in AutoGemmParameters.precisions:
        kernel.precision = precision
        kss.newPrecision(precision)

        # valid tiles for this precision
        tiles = AutoGemmParameters.getTilesForPrecision(precision)

        # for non tile parameters
        for order in AutoGemmParameters.orders:
            kernel.order = order
            kss.newOrder(order)
            for transA in AutoGemmParameters.transposes[precision]:
                kernel.transA = transA
                for transB in AutoGemmParameters.transposes[precision]:
                    kernel.transB = transB
                    kss.newTrans(transA, transB)
                    for beta in AutoGemmParameters.betas:
                        kernel.beta = beta
                        kss.newBeta(beta)

                        # for tile parameters
                        for tile in tiles:
                            kernel.useTile(tile)
                            kss.newKernel(kernel)

    kss.writeToFile()

    ########################################
    # kernel selection
    ks = KernelSelection( \
        AutoGemmParameters.precisions, \
        AutoGemmParameters.orders, \
        AutoGemmParameters.transposes, \
        AutoGemmParameters.betas, \
        AutoGemmParameters.unrolls, \
        AutoGemmParameters.kernelSelectionData )
    ks.writeToFile()
コード例 #5
0
def writeKernelSelection():
  print("AutoGemm.py: Generating kernel selection.")
  if not os.path.exists( Common.getIncludePath() ):
    os.makedirs( Common.getIncludePath() )

  ########################################
  # kernel selection specific
  kss = KernelSelectionSpecific()

  # for each precision
  kernel = KernelParameters.KernelParameters()
  for precision in AutoGemmParameters.precisions:
    kernel.precision = precision
    kss.newPrecision(precision)

    # valid tiles for this precision
    tiles = AutoGemmParameters.getTilesForPrecision(precision)

    # for non tile parameters
    for order in AutoGemmParameters.orders:
      kernel.order = order
      kss.newOrder(order)
      for transA in AutoGemmParameters.transposes[precision]:
        kernel.transA = transA
        for transB in AutoGemmParameters.transposes[precision]:
          kernel.transB = transB
          kss.newTrans(transA, transB)
          for beta in AutoGemmParameters.betas:
            kernel.beta = beta
            kss.newBeta(beta)

            # for tile parameters
            for tile in tiles:
              kernel.useTile(tile)
              kss.newKernel(kernel)

  kss.writeToFile()

  ########################################
  # kernel selection
  ks = KernelSelection( \
      AutoGemmParameters.precisions, \
      AutoGemmParameters.orders, \
      AutoGemmParameters.transposes, \
      AutoGemmParameters.betas, \
      AutoGemmParameters.unrolls, \
      AutoGemmParameters.kernelSelectionData )
  ks.writeToFile()
コード例 #6
0
ファイル: KernelOpenCL.py プロジェクト: AndreasMiller/clBLAS
def writeOpenCLKernels():

  if not os.path.exists( Common.getKernelSourcePath() ):
    os.makedirs( Common.getKernelSourcePath() )
  if not os.path.exists( Common.getKernelBinaryPath() ):
    os.makedirs( Common.getKernelBinaryPath() )

  numKernels = 0
  # for each precision
  kernel = KernelParameters.KernelParameters()
  for precision in AutoGemmParameters.precisions:
    kernel.precision = precision

    # valid tiles for this precision
    tiles = AutoGemmParameters.getTilesForPrecision(precision)

    # for non tile parameters
    for order in AutoGemmParameters.orders:
      kernel.order = order
      for transA in AutoGemmParameters.transposes[precision]:
        kernel.transA = transA
        for transB in AutoGemmParameters.transposes[precision]:
          kernel.transB = transB
          for beta in AutoGemmParameters.betas:
            kernel.beta = beta

            # for tile parameters
            for tile in tiles:
              # tile kernel
              kernel.useTile(tile)
              writeOpenCLKernelToFile(kernel)
              # row kernel
              rowKernel = copy.copy(kernel)
              rowKernel.macroTileNumRows = 1
              writeOpenCLKernelToFile(rowKernel)
              # col kernel
              colKernel = copy.copy(kernel)
              colKernel.macroTileNumCols = 1
              writeOpenCLKernelToFile(colKernel)
              # corner kernel
              cornerKernel = copy.copy(kernel)
              cornerKernel.macroTileNumRows = 1
              cornerKernel.macroTileNumCols = 1
              writeOpenCLKernelToFile(cornerKernel)
              numKernels += 4
  print("AutoGemm.py: generated %d kernels" % numKernels)
コード例 #7
0
def writeOpenCLKernels():

    if not os.path.exists(Common.getKernelSourcePath()):
        os.makedirs(Common.getKernelSourcePath())
    if not os.path.exists(Common.getKernelBinaryPath()):
        os.makedirs(Common.getKernelBinaryPath())

    numKernels = 0
    # for each precision
    kernel = KernelParameters.KernelParameters()
    for precision in AutoGemmParameters.precisions:
        kernel.precision = precision

        # valid tiles for this precision
        tiles = AutoGemmParameters.getTilesForPrecision(precision)

        # for non tile parameters
        for order in AutoGemmParameters.orders:
            kernel.order = order
            for transA in AutoGemmParameters.transposes[precision]:
                kernel.transA = transA
                for transB in AutoGemmParameters.transposes[precision]:
                    kernel.transB = transB
                    for beta in AutoGemmParameters.betas:
                        kernel.beta = beta

                        # for tile parameters
                        for tile in tiles:
                            # tile kernel
                            kernel.useTile(tile)
                            writeOpenCLKernelToFile(kernel)
                            # row kernel
                            rowKernel = copy.copy(kernel)
                            rowKernel.macroTileNumRows = 1
                            writeOpenCLKernelToFile(rowKernel)
                            # col kernel
                            colKernel = copy.copy(kernel)
                            colKernel.macroTileNumCols = 1
                            writeOpenCLKernelToFile(colKernel)
                            # corner kernel
                            cornerKernel = copy.copy(kernel)
                            cornerKernel.macroTileNumRows = 1
                            cornerKernel.macroTileNumCols = 1
                            writeOpenCLKernelToFile(cornerKernel)
                            numKernels += 4
    print("AutoGemm.py: generated %d kernels" % numKernels)
コード例 #8
0
ファイル: KernelsToPreCompile.py プロジェクト: zwets/clBLAS
    ap.add_argument("--output-path", dest="output")
    ap.add_argument("--precisions",
                    dest="precisions",
                    action="store",
                    nargs="+",
                    choices=AutoGemmParameters.precisions)
    ap.add_argument("--orders",
                    dest="orders",
                    action="store",
                    nargs="+",
                    choices=AutoGemmParameters.orders)
    ap.add_argument("--transposes",
                    dest="transposes",
                    action="store",
                    nargs="+",
                    choices=AutoGemmParameters.getTransposeChoices())
    ap.add_argument("--betas",
                    dest="betas",
                    action="store",
                    nargs="+",
                    type=int,
                    choices=AutoGemmParameters.betas)
    args = ap.parse_args()
    if args.output:
        Common.setOutputPath(args.output)
    else:
        print(
            "Warning: No output path specified; default is working directory.")

    # write offline compilation header
    if args.precisions is None:
コード例 #9
0
                        # for tile parameters
                        for tile in tiles:
                            kernel.useTile(tile)
                            kss.newKernel(kernel)

    kss.writeToFile()

    ########################################
    # kernel selection
    ks = KernelSelection( \
        AutoGemmParameters.precisions, \
        AutoGemmParameters.orders, \
        AutoGemmParameters.transposes, \
        AutoGemmParameters.betas, \
        AutoGemmParameters.unrolls, \
        AutoGemmParameters.kernelSelectionData )
    ks.writeToFile()


################################################################################
# Main
################################################################################
if __name__ == "__main__":
    if len(sys.argv) == 3:
        Common.setOutputPath(sys.argv[1])
        AutoGemmParameters.setArchitecture(sys.argv[2])
        writeKernelSelection()
    else:
        print("USAGE: python KernelSelection.py output_path architecture")
コード例 #10
0
import Common
import Includes
import KernelSelection
import AutoGemmParameters
import KernelOpenCL


################################################################################
# Main
################################################################################
if __name__ == "__main__":
  # parse arguments
  ap = argparse.ArgumentParser(description="AutoGemm")
  ap.add_argument("--output-path", dest="output" )
  ap.add_argument("--opencl-compiler-version", dest="clCompilerVersion", action="store", choices=["1.1", "1.2", "2.0" ])
  ap.add_argument("--architecture", dest="architecture", action="store", choices=["Hawaii", "Fiji" ])
  args = ap.parse_args()
  if args.output:
    Common.setOutputPath(args.output)
  else:
    print("AutoGemm.py: Warning: No output path specified; default is working directory.")

  print("AutoGemm.py: using OpenCL " + args.clCompilerVersion + " compiler")
  Common.setClCompilerVersion(args.clCompilerVersion)
  AutoGemmParameters.setArchitecture(args.architecture)

  KernelOpenCL.writeOpenCLKernels()
  KernelSelection.writeKernelSelection()
  Includes.writeIncludes()
コード例 #11
0
  ocFile.close()
  count *= 4
  print("AutoGemm.py: %u kernels will be pre-compiled." % count)


################################################################################
# Main
################################################################################
if __name__ == "__main__":

  # parse arguments
  ap = argparse.ArgumentParser(description="Which gemm kernels to compile offline.")
  ap.add_argument("--output-path", dest="output" )
  ap.add_argument("--precisions", dest="precisions", action="store", nargs="+", choices=AutoGemmParameters.precisions )
  ap.add_argument("--orders", dest="orders", action="store", nargs="+", choices=AutoGemmParameters.orders )
  ap.add_argument("--transposes", dest="transposes", action="store", nargs="+", choices=AutoGemmParameters.getTransposeChoices() )
  ap.add_argument("--betas", dest="betas", action="store", nargs="+", type=int, choices=AutoGemmParameters.betas )
  args = ap.parse_args()
  if args.output:
    Common.setOutputPath(args.output)
  else:
    print("Warning: No output path specified; default is working directory.")

  # write offline compilation header
  if args.precisions is None:
    args.precisions = []
  if args.transposes is None:
    args.transposes = []
  if args.orders is None:
    args.orders = []
  if args.betas is None:
コード例 #12
0
  ocFile.close()
  count *= 4
  print "AutoGemm.py: %u kernels will be pre-compiled." % count


################################################################################
# Main
################################################################################
if __name__ == "__main__":

  # parse arguments
  ap = argparse.ArgumentParser(description="Which gemm kernels to compile offline.")
  ap.add_argument("--output-path", dest="output" )
  ap.add_argument("--precisions", dest="precisions", action="store", nargs="+", choices=AutoGemmParameters.precisions )
  ap.add_argument("--orders", dest="orders", action="store", nargs="+", choices=AutoGemmParameters.orders )
  ap.add_argument("--transposes", dest="transposes", action="store", nargs="+", choices=AutoGemmParameters.getTransposeChoices() )
  ap.add_argument("--betas", dest="betas", action="store", nargs="+", type=int, choices=AutoGemmParameters.betas )
  args = ap.parse_args()
  if args.output:
    Common.setOutputPath(args.output)
  else:
    print "Warning: No output path specified; default is working directory."

  # write offline compilation header
  if args.precisions is None:
    args.precisions = []
  if args.transposes is None:
    args.transposes = []
  if args.orders is None:
    args.orders = []
  if args.betas is None:
コード例 #13
0
            # for tile parameters
            for tile in tiles:
              kernel.useTile(tile)
              kss.newKernel(kernel)

  kss.writeToFile()

  ########################################
  # kernel selection
  ks = KernelSelection( \
      AutoGemmParameters.precisions, \
      AutoGemmParameters.orders, \
      AutoGemmParameters.transposes, \
      AutoGemmParameters.betas, \
      AutoGemmParameters.unrolls, \
      AutoGemmParameters.kernelSelectionData )
  ks.writeToFile()



################################################################################
# Main
################################################################################
if __name__ == "__main__":
  if len(sys.argv) == 3:
    Common.setOutputPath(sys.argv[1])
    AutoGemmParameters.setArchitecture(sys.argv[2])
    writeKernelSelection()
  else:
    print("USAGE: python KernelSelection.py output_path architecture")