コード例 #1
0
ファイル: fluidsGL.cpp プロジェクト: Aahung/CudaSample
void cleanup(void)
{
    cudaGraphicsUnregisterResource(cuda_vbo_resource);

    unbindTexture();
    deleteTexture();

    // Free all host and device resources
    free(hvfield);
    free(particles);
    cudaFree(dvfield);
    cudaFree(vxfield);
    cudaFree(vyfield);
    cufftDestroy(planr2c);
    cufftDestroy(planc2r);

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
    glDeleteBuffersARB(1, &vbo);

    sdkDeleteTimer(&timer);

    if (g_bExitESC)
    {
        checkCudaErrors(cudaDeviceReset());
    }
}
コード例 #2
0
ファイル: FBO.cpp プロジェクト: Homletmoo/HM-004
/*!
 * Creates a new FBO on the GPU.
 *
 * @param derived If the FBO is actually an instance of a derived type (eg. ShadowMap). In
 *                this case, no setup is performed as this is the job of the derived constructor.
 *                It is false by default, so you usually don't need to bother with it.
 */
FBO::FBO( bool derived )
{
	if ( !derived )
	{
		glGenFramebuffers(  1, &ID        );
		glGenTextures(      1, &textureID );
		glGenRenderbuffers( 1, &depthID   );

		bind();
		bindTexture();
		{
			glActiveTexture( GL_TEXTURE0 + 1 );
			glTexImage2D(    GL_TEXTURE_2D, 0, GL_RGB, WIN_W, WIN_H, 0, GL_RGB, GL_UNSIGNED_BYTE, 0 );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );

			glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT, WIN_W, WIN_H );

			glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,  GL_RENDERBUFFER, depthID );
			glFramebufferTexture(      GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, textureID, 0 );

			GLenum draw_buffers[1] = { GL_COLOR_ATTACHMENT0 };
			glDrawBuffers( 1, draw_buffers );

			if ( glCheckFramebufferStatus( GL_FRAMEBUFFER ) != GL_FRAMEBUFFER_COMPLETE )
				throw std::exception( "Failed to create framebuffer." );
		}
		unbind();
		unbindTexture();

		glActiveTexture( GL_TEXTURE0 );
	}
}
コード例 #3
0
ファイル: TextureManager.cpp プロジェクト: artcom/y60
 void
 TextureManager::unbindTextures() {
     AC_DEBUG << "TextureManager::unbindTextures";
     std::vector<TexturePtr> myTextures = _myTextureList->getAllFacades<Texture>(TEXTURE_NODE_NAME);
     for (unsigned i = 0; i < myTextures.size(); ++i) {
         unbindTexture(myTextures[i].get());
     }
 }
コード例 #4
0
void gpuNUFFT::TextureGpuNUFFTOperator::forwardConvolution(
    CufftType *data_d, DType *crds_d, CufftType *gdata_d, DType *kernel_d,
    IndType *sectors_d, IndType *sector_centers_d,
    gpuNUFFT::GpuNUFFTInfo *gi_host)
{
  bindTo1DTexture("texGDATA", gdata_d,
                  gi_host->grid_width_dim * gi_host->n_coils_cc);

  performTextureForwardConvolution(data_d, crds_d, gdata_d, kernel_d, sectors_d,
                                   sector_centers_d, gi_host);

  unbindTexture("texGDATA");
}
コード例 #5
0
void gpuNUFFT::TextureGpuNUFFTOperator::adjConvolution(
    DType2 *data_d, DType *crds_d, CufftType *gdata_d, DType *kernel_d,
    IndType *sectors_d, IndType *sector_centers_d,
    gpuNUFFT::GpuNUFFTInfo *gi_host)
{
  bindTo1DTexture("texDATA", data_d,
                  this->kSpaceTraj.count() * gi_host->n_coils_cc);

  performTextureConvolution(data_d, crds_d, gdata_d, kernel_d, sectors_d,
                            sector_centers_d, gi_host);

  unbindTexture("texDATA");
}
コード例 #6
0
ファイル: ccImage.cpp プロジェクト: Bingyu1413/trunk
void ccImage::setData(const QImage& image)
{
	//previous image?
	if (!m_image.isNull())
		unbindTexture();

	m_image = image;
	m_width = m_image.width();
	m_height = m_image.height();
	setAspectRatio(m_height>0 ? (float)m_width/(float)m_height : 1.0f);

	//default behavior (this will be updated later, depending
	//on the OpenGL version of the bound QGLWidget)
	m_texU = 1.0;
	m_texV = 1.0;
}
コード例 #7
0
void CudaImagePyramidHost::clear() 
{
    if (!isInitialized()) {
        return;
    }

    // Don't bother unbinding the texture if everything is getting destroyed,
    // because it's likely that CUDA has already destroyed the texture.
    if (!_in_destructor) {
        unbindTexture();
    }

    cudaFreeArray(_storage);
    checkCUDAError("Free error", _name);

    _storage = NULL;
    _baseWidth = 0; _baseHeight = 0; _baseWidth = 0; _baseHeight = 0;
}
コード例 #8
0
void TextureState::deleteTexture(GLuint texture) {
    // When glDeleteTextures() is called on a currently bound texture,
    // OpenGL ES specifies that the texture is then considered unbound
    // Consider the following series of calls:
    //
    // glGenTextures -> creates texture name 2
    // glBindTexture(2)
    // glDeleteTextures(2) -> 2 is now unbound
    // glGenTextures -> can return 2 again
    //
    // If we don't call glBindTexture(2) after the second glGenTextures
    // call, any texture operation will be performed on the default
    // texture (name=0)

    unbindTexture(texture);

    glDeleteTextures(1, &texture);
}
コード例 #9
0
ファイル: RenderUtil.cpp プロジェクト: Reyfin/MyEngine
void RenderUtil::deleteTextures(GLuint Num,GLuint &Texture)
{  
	if(Num > 1)
	{
		for(GLuint i = 0; i < Num;i++)
		{
			for(GLuint j = 0; j < _Textures.size();j++)
			{
				if(_Textures[j] == Texture)
				{
					_Textures.erase(_Textures.begin() + j);
					j -= 1;
					unbindTexture(Texture);
				}
			}
		}
	}
	glDeleteTextures(Num,&Texture);
}
コード例 #10
0
ファイル: FBO.cpp プロジェクト: Homletmoo/HM-004
/*!
 * Creates a new FBO for shadow mapping.
 */
ShadowMap::ShadowMap( void ) :
	FBO( true )
{
	glGenFramebuffers(  1, &ID        );
	glGenTextures(      1, &textureID );
	
	bind();
	bindTexture();
	{
		glActiveTexture( GL_TEXTURE0 + 1 );
		glTexImage2D(
			GL_TEXTURE_2D,
			0,
			GL_DEPTH_COMPONENT16,
			512,
			512,
			0,
			GL_DEPTH_COMPONENT,
			GL_FLOAT,
			0
		);
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );

		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE );
		glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL );
		glTexParameteri( GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE,   GL_INTENSITY );

		glFramebufferTexture( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, textureID, 0 );

		glDrawBuffer( GL_NONE );

		if ( glCheckFramebufferStatus( GL_FRAMEBUFFER ) != GL_FRAMEBUFFER_COMPLETE )
			throw std::exception( "Failed to create shadow map framebuffer." );
	}
	unbind();
	unbindTexture();

	glActiveTexture( GL_TEXTURE0 );
}
コード例 #11
0
ファイル: ccImage.cpp プロジェクト: Bingyu1413/trunk
bool ccImage::bindToGlTexture(ccGenericGLDisplay* win, bool pow2Texture/*=false*/)
{
	assert(win);

	if (m_image.isNull())
		return false;

	if (!m_textureID || m_boundWin != win)
	{
		if (m_textureID && m_boundWin != win)
			unbindTexture();

		m_boundWin = win;
		m_textureID = m_boundWin->getTexture(m_image);

		//OpenGL version < 2.0 require texture with 2^n width & height
		if (!win->supportOpenGLVersion(QGLFormat::OpenGL_Version_2_0)
			&& glewIsSupported("GL_ARB_texture_non_power_of_two") == 0)
		{
			// update nearest smaller power of 2 (for textures with old OpenGL versions)
			unsigned paddedWidth = (m_width > 0 ? 1 << (unsigned)floor(log((double)m_width)/log(2.0)) : 0);
			unsigned paddedHeight = (m_height > 0 ? 1 << (unsigned)floor(log((double)m_height)/log(2.0)) : 0);
			m_texU = float(m_width)/float(paddedWidth);
			m_texV = float(m_height)/float(paddedHeight);
		}
		else
		{
			m_texU = 1.0;
			m_texV = 1.0;
		}
	}

	if (m_textureID != GL_INVALID_TEXTURE_ID)
	{
		glBindTexture( GL_TEXTURE_2D, m_textureID );
		return true;
	}

	return false;
}
コード例 #12
0
  // Called by Rocket when it wants to render application-compiled geometry.		
  void RocketRenderInterface::RenderCompiledGeometry(
    Rocket::Core::CompiledGeometryHandle geometry, 
    const Rocket::Core::Vector2f& translation) {

    if (geometry <= 0) {
      throw runtime_error("RocketRenderInterface::"
        "RenderCompiledGeometry() - ERROR: geometry index = 0!");
    }

    uint32_t i_geometry = static_cast<uint32_t>(geometry);
    ROCKET_SHADER_TYPE cur_shader = _shader_types[i_geometry-1];
    
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glDisable(GL_DEPTH_TEST);
    glDisable(GL_CULL_FACE);
    GetGLError();

    _shader_programs[cur_shader]->bind();

    bindTexture(i_geometry-1);
    GetGLError();

    bindUniforms(cur_shader, translation);
    GetGLError();

    glBindVertexArray(_vao[i_geometry-1]);
    GetGLError();

    glDrawElements(GL_TRIANGLES, _index_size[i_geometry-1], 
      GL_UNSIGNED_INT, BUFFER_OFFSET(0));

    GetGLError();
    glBindVertexArray(0);
    GetGLError();

    unbindTexture();
    GetGLError();
    glDisable(GL_BLEND);
  }
コード例 #13
0
ファイル: fluidsGL.cpp プロジェクト: apc-llc/fluidsGL-optimus
void cleanup(void)
{
    cudaGraphicsUnregisterResource(cuda_vbo_resource);

    unbindTexture();
    deleteTexture();

    // Free all host and device resources
    free(hvfield);
    free(particles);
#ifdef BROADCAST
	free(packets);
#endif
    cudaFree(dvfield);
    cudaFree(vxfield);
    cudaFree(vyfield);
    cufftDestroy(planr2c);
    cufftDestroy(planc2r);

    glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
    glDeleteBuffersARB(1, &vbo);

    sdkDeleteTimer(&timer);
}
コード例 #14
0
ファイル: glwrapper.cpp プロジェクト: linksblackmask/vdrift
void GLWrapper::generateMipmaps(GLenum target, GLuint handle)
{
	BindTexture(target, handle);ERROR_CHECK;
	GLLOG(glGenerateMipmap(target));ERROR_CHECK;
	unbindTexture(target);ERROR_CHECK;
}
コード例 #15
0
ファイル: GLCaches.cpp プロジェクト: lij0511/pandora
void GLCaches::deleteTexture(GLuint texture) {
	if (texture) {
		unbindTexture(texture);
		glDeleteTextures(1, &texture);
	}
}
コード例 #16
0
////////////////////////////////////////////////////////////////////////////////
//! Run a simple test for CUDA
////////////////////////////////////////////////////////////////////////////////
void
runTest( int argc, char** argv)
{
	ocd_options opts = ocd_get_options();
	platform_id = opts.platform_id;
	n_device = opts.device_id;

	if ( argc != 8)
	{
		printf("Usage: GpuTemporalDataMining [<platform> <device> --] <file path> <temporal constraint path> <threads> <support> <(a)bsolute or (r)atio> <(s)tatic | (d)ynamic> <(m)ap and merge | (n)aive | (o)hybrid> \n");
		return;
	}

//    CUT_DEVICE_INIT();
    initGpu();

    getDeviceVariables(device_id);


	printf("Dataset, Support Threshold, PTPE or MapMerge, A1 or A1+A2, Level, Episodes (N), Episodes Culled (X), A1 Counting Time, A2 Counting Time, Generation Time, Total Counting Time\n");

    //CUT_SAFE_CALL( cutCreateTimer( &timer));
    //CUT_SAFE_CALL( cutCreateTimer( &generating_timer));
    //CUT_SAFE_CALL( cutCreateTimer( &a1_counting_timer));
    //CUT_SAFE_CALL( cutCreateTimer( &a2_counting_timer));
    //CUT_SAFE_CALL( cutCreateTimer( &total_timer));

    //CUT_SAFE_CALL( cutStartTimer( total_timer));
    //CUT_SAFE_CALL( cutStartTimer( timer));
    //CUT_SAFE_CALL( cutStartTimer( generating_timer));
    //CUT_SAFE_CALL( cutStartTimer( a1_counting_timer));
    //CUT_SAFE_CALL( cutStartTimer( a2_counting_timer));

    unsigned int num_threads = atoi(argv[3]);
    // allocate host memory
    //initEpisodeCandidates();
	if ( loadData( argv[1] ) != 0 )
		return;
	if ( loadTemporalConstraints(argv[2]) != 0 )
		return;

	// Check whether value supplied is absolute or ratio support
	supportType = *(argv[5]) == 'a' ? ABSOLUTE : RATIO;
	memoryModel = *(argv[6]) == 's' ? STATIC : DYNAMIC;

	switch (*(argv[7]))
	{
	case 'm':
		algorithmType = MAP_AND_MERGE;
		break;
	case 'n':
		algorithmType = NAIVE;
		break;
	case 'o':
		algorithmType = OPTIMAL;
		break;
	}

	support = atof(argv[4]);

	dumpFile = fopen( "episode.txt", "w" );

	//printf("Initializing GPU Data...\n");

	setupGpu();

	// setup execution parameters
    size_t grid[3];
    size_t threads[3];

	//printf("Event stream size: %i\n", eventSize);

	// BEGIN LOOP
	for ( int level = 1; level <= eventSize; level++ )
	{
		printf("Generating episode candidates for level %i...\n", level);
//		CUT_SAFE_CALL( cutResetTimer( total_timer));
//		CUT_SAFE_CALL( cutStartTimer( total_timer));

		//CUDA_SAFE_CALL( cudaUnbindTexture( candidateTex ) );
		if(level != 1){
			unbindTexture(&candidateTex, d_episodeCandidates, numCandidates * (level-1) * sizeof(UBYTE) );
		//CUDA_SAFE_CALL( cudaUnbindTexture( intervalTex ) );
		unbindTexture(&intervalTex, d_episodeIntervals, numCandidates * (level-2) * 2 * sizeof(float));
        }

//		CUT_SAFE_CALL( cutResetTimer( generating_timer));
//		CUT_SAFE_CALL( cutStartTimer( generating_timer));

//		int test1, test = numCandidates;
//		generateEpisodeCandidatesCPU( level );
//		test1 = numCandidates;
//		numCandidates = test;
        printf("Generating Episodes\n");
#ifdef CPU_EPISODE_GENERATION
		generateEpisodeCandidatesCPU( level );
#else
		generateEpisodeCandidatesGPU( level, num_threads );
#endif

//		CUT_SAFE_CALL( cutStopTimer( generating_timer));
		//printf( "\tGenerating time: %f (ms)\n", cutGetTimerValue( generating_timer));


		if ( numCandidates == 0 )
			break;
        printf("Writing to buffer\n");
		// Copy candidates to GPU
#ifdef CPU_EPISODE_GENERATION
		clEnqueueWriteBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent);
                START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer)
                END_TIMER(ocdTempTimer)
		clEnqueueWriteBuffer(commands, d_episodeIntervals, CL_TRUE, 0, numCandidates * (level-1) * 2 * sizeof(float), h_episodeIntervals, 0, NULL, &ocdTempEvent);
                clFinish(commands);
		START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer)
                END_TIMER(ocdTempTimer)
#endif

        bindTexture( 0, &candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE), CL_UNSIGNED_INT8);

		bindTexture( 0, &intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float), CL_FLOAT );

		//printf("Executing kernel on %i candidates...\n", numCandidates, level);

		// execute the kernel
		calculateGrid(grid, num_threads, numCandidates);
		calculateBlock(threads, num_threads, numCandidates);

		int sections;
		unsigned int shared_mem_needed;
		//CUT_SAFE_CALL( cutStartTimer( counting_timer));

		int aType = algorithmType;
		if ( algorithmType == OPTIMAL )
			aType = chooseAlgorithmType( level, numCandidates, num_threads );

		if ( memoryModel == DYNAMIC )
		{
			if ( aType == NAIVE )
			{
				shared_mem_needed = MaxListSize*level*threads[0]*sizeof(float);
                printf("Shared memory needed %d\n", shared_mem_needed);
				//CUT_SAFE_CALL( cutResetTimer( a1_counting_timer));
				//CUT_SAFE_CALL( cutStartTimer( a1_counting_timer));
				countCandidates(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );

			}
			else
			{
                printf("DYNAMIC MAP MERGE\n");
				calculateLevelParameters(level, threads, grid, sections);
				shared_mem_needed = 16000;
                printf("numCandidates=%d\n", numCandidates);
				//CUT_SAFE_CALL( cutResetTimer( a1_counting_timer));
				//CUT_SAFE_CALL( cutStartTimer( a1_counting_timer));
				countCandidatesMapMerge(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates,
                    candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );
				//countCandidatesMapMergeStatic<<< grid, threads, shared_mem_needed >>>( d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates );
			}
		}
		else
		{
			if ( aType == NAIVE )
			{
				shared_mem_needed = level*threads[0]*sizeof(float);
			}
			else
			{
				calculateLevelParameters(level, threads, grid, sections);
				shared_mem_needed = 16000;
			}

				//CUT_SAFE_CALL( cutResetTimer( a2_counting_timer));
				//CUT_SAFE_CALL( cutStartTimer( a2_counting_timer));
			if ( aType == NAIVE )
                countCandidatesStatic(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates, candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed  );
			else
                countCandidatesMapMergeStatic(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates,
                    candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );
			clFinish(commands);

			//CUT_SAFE_CALL( cutStopTimer( a2_counting_timer));

            int err;
            err = clEnqueueReadBuffer(commands,d_episodeSupport, CL_TRUE, 0, numCandidates * sizeof(float), h_episodeSupport, 0, NULL, &ocdTempEvent);
            clFinish(commands);
            	START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer)
            END_TIMER(ocdTempTimer)
		CHKERR(err, "Unable to read buffer from device.");

			unbindTexture(&candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE) );
			unbindTexture(&intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float));

			// Remove undersupported episodes
			cullCandidates( level );

			if ( numCandidates == 0 )
				break;
			unsigned int mmthreads = num_threads;
			if ( MaxListSize*level*num_threads*sizeof(float) > 16384 )
			{
				if ( MaxListSize*level*96*sizeof(float) < 16384 )
					mmthreads = 96;
				else if ( MaxListSize*level*64*sizeof(float) < 16384)
					mmthreads = 64;
				else if ( MaxListSize*level*32*sizeof(float) < 16384)
					mmthreads = 32;
				printf("More shared memory needed for %d threads. Changed to %d threads.\n", num_threads, mmthreads );
			}

#ifdef CPU_EPISODE_GENERATION
            err = clEnqueueWriteBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent);
	START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer)
            END_TIMER(ocdTempTimer)
            CHKERR(err, "Unable to write buffer 1.");
            if(numCandidates * (level - 1) * 2 * sizeof(float) != 0)
            err = clEnqueueWriteBuffer(commands, d_episodeIntervals, CL_TRUE, 0, numCandidates * (level-1) * 2 * sizeof(float), h_episodeIntervals, 0, NULL, &ocdTempEvent);
        clFinish(commands);
            START_TIMER(ocdTempEvent, OCD_TIMER_H2D, "TDM Episode Copy", ocdTempTimer)
        CHKERR(err, "Unable to write buffer 2.");
		END_TIMER(ocdTempTimer)
#endif
            bindTexture( 0, &candidateTex, d_episodeCandidates, numCandidates * level * sizeof(UBYTE), CL_UNSIGNED_INT8);
            bindTexture( 0, &intervalTex, d_episodeIntervals, numCandidates * (level-1) * 2 * sizeof(float), CL_FLOAT );

			if ( algorithmType == OPTIMAL )
				aType = chooseAlgorithmType( level, numCandidates, mmthreads );

			// Run (T1,T2] algorithm
			if ( aType == NAIVE )
			{
				shared_mem_needed = MaxListSize*level* mmthreads*sizeof(float);
				calculateGrid(grid, mmthreads, numCandidates );
				calculateBlock(threads, mmthreads, numCandidates );
			}
			else
			{
				calculateLevelParameters(level, threads, grid, sections);
				shared_mem_needed = 16000;
			}
			//CUT_SAFE_CALL( cutResetTimer( a1_counting_timer));
			//CUT_SAFE_CALL( cutStartTimer( a1_counting_timer));

			if ( aType == NAIVE )
                countCandidates(grid, threads, d_episodeSupport, eventSize, level, supportType, numCandidates,
                    candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );
			else
                countCandidatesMapMerge(grid, threads, d_episodeSupport, padEventSize, level, supportType, sections, padEventSize / sections, numCandidates,
                    candidateTex, intervalTex, eventTex, timeTex, shared_mem_needed );

		}
        printf("Finishing\n");
		clFinish(commands);
		//CUT_SAFE_CALL( cutStopTimer( a1_counting_timer));
		//printf( "\tCounting time: %f (ms)\n", cutGetTimerValue( counting_timer));

		// check if kernel execution generated an error
		//CUT_CHECK_ERROR("Kernel execution failed");

		//printf("Copying result back to host...\n\n");

        int err = clEnqueueReadBuffer(commands, d_episodeSupport, CL_TRUE, 0, numCandidates * sizeof(float), h_episodeSupport, 0, NULL, &ocdTempEvent);
        clFinish(commands);
		START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer)
        END_TIMER(ocdTempTimer)
		CHKERR(err, "Unable to read memory 1.");
		err = clEnqueueReadBuffer(commands, d_episodeCandidates, CL_TRUE, 0, numCandidates * level * sizeof(UBYTE), h_episodeCandidates, 0, NULL, &ocdTempEvent);
                clFinish(commands);
                START_TIMER(ocdTempEvent, OCD_TIMER_D2H, "TDM Episode Copy", ocdTempTimer)
                END_TIMER(ocdTempTimer)
		CHKERR(err, "Unable to read memory 2.");
		//CUDA_SAFE_CALL( cudaMemcpy( h_mapRecords, d_mapRecords, 3 * numSections * maxLevel * maxCandidates * sizeof(float), cudaMemcpyDeviceToHost ));
		saveResult(level);
		fflush(dumpFile);
	// END LOOP

		//CUT_SAFE_CALL( cutStopTimer( total_timer));

		// Print Statistics for this run
		printf("%s, %f, %s, %s, %d, %d, %d\n",
			argv[1],											// Dataset
			support,											// Support Threshold
			algorithmType == NAIVE ? "PTPE" : algorithmType == MAP_AND_MERGE ? "MapMerge" : "Episode-Based",		// PTPE or MapMerge or Episode-Based
			memoryModel == STATIC ? "A1+A2" : "A1",				// A1 or A1+A2
			level,												// Level
			numCandidates+episodesCulled,						// Episodes counted
			episodesCulled  									// Episodes removed by A2
	//		cutGetTimerValue( a1_counting_timer),				// Time for A1
//			memoryModel == STATIC ? cutGetTimerValue( a2_counting_timer) : 0.0f,				// Time for A2
		//	cutGetTimerValue( generating_timer),				// Episode generation time
		//	cutGetTimerValue( total_timer) );					// Time for total loop
            );
	}
	printf("Done!\n");

    cleanup();

    //CUT_SAFE_CALL( cutStopTimer( timer));
    //printf( "Processing time: %f (ms)\n", cutGetTimerValue( timer));
    //CUT_SAFE_CALL( cutDeleteTimer( timer));
    //CUT_SAFE_CALL( cutDeleteTimer( generating_timer));
    //CUT_SAFE_CALL( cutDeleteTimer( a1_counting_timer));
    //CUT_SAFE_CALL( cutDeleteTimer( a2_counting_timer));
    //CUT_SAFE_CALL( cutDeleteTimer( total_timer));

}