• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
OpenCL with gcl buffer handling
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

OpenCL with gcl buffer handling


  • Subject: OpenCL with gcl buffer handling
  • From: "Gerriet M. Denkmann" <email@hidden>
  • Date: Sun, 23 Feb 2014 12:58:37 +0700

//	the host has a (big) malloced hostArray, on which OpenCl should work.

- (void)makeBufferOfSize: (size_t)arraySize  from: (void *)hostArray
{
	_clArray = clCreateBuffer( context, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR, arraySize, hostArray, NULL );
	_hostArray = hostArray;
}

for(;;)
{
	//	the host tells OpenCL to run a kernel which modifies _clArray

	//	then the host needs some of the data which OpenCL has modified:

	- (void)theHostWantsDataFrom: (NSUInteger)sta  to: (NSUInteger)end
	{
		clEnqueueReadBuffer( commands, _clArray, CL_TRUE, sta, end - sta, _hostArray + sta, 0, NULL, NULL );
	}
}

This works fine. clEnqueueReadBuffer is a no-op for DEVICE_HOST_UNIFIED_MEMORY and is reasonably fast else (i.e. for an external GPU).


But now for an exercise in gcl:

- (void)makeBufferOfSize: (size_t)arraySize  from: (void *)hostArray
{
	_clArray = gcl_malloc( arraySize, hostArray, CL_MEM_READ_WRITE | CL_MEM_USE_HOST_PTR );
	_hostArray = hostArray;
}

- (void)theHostWantsDataFrom: (NSUInteger)sta  to: (NSUInteger)end
{
	if ( DEVICE_HOST_UNIFIED_MEMORY )
	{
		//	nothing needs to be done here; just wait till all work has been done
		dispatch_group_wait( group, DISPATCH_TIME_FOREVER );
	}
	else	//	very bad code here
	{
		NSUInteger bytesToCopy = end - sta;
		uint8 *tempBuff = malloc( bytesToCopy );
	 	dispatch_sync( queue, ^void{ gcl_memcpy( tempBuff, _clArray + sta, bytesToCopy ); } );
		memcpy( _hostArray + sta, tempBuff, bytesToCopy ); // (BAD)
		free( tempBuff );
	};
}

This works, but the double copy at (BAD) does not look very efficient.
There clearly must be a better way. But how?

Gerriet.


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden


  • Prev by Date: Re: Disabling screen capture
  • Next by Date: A possibly simpler way to do custom Core Data migration
  • Previous by thread: Re: Application size growing
  • Next by thread: A possibly simpler way to do custom Core Data migration
  • Index(es):
    • Date
    • Thread