calling CUDA functions from the computing platform Ice (from ZeroC)

Dear All,

I’m working on integration of some my shared libraries using CUDA (for Nvidia Tesla T10 card) into the Ice framework. However, I’m facing the following problem.

For example, one class is declared within a shared library which performs some computations on the GPU using CUDA. In the Ice module (within the Ice interface function) an object of this class is created only once and used for all Ice calls from outside. But it works fine only for the very first call (the first portion of data). During the second call it crashes… I’ve figured out that CUDA calls in the shared library crash when they are called second time from our Ice module by the created object. The error message is “cudaSafeCall() Runtime API error : invalid argument”. Here is an example of a testing class which doesn’t work with Ice:

CCudaTest::CCudaTest(): m_pData(0){

m_pData = new unsigned char[320 * 256];

  bzero(m_pData, 320 * 256);

for(int i = 0; i < 320 * 256; ++i)

    *(m_pData + i) = i;

// allocate device memory

  SC( cudaMalloc((void**)&m_d_CudaData, 320 * 256) );

  SC( cudaMemcpy(m_d_CudaData, m_pData, 320 * 256, cudaMemcpyHostToDevice) );



delete[] m_pData;

// release device memory

  SC( cudaFree(m_d_CudaData) );


void CCudaTest::PrintString(){

std::cout << "CCudaTest: print string function !!!" << std::endl;


void CCudaTest::CudaTestFunction(){

bzero(m_pData, 320 * 256);

cudaMemcpy(m_pData, m_d_CudaData, 320 * 256, cudaMemcpyDeviceToHost);

for(int i = 0; i < 100; ++i)

    std::cout << "val = " << (int)*(m_pData + i) << " ";


Calling “CudaTestFunction” from the Ice interface function with the same object fails on the second call and no proper values are being printed. However, it works without problems if an object of this class is created every Ice call… Furthermore, everything works fine if this function is called in a loop by the same object outside the Ice functions… “PrintString” function works in all cases.

Does anybody here have an experience using Ice with CUDA? I suspect that something weird happens here with GPU memory addresses or thread contexts.

Any suggestions and/or ideas are kindly welcome!

Thanks a lot for your help!