BindTexture Problem

Hello,

It’s nice that cuda does support classes but somehow they don’t work as expected … Suppose:

template<T>

class BLA {

   texture<T,2,cudaReadModeNormalizedFloat> m_texture;

    cudaArray* m_array;

    cudaChannelDesc<T> m_desc;

   void init() {

        [...]

        CUDA_SAFE_CALL( cudaBindTexture( m_texture, m_array, m_desc));

        [...]

    }

};

CudaBindTexture always fails if m_texture is a class member. As soon as I define the variable outside the class it works.

This hack works as well but it’s not really nice:

texture<uchar4,2,cudaReadModeNormalizedFloat> texRef;

template<T>

class BLA {

   texture<T,2,cudaReadModeNormalizedFloat> m_texture;

    cudaArray* m_array;

    cudaChannelDesc<T> m_desc;

   void init() {

        [...]

        memcpy((void*)&texRef, (void*)&m_texture, sizeof( texture<T, 2, cudaReadModeNormalizedFloat>));

        CUDA_SAFE_CALL( cudaBindTexture( texRef, m_array, m_desc));

        [...]

    }

};

Is my problem a compiler bug or am I doing anything wrong?

regards

Pototschnig

nvcc seems to just hack global texture variables to appear in both CPU code and GPU code, and connected by a name or something.
to make a texture usable, it has to be a global after the C++ to C preprocess.
thus, maybe you can declare a static member in that template class and use that one. if i were writing nvcc, i’d make that work.
if that doesn’t work, one could always #define and #include FILE