-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SEGFAULT, when loaded from C++ frontend #49
Comments
What is pytorch version you build against? |
Ahhh I see it is C++. Can you give full C++ code sample and makefile or something. I honestly hadn't tested it against C++ yet. |
Hello, thanks for your quick response.
The code is very simple, it just tries to copy torch::Tensor to the ocl device:
Compiled with: Also, i discovered a strange thing, that when the C++ code is compiled as a library (using So maybe, the problem could be some uninitialized libpython global variable. |
You don't check the result... if library isn't loaded it is indeed aborted (not segfault) If it isn't the issue can you try the second device i.e. ocl:1 since 2nd driver is generally works better and supports OpenCL 2.0 - so it is preferred - and it gave me better performance on 560 |
The #include <stdio.h>
#include <dlfcn.h>
#include <cstring>
#include <cstdlib>
typedef int(*RunFunc)();
int main(int argc, char** argv){
if((argc < 2) || (strcmp(argv[1], "--help") == 0)){
printf("frontend [libraryPath]");
exit(1);
}
printf("Loading library from %s\n", argv[1]);
void* lib = dlopen(argv[1], RTLD_NOW); ///RTLD_GLOBAL also leads to SEGFAULT!!!!
if(!lib){
fprintf(stderr, "ERROR: Cannot load library from \"%s\"\n", argv[1]);
exit(5);
}
void* func = dlsym(lib, "run");
if(!func){
puts("ERROR: \"run\" function not present in library");
exit(5);
}
printf("Function returned: %d", ((RunFunc) func)());
} The problem also disappears, but once the Another strange thing is, that when running python interpreter from C++, the app also receives SEGV at the #include <stdio.h>
#include <dlfcn.h>
#include <cstring>
#include <cstdlib>
#include <python3.11/Python.h>
int main(){
Py_Initialize();
PyRun_SimpleString("import torch; torch.ops.load_library(\"/run/media/tada/1976709e-d15f-4ba0-8cb3-5f34ce866960/Temp/pytorch_dlprim/build/libpt_ocl.so\"); torch.utils.rename_privateuse1_backend('ocl'); print(\"dev\"); dev = torch.device('ocl:0'); print(\"tens\"); t = torch.tensor([0.2, 0.5]); print("Moving to ocl"); ot = t.to(dev); print(\"otprint\"); print(ot)");
Py_FinalizeEx();
PyMem_RawFree(pyprogname);
return 0;
} |
UPDATE:
In the working case, the |
Loaded the library using
dlopen("libpt_ocl.so", RTLD_GLOBAL)
, but following segfaults:Equivalent code in python works:
The text was updated successfully, but these errors were encountered: