2017-08-29 1657 views
0

我是CUDA和CUB的新手。我发现下面的代码,并试图编译它,但我有这个错误: 致命错误:cub/cub.cuh:没有这样的文件或目录。致命错误:cub/cub.cuh:没有这样的文件或目录

CUDA的版本是7.0.27 我该如何解决这个错误?

谢谢!

所有的
#include <cuda.h> 
#include <cub/cub.cuh> 
#include <stdio.h> 

int main(){ 

    // Declare, allocate, and initialize device pointers for input and output 
    int num_items = 7; 
    int *d_in; 
    int h_in[] = {8, 6, 7, 5, 3, 0, 9}; 
    int sz = sizeof(h_in)/sizeof(h_in[0]); 
    int *d_out; // e.g., [ , , , , , , ] 
    cudaMalloc(&d_in, sz*sizeof(h_in[0])); 
    cudaMalloc(&d_out, sz*sizeof(h_in[0])); 
    cudaMemcpy(d_in, h_in, sz*sizeof(h_in[0]), cudaMemcpyHostToDevice); 
    printf("\nInput:\n"); 
    for (int i = 0; i < sz; i++) printf("%d ", h_in[i]); 
    // Determine temporary device storage requirements 
    void *d_temp_storage = NULL; 
    size_t temp_storage_bytes = 0; 
    cub::DeviceScan::InclusiveSum(d_temp_storage, temp_storage_bytes, d_in, d_out, num_items); 
    // Allocate temporary storage 
    cudaMalloc(&d_temp_storage, temp_storage_bytes); 
    // Run inclusive prefix sum 
    cub::DeviceScan::InclusiveSum(d_temp_storage, temp_storage_bytes, d_in, d_out, num_items); 
// d_out s<-- [8, 14, 21, 26, 29, 29, 38] 
    cudaMemcpy(h_in, d_out, sz*sizeof(h_in[0]), cudaMemcpyDeviceToHost); 
    printf("\nOutput:\n"); 
    for (int i = 0; i < sz; i++) printf("%d ", h_in[i]); 
    printf("\n"); 
    return 0; 
} 
+1

您必须单独安装CUB。它不包含在cuda工具包中。你可以得到CUB [这里](https://github.com/NVlabs/cub)。请注意,CUDA 7现在已经很老了。您可能需要为此选择较旧版本的CUB。 –

回答

0

首先,你应该升级到CUDA 8.此错误致命错误:幼崽/ cub.cuh因为编译器无法找到该文件。如果您使用cmake,则必须通过命令include_directories添加小目录,如果您使用IDE或其他,请尝试将cub目录添加到您的项目中。

相关问题