1
votes

I have two problems in CUDA programming.

  1. I want to pass matrix as a function parameter in a CUDA program. I tried following. GCC compiler compiles the following code but NVIDIA CUDA C compiler does not compiles this code and prompts error. (I have installed CUDA 7.5)

    void printMatrix( size_t rows, size_t cols, int a[][cols] )
    

    and

    void printMatrix(int row, int col, int matrix[row][col])
    

Both are not working. It gives "a parameter is not allowed" error.

  1. Inside the main method I want to declare a matrix

    int a[n][n];
    

    where n runs from 1 to 5 (in a for loop). It gives "expression must have a constant value" error.

Where am I making the error.

I have tried to compile the code from this question with gcc and nvcc compiler, gcc compiles and nvcc does not.

compiler results

1
You have already asked this question once today. I think that is enough. - talonmies
@talonmies my problem is, gcc compiler compiles where CUDA compiler does not. Can you understand my problem - user4576114
Someone already provided you with a complete answer to your question here. nvcc uses the host C++ compiler by default, so the second version is the most suitable. If you try and compile the first version in that answer, nvcc/g++ will tell you exactly what option you must use to compile C99 code without error. This doesn't warrant a new question. - talonmies
@talonmies i have edited the question and added a picture of the results I get - user4576114
@talonmies I have tried "nvcc -Xcompiler -std=c99 printmatrix.cu", "nvcc -arch=sm_20 printmatrix.cu" both are not compiling - user4576114

1 Answers

2
votes

Because you are doing this on Windows, nvcc (note nvccis not a compiler) uses the Visual Studio compiler to compile host host. Visual Studio does not support C99 language features, so you cannot use them in any host code you will compile on Windows in conjunction with CUDA. You will have to rewrite your code without using C99 language features in your host code.

If you were doing this on linux, you would be using gcc to compile the host code via nvcc, and C99 language features would be available if you provide the correct command line options and pass the file with a .c extension, as you have ably demonstrated in your question. C99 features and CUDA cannot be mixed in a .cu file because CUDA requires a C++ compiler to compile host code contain CUDA language extensions.