Jump to content
  • Advertisement
Sign in to follow this  
zerorepent

cl::vector vs std::vector with cl::Event error

This topic is 2023 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi!

I am trying to figure out why this code generates an error (Unhandled exception, Access violation reading location...)  when releasing the events if __NO_STD_VECTOR is defined, i.e. using the built in more simple vector class in OpenCL, but works perfectly fine using std::vector. i've been scratching my head bout this issue for quite some time now. Its like the destructor of cl::Event is called twice, once in destructor of the vector and once when leaving the scope of main. But it feels like this isn't the intended behaviour considering they are vectors of cl::Event everywhere in the c++ API of openCL, which in turn makes me believe i've overseen an obvious error in the code. Still it works with std::vector and not cl::vector... 

#define __NO_STD_STRING 
#define __NO_STD_VECTOR

#include <CL/cl.hpp>

const __int64 FILE_LENGTH = 1024*128;
#define NUM_WRITES 2

int main()
{
	
	cl::CommandQueue commandQueues;
	cl::Program program;
	cl::Context context;
	cl_device_id device_id; 
	VECTOR_CLASS<cl::Platform> platforms;
	VECTOR_CLASS<cl::Device> devices;

	cl_int error;
	error = cl::Platform::get(&platforms);

	if(error !=CL_SUCCESS)//handle error better
	{
		return false;
	}

	cl_device_type type = CL_DEVICE_TYPE_GPU;
#ifdef ENCODE_CPU
	type = CL_DEVICE_TYPE_CPU;
#endif

	error = platforms[0].getDevices (type, &devices);
	if(error != CL_SUCCESS) //handle error better
	{
		return false; 
	}

	context =  cl::Context(devices);

	cl::CommandQueue queue = cl::CommandQueue(context, devices[0]);


	VECTOR_CLASS<cl::Event> m_Events;
	cl::Buffer destinationbuffer[NUM_WRITES];
	int n = 0;
	for(int i = 0;i<NUM_WRITES;i++)
	{
		destinationbuffer = cl::Buffer(context,CL_MEM_ALLOC_HOST_PTR|CL_MEM_READ_ONLY,FILE_LENGTH,0,&error);
		if(error != CL_SUCCESS) //handle error better
		{
			printf("error");
		}
		m_Events.push_back(cl::Event());
		error = queue.enqueueFillBuffer<int>(destinationbuffer,n,0,FILE_LENGTH,0,&m_Events);
		if(error != CL_SUCCESS) //handle error better
		{
			printf("error");
		}
	}
	cl::WaitForEvents(m_Events);
	m_Events.clear();
	return 0;
}

(removing m_Events.clear() doesn't change anything)

 

I've been requested to not use std::vector or std::string, so going with what works is not really an option. 

 

The error occurs in both intel and amd sdk of opencl. 

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!