1

I am new to CUDA and CUB. I found the following code and tried to compile it, but I had this error: fatal error: cub/cub.cuh: No such file or directory.

The version of CUDA is 7.0.27 How I can fix this error?

Thanks!

#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;
}
S.M.K
  • 11
  • 1
  • 2
  • 1
    You have to install CUB separately. It is not included with the cuda toolkit. You can get CUB [here](https://github.com/NVlabs/cub). Note that CUDA 7 is pretty old now. You may need to choose an older version of CUB for that. – Robert Crovella Aug 29 '17 at 19:26

1 Answers1

1

First of all, you should upgrade to cuda 8. This error fatal error: cub/cub.cuh because the compiler can not find this file. If you use cmake, you must add cub directory by the command include_directories, if you use IDE or something else, try to add cub directory to your project.

dk1111
  • 188
  • 1
  • 5