-1

Why when I try to compile a cuda program throws those errors: clang: error: unsupported option '-dumpspecs' and clang: error: no input files?

I type on the terminal: nvcc -o hello matrix_product.cu as an internet tutorial showed me but seems not to work... Do I have to add some variables or something like that?

And the code of the file.cu is:

using namespace std;

void CheckCudaError(string &e);


__global__ void productMatrix(int *matrix_a, int *matrix_b, int *matrix_c)
{

    int blockidx = blockIdx.x;
    int blockidy = blockIdx.y;

    int threadx = threadIdx.x;
    int thready = threadIdx.y;

    __shared__ int Asub[BLOCK_SIZE][BLOCK_SIZE];
    __shared__ int Bsub[BLOCK_SIZE][BLOCK_SIZE];

    Asub[threadx][thready] = matrix_a[blockidx * BLOCK_SIZE + threadx + blockidy * BLOCK_SIZE + thready];
    Bsub[threadx][thready] = matrix_b[blockidx * BLOCK_SIZE + threadx + blockidy * BLOCK_SIZE + thready];

    __syncthreads();

    int suma;

    for (int i = 0; i < BLOCK_SIZE; ++i)
    {
        suma += Asub[e][thready]* Bsub[threadx][e];
    }

    __syncthreads();

    matrix_c[blockidx * BLOCK_SIZE + threadx + blockidy * BLOCK_SIZE + thready] = suma;


}


int main(){

    //Creamos punteros para apuntar tanto al dispositivo como a memoria.
    int *h_a, *h_b;
    int *d_a, *d_b, *d_c;

    int NumBlocks = 100 * 100 / BLOCK_SIZE;
    int num_elements = NumBlocks * BLOCK_SIZE;


    //Apuntamos los punteros hacia un espacio de 100*100 elementos en el host
    h_a = malloc(num_elements * sizeof(int));
    h_b = malloc(num_elements * sizeof(int));
    CheckCudaError("malloc_host_error");


    //LLenamos la memoria
    for (int i = 0; i < num_elements; ++i)
    {
        h_a[i] = i;
        h_b[i] = num_elements - 1 - i;
    }


    //Apuntamos los punteros del dispositivo hacia una reserva de memoria de 100*100 elementos.
    cudaMalloc(&d_a, num_elements * sizeof(int));
    cudaMalloc(&d_b, num_elements * sizeof(int));
    cudaMalloc(&d_c, num_elements * sizeof(int));
    CheckCudaError("malloc_device_error");


    /*Copiamos los elementos del host ya llenados anteriormente (llenamos memoria,
        copiando las matrizes del host hacia la tarjeta gráfica (device).*/
    cudaMemcpy(d_a, h_a, num_elements * sizeof(int), cudaMemcpyHostToDevice);
    cudaMemcpy(d_b, h_b, num_elements * sizeof(int), cudaMemcpyHostToDevice);
    CheckCudaError("memcpy_error");


    free(h_b); 
    CheckCudaError("Free_host_error");


    //Establecemos el num de threas y blocks que utilizaremos
    dim3 gridDim (NumBlocks, NumBlocks);
    dim3 blockDim (BLOCK_SIZE, BLOCK_SIZE);
    //LLamamos la función.
    productMatrix <<< gridDim, blockDim >>> (d_a, d_b, d_c);
    CheckCudaError("Calling_device_function_error");


    /*Esperamos a que todos los threads hayan hecho su trabajo (multiplicar las matrizes)
        antes de copy back.*/
    cudaThreadSyncronize();
    CheckCudaError("Syncronize_threads_error");


    //Una vez sincronizados los volvemos a copiar hacia el host.
    cudaMemcpy(h_a, d_c, num_elements * sizeof(int), cudaMemcpyDeviceToHost);
    CheckCudaError("mempcy_host_error");


    //Imprimimos por pantalla
    for (int i = 0; i < num_elements; ++i) cout << h_a[i];


    //Aliberamos memoria en el device
    cudaFree(d_a);
    cudaFree(d_b);
    cudaFree(d_c);

    //Aliveramos meomria en host.
    free(h_a);

    CheckCudaError("free_device_error");

}


void CheckCudaError(string &e)
{   
    //Obtenemos el ultimo error.
    cudaError_t err = cudaGetLastError();
    //Si hay error imprime el error por pantalla
    if(cudaSuccess != err){
        cout << e << endl;
    }
}
  • 1
    Seems that nvcc asks the system compiler (gcc) for information about the system (-dumpspecs) but you have something called clang pretending to be gcc and failing. I'm sure nvidia has instructions for you, but you could try adding in front of PATH a directory that contains a real gcc. – Marc Glisse Feb 07 '14 at 19:30
  • 1
    Dup of http://stackoverflow.com/q/19649541/1918193 which was already a dup of... – Marc Glisse Feb 07 '14 at 19:33

1 Answers1

1

Please try explicitely point NVCC to clang compiler.

NVCC := nvcc -ccbin /usr/bin/clang

or maybe

NVCC := nvcc -ccbin /usr/local/cuda/bin/clang

Additionally don't forget also to add all necessary includes:

nvcc -I/usr/local/cuda-5.0/include -I. -I.. -I../../common/inc -o MonteCarlo_kernel.o -c MonteCarlo_kernel.cu
4pie0
  • 29,204
  • 9
  • 82
  • 118
  • This has absolutely nothing to do with the problem. How can specifying include files possibly change the error `clang: error: unsupported option '-dumpspecs'`? (and note the compiler is clang, not gcc, were you using clang?) – talonmies Feb 08 '14 at 10:25
  • OK so now you have edited in the *exact cause* of the problem as a solution, which is as equally wrong as your first answer. The whole point here is that nvcc will try and work out whether the host compiler is gcc or clang, but to do that it must be explicitly pointed to clang, and not a gcc symbolic link to clang, which exactly the root cause of the problem and exactly what your answer will do. – talonmies Feb 09 '14 at 13:54
  • @talonmies corrected, please review – 4pie0 Feb 10 '14 at 11:10