Simple Example to create DLL with NVCC

A very nice tutorial. External Image

Hey Sarnath,

Thanks for the reply. It turns out there was something funky with my Visual Studio build configuration. Once I fixed that, the timing difference was negligible.

Thanks again for this wonderful resource!

@JPH,

Thanks! And it is assuring that there is no major time problems in having code as DLLs.

@Pimbolie,

Thanks!! :-)

Hi Sarnath and all,
I’ve a bit problem… :-P
Then, I built the dll. It export this function:

extern “C” __declspec(dllexport)
void my_intcopy_caller(int* gpuSource, int* gpuDest, int n, int* g, int* f[2], int* h[2], int* c[2])
{

*g = 5; //this is to test for the "var" direttivo with delphi.it's work, this isn't the problem

my_intcopy <<< 1, 1 >>>(gpuSource, gpuDest, n, f,h,c);  ///I use "1,1" for test. 
cudaThreadSynchronize();

}

and this funciont call another function:

global void my_intcopy(int *src, int *dest, int n, int *f[2], int *h[2], int *c[2])
{
int i;
for(i=0; i<10; i++)
{
dest[i] = src[i] + i ; //this work well!!!
}

int a,b;
for(a=0; a<2; a++)
 for(b=0; b<2; b++)
 {
  //h[a][b] = f[a][b] + 2;                   //this DOESN'T WORK!!!
  //h[a][b] = f[a][b] + c[a][b];           //this DOESN'T WORK!!!
  //h[a][b] = f[a][b] + f[a][b];           //this DOESN'T WORK!!!
  h[a][b] = f[a][b]  // this works well...this line copies every elements of f in h.
 }    
__syncthreads();

}

I can not add f and an integer to store in h, why?
Assumed every elements of f are “1” (integer), the result should be equal to “3”, but it gives me “0”!!!
Why??? :huh: :(
Thanx!!! :-)

Thanks a lot for this. I don’t need it now, but it will be very handy when I do External Media

@NV Moderators,

The DLL and App Create WMV files are NO Longer Downloadable (an earlier post by me). I am getting requests to send it over via e-mail.

Can some1 fix this please??

I am unable to upload attachments (I tried with this post… but could not)… :(

I just downloaded.
Man, you make a great favor to newby.
Thank you very much.

Sarnath

Great thanks!

I am surprised to see this thread still active… Thanks a lot guys! Very happy that you all find it useful!

Best Regards,
Sarnath

Thanks for your posting. It is very useful for me. I think that your work gives novice cuda programmer and student valuable tips and lecture.

Signed. External Media

Great Work and thanks a lot! - I’ll follow the instructions right after posting this.

Hello Sarnath! :)
After a while, I’m here again!! :)
Can you explain how to compile a module Cubin file ? So to call from my delphi applications? :)
Without creating a dll?
thanks in advance :-)))

Regards,

Guido

Hello Sarnath! :)
After a while, I’m here again!! :)
Can you explain how to compile a module Cubin file ? So to call from my delphi applications? :)
Without creating a dll?
thanks in advance :-)))

Regards,

Guido

Hi Sarnath,

Your video was very helpful however I was not able to compile. I am using Visual Studio 2010 Ultimate and CUDA toolkit 4.1

I get the following error

1>LINK : fatal error LNK1104: cannot open file ‘Debug\kernel.obj’

I used the following custom build command

nvcc -I"$(CUDA_INC_PATH)" -c -o $(ConfigurationName)\kernel.obj kernel.cu

I have compiled this code before where I had the main function in the same file as the kernel.cu and it worked at that time. That is I successfully created the .exe file. However now i am trying to separate out my CUDA functions into a dll so that I can load them into different projects.

Any help in this regard would be great.

Thanks in advance,

Sai.

Add “-v” verbose option to NVCC and see if NVCC is getting called… It will produce lot of messages and command line and hence you will understand what is going on… Then, start debugging from the messages as to why “kernel.obj” was not created…

If yuo dont see a flurry of messages then that means that NVCC is not being called… So, you need to debug that first!

HTH!

I haven’t had a lot of experience or luck with VS, I’m using VS2005 on . I followed the video posted by Sarnath to create and compile a .DLL file, but i was unable to get it to compile.

I get this error in the output:
Linking…
\debug\stdafx.obj : fatal error LNK1112: module machine type ‘X86’ conflicts with target machine type ‘x64’
[attachment=25232:BuildLog.htm]
I’ve attached the buildLog as well for anyone to have a look at

To me, this looks like the configured build options thinks the module machine is x86 and target machine is x64. I assume the target machine is the one i’m building on, but can someone explain what the module machine means and how i can change this to x64 to be compatible?
I tried looking in the build configuration properties for somewhere to change this, but i could only find the target machine that could be set.

I followd the solution from this post (Software - Intel Communities) and that seemed to remove ther prvious error, but now i have more new ones. Several variables are already defined in other libraries.

1>LIBCMT.lib(tidtable.obj) : error LNK2005: _encode_pointer already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: _encoded_null already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(tidtable.obj) : error LNK2005: _decode_pointer already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _amsg_exit already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(crt0dat.obj) : error LNK2005: _initterm_e already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: _unlock already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(mlock.obj) : error LNK2005: _lock already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(winxfltr.obj) : error LNK2005: __CppXcptFilter already defined in MSVCRTD.lib(MSVCR80D.dll)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: __xi_a already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: __xi_z already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: __xc_a already defined in MSVCRTD.lib(cinitexe.obj)
1>LIBCMT.lib(crt0init.obj) : error LNK2005: __xc_z already defined in MSVCRTD.lib(cinitexe.obj)
1> Creating library C:\Users\bellamyb\Documents\Visual Studio 2005\Projects\cuda_dll\x64\Debug\cuda_dll.lib and object C:\Users\bellamyb\Documents\Visual Studio 2005\Projects\cuda_dll\x64\Debug\cuda_dll.exp
1>LINK : warning LNK4098: defaultlib ‘MSVCRTD’ conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4098: defaultlib ‘LIBCMT’ conflicts with use of other libs; use /NODEFAULTLIB:library
1>LIBCMT.lib(crt0.obj) : error LNK2019: unresolved external symbol main referenced in function __tmainCRTStartup
1>C:\Users\bellamyb\Documents\Visual Studio 2005\Projects\cuda_dll\x64\Debug\cuda_dll.dll : fatal error LNK1120: 1 unresolved externals

The build log has been attached as well.

In the tutorial we have seen that it is possible to export from a DLL.

I’d like to know if it is possible to import things to a DLL.

In the same way, I’d like to know if it is possible to export from an application.

A DLL can depend on other DLL’s - I would guess.

So, Using “DllImport” inside a DLL code should just work fine provided the reference gets resolved through another DLL at run-time.

I am not too sure if the dynamic linker would resolve something like that.

But I am not a windows guru.

May be,

You can try declaring that function as an external function and see if the

DLL linker is smart enough to link it. BUt I would doubt that since the linking

is happening dynamically at run-time.

Probably the best way is to move that function from app to DLL and keep everybody happy.

Any way, Please do check with some good windows DLL guy.

Good luck!

Best Regards

Sarnath