Beispiel #1
0
        private void TestCommandQueueMemCopy(Context c, CommandQueue cq)
        {
            Output("Testing synchronous host memory->memory copy");

            AlignedArrayFloat aafSrc = new AlignedArrayFloat(1024 * 1024, 64);
            AlignedArrayFloat aafDst = new AlignedArrayFloat(1024 * 1024, 64);

            SetAAF(aafSrc, 0.0f);
            SetAAF(aafDst, 1.0f);

            /// Test HOST_PTR -> HOST_PTR copy
            /// The call to EnqueueMapBuffer synchronizes caches before testing the result
            using (Mem memSrc = c.CreateBuffer((MemFlags)((ulong)MemFlags.READ_WRITE+(ulong)MemFlags.USE_HOST_PTR), aafSrc.ByteLength, aafSrc))
            {
                using (Mem memDst = c.CreateBuffer((MemFlags)((ulong)MemFlags.READ_WRITE+(ulong)MemFlags.USE_HOST_PTR), aafDst.ByteLength, aafDst))
                {
                    cq.EnqueueCopyBuffer(memSrc, memDst, IntPtr.Zero, IntPtr.Zero, (IntPtr)aafSrc.ByteLength);
                    cq.EnqueueBarrier();
                    IntPtr mappedPtr = cq.EnqueueMapBuffer(memDst, true, MapFlags.READ_WRITE, (IntPtr)0, (IntPtr)aafDst.ByteLength);
                    if (!TestAAF(aafDst, 0.0f))
                        Error("EnqueueCopyBuffer failed, destination is invalid");
                    cq.EnqueueUnmapMemObject(memDst, mappedPtr);
                    cq.EnqueueBarrier();
                }
            }

            /// Test COPY_HOST_PTR -> COPY_HOST_PTR copy
            /// Verify that original source buffers are intact and that the copy was successful
            SetAAF(aafSrc, 0.0f);
            SetAAF(aafDst, 1.0f);
            using (Mem memSrc = c.CreateBuffer(MemFlags.COPY_HOST_PTR, aafSrc.ByteLength, aafSrc))
            {
                using (Mem memDst = c.CreateBuffer(MemFlags.COPY_HOST_PTR, aafSrc.ByteLength, aafDst))
                {
                    SetAAF(aafSrc, 2.0f);
                    SetAAF(aafDst, 3.0f);

                    cq.EnqueueCopyBuffer(memSrc, memDst, IntPtr.Zero, IntPtr.Zero, (IntPtr)aafSrc.ByteLength);
                    cq.Finish();

                    if (!TestAAF(aafSrc, 2.0f))
                        Error("Memory copy destroyed src buffer");
                    if (!TestAAF(aafDst, 3.0f))
                        Error("Memory copy destroyed dst buffer");
                    Event ev;
                    cq.EnqueueReadBuffer(memDst, false, IntPtr.Zero, (IntPtr)aafDst.ByteLength, aafDst,0, null, out ev);
                    cq.EnqueueWaitForEvents(1, new Event[] { ev });
                    ev.Dispose();
                    cq.Finish();
                    if (!TestAAF(aafDst, 0.0f))
                        Error("Memory copy failed");
                }
            }

            /// Test ALLOC_HOST_PTR -> ALLOC_HOST_PTR copy
            SetAAF(aafSrc, 0.0f);
            SetAAF(aafDst, 1.0f);
            using (Mem memSrc = c.CreateBuffer((MemFlags)((ulong)MemFlags.ALLOC_HOST_PTR + (ulong)MemFlags.READ_WRITE), aafSrc.ByteLength, IntPtr.Zero))
            {
                using (Mem memDst = c.CreateBuffer((MemFlags)((ulong)MemFlags.ALLOC_HOST_PTR + (ulong)MemFlags.WRITE_ONLY), aafSrc.ByteLength, IntPtr.Zero))
                {
                    cq.EnqueueWriteBuffer(memSrc, false, (IntPtr)0, (IntPtr)aafSrc.ByteLength, aafSrc);
                    cq.EnqueueWriteBuffer(memDst, false, (IntPtr)0, (IntPtr)aafSrc.ByteLength, aafSrc);
                    cq.EnqueueBarrier();

                    cq.EnqueueCopyBuffer(memSrc, memDst, IntPtr.Zero, IntPtr.Zero, (IntPtr)aafSrc.ByteLength);
                    cq.EnqueueBarrier();

                    cq.EnqueueReadBuffer(memDst, true, IntPtr.Zero, (IntPtr)aafDst.ByteLength, aafDst);
                    if (!TestAAF(aafDst, 0.0f))
                        Error("Memory copy failed");
                }
            }

            /// Test DEFAULT -> DEFAULT copy
            SetAAF(aafSrc, 0.0f);
            SetAAF(aafDst, 1.0f);
            using (Mem memSrc = c.CreateBuffer((MemFlags)((ulong)MemFlags.ALLOC_HOST_PTR + (ulong)MemFlags.READ_ONLY), aafSrc.ByteLength, IntPtr.Zero))
            {
                using (Mem memDst = c.CreateBuffer((MemFlags)((ulong)MemFlags.ALLOC_HOST_PTR + (ulong)MemFlags.WRITE_ONLY), aafSrc.ByteLength, IntPtr.Zero))
                {
                    cq.EnqueueWriteBuffer(memSrc, false, (IntPtr)0, (IntPtr)aafSrc.ByteLength, aafSrc);
                    cq.EnqueueWriteBuffer(memDst, false, (IntPtr)0, (IntPtr)aafSrc.ByteLength, aafSrc);
                    cq.EnqueueBarrier();

                    cq.EnqueueCopyBuffer(memSrc, memDst, IntPtr.Zero, IntPtr.Zero, (IntPtr)aafSrc.ByteLength);
                    cq.EnqueueBarrier();

                    cq.EnqueueReadBuffer(memDst, true, IntPtr.Zero, (IntPtr)aafDst.ByteLength, aafDst);
                    if (!TestAAF(aafDst, 0.0f))
                        Error("Memory copy failed");
                }
            }
        }
Beispiel #2
0
        private void TestCommandQueueAsync(Context c, CommandQueue cq, Kernel kernel )
        {
            List<Event> events = new List<Event>();
            Event clEvent;

            Output("Testing asynchronous task issuing (clEnqueueTask) and waiting for events");

            // Issue a bunch of slow operations
            kernel.SetArg(0, 5000000);
            for (int i = 0; i < 10; i++)
            {
                cq.EnqueueTask(kernel, 0, null, out clEvent);
                events.Add(clEvent);
            }

            // Issue a bunch of fast operations
            kernel.SetArg(0, 500);
            for (int i = 0; i < 10; i++)
            {
                cq.EnqueueTask(kernel, 0, null, out clEvent);
                events.Add(clEvent);
            }

            Event[] eventList = events.ToArray();
            cq.EnqueueWaitForEvents(eventList.Length, eventList);
            while (events.Count > 0)
            {
                if ((int)events[0].ExecutionStatus < 0)
                {
                    Output(cq.Device.Name + ": TestCommandQueueAsync failed with error code " + (ErrorCode)events[0].ExecutionStatus);
                }
                events[0].Dispose();
                events.RemoveAt(0);
            }
        }