Ptx装配由于错误而中止

时间:2014-04-16 10:22:09

标签: c++ cuda ptx

我曾尝试在MS Visual Studio 2012中的C / CUDA 5.5上编写用于乘法CSR矩阵和向量的程序,但遇到了ptx错误。 我的代码列表:

__global__ void multKernelSymm(double* s, double* u, double* val, int* rowPtr, int* colInd)
    {
        int l = 0, jl, i;
        int idx = blockDim.x*blockIdx.x;

        l = rowPtr[idx] - 1;
        for ( i = 0; i < (rowPtr[idx + 1] - rowPtr[idx]); i++){
            jl = colInd[l] - 1;
            s[idx] = s[idx] + val[l] * u[jl];
            l+=1;
        }

        l = 0;
        l = rowPtr[idx] - 1;
        for (int i = 0; i < (rowPtr[idx + 1] - rowPtr[idx]); i++){
            jl = colInd[l] - 1;
            if(jl > idx)
                atomicAdd(&s[jl], val[l] * u[idx]);
                //s[jl] = s[jl] + val[l] * u[idx];
            l+=1;
        }


    }

    __device__ double atomicAdd(double* address, double val)
    {
         unsigned long long int* address_as_ull =
         (unsigned long long int*)address;
         unsigned long long int old = *address_as_ull, assumed;
         do {
            assumed = old;
            old = atomicCAS(address_as_ull, assumed, __double_as_longlong(val + __longlong_as_double(assumed)));
         } while (assumed != old);
         return __longlong_as_double(old);
    }

我进入VS:

 C:\Users\Дмитрий\Documents\Visual Studio 2012\Projects\matrix mult simple\matrix mult simple>"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include"  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o x64\Debug\kernel.cu.obj "C:\Users\Дмитрий\Documents\Visual Studio 2012\Projects\matrix mult simple\matrix mult simple\kernel.cu" 
1>  ptxas C:/Users/AACE~1/AppData/Local/Temp/tmpxft_00001b88_00000000-4_kernel.ptx, line 479; : fatal error : Parsing error near '-': syntax error
1>ptxas : fatal error : Ptx assembly aborted due to errors
1>  kernel.cu
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\BuildCustomizations\CUDA 6.0.targets(597,9): error MSB3721: The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\bin\nvcc.exe" -gencode=arch=compute_20,code=\"sm_20,compute_20\" --use-local-env --cl-version 2012 -ccbin "C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\bin\x86_amd64"  -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v6.0\include"  -G   --keep-dir x64\Debug -maxrregcount=0  --machine 64 --compile -cudart static  -g   -DWIN64 -D_DEBUG -D_CONSOLE -D_MBCS -Xcompiler "/EHsc /W3 /nologo /Od /Zi /RTC1 /MDd  " -o x64\Debug\kernel.cu.obj "C:\Users\Дмитрий\Documents\Visual Studio 2012\Projects\matrix mult simple\matrix mult simple\kernel.cu"" exited with code -1.
1>
 >     ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我能解决吗?

1 个答案:

答案 0 :(得分:1)

我能够通过进行3次更改来编译代码:

  1. 如@PaulR所示,请在调用自定义double功能时删除atomicAdd关键字。
  2. atomicAdd的第一个参数应该是要更新的地址的指针(要将值添加到的地址。)而是传递该地址的价值。所以你的函数调用应该是这样的:

    atomicAdd(&(s[jl]), val[l] * u[idx]);
    
  3. 最后,在内核定义之前,将自定义atomicAdd函数的声明和定义移至

  4. 通过这些更改,我可以让您的代码进行编译。