示例#1
0
def _jitify_prep(source, options, cu_path):
    # TODO(leofang): refactor this?
    global _jitify_header_source_map_populated
    if not _jitify_header_source_map_populated:
        from cupy.core import core
        _jitify_header_source_map = core._get_header_source_map()
        _jitify_header_source_map_populated = True
    else:
        # this is already cached at the C++ level, so don't pass in anything
        _jitify_header_source_map = None

    # jitify requires the 1st line to be the program name
    old_source = source
    source = cu_path + '\n' + source

    # Upon failure, in addition to throw an error Jitify also prints the log
    # to stdout. In principle we could intercept that by hijacking stdout's
    # file descriptor (tested locally), but the problem is pytest also does
    # the same thing internally, causing strange errors when running the tests.
    # As a result, we currently maintain Jitify's default behavior for easy
    # debugging, and wait for the upstream to address this issue
    # (NVIDIA/jitify#79).

    try:
        name, options, headers, include_names = jitify(
            source, options, _jitify_header_source_map)
    except Exception as e:  # C++ could throw all kinds of errors
        cex = CompileException(str(e), old_source, cu_path, options, 'jitify')
        dump = _get_bool_env_variable('CUPY_DUMP_CUDA_SOURCE_ON_ERROR', False)
        if dump:
            cex.dump(sys.stderr)
        raise JitifyException(str(cex))
    assert name == cu_path

    return options, headers, include_names
示例#2
0
文件: compiler.py 项目: dmargala/cupy
def _jitify_prep(source, options, cu_path):
    # TODO(leofang): refactor this?
    global _jitify_header_source_map
    if _jitify_header_source_map is None:
        from cupy.core import core
        _jitify_header_source_map = core._get_header_source_map()

    # jitify requires the 1st line to be the program name
    source = cu_path + '\n' + source

    # Upon failure, in addition to throw an error Jitify also prints the log
    # to stdout. In principle we could intercept that by hijacking stdout's
    # file descriptor (tested locally), but the problem is pytest also does
    # the same thing internally, causing strange errors when running the tests.
    # As a result, we currently maintain Jitify's default behavior for easy
    # debugging, and wait for the upstream to address this issue
    # (NVIDIA/jitify#79).

    try:
        name, options, headers, include_names, hdr_map = jitify(
            source, options, _jitify_header_source_map)
    except Exception as e:  # C++ could throw all kinds of errors
        raise JitifyException(str(e))
    assert name == cu_path
    _jitify_header_source_map = hdr_map

    return options, headers, include_names