Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

reduce fail due to integer overflow. #1315

@trivialfis

Description

@trivialfis

Platform

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Wed_Jul_22_19:09:09_PDT_2020
Cuda compilation tools, release 11.0, V11.0.221
Build cuda_11.0_bu.TC445_37.28845127_0

Reproduce

#include <thrust/iterator/counting_iterator.h>
#include <thrust/reduce.h>
#include <limits>

void Sync() {
  assert(cudaDeviceSynchronize() == cudaSuccess);
  assert(cudaGetLastError() == cudaSuccess);
}

void TestReduceFails() {
  auto iter = thrust::make_counting_iterator<size_t>(0ul);
  size_t limit = std::numeric_limits<int32_t>::max();
  // after reduction step 2: cudaErrorInvalidConfiguration: invalid configuration argument
  auto ret = thrust::reduce(thrust::device, iter, iter + limit, size_t(0ul), thrust::maximum<size_t>{});
  Sync();
  assert(ret == limit - 1);
}

void TestReduceWorks() {
  auto iter = thrust::make_counting_iterator<size_t>(0ul);
  size_t limit = std::numeric_limits<int32_t>::max() / 2;
  auto ret = thrust::reduce(thrust::device, iter, iter + limit, size_t(0ul), thrust::maximum<size_t>{});
  Sync();
  assert(ret == limit - 1);
}

int main() {
  TestReduceFails();
  TestReduceWorks();
  return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions