@@ -29,6 +29,9 @@ Texture::Texture(void *textureHandle, int textureWidth, int textureHeight,
2929 // initialize surface object
3030 _surfObjArray = new cudaSurfaceObject_t[textureDepth];
3131
32+ CUDA_CHECK (cudaMalloc (&d_surfObjArray,
33+ _textureDepth * sizeof (cudaSurfaceObject_t)));
34+
3235 for (int i = 0 ; i < textureDepth; i++)
3336 {
3437 _surfObjArray[i] = 0 ;
@@ -40,6 +43,7 @@ Texture::Texture(void *textureHandle, int textureWidth, int textureHeight,
4043Texture::~Texture ()
4144{
4245 delete (_surfObjArray);
46+ CUDA_CHECK (cudaFree (d_surfObjArray));
4347}
4448
4549void Texture::mapTextureToSurfaceObject ()
@@ -63,6 +67,9 @@ void Texture::mapTextureToSurfaceObject()
6367 CUDA_CHECK (cudaCreateSurfaceObject (&_surfObjArray[i], &resDesc));
6468 CUDA_CHECK (cudaGetLastError ());
6569 }
70+ CUDA_CHECK (cudaMemcpy (d_surfObjArray, _surfObjArray,
71+ _textureDepth * sizeof (cudaSurfaceObject_t),
72+ cudaMemcpyHostToDevice));
6673}
6774
6875void Texture::unmapTextureToSurfaceObject ()
@@ -108,7 +115,9 @@ void *Texture::getNativeTexturePtr() const
108115
109116cudaSurfaceObject_t *Texture::getSurfaceObjectArray () const
110117{
111- return _surfObjArray;
118+ // to use a complete array of surface object in a kernel,
119+ // we need to use the array allocate on device memory
120+ return d_surfObjArray;
112121}
113122
114123cudaSurfaceObject_t Texture::getSurfaceObject (int indexInArray) const
@@ -121,5 +130,10 @@ cudaSurfaceObject_t Texture::getSurfaceObject(int indexInArray) const
121130 return 0 ;
122131 }
123132
133+ // to use a single surface object in a kernel
134+ // we can use directly the surface object that
135+ // is on host side, because cudaSurfaceObject_t is a
136+ // typename for unsigned long long which can be directly
137+ // send to kernel as it's managed memory ?
124138 return _surfObjArray[indexInArray];
125139}
0 commit comments