     err = cudaFreeArray( _dog_3d );
     if( err != cudaSuccess ) {
         cerr << "CUDA array free failed" << endl;
+        exit( -1 );
     } else {
         cerr << "CUDA array free success" << endl;
     }

#include <cuda_runtime.h>
#include <iostream>

using namespace std;


                                   &dog_tex_desc, 0 );
    if( err != cudaSuccess ) {
        cerr << "CUDA create texture failed: " << cudaGetErrorString(err) << endl;
        exit( -1 );
    } else {
        cerr << "CUDA create texture succeeded" << endl;
    }

    // cudaResourceDesc dog_res_desc;
    // dog_res_desc.resType         = cudaResourceTypeArray;
    // dog_res_desc.res.array.array = _dog_3d;

#ifdef WITH_SURFACE
    err = cudaCreateSurfaceObject( &_dog_3d_surf, &dog_res_desc );
    if( err != cudaSuccess ) {
        cerr << "CUDA create surface failed: " << cudaGetErrorString(err) << endl;
        exit( -1 );
    } else {
        cerr << "CUDA create surface succeeded" << endl;
    }
#endif // WITH_SURFACE

    float* array;
    err = cudaMallocHost( &array, width*height*levels*sizeof(float) );
    if( err != cudaSuccess ) {
        cerr << "CUDA malloc host failed: " << cudaGetErrorString(err) << endl;
        exit( -1 );
    } else {
        cerr << "CUDA malloc host succeeded" << endl;
    }

    cerr << "== host-sided printing of array ==" << endl;
    for( int z=0; z<levels; z++ ) {
        for( int y=0; y<height; y++ ) {
            for( int x=0; x<width; x++ ) {
                int val = x + 10*y + 100*z;
                array[(z*height + y)*width + x] = val;
                cerr << val << " ";
            }
            cerr << endl;
        }
