Calling Thrust from CUDA Fortran


I am trying to call Thrust from CUDA Fortran.

I am having trouble compiling the C code to get the .obj file.

For the Fortran code, I am using PVF 10.13 with CUDA 5.5 on a Windows system.

For the c code, I am trying to compile from Visual Studio 2012. Here is the code:

#include <thrust/device_vector.h>
#include <thrust/device_vector.h>
#include <thrust/sort.h>
extern "C" {
//Sort for integer arrays
void sort_int_wrapper( int *data, int N)
// Wrap raw pointer with a device_ptr
thrust::device_ptr <int> dev_ptr(data);
// Use device_ptr in Thrust sort algorithm
thrust::sort(dev_ptr, dev_ptr+N);
//Sort for float arrays
void sort_float_wrapper( float *data, int N)
thrust::device_ptr <float> dev_ptr(data);
thrust::sort(dev_ptr, dev_ptr+N);
//Sort for double arrays
void sort_double_wrapper( double *data, int N)
thrust::device_ptr <double> dev_ptr(data);
thrust::sort(dev_ptr, dev_ptr+N);

I get an error when I try to build:

error LNK1561: entry point must be defined

I also get warnings:

warning: Cannot tell what pointer points to, assuming global memory space

Can someone help me with this? The .obj file is not being created.

Thank you,


This is what my linker command line looks like for the c code:

/OUT:“C:\Users\kirk\Desktop\CUDA Fortran\Thrust\Sort\Debug\Sort.exe” /MANIFEST /NXCOMPAT /PDB:“C:\Users\kirk\Desktop\CUDA Fortran\Thrust\Sort\Debug\Sort.pdb” /DYNAMICBASE “kernel32.lib” “user32.lib” “gdi32.lib” “winspool.lib” “comdlg32.lib” “advapi32.lib” “shell32.lib” “ole32.lib” “oleaut32.lib” “uuid.lib” “odbc32.lib” “odbccp32.lib” /DEBUG /MACHINE:X86 /INCREMENTAL /PGD:“C:\Users\kirk\Desktop\CUDA Fortran\Thrust\Sort\Debug\Sort.pgd” /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /ManifestFile:“Debug\Sort.exe.intermediate.manifest” /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v5.5\lib\Win32” /TLBID:1


Since I only want the .obj file, maybe I need to suppress the linking phase when building the c code?


Hi Kirk,

I haven’t tried using Thrust on Windows but on Linux I compiled the Thrust wrapper using NVCC -c. It sounds like you’re trying using CL.

Compiling multi-language in Visual Studio is a bit of a pain since VS doesn’t allow you to mix languages in the same project. Hence, you need to create a library of all the object of one language and then link the library in with another.

What I’d try is compiling the CUDA C thrust interface source file using NVCC on the command line and then link this object into the PVF project.

Personally I was never happy with the performance I got out of thrust when calling it from CUDA Fortran. At least for me, any performance gains that thrust provided was off-set by the fact that I had to use this interface.

If you don’t mind blazing trail, there is a new library out of NVLabs called CUB ( that producing much better performance than Thrust. You’d still have to provide an CUDA C interface but it may be worth a try. Granted, I have not tried using it with CUDA Fortan so have no idea what problems you might encounter.

  • Mat

OK, I got the .cu file to compile. I finally have an .obj file ready for use with my Fortran code.

The trick was that I had to have Visual Studio Pro installed, otherwise nvcc complained about a bunch of stuff.

I am now able to use Thrust!

I will try to use CUB as well, if I succeed, I will post a comparison between sorting in Thrust and CUB.