 	CUDA_SAFE_CALL (cudaFree(temp_black_d));
 	
 	CUDA_SAFE_CALL (cudaFree(bl_norm_L2_d));
+	
+	#ifdef TEXTURE
+	// unbind textures
+	CUDA_SAFE_CALL (cudaUnbindTexture(aP_t));
+	CUDA_SAFE_CALL (cudaUnbindTexture(aW_t));
+	CUDA_SAFE_CALL (cudaUnbindTexture(aE_t));
+	CUDA_SAFE_CALL (cudaUnbindTexture(aS_t));
+	CUDA_SAFE_CALL (cudaUnbindTexture(aN_t));
+	CUDA_SAFE_CALL (cudaUnbindTexture(b_t));
+	#endif
 	
 	/////////////////////////////////
 	// end timer

#include <cutil.h>

/** Double precision */
#define Real double

typedef unsigned int uint;


	CUDA_SAFE_CALL (cudaMemcpy (temp_red_d, temp_red, size_temp * sizeof(Real), cudaMemcpyHostToDevice));
	CUDA_SAFE_CALL (cudaMemcpy (temp_black_d, temp_black, size_temp * sizeof(Real), cudaMemcpyHostToDevice));
	
	#ifdef TEXTURE
	// bind to textures
	CUDA_SAFE_CALL (cudaBindTexture (NULL, aP_t, aP_d, size * sizeof(Real)));
	CUDA_SAFE_CALL (cudaBindTexture (NULL, aW_t, aW_d, size * sizeof(Real)));
	CUDA_SAFE_CALL (cudaBindTexture (NULL, aE_t, aE_d, size * sizeof(Real)));
	CUDA_SAFE_CALL (cudaBindTexture (NULL, aS_t, aS_d, size * sizeof(Real)));
	CUDA_SAFE_CALL (cudaBindTexture (NULL, aN_t, aN_d, size * sizeof(Real)));
	CUDA_SAFE_CALL (cudaBindTexture (NULL, b_t, b_d, size * sizeof(Real)));
	#endif
	
	// block and grid dimensions
	
	///////////////////////////////////////
