【问题标题】:Thrust error with CUDA separate compilationCUDA单独编译的推力错误
【发布时间】: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:您能否添加一个简短的答案来描述您的解决方案,以供下一个遇到相同问题的人使用?

标签: cuda thrust


【解决方案1】:

正如 Robert Crovella 在 cmets 中提到的:

将 CUDA 架构更改为更高的值将解决此问题。就我而言,我在 CUDA C++ -> Device -> Code Generation 下将其更改为 compute_30 和 sm_30。

编辑:

一般建议是为您的特定 GPU 选择最适合的层次结构。有关更多信息,请参阅 cmets 中的链接。

【讨论】:

    猜你喜欢
    • 2015-05-11
    • 2012-11-11
    • 1970-01-01
    • 1970-01-01
    • 2011-02-21
    • 2016-12-16
    • 2017-02-14
    • 2020-11-07
    • 1970-01-01
    相关资源
    最近更新 更多