nvcc problem with loading data from file

Hello all

After finally getting around getting the GPU doing some computations with simple numbers and vectors successfully, I decided it was time to move on writing some kernels that can take in large amounts of experimental data from file.

However I cant seem to get nvcc to compile code that includes any form of IO code. My simple test example is

[codebox]#include <stdio.h>

#include

#include

#include <assert.h>

#include <cuda.h>

using namespace std;

int main(void)

{

ofstream inputfile;

inputfile.open (“Datafile.dat”);

inputfile.close();

cout << “Data read from file Successfully!”;

}[/codebox]

However I keep getting the following

/usr/include/c++/4.4/ext/atomicity.h(46): error: identifier “__sync_fetch_and_add” is undefined

/usr/include/c++/4.4/ext/atomicity.h(50): error: identifier “__sync_fetch_and_add” is undefined

2 errors detected in the compilation of “/tmp/tmpxft_00000c77_00000000-4_Powerspec.cpp1.ii”.

I tried using both the stdio.h and iosteam libraries since I figured that might be the cause, but I get the same error in all cases. I hope someone can spread some light on how to tackle this problem since I have been unable to locate anything about it in the CUDA material I have on hand. Thanks in advance.

Looks like you are using gcc 4.4. That is presently unsupported and known not to work with nvcc.

Yes I am using gcc 4.4. If that is a problem can you recommend another compiler to use instead that will work? And since I am using ubuntu, will it be enough to get it through its package system and just install it. Or do I need to do something to CUDA as well to make it work ?

If you install gcc-4.3 and then follow the instructions in this thread, you might be able to get it to work.

Okay I found out i had gcc-4.3 installed already, since I had ubuntu 9.04 back when I installed CUDA and it worked fine. I did however upgrade to 9.10 when it was released. I just assumed that everything still worked since all my CUDA projects could still compile, but they of course did not include any IO commands except printf() which worked fine.

I have been reading over that other thread, and I must admit that I am at a loss about what it says.
The only makefile related to CUDA I can find is with the SDK. But I guess those are not the ones meant.
I figure that I need to make sure that the command gcc and g++ relates to their 4.3 variants instead of the 4.4 ones.
So my question is how do I make nvcc use 4.3 instead. Do I have to make a local makefile in the folder I am in that specify it or type in some sort of command before I try to compile ? Please bear in mind that I am not an expert linux user.
Thanks for your help and comments so far btw.

Nevermind I think I figured it out!
I just added to the dir where I compile my CUDA work.
ln -s $(which g+±4.3) g++
ln -s $(which gcc-4.3) gcc

in my dir and compile with the nvcc TestIO.cu --compiler-bindir=/home/Cudatest instead and no more errors!

I have a similar problem here. I tried to change the compiler as you suggested. But I have others errors.

Anyone can help please?

nanoscope@lpmvpc25:~/Desktop/project$ sudo ln -sf /usr/bin/gcc-4.3 /usr/bin/gcc

nanoscope@lpmvpc25:~/Desktop/project$ sudo ln -sf /usr/bin/g++-4.3 /usr/bin/g++

nanoscope@lpmvpc25:~/Desktop/project$ g++ --version

g++ (Ubuntu 4.3.4-10ubuntu1) 4.3.4

Copyright (C) 2008 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

nanoscope@lpmvpc25:~/Desktop/project$ gcc --version

gcc (Ubuntu 4.3.4-10ubuntu1) 4.3.4

Copyright (C) 2008 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

nanoscope@lpmvpc25:~/Desktop/project$ nvcc unf_max_cuda.cu

unf_max_cuda.cu(95): error: identifier "_ZSt4cout" is undefined

unf_max_cuda.cu(95): error: identifier "_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_" is undefined

2 errors detected in the compilation of "/tmp/tmpxft_0000121f_00000000-5_unf_max_cuda.cpp2.i".

If I remove a line where appear just a “cout” and an “endl” I get this:

nanoscope@lpmvpc25:~/Desktop/project$ nvcc unf_max_cuda.cu

Signal: Segmentation fault in Code_Expansion phase.

<input>(0): Error: Signal Segmentation fault in phase Code_Expansion -- processing aborted

*** Internal stack backtrace:

    /usr/local/cuda/open64/lib//be() [0x6c09bf]

    /usr/local/cuda/open64/lib//be() [0x6c1609]

    /usr/local/cuda/open64/lib//be() [0x6c0d5d]

    /usr/local/cuda/open64/lib//be() [0x6c1fa6]

    /lib/libc.so.6(+0x33af0) [0x2b0f7b55aaf0]

    /usr/local/cuda/open64/lib//be() [0x544449]

    /usr/local/cuda/open64/lib//be() [0x56fcec]

    /usr/local/cuda/open64/lib//be() [0x56c7bc]

    /usr/local/cuda/open64/lib//be() [0x56dc31]

    /usr/local/cuda/open64/lib//be() [0x56c7a8]

    /usr/local/cuda/open64/lib//be() [0x57132b]

    /usr/local/cuda/open64/lib//be() [0x571e46]

    /usr/local/cuda/open64/lib//be() [0x5723fc]

    /usr/local/cuda/open64/lib//be() [0x54e980]

    /usr/local/cuda/open64/lib//be() [0x405443]

    /usr/local/cuda/open64/lib//be() [0x4061f1]

    /usr/local/cuda/open64/lib//be() [0x40751d]

    /lib/libc.so.6(__libc_start_main+0xfd) [0x2b0f7b545c4d]

    /usr/local/cuda/open64/lib//be() [0x4038da]

nvopencc INTERNAL ERROR: /usr/local/cuda/open64/lib//be died due to signal 4

I have a similar problem here. I tried to change the compiler as you suggested. But I have others errors.

Anyone can help please?

nanoscope@lpmvpc25:~/Desktop/project$ sudo ln -sf /usr/bin/gcc-4.3 /usr/bin/gcc

nanoscope@lpmvpc25:~/Desktop/project$ sudo ln -sf /usr/bin/g++-4.3 /usr/bin/g++

nanoscope@lpmvpc25:~/Desktop/project$ g++ --version

g++ (Ubuntu 4.3.4-10ubuntu1) 4.3.4

Copyright (C) 2008 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

nanoscope@lpmvpc25:~/Desktop/project$ gcc --version

gcc (Ubuntu 4.3.4-10ubuntu1) 4.3.4

Copyright (C) 2008 Free Software Foundation, Inc.

This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

nanoscope@lpmvpc25:~/Desktop/project$ nvcc unf_max_cuda.cu

unf_max_cuda.cu(95): error: identifier "_ZSt4cout" is undefined

unf_max_cuda.cu(95): error: identifier "_ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_" is undefined

2 errors detected in the compilation of "/tmp/tmpxft_0000121f_00000000-5_unf_max_cuda.cpp2.i".

If I remove a line where appear just a “cout” and an “endl” I get this:

nanoscope@lpmvpc25:~/Desktop/project$ nvcc unf_max_cuda.cu

Signal: Segmentation fault in Code_Expansion phase.

<input>(0): Error: Signal Segmentation fault in phase Code_Expansion -- processing aborted

*** Internal stack backtrace:

    /usr/local/cuda/open64/lib//be() [0x6c09bf]

    /usr/local/cuda/open64/lib//be() [0x6c1609]

    /usr/local/cuda/open64/lib//be() [0x6c0d5d]

    /usr/local/cuda/open64/lib//be() [0x6c1fa6]

    /lib/libc.so.6(+0x33af0) [0x2b0f7b55aaf0]

    /usr/local/cuda/open64/lib//be() [0x544449]

    /usr/local/cuda/open64/lib//be() [0x56fcec]

    /usr/local/cuda/open64/lib//be() [0x56c7bc]

    /usr/local/cuda/open64/lib//be() [0x56dc31]

    /usr/local/cuda/open64/lib//be() [0x56c7a8]

    /usr/local/cuda/open64/lib//be() [0x57132b]

    /usr/local/cuda/open64/lib//be() [0x571e46]

    /usr/local/cuda/open64/lib//be() [0x5723fc]

    /usr/local/cuda/open64/lib//be() [0x54e980]

    /usr/local/cuda/open64/lib//be() [0x405443]

    /usr/local/cuda/open64/lib//be() [0x4061f1]

    /usr/local/cuda/open64/lib//be() [0x40751d]

    /lib/libc.so.6(__libc_start_main+0xfd) [0x2b0f7b545c4d]

    /usr/local/cuda/open64/lib//be() [0x4038da]

nvopencc INTERNAL ERROR: /usr/local/cuda/open64/lib//be died due to signal 4