示例#1
0
文件: cuda.cpp 项目: kgnk/Halide
extern "C" WEAK void *halide_cuda_get_symbol(void *user_context, const char *name) {
    // Only try to load the library if we can't already get the symbol
    // from the library. Even if the library is NULL, the symbols may
    // already be available in the process.
    void *symbol = halide_get_library_symbol(lib_cuda, name);
    if (symbol) {
        return symbol;
    }

    const char *lib_names[] = {
#ifdef WINDOWS
        "nvcuda.dll",
#else
        "libcuda.so",
        "libcuda.dylib",
        "/Library/Frameworks/CUDA.framework/CUDA",
#endif
    };
    for (size_t i = 0; i < sizeof(lib_names) / sizeof(lib_names[0]); i++) {
        lib_cuda = halide_load_library(lib_names[i]);
        if (lib_cuda) {
            debug(user_context) << "    Loaded CUDA runtime library: " << lib_names[i] << "\n";
            break;
        }
    }

    return halide_get_library_symbol(lib_cuda, name);
}
示例#2
0
// Load the hexagon remote runtime.
WEAK int init_hexagon_runtime(void *user_context) {
    if (remote_initialize_kernels && remote_run && remote_release_kernels) {
        // Already loaded.
        return 0;
    }

    debug(user_context) << "Hexagon: init_hexagon_runtime (user_context: " << user_context << ")\n";

    // Load the library.
    const char *host_lib_name = "libhalide_hexagon_host.so";
    debug(user_context) << "    halide_load_library('" << host_lib_name << "') -> \n";
    void *host_lib = halide_load_library(host_lib_name);
    debug(user_context) << "        " << host_lib << "\n";
    if (!host_lib) {
        error(user_context) << host_lib_name << " not found.\n";
        return -1;
    }

    // Get the symbols we need from the library.

    get_symbol(user_context, host_lib, "halide_hexagon_remote_initialize_kernels", remote_initialize_kernels);
    if (!remote_initialize_kernels) return -1;
    get_symbol(user_context, host_lib, "halide_hexagon_remote_get_symbol", remote_get_symbol);
    if (!remote_get_symbol) return -1;
    get_symbol(user_context, host_lib, "halide_hexagon_remote_run", remote_run);
    if (!remote_run) return -1;
    get_symbol(user_context, host_lib, "halide_hexagon_remote_release_kernels", remote_release_kernels);
    if (!remote_release_kernels) return -1;

    // There's an optional symbol in libadsprpc.so that enables
    // buffers to be zero copy that we *try* to load.
    debug(user_context) << "    halide_load_library('libadsprpc.so') -> \n";
    void *adsprpc_lib = halide_load_library("libadsprpc.so");
    debug(user_context) << "        " << adsprpc_lib << "\n";
    if (adsprpc_lib) {
        debug(user_context) << "    halide_get_library_symbol('remote_register_buf') -> \n";
        remote_register_buf = (remote_register_buf_fn)halide_get_library_symbol(adsprpc_lib, "remote_register_buf");
        debug(user_context) << "        " << (void *)remote_register_buf << "\n";
        // This symbol is optional, don't error if it isn't available.
    }

    return 0;
}