Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sorting cuda/推力:试图在6GB的GPU RAM中按2.8GB的数据键对U进行排序会导致错误_Sorting_Cuda_Thrust_Bad Alloc - Fatal编程技术网

Sorting cuda/推力:试图在6GB的GPU RAM中按2.8GB的数据键对U进行排序会导致错误

Sorting cuda/推力:试图在6GB的GPU RAM中按2.8GB的数据键对U进行排序会导致错误,sorting,cuda,thrust,bad-alloc,Sorting,Cuda,Thrust,Bad Alloc,我刚刚开始使用推力,到目前为止,我遇到的最大问题之一是似乎没有关于操作需要多少内存的文档。因此,我不知道为什么下面的代码在尝试排序时抛出错误的alloc(在排序之前,我仍然有>50%的GPU内存可用,CPU上有70GB的RAM可用)——有人能解释一下吗 #include <thrust/device_vector.h> #include <thrust/sort.h> #include <thrust/random.h> void initialize_da

我刚刚开始使用推力,到目前为止,我遇到的最大问题之一是似乎没有关于操作需要多少内存的文档。因此,我不知道为什么下面的代码在尝试排序时抛出错误的alloc(在排序之前,我仍然有>50%的GPU内存可用,CPU上有70GB的RAM可用)——有人能解释一下吗

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

void initialize_data(thrust::device_vector<uint64_t>& data) {
  thrust::fill(data.begin(), data.end(), 10);
}

int main(void) {
  size_t N = 120 * 1024 * 1024;
  char line[256];
  try {
    std::cout << "device_vector" << std::endl;
    typedef thrust::device_vector<uint64_t>  vec64_t;

    // Each buffer is 900MB

    vec64_t c[3] = {vec64_t(N), vec64_t(N), vec64_t(N)};
    initialize_data(c[0]);
    initialize_data(c[1]);
    initialize_data(c[2]);

    std::cout << "initialize_data finished... Press enter";
    std::cin.getline(line, 0);

    // nvidia-smi reports 48% memory usage at this point (2959MB of                 
    // 6143MB)

    std::cout << "sort_by_key col 0" << std::endl;

    // throws bad_alloc

    thrust::sort_by_key(c[0].begin(), c[0].end(),
      thrust::make_zip_iterator(thrust::make_tuple(c[1].begin(),
      c[2].begin())));

    std::cout << "sort_by_key col 1" << std::endl;
    thrust::sort_by_key(c[1].begin(), c[1].end(),
        thrust::make_zip_iterator(thrust::make_tuple(c[0].begin(),
        c[2].begin())));
  } catch(thrust::system_error &e) {
    std::cerr << "Error: " << e.what() << std::endl;
    exit(-1);
  }
  return 0;
}

考虑到Robert Crovella的评论,这就是我使用cudaMemGetInfo()使用39%的GPU RAM(这是在禁用ECC的nvidia特斯拉卡上,否则值需要更低)的代码工作方式

#包括
#包括
#包括
无效初始化\u数据(推力::设备\u向量和数据){
推力::填充(data.begin(),data.end(),10);}
#定义缓冲区3
int main(void){
大小\u t总\u gpu\u字节;
cudaMemGetInfo(0,&total_gpu_字节);
大小\u t N=(总的\u gpu\u字节*.39)/sizeof(uint64\u t)/BUFFERS;
试一试{
std::cout sort_by_key,加上GPU操作通常会有一些开销。我怀疑如果你减少向量的大小,使它们消耗大约40-45%的可用内存,排序操作就会成功。如果你想发现故障点,你可以微调数字,我怀疑你已经为这是一个测试用例。
nvcc -o ./bad_alloc ./bad_alloc.cu
#include <thrust/device_vector.h>
#include <thrust/sort.h>
#include <thrust/random.h>

void initialize_data(thrust::device_vector<uint64_t>& data) {
  thrust::fill(data.begin(), data.end(), 10); }

#define BUFFERS 3

int main(void) {                                                                  
  size_t total_gpu_bytes;
  cudaMemGetInfo(0, &total_gpu_bytes);
  size_t N = (total_gpu_bytes * .39) / sizeof(uint64_t) / BUFFERS;
  try {
    std::cout << "device_vector " << (N/1024.0/1024.0) << std::endl;
    typedef thrust::device_vector<uint64_t>  vec64_t;
    vec64_t c[BUFFERS] = {vec64_t(N), vec64_t(N), vec64_t(N)};
    initialize_data(c[0]);
    initialize_data(c[1]);
    initialize_data(c[2]);
    thrust::sort_by_key(c[0].begin(), c[0].end(),
        thrust::make_zip_iterator(thrust::make_tuple(c[1].begin(),
        c[2].begin())));
    thrust::sort_by_key(c[1].begin(), c[1].end(),
        thrust::make_zip_iterator(thrust::make_tuple(c[0].begin(),
        c[2].begin())));
  } catch(thrust::system_error &e) {
    std::cerr << "Error: " << e.what() << std::endl;
    exit(-1);
  }
  return 0;
}