I'm trying to build the following program:
#include <iostream>
#include <cuda.h>
int main() {
const char* str;
auto status = cuInit(0);
cuGetErrorString(status, &str);
std::cout << "status = " << str << std::endl;
int device_id = 0;
CUcontext primary_context_id;
status = cuDevicePrimaryCtxRetain(&primary_context_id, device_id);
cuGetErrorString(status, &str);
std::cout << "status = " << str << std::endl;
status = cuDevicePrimaryCtxRelease(device_id);
cuGetErrorString(status, &str);
std::cout << "status = " << str << std::endl;
}
Compilation always goes fine; but, with CUDA 10.2, linking works, while with CUDA 11.2, I get:
/usr/bin/ld: a.o: in function `main':
a.cpp:(.text+0xcc): undefined reference to `cuDevicePrimaryCtxRelease_v2'
collect2: error: ld returned 1 exit status
Why is this happening and how can I fix it?
Note: I'm using Devuan Beowulf with driver version 440.82 (have not installed a new driver for CUDA 11.2).
Well, I think I have an idea of why this happens.
This is about how
cuDevicePrimaryCtxRelease()
is defined. Let's run:In CUDA 10.2, we get:
while in CUDA 11.2, we get:
That is, the API name has changed, but the header file leaves an alias to the new name. (And that's a confusing piece of code, I would say.)
Now, let's peer into the object files I get in the two different versions of CUDA, using
objdump -t | c++filt | grep cu
. With CUDA 10.2, it's:while with CUDA 11.2, it's:
(note the
_v2
).so it's probably the case that the installed driver only contains the non-
_v2
symbol, hence the undefined symbol.What I would still appreciate help with is how to work around this issue other than by updating the driver.