How to compile CUDA applications?

I'm trying to get CUDA to work on:
Code:
FreeBSD silvers 9.1-RELEASE-p4 FreeBSD 9.1-RELEASE-p4 #0: Sun Jun 30 01:07:52 MSK 2013     root@silvers:/usr/obj/usr/src/sys/GENERIC  amd64
I installed toolkit 2.3 (32 bit) for Fedora 10 but when I run nvcc cuda.cpp I get:
Code:
[CMD=sh-3.2$]/usr/local/cuda/bin/nvcc cuda.cpp[/CMD]
/usr/local/cuda/bin/../lib/libcudart.so: could not read symbols: File in wrong format
I suppose this is because 32-bit NVCC runs a 64-bit compiler. how do I use a 32-bit native Linux environment for building a CUDA application?

Thank you.
 
Unfortunately, there is no native CUDA toolchain. Although, I did see some Japanese blog (I can't read Japanese) a while ago that seemed to suggest that the author was able to compile and run CUDA applications on FreeBSD through the Linux CUDA toolchain (through Linux emulation).

That aside, does the FreeBSD nVidia driver blob even officially support CUDA?
 
From what I've seen while googling about FreeBSD and CUDA, it seems that FreeBSD Nvidia drivers support CUDA, so basically, a compiled application should run fine. The problem is to compile it using 32-bit Linux capability. I guess I need to chroot to /compat/linux and compile CUDA applications from there, but there is no Linux GCC. I saw that there was a package linux_devel, but there is no one now.
 
I've managed to compile a simple CUDA application under Linux emulation, but can't execute the compiled application:
Code:
./a.out: error while loading shared libraries: libcudart.so.2: cannot open shared object file: No such file or directory
I have libcudart.so.2 in /usr/local/cuda/lib and symlinked it into /usr/local/lib.

Any ideas?
 
The libcudart.so should be in your /compat/linux/usr/lib and not /usr/local/lib. For Linux applications, the runtime linker will implicitly look in /compat/linux (if this is where your Linux environment lives).

You could also add libcudart.so to /etc/libmap.conf to help the runtime linker locate the dependency (See libmap.conf(5)). That's a little more direct than a symlink.
 
@nslay thank you very much. The problem is solved. nvcc compiled an application with some warnings. The application starts ok, but I just found that my card doesn't support CUDA (I thought it does), so it crashes with a message that the card is not supported.

In case somebody needs it, here is a summary:

Set up Linux emulation (I used linux_base-f10-10_5) and download and install the CUDA toolkit 2.3 (32 bit) for Fedora 10 in /compat/linux. Actually you don't need to "install" it, just unpack say to /compat/linux/bin/local/cuda.
[*]Using rpm2cpio.pl ( pkg_add -r rpm2cpio) add some Fedora 10 RPMs from here: http://archives.fedoraproject.org/pub/archive/fedora/linux/releases/10/Fedora/i386/os/Packages/. You'll need the following packages (sorry if I forget something):
cpp, binutils-devel, gcc, gcc-c++, glibc-devel, glibc-common, glibc-headers, kernel-devel, kernel-headers, libgcc, mpfr, gmp. To install them cd to /compat/linux and run
rpm2cpio.pl < package_name.rpm | cpio -id.

Chroot to /compat/linux and create in /usr/lib the symbolic links to the libraries located in cuda/lib.

To compile an application run /usr/local/cuda/bin/nvcc app.cu
 
Last edited by a moderator:
Back
Top