-1

I'm desperately trying to make a dll with CUDA functions but I can't make it work.

I tried the method explained here :Creating DLL from CUDA using nvcc to compile but I've got the following errors :

nvcc : 
warning: __declspec attributes ignored
At line:1 char:1
+ nvcc -o  ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (...ributes ignored:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError



...\kernel.cu(81): warning: __declspec attributes ignored


...\cudaFFT.h(21): warning: __declspec attributes ignored


.../kernel.cu(81): warning: __declspec attributes ignored


nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
kernel.cu
   CrÚation de la bibliothÞque C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.lib et de l'objet C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.exp
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftPlan1d rÚfÚrencÚ dans la fonction AllocateMemoryForFFTs
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftExecD2Z rÚfÚrencÚ dans la fonction ComputeFFT
tmpxft_00003b9c_00000000-30_kernel.obj : error LNK2019: symbole externe non rÚsolu cufftDestroy rÚfÚrencÚ dans la fonction DeAllocateMemoryForFFTs
C:/Users/alombet/Documents/Visual Studio 2015/Projects/Test/kernel.dll : fatal error LNK1120: 3 externes non rÚsolus

First of all the __declspec seems to be ignored, and after that it seems the compiler doesn't find the functions I use in the cuda libraries. I'm really not accustomed to compiling by hand. Usually, I rely on the IDE to do it and thus I am completely lost here.

Here is the code :

#include "cuda_runtime.h"
#include "device_launch_parameters.h"

#include <stdio.h>
#include <iostream>
// includes, system
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>

// includes, project
#include <cuda_runtime.h>
#include <cufft.h>
#include <cufftXt.h>


#define LIBRARY_EXPORTS 1

#ifdef LIBRARY_EXPORTS  
#define LIBRARY_API __declspec(dllexport)   
#else  
#define LIBRARY_API __declspec(dllimport)   
#endif 

#include "cudaFFT.h"

#ifdef __cplusplus
extern "C" {
#endif

int LIBRARY_API __cdecl numberOfGpus()
{
    int nDevices;
    cudaGetDeviceCount(&nDevices);

    return nDevices;
}


cufftDoubleReal *host_input;
cufftDoubleReal *device_input;

cufftDoubleComplex *host_output;
cufftDoubleComplex *device_output;

cufftHandle plan;




cudaError LIBRARY_API __cdecl AllocateMemoryForFFTs(int maxSize, int maxBatch)
    {

        int width = maxSize; int height = maxBatch;

        cudaError err = cudaMallocHost((void **)&host_input, sizeof(cufftDoubleReal) * width * height);
        if (err)
            return err;

        err = cudaMallocHost((void **)&host_output, sizeof(cufftDoubleComplex) * (width / 2 + 1) * height);
        if (err)
            return err;

        err = cudaMalloc((void **)&device_input, sizeof(cufftDoubleReal) * width * height);
        if (err)
            return err;

        err = cudaMalloc((void **)&device_output, sizeof(cufftDoubleComplex) * (width / 2 + 1) * height);
        if (err)
            return err;

        cufftResult res = cufftPlan1d(&plan, width, CUFFT_D2Z, height);
        if (res)
            return (cudaError)res;

        return cudaSuccess;
    }


double* LIBRARY_API __cdecl GetInputDataPointer()
    {
        return host_input;
    }

cudaError LIBRARY_API __cdecl ComputeFFT(int size, int batch, double2** result)
    {
        cudaError err = cudaMemcpy(device_input, host_input, sizeof(cufftDoubleReal) * size * batch, cudaMemcpyHostToDevice);
        if (err)
            return err;

        cufftResult res = cufftExecD2Z(plan, device_input, device_output);
        if (res)
            return (cudaError)res;


        err = cudaMemcpy(host_output, device_output, sizeof(cufftDoubleComplex) * (size / 2 + 1) * batch, cudaMemcpyDeviceToHost);
        if (err)
            return err;

        *result = host_output;
        return cudaSuccess;
    }

void LIBRARY_API __cdecl DeAllocateMemoryForFFTs()
    {
        cufftDestroy(plan);
        cudaFree(device_input);
        cudaFree(device_output);
        cudaFreeHost(host_input);
        cudaFreeHost(host_output);
    }

#ifdef __cplusplus
}
#endif
Community
  • 1
  • 1

1 Answers1

2

Ok I found my problems, I leave the solution here in case it can help someone.

  1. I removed the LIBRARY_API keyword from the .cu
  2. In the .h I moved the LIBRARY_API at the very beginning of each declaration.
  3. I changed the project properties in vs to generate a dll.
  4. Let VS compile
talonmies
  • 70,661
  • 34
  • 192
  • 269