I want to allocate memory on the gpu in one DLL, then make my calculations in a second DLL that will be executed in a while loop and finally free the memory in a third DLL that will be called once after the while loop ended.
To make sure that all DLLs can access the allocated data I tried to use a Cuda context that will be created in the first DLL and detatched there from the host thread. The second DLL should “catch” this context, do some calculations and detatch it again. Finally the third DLL should destroy the context.
How it seems that first idea does not work, I hope someone can help me using these functions or to make it work by another way.
Here is a scheme of my first trial, that does not work:
[codebox]//First DLL: allocate memory, executes one time before a while loop
I’ve your same problem!..I’m answering here in the nvidia forum but no one replies! have you solved your problem? can you give me an hand with my program:
I’m trying to write a simple program to understando how CUDA context works:
is corret to use the context in this way? I need that the first thread allocate the memory on device and the second thread print 1.0 and 2.0 but without cuda context doesn’t work. With this solution the compiler return the following errors:
/tmp/tmpxft_00006a46_00000000-12_th1.o: In function `main’:
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10a5c): undefined reference to `cuCtxDestroy’
/tmp/tmpxft_00006a46_00000000-12_th1.o: In function `compute_function(void*)':
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10a80): undefined reference to `cuCtxPushCurrent’
/tmp/tmpxft_00006a46_00000000-12_th1.o: In function `inizialize(void*)':
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10b12): undefined reference to `cuDeviceGet’
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10b24): undefined reference to `cuCtxCreate’
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10b90): undefined reference to `cuCtxPopCurrent’
give me an hand please i need it works for my degree thesis
I’ve your same problem!..I’m answering here in the nvidia forum but no one replies! have you solved your problem? can you give me an hand with my program:
I’m trying to write a simple program to understando how CUDA context works:
is corret to use the context in this way? I need that the first thread allocate the memory on device and the second thread print 1.0 and 2.0 but without cuda context doesn’t work. With this solution the compiler return the following errors:
/tmp/tmpxft_00006a46_00000000-12_th1.o: In function `main’:
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10a5c): undefined reference to `cuCtxDestroy’
/tmp/tmpxft_00006a46_00000000-12_th1.o: In function `compute_function(void*)':
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10a80): undefined reference to `cuCtxPushCurrent’
/tmp/tmpxft_00006a46_00000000-12_th1.o: In function `inizialize(void*)':
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10b12): undefined reference to `cuDeviceGet’
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10b24): undefined reference to `cuCtxCreate’
tmpxft_00006a46_00000000-1_th1.cudafe1.cpp:(.text+0x10b90): undefined reference to `cuCtxPopCurrent’
give me an hand please i need it works for my degree thesis
First, a CUDA context is just a pointer to a special structure, as defined in cuda.h.
typedef struct CUctx_st *CUcontext;
The crucial question, which I’m not sure I can answer in detail, is who is responsible for managing the context pool. Intuitively it must be the thread from which you call cuInit(). The context pool is most likely a static variable declared in cuInit().
If that’s the case, you need to call cuInit() in your main() function. I would create and destroy the contexts here too.
Since the context pool is a static variable, if you call cuInit() in a DLL, the context pool will be visible in that DLL only. Therefore, any context pointer will be meaningless outside the DLL.
Remember that a DLL has its own address space. Also google about DLLs and static functions. One useful link:
First, a CUDA context is just a pointer to a special structure, as defined in cuda.h.
typedef struct CUctx_st *CUcontext;
The crucial question, which I’m not sure I can answer in detail, is who is responsible for managing the context pool. Intuitively it must be the thread from which you call cuInit(). The context pool is most likely a static variable declared in cuInit().
If that’s the case, you need to call cuInit() in your main() function. I would create and destroy the contexts here too.
Since the context pool is a static variable, if you call cuInit() in a DLL, the context pool will be visible in that DLL only. Therefore, any context pointer will be meaningless outside the DLL.
Remember that a DLL has its own address space. Also google about DLLs and static functions. One useful link: