2

I am new to thrust library and trying to use it in my project. Here is a very simple code example. It can be compiled without any problem. However, when I try to run it, it gives me an error:

terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'
what():  std::bad_alloc: unknown error

along with a warning:

nvlink warning : SM Arch ('sm_20') not found in ...

The project can be reproduced by using the following two files.

test.cpp

#include <thrust/device_vector.h>
int main(){
    thrust::device_vector<int> x;
    x.resize(10);
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.8.9)
project(test_project)
find_package(CUDA QUIET REQUIRED)                                                                                                     
list(APPEND CUDA_NVCC_FLAGS "-std=c++11;-arch=compute_52")
set(CUDA_SEPARABLE_COMPILATION ON)
cuda_add_executable("cuda_test" "test.cu")

After some testing, it is obvious that if the line "set(CUDA_SEPARABLE_COMPILATION ON)" is removed, the program runs without problem. But I really need separable compilation activated for my project.

Any help or hint would be appreciated.

UPDATE:

Requested by @RobertCrovella, here are some more infos.

The CUDA version is 7.5, which is newly installed on UBUNTU 14.04 with GTX980. I did not update the Thrust library after that.

The following is the actual command generated by cmake by using "make VERBOSE=1".

CMake script with separable compilation

CMake script without separable compilation

UPDATE 2:

The same error is confirmed by @merelyMark. Since both the code and the CMakeLists file are extremely simple, is it possible that this is a bug in Thrust / CUDA ? [EDIT] No.

UPDATE 3:

Pointed out by @RobertCrovella, thrust library is working fine with proper cmake comands. Now the question: how can I generate those commands using CMakeLists?

Community
  • 1
  • 1
Zheng Qu
  • 781
  • 6
  • 22
  • what are the actual compile commands being generated by cmake? Which CUDA version are you using? Have you updated the thrust version at all? – Robert Crovella May 27 '16 at 14:14
  • @RobertCrovella Thanks for asking. I have updated the info you requested on the main post. – Zheng Qu May 27 '16 at 15:47
  • 1
    The commands you've shown aren't generating relocatable device code in CUDA. Are you sure this is using a CMake script with `CUDA_SEPARABLE_COMPILATION ON` ? – Robert Crovella May 27 '16 at 16:13
  • @RobertCrovella Sorry, my bad. What I posted was the CMake script without separable compilation on. It is fixed now. – Zheng Qu May 30 '16 at 08:06
  • 1
    There is no problem with CUDA or thrust. The problem lies within CMake, or else with your CMakeLists.txt file. I can compile and run your code successfully with a sequence of proper compile commands, even with separable compilation. A fully worked example is [here](http://pastebin.com/NpNArGC7), showing the critical compilation commands that CMake is generating along with the warning and runtime error, followed by the correct compilation commands, which produce no compilation warning, and no runtime error. – Robert Crovella May 31 '16 at 17:16
  • If you want help with CMake, you might want to tag your question with `CMake` – Robert Crovella May 31 '16 at 17:19
  • 1
    [Here](http://stackoverflow.com/questions/37519394/thrust-error-with-cuda-separate-compilation) is a working example of thrust with separable compilation turned on (not using CMake). – Robert Crovella May 31 '16 at 17:22

1 Answers1

1

Apologies in advance, I don't have enough points to add a comment, but I can confirm the behavior on my rig. This compiles properly on my machine with an E5-1650 v3 and a Quadro M4000 with CUDA 7.5 and Ubuntu 14.04.3. I get one warning error:

nvlink warning : SM Arch ('sm_20') not found in ...

I can confirm the behavior when I run it:

./cuda_test 
terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'
  what():  std::bad_alloc: unknown error
Aborted (core dumped)

I agree with @RobertCrovella, I'm not really sure what you're trying to accomplish here.

Here's my VERBOSE output for separable compilation.

Here's my VERBOSE output without separable compilation.

merelyMark
  • 367
  • 3
  • 9
  • Thanks for the confirmation. I actually also have the same warning. But I still need to double check after I get back to the code on Monday. Then my post will be updated. – Zheng Qu May 28 '16 at 20:07
  • What I am trying to acomplish is to get Thrust::device_vector::resize() running with separable compilation activated. – Zheng Qu May 30 '16 at 11:39
  • 1
    @RobertCrovella is probably correct that this is a CMake problem. You should tag CMake to this as well. There have been some issues with CMake and separable compilation. Here's an bug tracker from 2014 that's still an open issues. https://cmake.org/Bug/view.php?id=15157 FWIW, I updated to the latest CMake, and it's still a problem. – merelyMark Jun 01 '16 at 14:05