Tony-Tan / CUDA_Freshman

2.18k stars 435 forks source link

why this can not be compiled success? #10

Open cqray1990 opened 2 years ago

cqray1990 commented 2 years ago

/**

include

include

static const int WORK_SIZE = 256;

/**

int main(int argc, char **argv) { CUmodule module; CUcontext context; CUdevice device; CUdeviceptr deviceArray; CUfunction process;

void *kernelArguments[] = { &deviceArray };
int deviceCount;
unsigned int idata[WORK_SIZE], odata[WORK_SIZE];

for (int i = 0; i < WORK_SIZE; ++i) {
    idata[i] = i;
}

CHECK_CUDA_RESULT(cuInit(0));
CHECK_CUDA_RESULT(cuDeviceGetCount(&deviceCount));
if (deviceCount == 0) {
    printf("No CUDA-compatible devices found\n");
    exit(1);
}
CHECK_CUDA_RESULT(cuDeviceGet(&device, 0));
CHECK_CUDA_RESULT(cuCtxCreate(&context, 0, device));

CHECK_CUDA_RESULT(cuModuleLoad(&module, "bitreverse.fatbin"));
CHECK_CUDA_RESULT(cuModuleGetFunction(&process, module, "bitreverse"));

CHECK_CUDA_RESULT(cuMemAlloc(&deviceArray, sizeof(int) * WORK_SIZE));
CHECK_CUDA_RESULT(
        cuMemcpyHtoD(deviceArray, idata, sizeof(int) * WORK_SIZE));

CHECK_CUDA_RESULT(
        cuLaunchKernel(process, 1, 1, 1, WORK_SIZE, 1, 1, 0, NULL, kernelArguments, NULL));

CHECK_CUDA_RESULT(
        cuMemcpyDtoH(odata, deviceArray, sizeof(int) * WORK_SIZE));

for (int i = 0; i < WORK_SIZE; ++i) {
    printf("Input value: %u, output value: %u\n", idata[i], odata[i]);
}

CHECK_CUDA_RESULT(cuMemFree(deviceArray));
CHECK_CUDA_RESULT(cuCtxDestroy(context));

return 0;

} :对‘cuDeviceGetCount’未定义的引用 HSigmoid.cu:58:对‘cuModuleLoad’未定义的引用 /cudaHelloworld/src/HSigmoid.cu:59:对‘cuModuleGetFunction’未定义的引用 cudaHelloworld/src/HSigmoid.cu:61:对‘cuMemAlloc_v2’未定义的引用 cudaHelloworld/src/HSigmoid.cu:62:对‘cuMemcpyHtoD_v2’未定义的引用 cudaHelloworld/src/HSigmoid.cu:68:对‘cuMemcpyDtoH_v2’未定义的引用 cudaHelloworld/src/HSigmoid.cu:75:对‘cuMemFree_v2’未定义的引用 /cudaHelloworld/src/HSigmoid.cu:76:对‘cuCtxDestroy_v2’未定义的引用