2016-05-30 41 views
0

当我尝试使用可重定位设备代码启用(-rdc = true)来编译CUDA时,我遇到错误。我使用Visual Studio 2013作为CUDA 7.5的编译器。下面是一个显示错误的小例子。为了澄清,当-rdc = false时,下面的代码运行良好,但是当设置为true时,错误显示出来。使用CUDA独立编译导致推力错误

错误简单地说:CUDA错误11 [\ CUDA \详细\幼兽\设备\调度/ device_radix_sort_dispatch.cuh,687]:无效参数

然后我发现this,它说:

When invoked with primitive data types, thrust::sort, thrust::sort_by_key,thrust::stable_sort, thrust::stable_sort_by_key may fail to link in some cases with nvcc -rdc=true. 

是否有一些解决方法允许单独编译?

main.cpp中:

#include <stdio.h> 
#include <vector> 
#include "cuda_runtime.h" 
#include "RadixSort.h" 

typedef unsigned int uint; 
typedef unsigned __int64 uint64; 

int main() 
{ 
    RadixSort sorter; 

    uint n = 10; 
    std::vector<uint64> test(n); 
    for (uint i = 0; i < n; i++) 
     test[i] = i + 1; 

    uint64 * d_array; 
    uint64 size = n * sizeof(uint64); 

    cudaMalloc(&d_array, size); 
    cudaMemcpy(d_array, test.data(), size, cudaMemcpyHostToDevice); 

    try 
    { 
     sorter.Sort(d_array, n); 
    } 
    catch (const std::exception & ex) 
    { 
     printf("%s\n", ex.what()); 
    } 
} 

RadixSort.h:

#pragma once 
typedef unsigned int uint; 
typedef unsigned __int64 uint64; 

class RadixSort 
{ 
public: 
    RadixSort() {} 
    ~RadixSort() {} 

    void Sort(uint64 * input, const uint n); 
}; 

RadixSort.cu:

#include "RadixSort.h" 

#include <thrust/device_vector.h> 
#include <thrust/device_ptr.h> 
#include <thrust/sort.h> 

void RadixSort::Sort(uint64 * input, const uint n) 
{ 
    thrust::device_ptr<uint64> d_input = thrust::device_pointer_cast(input); 
    thrust::stable_sort(d_input, d_input + n); 
    cudaDeviceSynchronize(); 
} 
+0

关于此问题:“是否有一些解决方法可以单独编译?您正在运行哪个GPU? –

+0

目前的GTX 760. – RobbinMarcus

+0

尝试编译架构设置为匹配您的GTX 760,我相信应该是cc3.0。 –

回答

1

正如罗伯特Crovella的评论提到:

将CUDA体系结构更改为更高的价值将解决这个问题。在我的情况下,我将它改为CUDA C++ - > Device - > Code Generation下的compute_30和sm_30。

编辑:

一般建议是为您的特定GPU选择最适合的层次结构。请参阅评论中的链接以获取更多信息。