Я пытаюсь перехватить вызовы API драйвера CUDA (например, Cuinit), создав прокси -библиотеку (libcuda_override.so), которая направляет призывы к настоящему Libcuda.so. Мой текущий подход: < /p>
Setup:
libcuda.so.1 symlinks to my proxy (libcuda_override.so).
The proxy dynamically loads the real library (libcuda_real.so.1).
I manually intercept cuInit and forward other calls to the real library.
Problem:
When running a Python script with LD_LIBRARY_PATH=./, I get symbol lookup errors for other CUDA functions (e.g., cuGetProcAddress_v2). The dynamic linker expects all CUDA symbols to be defined in my proxy, but I only want to intercept specific functions (like cuInit).
What I Want:
Only resolve intercepted functions (e.g., cuInit) in my proxy.
Automatically forward all other symbols to the real libcuda.so without manual declarations.
Constraints:
Avoid parsing cuda.h or manually declaring every CUDA function.
Prefer a solution that doesn’t require maintaining a full symbol list.
< /code>
Текущий код: < /p>
static void* real_libcuda = nullptr;
static std::once_flag libcuda_loaded;
static void ensure_real_libcuda_loaded() {
std::call_once(libcuda_loaded, []() {
const char* msg = "[🔥 LIBCUDA WRAP LOADED]\n";
size_t msg_len = 0;
while (msg[msg_len] != '\0') {
++msg_len;
}
write(STDERR_FILENO, msg, msg_len);
const char* libcuda_path = "libcuda_real.so.1";
real_libcuda = dlopen(libcuda_path, RTLD_LAZY | RTLD_GLOBAL);
if (!real_libcuda) {
fprintf(stderr, "[‼️] Failed to load real libcuda.so.1 from %s: %s\n", libcuda_path, dlerror());
_exit(1);
}
});
}
__attribute__((constructor))
static void libcuda_wrap_ctor() {
ensure_real_libcuda_loaded();
}
template
T resolve(const char* name) {
ensure_real_libcuda_loaded();
void* sym = dlsym(real_libcuda, name);
if (!sym) {
fprintf(stderr, "[‼️] dlsym failed for %s: %s\n", name, dlerror());
}
return reinterpret_cast(sym);
}
extern "C" __attribute__((visibility("default")))
CUresult cuInit(unsigned int Flags) {
static auto real = resolve("cuInit");
std::cout
Ошибка:
./libcuda.so.1: undefined symbol: cuGetProcAddress_v2 (fatal)
Вопрос:
Есть ли способ:
явно перехватывает только Cuinit (или подмножество функций) и неявно пересылав все другие символы в реальную либкуда.>
Я пытаюсь перехватить вызовы API драйвера CUDA (например, Cuinit), создав прокси -библиотеку (libcuda_override.so), которая направляет призывы к настоящему Libcuda.so. Мой текущий подход: < /p> [code]Setup:
libcuda.so.1 symlinks to my proxy (libcuda_override.so).
The proxy dynamically loads the real library (libcuda_real.so.1).
I manually intercept cuInit and forward other calls to the real library.
Problem: When running a Python script with LD_LIBRARY_PATH=./, I get symbol lookup errors for other CUDA functions (e.g., cuGetProcAddress_v2). The dynamic linker expects all CUDA symbols to be defined in my proxy, but I only want to intercept specific functions (like cuInit).
What I Want:
Only resolve intercepted functions (e.g., cuInit) in my proxy.
Automatically forward all other symbols to the real libcuda.so without manual declarations.
Constraints:
Avoid parsing cuda.h or manually declaring every CUDA function.
Prefer a solution that doesn’t require maintaining a full symbol list. < /code> Текущий код: < /p>
template T resolve(const char* name) { ensure_real_libcuda_loaded(); void* sym = dlsym(real_libcuda, name); if (!sym) { fprintf(stderr, "[‼️] dlsym failed for %s: %s\n", name, dlerror()); } return reinterpret_cast(sym); }
extern "C" __attribute__((visibility("default"))) CUresult cuInit(unsigned int Flags) { static auto real = resolve("cuInit"); std::cout Ошибка: ./libcuda.so.1: undefined symbol: cuGetProcAddress_v2 (fatal)[/code] Вопрос: Есть ли способ: явно перехватывает только Cuinit (или подмножество функций) и неявно пересылав все другие символы в реальную либкуда.>