int initialize_kernels(const unsigned char *code, int codeLen, bool use_dlopenbuf, handle_t *module_ptr) { void *lib = NULL; if (use_dlopenbuf) { if (!dlopenbuf) { log_printf("dlopenbuf not available.\n"); return -1; } // We need a unique soname, or dlopenbuf will return a // previously opened library. static int unique_id = 0; char soname[256]; sprintf(soname, "libhalide_kernels%04d.so", __sync_fetch_and_add(&unique_id, 1)); // Open the library dllib_init(); // We need to use RTLD_NOW, the libraries we build for Hexagon // offloading do not support lazy bindin. lib = dlopenbuf(soname, (const char*)code, codeLen, RTLD_LOCAL | RTLD_NOW); if (!lib) { halide_print(NULL, "dlopenbuf failed\n"); halide_print(NULL, dlerror()); return -1; } } else { lib = mmap_dlopen(code, codeLen); if (!lib) { halide_print(NULL, "mmap_dlopen failed\n"); return -1; } } *module_ptr = reinterpret_cast<handle_t>(lib); return 0; }
int halide_hexagon_remote_load_library(const char *soname, int sonameLen, const unsigned char *code, int codeLen, handle_t *module_ptr) { void *lib = NULL; if (use_dlopenbuf()) { // We need to use RTLD_NOW, the libraries we build for Hexagon // offloading do not support lazy binding. lib = dlopenbuf(soname, (const char*)code, codeLen, RTLD_GLOBAL | RTLD_NOW); if (!lib) { log_printf("dlopenbuf failed: %s\n", dlerror()); return -1; } } else { lib = mmap_dlopen(code, codeLen); if (!lib) { log_printf("mmap_dlopen failed\n"); return -1; } } *module_ptr = reinterpret_cast<handle_t>(lib); return 0; }