/// <summary> /// Initializes a new instance of the <see cref="FastBufferManager"/> class. /// </summary> /// <param name="maxBufferPoolSize">The maximum size of the pooled buffers.</param> /// <param name="bufferSize">The size of the each buffer.</param> /// <param name="allocate">If set to <c>true</c> all buffers will be allocated.</param> public FastBufferManager(int maxBufferPoolSize, int bufferSize, bool allocate) { if (maxBufferPoolSize < bufferSize) { throw new ArgumentOutOfRangeException("maxBufferPoolSize"); } if (bufferSize <= 0) { throw new ArgumentOutOfRangeException("bufferSize"); } _maxBuffers = ((maxBufferPoolSize - 1 + bufferSize) / bufferSize) / Decongest; _bufferSize = bufferSize; _buffers = new CpuBuffer[Decongest]; for (var i = 0; i < Decongest; i++) { _buffers[i] = new CpuBuffer(_maxBuffers, bufferSize, allocate); } }
public void ClooExecuteHistogramN() { var gpuHist = new ClooBuffer<uint>(Context, Cloo.ComputeMemoryFlags.ReadWrite | ComputeMemoryFlags.AllocateHostPointer, 64); var cpuHist = new CpuBuffer<uint>(64); var gpuImage = CreateClooImageByteRgbA(100, 100); ClooImaging.HistogramN(Queue, gpuImage, gpuHist, 4); gpuHist.ReadFromDevice(Queue); // compare GPU histogram with CPU version CpuImaging.HistogramN(gpuImage, cpuHist, 4); Assert.AreNotEqual(0, cpuHist.HostBuffer.Sum(x => x)); Assert.AreEqual(cpuHist.HostBuffer.Sum(x => x), gpuHist.HostBuffer.Sum(x => x)); // check each value for (int i = 0; i < cpuHist.HostBuffer.Length; i++) Assert.AreEqual(cpuHist.HostBuffer[i], gpuHist.HostBuffer[i], "Histogram comparison failed at index " + i); }
/// <summary> /// Creates a ClooBuffer and fills it with random values /// </summary> /// <param name="length">buffer length</param> /// <returns></returns> public virtual CpuBuffer<uint> CreateCpuBufferUInt(int length = 9999) { ResetRandomSeed(); var buffer = new CpuBuffer<uint>(length); Assert.AreNotEqual(0, buffer.HostBuffer.Length); Assert.AreEqual(4 * buffer.HostBuffer.Length, buffer.Size); for (int i = 0; i < length; i++) buffer.HostBuffer[i] = (uint)Random.Next(256); Assert.AreNotEqual(0, buffer.HostBuffer.Sum(x => x)); return buffer; }