【发布时间】:2016-05-30 06:56:02
【问题描述】:
当我尝试在启用可重定位设备代码 (-rdc = true) 的情况下编译 CUDA 时遇到错误。我使用 Visual Studio 2013 作为 CUDA 7.5 的编译器。下面是一个显示错误的小示例。澄清一下,下面的代码在 -rdc = false 时运行良好,但是当设置为 true 时,就会出现错误。
错误只是说:CUDA error 11 [\cuda\detail\cub\device\dispatch/device_radix_sort_dispatch.cuh, 687]: invalid argument
然后我找到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());
}
}
基数排序.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();
}
【问题讨论】:
-
关于这个:
Is there some workaround to allow separate compilation?你在哪个 GPU 上运行? -
目前是 GTX 760。
-
尝试使用与您的 GTX 760 匹配的架构集进行编译,我相信应该是 cc3.0。
-
谢谢,配合compute_30 和sm_30 确实是解决方案。知道为什么不支持 _20 吗?
-
@Spectrallic:您能否添加一个简短的答案来描述您的解决方案,以供下一个遇到相同问题的人使用?