/// <summary> /// Added by Hybrid DSP /// </summary> /// <typeparam name="T"></typeparam> /// <param name="destinationHandle">The destination.</param> /// <param name="blocking">if set to <c>true</c> [blocking].</param> /// <param name="destinationOffset">The destination offset.</param> /// <param name="region">The region.</param> /// <param name="source">The source.</param> /// <param name="events">The events.</param> public void WriteEx <T>(CLMemoryHandle destinationHandle, bool blocking, long destinationOffset, long region, IntPtr source, ICollection <ComputeEventBase> events) where T : struct { int sizeofT = HDSPUtils.SizeOf(typeof(T)); int eventWaitListSize; CLEventHandle[] eventHandles = ComputeTools.ExtractHandles(events, out eventWaitListSize); bool eventsWritable = (events != null && !events.IsReadOnly); CLEventHandle[] newEventHandle = (eventsWritable) ? new CLEventHandle[1] : null; ComputeErrorCode error = CL10.EnqueueWriteBuffer(Handle, destinationHandle, blocking, new IntPtr(destinationOffset * sizeofT), new IntPtr(region * sizeofT), source, eventWaitListSize, eventHandles, newEventHandle); ComputeException.ThrowOnError(error); if (eventsWritable) { events.Add(new ComputeEvent(newEventHandle[0], this)); } }
/// <summary> /// Enqueues a command to write data to a buffer. /// </summary> /// <param name="destination"> The buffer to write to. </param> /// <param name="blocking"> The mode of operation of this command. If <c>true</c> this call will not return until the command has finished execution. </param> /// <param name="destinationOffset"> The <paramref name="destination"/> element position where writing starts. </param> /// <param name="region"> The region of elements to write. </param> /// <param name="source"> The data written to the buffer. </param> /// <param name="events"> A collection of events that need to complete before this particular command can be executed. If <paramref name="events"/> is not <c>null</c> or read-only a new <see cref="OpenCLEvent"/> identifying this command is created and attached to the end of the collection. </param> /// <remarks> If <paramref name="blocking"/> is <c>true</c> this method will not return until the command completes. If <paramref name="blocking"/> is <c>false</c> this method will return immediately after the command is enqueued. </remarks> public void Write(OpenCLBufferBase destination, bool blocking, long destinationOffset, long region, IntPtr source, IReadOnlyList <OpenCLEventBase> events = null, IList <OpenCLEventBase> newEvents = null) { int sizeofT = Marshal.SizeOf(destination.ElementType); int eventWaitListSize; CLEventHandle[] eventHandles = OpenCLTools.ExtractHandles(events, out eventWaitListSize); CLEventHandle[] newEventHandle = (newEvents != null) ? new CLEventHandle[1] : null; OpenCLErrorCode error = CL10.EnqueueWriteBuffer(Handle, destination.Handle, blocking, new IntPtr(destinationOffset * sizeofT), new IntPtr(region * sizeofT), source, eventWaitListSize, eventHandles, newEventHandle); OpenCLException.ThrowOnError(error); if (newEvents != null) { lock (newEvents) { newEvents.Add(new OpenCLEvent(newEventHandle[0], this)); } } }
public void sortKeysValue(CLMemoryHandle key, CLMemoryHandle value, int numElements) { debugRead = new int[Math.Max(numElements, numCounters)]; ComputeErrorCode error; ComputeEvent eve; /* * error = CL10.EnqueueReadBuffer(cqCommandQueue, input, Bool.True, IntPtr.Zero, (IntPtr)(numElements * 4), * debugRead, 0, null, out eve); * CheckErr(error, "CL10.EnqueueReadBuffer"); */ mCounters = CL10.CreateBuffer(cxGPUContext, ComputeMemoryFlags.ReadWrite, gpuConstants.numGroupsPerBlock * gpuConstants.numRadices * gpuConstants.numBlocks * sizeof(int), out error); CheckErr(error, "CL10.CreateBuffer"); mRadixPrefixes = CL10.CreateBuffer(cxGPUContext, ComputeMemoryFlags.ReadWrite, gpuConstants.numRadices * sizeof(int), out error); CheckErr(error, "CL10.CreateBuffer"); CLMemoryHandle outputValue = CL10.CreateBuffer(cxGPUContext, ComputeMemoryFlags.ReadWrite, (IntPtr)(8 * numElements), out error); CheckErr(error, "CL10.CreateBuffer"); CLMemoryHandle outputKey = CL10.CreateBuffer(cxGPUContext, ComputeMemoryFlags.ReadWrite, (IntPtr)(4 * numElements), out error); CheckErr(error, "CL10.CreateBuffer"); gpuConstants.numElementsPerGroup = (numElements / (gpuConstants.numBlocks * gpuConstants.numGroupsPerBlock)) + 1; gpuConstants.numTotalElements = numElements; int i; for (i = 0; i < 8; i++) { error = CL10.EnqueueWriteBuffer(cqCommandQueue, mCounters, Bool.True, IntPtr.Zero, (IntPtr)(numCounters * 4), counters, 0, null, out eve); CheckErr(error, "CL10.EnqueueWriteBuffer Counter initialize"); if (i % 2 == 0) { SetupAndCount(key, 4 * i); SumIt(key, 4 * i); ReorderingKeyValue(key, outputKey, value, outputValue, 4 * i); } else { SetupAndCount(outputKey, 4 * i); SumIt(outputKey, 4 * i); ReorderingKeyValue(outputKey, key, outputValue, value, 4 * i); } } if (i % 2 == 0) { error = CL10.EnqueueCopyBuffer(cqCommandQueue, outputKey, key, IntPtr.Zero, IntPtr.Zero, (IntPtr)(numElements * 4), 0, null, out eve); CheckErr(error, "CL10.EnqueueCopyBuffer"); error = CL10.Finish(cqCommandQueue); CheckErr(error, "CL10.Finish Copybuffer"); error = CL10.EnqueueCopyBuffer(cqCommandQueue, outputValue, value, IntPtr.Zero, IntPtr.Zero, (IntPtr)(numElements * 8), 0, null, out eve); CheckErr(error, "CL10.EnqueueCopyBuffer"); error = CL10.Finish(cqCommandQueue); CheckErr(error, "CL10.Finish Copybuffer"); } error = CL10.ReleaseMemObject(outputKey); CheckErr(error, "CL10.ReleaseMemObj"); error = CL10.ReleaseMemObject(outputValue); CheckErr(error, "CL10.ReleaseMemObj"); error = CL10.ReleaseMemObject(mRadixPrefixes); CheckErr(error, "CL10.ReleaseMemObj"); error = CL10.ReleaseMemObject(mCounters); CheckErr(error, "CL10.ReleaseMemObj"); Log_Idx++; }
public void sortKeysOnly(CLMemoryHandle input, CLMemoryHandle output, int numElements) { debugRead = new int[Math.Max(numElements, numCounters)]; ComputeErrorCode error; Compute ComputeEvent eve; mCounters = CL10.CreateBuffer(cxGPUContext, ComputeMemoryFlags.ReadWrite, gpuConstants.numGroupsPerBlock * gpuConstants.numRadices * gpuConstants.numBlocks * sizeof(int), out error); CheckErr(error, "CL10.CreateBuffer"); mRadixPrefixes = CL10.CreateBuffer(cxGPUContext, ComputeMemoryFlags.ReadWrite, gpuConstants.numRadices * sizeof(int), out error); CheckErr(error, "CL10.CreateBuffer"); gpuConstants.numElementsPerGroup = (numElements / (gpuConstants.numBlocks * gpuConstants.numGroupsPerBlock)) + 1; gpuConstants.numTotalElements = numElements; if (DEBUG) { CL10.EnqueueReadBuffer(cqCommandQueue, input, Bool.True, IntPtr.Zero, (IntPtr)(gpuConstants.numTotalElements * 4), debugRead, 0, null, out eve); CheckErr(error, "CL10.EnqueueReadBuffer"); PrintAsArray(debugRead, gpuConstants.numTotalElements); } int i; for (i = 0; i < 8; i++) { error = CL10.EnqueueWriteBuffer(cqCommandQueue, mCounters, true, IntPtr.Zero, (IntPtr)(numCounters * 4), counters, 0, null, out eve); CheckErr(error, "CL10.EnqueueWriteBuffer Counter initialize"); if (i % 2 == 0) { DateTime before = DateTime.Now; SetupAndCount(input, 4 * i); if (DEBUG_CONSOLE_OUTPUT) { Console.WriteLine("Setup and Count =" + (DateTime.Now - before).TotalMilliseconds); } before = DateTime.Now; SumIt(input, 4 * i); if (DEBUG_CONSOLE_OUTPUT) { Console.WriteLine("SumIt =" + (DateTime.Now - before).TotalMilliseconds); } before = DateTime.Now; ReorderingKeysOnly(input, output, 4 * i); if (DEBUG_CONSOLE_OUTPUT) { Console.WriteLine("Reorder =" + (DateTime.Now - before).TotalMilliseconds); } } else { SetupAndCount(output, 4 * i); SumIt(output, 4 * i); ReorderingKeysOnly(output, input, 4 * i); } } if (i % 2 != 0) { error = CL10.EnqueueCopyBuffer(cqCommandQueue, input, output, IntPtr.Zero, IntPtr.Zero, (IntPtr)(numElements * 4), 0, null, out eve); CheckErr(error, "CL10.EnqueueCopyBuffer"); error = CL10.Finish(cqCommandQueue); CheckErr(error, "CL10.Finish Copybuffer"); } error = CL10.ReleaseMemObject(mRadixPrefixes); CheckErr(error, "CL10.ReleaseMemObj"); error = CL10.ReleaseMemObject(mCounters); CheckErr(error, "CL10.ReleaseMemObj"); Log_Idx++; }