2

Visual studio highlights "threadIdx" with a red line in the following example.

It seems as if the execution of the program is successful, so the problem is merely a display issue in VisualStudio.

How can I make it so Visual Studio no longer highlights threadIdx as invalid?

My environment: * OS:Windows7,64bit * VisualStudio2010, CUDA5.5


Source code:

 #include <cuda_runtime.h>
 #include <stdio.h> 
 #include <math.h> 
 #include <cuda.h> 


 #define N 256
 __global__ void matrix_vector_multi_gpu_1_256(float *A_d, float *B_d, float *C_d);
 int main(){
    int i,j;
    float A[N], B[N*N], C[N];
    float *A_d, *B_d, *C_d;

    dim3 blocks(1,1,1);
    dim3 threads(256,1,1);

    for(j=0;j<N;j++){
       for(i=0;i<N;i++){
        B[j*N+i]=((float)j)/256.0;
        }
    }

    for(j=0;j<N;j++){
       C[j]=1.0F;
    }

    cudaMalloc((void**)&A_d, N*sizeof(float));
    cudaMalloc((void**)&B_d, N*N*sizeof(float));
    cudaMalloc((void**)&C_d, N*sizeof(float));

    cudaMemcpy(A_d,A,N*sizeof(float),cudaMemcpyHostToDevice);
    cudaMemcpy(B_d,B,N*N*sizeof(float),cudaMemcpyHostToDevice);
    cudaMemcpy(C_d,C,N*sizeof(float),cudaMemcpyHostToDevice);

    matrix_vector_multi_gpu_1_256<<<blocks,threads>>>(A_d,B_d,C_d);
    cudaMemcpy(A,A_d,N*sizeof(float),cudaMemcpyDeviceToHost);

    for(j=0;j<N;j++){
        printf("A[ %d ]=%f \n",j,A[j]);
    }
    getchar();

    cudaFree(A_d);
    cudaFree(B_d);
    cudaFree(C_d);
    return 0;
 }

 __global__ void matrix_vector_multi_gpu_1_256(float *A_d, float *B_d, float *C_d){
     int i;

     A_d[threadIdx.x]=0.0F; 
        for(i=0;i<N;i++){
             A_d[threadIdx.x]=A_d[threadIdx.x]+B_d[threadIdx.x*N+i]*C_d[i];
        }
 }
Brian Cain
  • 14,403
  • 3
  • 50
  • 88
kuu
  • 197
  • 1
  • 4
  • 14
  • Please type "cuda red underline" in the search box in the upper right corner, and you'll get plenty of info about this. The red underline itself is an intellisense feature, and by itself it does not prevent you from compiling or building CUDA code. – Robert Crovella Oct 17 '13 at 14:26
  • I'm guessing that this is a design limitation in Visual Studio's CUDA support. – Brian Cain Oct 17 '13 at 14:28
  • The answer by Kovi solves the problem. If you need also syntax highligthing, see [Setting Visual Studio 2010 support (syntax highlighting) for CUDA projects](http://www.orangeowlsolutions.com/archives/547) and [Setting Visual Studio 2010 Intellisense for CUDA projects](http://www.orangeowlsolutions.com/archives/536). – Vitality Oct 17 '13 at 14:45

1 Answers1

7

try add

#include <device_launch_parameters.h>
Kovi
  • 81
  • 4
  • Yeah! Thank you Kovi! well, but I didn't understand that why It seems as if the execution of the program is successful, so the problem is merely a display issue in VisualStudio? – kuu Oct 17 '13 at 15:03
  • 2
    visual studio doesnt compile cu files so it dont need to know what is threadidx ... cu files are compiled with nvcc(it is called by VS) that is a reason of compiling without any errors – Kovi Oct 17 '13 at 16:48