def get_kernel()

in gen_kernels.py [0:0]


def get_kernel(base_name, major, minor, options=None):
    if major < 5:
        raise RuntimeError("sass kernels require Maxwell or greater class hardware")
    elif major >= 7:
        raise RuntimeError("sm version 7 or greater is not supported")

    arch = "sm_%d%d" % (major, minor)

    libprefix = "PERL5LIB=%s" % maxas_dir
    maxas_i = [libprefix, os.path.join(maxas_dir, "maxas.pl") + " -i -w"]
    maxas_p = [libprefix, os.path.join(maxas_dir, "maxas.pl") + " -p"]

    kernel_spec = kernels[base_name]
    kernel_name = base_name

    # static options
    if "args" in kernel_spec:
        for pair in kernel_spec["args"].items():
            maxas_i.append("-D%s %s" % pair)
            maxas_p.append("-D%s %s" % pair)

    # dynamic options
    if options is not None:
        for opt in options:
            if type(opt) is tuple:
                maxas_i.append("-D%s %s" % opt)
                maxas_p.append("-D%s %s" % opt)
                kernel_name += "_%s%s" % opt
            else:
                maxas_i.append("-D%s 1" % opt)
                maxas_p.append("-D%s 1" % opt)
                kernel_name += "_%s" % opt

    maxas_i.insert(2, "-k " + kernel_name)

    sass_name  = kernel_spec["sass"] + ".sass"
    cubin_name = kernel_name + ".cubin"
    cubin_dir  = _get_cache_dir([arch, 'cubin'])
    header_dir = os.path.join(base_dir, "include/kernels")

    ptx_version = "4.2" if major < 6 else "5.0"
    ptx_file   = get_ptx_file(kernel_spec, kernel_name, arch, ptx_version)
    cubin_file = os.path.join(cubin_dir, cubin_name)
    sass_file   = os.path.join(sass_dir, sass_name)
    header_file = os.path.join(header_dir, kernel_name + "_" + arch + ".h")

    if not os.path.exists(sass_file):
        raise RuntimeError("Missing: %s for kernel: %s" % (sass_name, kernel_name))

    # build the cubin and run maxas in the same command
    # we don't want the chance of a generated cubin not processed by maxas (in case user hits ^C in between these steps)
    command_string = [ "ptxas -v -arch", arch, "-o", cubin_file, ptx_file, ";" ] + maxas_i + [sass_file, cubin_file]
    run_command(command_string)
    cubin_mtime = time.time()

    # now also generate the associated header file containing the cubin
    with open(cubin_file, 'rb') as input_file:
        with open(header_file, 'wb') as output_file:
            output_file.write('const uint8_t %s[] = {' % (kernel_name + "_" + arch))
            byte = input_file.read(1)
            count = 0
            while byte:
                if count % 12 == 0:
                    output_file.write('\n   ')
                output_file.write(' 0x' + byte.encode('hex') + ',')
                byte = input_file.read(1)
                count += 1
            output_file.write('\n};')