Skip to content

Instantly share code, notes, and snippets.

@dangra
Created February 26, 2024 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangra/ea827d7de7bddf0523fdddcff197fda5 to your computer and use it in GitHub Desktop.
Save dangra/ea827d7de7bddf0523fdddcff197fda5 to your computer and use it in GitHub Desktop.
#include <assert.h>
#include <dlfcn.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
void *handle;
int (*nvmlInit)(void);
char *error;
handle = dlopen("libnvidia-ml.so", RTLD_LAZY);
if (!handle) {
fprintf(stderr, "%s\n", dlerror());
exit(EXIT_FAILURE);
}
dlerror();
nvmlInit = (int (*)(void)) dlsym(handle, "nvmlInit");
error = dlerror();
if (error != NULL) {
fprintf(stderr, "%s\n", error);
exit(EXIT_FAILURE);
}
assert(nvmlInit() == 0);
dlclose(handle);
return EXIT_SUCCESS;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment