[英]Missing symbol: cuDevicePrimaryCtxRelease vs cuDevicePrimaryCtxRelease_v2
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:
但是,使用 CUDA 10.2,链接工作,而使用 CUDA 11.2,我得到:
/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).注意:我正在使用带有驱动程序版本 440.82 的 Devuan Beowulf(尚未为 CUDA 11.2 安装新驱动程序)。
Well, I think I have an idea of why this happens.好吧,我想我知道为什么会发生这种情况。
This is about how cuDevicePrimaryCtxRelease()
is defined.这是关于如何定义
cuDevicePrimaryCtxRelease()
的。 Let's run:让我们运行:
grep PrimaryCtxRelease /usr/local/cuda/include/cuda.h | grep -v "^ "
In CUDA 10.2, we get:在 CUDA 10.2 中,我们得到:
CUresult CUDAAPI cuDevicePrimaryCtxRelease(CUdevice dev);
while in CUDA 11.2, we get:而在 CUDA 11.2 中,我们得到:
#define cuDevicePrimaryCtxRelease cuDevicePrimaryCtxRelease_v2
CUresult CUDAAPI cuDevicePrimaryCtxRelease(CUdevice dev);
That is, the API name has changed, but the header file leaves an alias to the new name.也就是说,API 名称已更改,但 header 文件为新名称留下了别名。 (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
现在,让我们看看我在两个不同版本的 CUDA 中得到的 object 文件,使用
objdump -t | c++filt | grep cu
objdump -t | c++filt | grep cu
objdump -t | c++filt | grep cu
. objdump -t | c++filt | grep cu
。 With CUDA 10.2, it's:使用 CUDA 10.2,它是:
0000000000000000 *UND* 0000000000000000 cuInit
0000000000000000 *UND* 0000000000000000 cuGetErrorString
0000000000000000 *UND* 0000000000000000 cuDevicePrimaryCtxRetain
0000000000000000 *UND* 0000000000000000 cuDevicePrimaryCtxRelease
while with CUDA 11.2, it's:而使用 CUDA 11.2,它是:
0000000000000000 *UND* 0000000000000000 cuInit
0000000000000000 *UND* 0000000000000000 cuGetErrorString
0000000000000000 *UND* 0000000000000000 cuDevicePrimaryCtxRetain
0000000000000000 *UND* 0000000000000000 cuDevicePrimaryCtxRelease_v2
(note the _v2
). (注意
_v2
)。
so it's probably the case that the installed driver only contains the non- _v2
symbol, hence the undefined symbol.所以可能是安装的驱动程序只包含非
_v2
符号,因此是未定义的符号。
What I would still appreciate help with is how to work around this issue other than by updating the driver.我仍然希望得到帮助的是如何解决这个问题,而不是更新驱动程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.