views:

406

answers:

3

I am tryint to integrate CUDA in an existing project, in which several libs (DLLs) are created. I started with a very simple kernel that computes a dot product :

// dotProd_kernel.cu

__global__ void dotProd( double* result, double* vec1, double* vec2)
{
    int i = threadIdx.x;
 result[i] = vec1[i] * vec2[i];
}

This kernel is called by a host script :

// doProd.cu

#include <cutil_inline.h>
#include <dotProd_kernel.cu>

extern "C" double CUDA_dot(THTensor *vec1, THTensor *vec2);

double CUDA_dot(THTensor *vec1, THTensor *vec2)
{
    // [content skipped]    

    // execute the kernel
    dotProd<<< 1, nbThreads >>>(device_vec1, device_vec2, device_result_array);

    // [content skipped]

    return sum;
}

I generate build files using cmake, and use Visual Studio 2008 Pro to compile it. If I simply use a .cu file with a foobar function that calls no kernel, it executes fine. But with the above code, I get the following error :

c:\cuda\include\math_functions.h(3459) : error C2491: 'log1p' : definition of dllimport function not allowed

The resulting code that calls the CUDA code is exported as a DLL. Is this the problem ?

+1  A: 

I don't even know what CUDA is, but I would look at the code that had the compiler error (math_functions.h) and look at line 3459 and see what it's trying to do and start from there. It seems unrelated to what you are trying to do in the code you posted.

Francis Upton
CUDA is an NVIDIA Extension of C which is used for accessing their GPU hardware for parallel processing. http://en.wikipedia.org/wiki/CUDA
fauxtrot
Also, always look up the C error number in the Visual Studio Help or online at MSDN. The explanation of C2491 is here: http://msdn.microsoft.com/en-us/library/62688esh(VS.71).aspx
Die in Sente
Thanks guys ! I looked at the code of course, but as it was in a library I already used and supposed to work, the problem had to be on my side. The code I posted is what I was working on when the error arose. But I figured it out, see my answer... Thanks for the help !
Wookai
A: 

Actually, the CUDA library defines the log1p function, and so was an obscure part of the code I'm trying to add CUDA to. Thus, there was some kind of conflict between the two. I simply renamed the function in my code, and it worked !

Wookai
+1  A: 

Incidentally, if you're using CUDA 2.3 (or, preferably 3.0) then you should be able to get rid of the extern "C".

Tom
I am currently using 2.3. Do you have any link about this ?
Wookai