Ejemplo n.º 1
0
    def __init__(self,
                 original_kernel,
                 device=0,
                 platform=0,
                 lang=None,
                 quiet=False,
                 compiler_options=None,
                 iterations=7):
        """ Instantiate the DeviceInterface, based on language in kernel source

        :param original_kernel: The source of the kernel as passed to tune_kernel
        :type original_kernel: kernel source as a string or a list of strings denoting filenames

        :param device: CUDA/OpenCL device to use, in case you have multiple
            CUDA-capable GPUs or OpenCL devices you may use this to select one,
            0 by default. Ignored if you are tuning host code by passing lang="C".
        :type device: int

        :param platform: OpenCL platform to use, in case you have multiple
            OpenCL platforms you may use this to select one,
            0 by default. Ignored if not using OpenCL.
        :type device: int

        :param lang: Specifies the language used for GPU kernels. The kernel_tuner
            automatically detects the language, but if it fails, you may specify
            the language using this argument, currently supported: "CUDA", "OpenCL", or "C"
        :type lang: string

        :param compiler_options: The compiler options to use when compiling kernels for this device.
        :type compiler_options: list of strings

        :param iterations: Number of iterations to be used when benchmarking using this device.
        :type iterations: int

        """
        logging.debug('DeviceInterface instantiated, lang=%s', lang)

        lang = util.detect_language(lang, original_kernel)
        if lang == "CUDA":
            dev = CudaFunctions(device,
                                compiler_options=compiler_options,
                                iterations=iterations)
        elif lang == "OpenCL":
            dev = OpenCLFunctions(device,
                                  platform,
                                  compiler_options=compiler_options,
                                  iterations=iterations)
        elif lang == "C":
            dev = CFunctions(compiler_options=compiler_options,
                             iterations=iterations)
        else:
            raise Exception(
                "Sorry, support for languages other than CUDA, OpenCL, or C is not implemented yet"
            )
        self.lang = lang
        self.dev = dev
        self.name = dev.name
        if not quiet:
            print("Using: " + self.dev.name)
Ejemplo n.º 2
0
    def __init__(self, kernel_sources, lang):
        if not isinstance(kernel_sources, list):
            kernel_sources = [kernel_sources]
        self.kernel_sources = kernel_sources
        if lang is None:
            if callable(self.kernel_sources[0]):
                raise TypeError("Please specify language when using a code generator function")
            kernel_string = self.get_kernel_string(0)
            lang = util.detect_language(kernel_string)

        # The validity of lang is checked later, when creating the DeviceInterface
        self.lang = lang
Ejemplo n.º 3
0
    def __init__(self, original_kernel, device=0, platform=0, lang=None, quiet=False, compiler=None, compiler_options=None, iterations=7):
        """ Instantiate the DeviceInterface, based on language in kernel source

        :param original_kernel: The source of the kernel as passed to tune_kernel
        :type original_kernel: kernel source as a string or a list of strings denoting filenames

        :param device: CUDA/OpenCL device to use, in case you have multiple
            CUDA-capable GPUs or OpenCL devices you may use this to select one,
            0 by default. Ignored if you are tuning host code by passing lang="C".
        :type device: int

        :param platform: OpenCL platform to use, in case you have multiple
            OpenCL platforms you may use this to select one,
            0 by default. Ignored if not using OpenCL.
        :type device: int

        :param lang: Specifies the language used for GPU kernels. The kernel_tuner
            automatically detects the language, but if it fails, you may specify
            the language using this argument, currently supported: "CUDA", "OpenCL", or "C"
        :type lang: string

        :param compiler_options: The compiler options to use when compiling kernels for this device.
        :type compiler_options: list of strings

        :param iterations: Number of iterations to be used when benchmarking using this device.
        :type iterations: int

        :param times: Return the execution time of all iterations.
        :type times: bool

        """
        logging.debug('DeviceInterface instantiated, lang=%s', lang)

        lang = util.detect_language(lang, original_kernel)
        if lang == "CUDA":
            dev = CudaFunctions(device, compiler_options=compiler_options, iterations=iterations)
        elif lang == "OpenCL":
            dev = OpenCLFunctions(device, platform, compiler_options=compiler_options, iterations=iterations)
        elif lang == "C":
            dev = CFunctions(compiler=compiler, compiler_options=compiler_options, iterations=iterations)
        else:
            raise Exception("Sorry, support for languages other than CUDA, OpenCL, or C is not implemented yet")
        self.lang = lang
        self.dev = dev
        self.units = dev.units
        self.name = dev.name
        if not quiet:
            print("Using: " + self.dev.name)