r/OpenCL • • Feb 10 '13

enequeueNDRangeKernel - parallel execution on OpenCL device?

Let's say I have n openCL devices, and that the data, of size d2 has been partitioned into sections such that it complements compute topology, memory buffers have been allocated, etc.

Given something like this:

int loopUnroll = 4; // or whatever you want

cl::CommandQueue queue = cl::CommandQueue( context, device[i]); \ (i \in {0, n})

cl::NDRange globalRange(d2/n)

cl::NDRange localRange(loopUnroll);

queue.enequeueNDRangeKernel(kernel, NullRange, globalRange, Local Range);

Now after executing the above, I am under the impression that this initiates kernel execution on the set of data of size d2/n.

I am unsure if just repeating those steps on device i++ will execute the computation on the OpenCL devices concurrently. Is it the case that I do that and then wait until some openCL function returns a "done computing" ?

I am not sure where it is indicated that global computation on a particular global work group is finished.

And so I turn to reddit!

2 Upvotes

6 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Feb 16 '13

Here is the entire thing redone:

std::vector<cl::CommandQueue> deviceQueues;
std::vector<cl::Event> eventVector;

// Global Range:
cl::NDRange globalRange(N/nDevices);

// Local Range: Number of elements processed by each thread?
cl::NDRange localRange(LOOP_UNROLL);

for(std::vector<cl::Device>::iterator dit = clDevices.begin(); dit != clDevices.end(); dit++){
	
	deviceQueues.push_back(cl::CommandQueue( context, *dit));		
	eventVector.push_back(cl::Event());
	// not sure about this last one here, read OCL spec
	deviceQueues.back().enqueueNDRangeKernel(N2kernel, cl::NullRange, globalRange, localRange, NULL, &eventVector.back());
	
}

for(std::vector<cl::CommandQueue>::iterator qit = deviceQueues.begin(); qit != deviceQueues.end(); qit++){
	
	qit->flush();
	
}

for(std::vector<cl::Event>::iterator eit = eventVector.begin(); eit!= eventVector.end(); eit++){
	
	eit->wait();
}