Question

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 ?

Was it helpful?

Solution 3

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 !

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top