cudaModuleLoadData失败,错误码201

cudaModuleLoadData fails with error code 201

本文关键字:误码 错误 失败 cudaModuleLoadData      更新时间:2023-10-16

我有一个ptx代码,我想在GPU上执行。我使用以下代码:

CUmodule cudaModule;
//the variable that stores the error associated with cuda API calls.
CUresult cudaErrorVariable;
//variable representing any cuda kernel function.
CUfunction CUDAPipelineKernel;
//initializing cuda driver
cudaErrorVariable = cuInit(0);
//checking for error while loading ptx code in CUmodule.
if(cudaErrorVariable != CUDA_SUCCESS){
    myLogger->error("Unable to initialize CUDA driver");
    return 1;
}
//loading the ptx code into the module.
cudaErrorVariable = cuModuleLoadData(&cudaModule, PTXCode);
//checking for error while loading ptx code in CUmodule.
if(cudaErrorVariable != CUDA_SUCCESS){
    cuGetErrorString(cudaErrorVariable, (const char **)&errorString);
    myLogger->error("Unable load ptx file into the module : CUDA Error {}", cudaErrorVariable);
    return 1;
}

cuModuleLoadData函数返回错误码201。我不知道这个错误代码是什么意思。有人能帮我找出错误吗?

这里是cuInit的链接,这是在任何cuda驱动程序API调用之前首先调用的函数,如文档中所述。

为完整起见,下面是创建上下文的链接:cuCtxCreate。

您也可以使用Primary上下文,正如cuda samples目录中的6_Advanced/ptxjit样例所启发的那样,它是用cudaMalloc惰性初始化的。

主上下文在每个设备上是唯一的,并与CUDA共享运行时API。这些函数允许与其他库集成使用CUDA。

正如您在相关文档中看到的,错误201是CUDA_ERROR_INVALID_CONTEXT,这意味着您在尝试加载模块之前没有正确设置上下文