CUDA 单独编译的推力错误
Thrust error with CUDA separate compilation
当我尝试在启用可重定位设备代码 (-rdc = true) 的情况下编译 CUDA 时,我 运行 遇到了错误。我使用 Visual Studio 2013 作为 CUDA 7.5 的编译器。下面是一个显示错误的小例子。澄清一下,下面的代码在 -rdc = false 时运行良好,但是当设置为 true 时,错误就会出现。
错误只是说:CUDA 错误 11 [\cuda\detail\cub\device\dispatch/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();
}
正如 Robert Crovella 在评论中提到的:
将 CUDA 架构更改为更高的值将解决此问题。在我的例子中,我在 CUDA C++ -> 设备 -> 代码生成下将其更改为 compute_30 和 sm_30。
编辑:
一般建议select 最适合您的特定 GPU 的层次结构。有关更多信息,请参阅评论中的 link。
当我尝试在启用可重定位设备代码 (-rdc = true) 的情况下编译 CUDA 时,我 运行 遇到了错误。我使用 Visual Studio 2013 作为 CUDA 7.5 的编译器。下面是一个显示错误的小例子。澄清一下,下面的代码在 -rdc = false 时运行良好,但是当设置为 true 时,错误就会出现。
错误只是说:CUDA 错误 11 [\cuda\detail\cub\device\dispatch/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();
}
正如 Robert Crovella 在评论中提到的:
将 CUDA 架构更改为更高的值将解决此问题。在我的例子中,我在 CUDA C++ -> 设备 -> 代码生成下将其更改为 compute_30 和 sm_30。
编辑:
一般建议select 最适合您的特定 GPU 的层次结构。有关更多信息,请参阅评论中的 link。