 #include <cuda_runtime.h>
 #include <iostream>
+
+#define WITH_SURFACE
 
 using namespace std;
 

    }

#if 0
    err = cudaMemcpyToArray( _dog_3d,
                             0, 0,
                             array,
                             10*4*2*sizeof(float),
                             // 10*4*sizeof(float),
                             cudaMemcpyHostToDevice );
#else
    cudaMemcpy3DParms s = { 0 };
    s.srcPtr = make_cudaPitchedPtr( array, 10*sizeof(float), 10, 4 );
    s.dstArray = _dog_3d;
    s.extent = make_cudaExtent( width, height, levels );
    s.kind = cudaMemcpyHostToDevice;
    err = cudaMemcpy3D( &s );
#endif
    if( err != cudaSuccess ) {
        cerr << "CUDA memcpy 3D failed: " << cudaGetErrorString(err) << endl;
    } else {
        cerr << "CUDA memcpy 3D succeeded" << endl;
    }

    testPrintArray
        <<<1,1>>>
        ( _dog_3d_tex, width, height, levels );

    err = cudaFreeHost( array );
    if( err != cudaSuccess ) {
        cerr << "CUDA free host failed" << endl;
    } else {
        cerr << "CUDA free host success" << endl;
    }

    err = cudaDestroyTextureObject( _dog_3d_tex );
    if( err != cudaSuccess ) {
        cerr << "CUDA destroy texture failed" << endl;
    } else {
        cerr << "CUDA destroy texture success" << endl;
    }

    }
}

#ifdef WITH_SURFACE
__global__
void writeToSurface( cudaSurfaceObject_t obj, int width, int height, int levels )
{
    for( int z=threadIdx.z; z<levels; z += blockDim.z ) {
        for( int y=threadIdx.y; y<height; y += blockDim.y ) {
            for( int x=threadIdx.x; x<width; x += blockDim.x ) {
                float v = x - 10*y + 100*z;
                surf2DLayeredwrite( v,
                                    obj,
                                    x*sizeof(float), y, z,
                                    cudaBoundaryModeZero );
                                    // x, y, z,
                                    // cudaBoundaryModeTrap );
            }
        }
    }
}
#endif // WITH_SURFACE

int main( )
{
    int width  = 10;
