CUDA 5.0:CUBIN和CUBLAS_设备,计算能力3.5
我正在尝试编译一个内核,它使用动态并行性将CUBLAS运行到cubin文件。 当我尝试使用命令编译代码时CUDA 5.0:CUBIN和CUBLAS_设备,计算能力3.5,cuda,nvcc,cublas,Cuda,Nvcc,Cublas,我正在尝试编译一个内核,它使用动态并行性将CUBLAS运行到cubin文件。 当我尝试使用命令编译代码时 nvcc -cubin -m64 -lcudadevrt -lcublas_device -gencode arch=compute_35,code=sm_35 -o test.cubin -c test.cu 我得到ptxas致命:未解析的外部函数'cublasCreate_v2 如果我添加-rdc=truecompile选项,它可以很好地编译,但是当我尝试使用cuModuleLoad加
nvcc -cubin -m64 -lcudadevrt -lcublas_device -gencode arch=compute_35,code=sm_35 -o test.cubin -c test.cu
我得到ptxas致命:未解析的外部函数'cublasCreate_v2
如果我添加-rdc=true
compile选项,它可以很好地编译,但是当我尝试使用cuModuleLoad加载模块时,会出现错误500:CUDA\u error\u NOT\u FOUND。来自cuda.h:
/**
* This indicates that a named symbol was not found. Examples of symbols
* are global/constant variable names, texture names, and surface names.
*/
CUDA_ERROR_NOT_FOUND = 500,
内核代码:
#include <stdio.h>
#include <cublas_v2.h>
extern "C" {
__global__ void a() {
cublasHandle_t cb_handle = NULL;
cudaStream_t stream;
if( threadIdx.x == 0 ) {
cublasStatus_t status = cublasCreate_v2(&cb_handle);
cublasSetPointerMode_v2(cb_handle, CUBLAS_POINTER_MODE_HOST);
if (status != CUBLAS_STATUS_SUCCESS) {
return;
}
cudaStreamCreateWithFlags(&stream, cudaStreamNonBlocking);
cublasSetStream_v2(cb_handle, stream);
}
__syncthreads();
int jp;
double A[3];
A[0] = 4.0f;
A[1] = 5.0f;
A[2] = 6.0f;
cublasIdamax_v2(cb_handle, 3, A, 1, &jp );
}
}
#include <stdio.h>
#include <cuda.h>
#include <cuda_runtime_api.h>
int main() {
CUresult error;
CUdevice cuDevice;
CUcontext cuContext;
CUmodule cuModule;
CUfunction testkernel;
// Initialize
error = cuInit(0);
if (error != CUDA_SUCCESS) printf("ERROR: cuInit, %i\n", error);
error = cuDeviceGet(&cuDevice, 0);
if (error != CUDA_SUCCESS) printf("ERROR: cuInit, %i\n", error);
error = cuCtxCreate(&cuContext, 0, cuDevice);
if (error != CUDA_SUCCESS) printf("ERROR: cuCtxCreate, %i\n", error);
error = cuModuleLoad(&cuModule, "test.cubin");
if (error != CUDA_SUCCESS) printf("ERROR: cuModuleLoad, %i\n", error);
error = cuModuleGetFunction(&testkernel, cuModule, "a");
if (error != CUDA_SUCCESS) printf("ERROR: cuModuleGetFunction, %i\n", error);
return 0;
}
主机代码是使用nvcc-lcuda test.cpp
编译的。
如果我用一个简单的内核(如下所示)替换内核,并在不使用-rdc=true
的情况下编译它,它就可以正常工作
简单工作内核
#include <stdio.h>
extern "C" {
__global__ void a() {
printf("hello\n");
}
}
#包括
外部“C”{
__全局无效a(){
printf(“hello\n”);
}
}
提前谢谢
- 索伦
- 在第一种方法中,您只是缺少了
-dlink
:
nvcc -cubin -m64 -lcudadevrt -lcublas_device -gencode arch=compute_35,code=sm_35 -o test.cubin -c test.cu -dlink
您还可以通过两个步骤完成此操作:
nvcc -m64 test.cu -gencode arch=compute_35,code=sm_35 -o test.o -dc
nvcc -dlink test.o -arch sm_35 -lcublas_device -lcudadevrt -cubin -o test.cubin
你使用驱动程序API有什么原因吗?KiaMorot:我使用pycuda,它使用驱动程序API。我加入C代码的原因是为了让它更透明谢谢,你让我高兴:)有人解释我为什么需要两步编译吗?好问题Soren,用一步的方式更新了我的答案。再次感谢你的跟进!