コード例 #1
0
        public override FractalEngine.Stats GatherStats()
        {
            queue.Finish();

            Stats stats = new Stats();

            NativeGlobalStatEntry gStats = new NativeGlobalStatEntry();

            globalStatBuffer.Read(queue, out gStats);

            stats.TotalIterCount      = gStats.IterCount;
            stats.TotalDotCount       = gStats.DotCount;
            stats.meanDotsPerSubpixel = (float)((double)stats.TotalDotCount / (double)(xRes * yRes * AALevel * AALevel));

            return(stats);
        }
コード例 #2
0
        public void TestKernelExecution()
        {
            int elemCount = 16;
            int localSize = 8;

            checkSetup();
            CommandQueue queue  = CommandQueue.Create(context, device, CommandQueueFlags.ProfilingEnable);
            Kernel       kernel = Kernel.Create(program, "vec_add");
            Buffer       a      = Buffer.Create(context, MemFlags.ReadWrite, (IntPtr)(elemCount * sizeof(float)));
            Buffer       b      = Buffer.Create(context, MemFlags.ReadWrite, (IntPtr)(elemCount * sizeof(float)));
            Buffer       c      = Buffer.Create(context, MemFlags.ReadWrite, (IntPtr)(elemCount * sizeof(float)));

            float[] aLoc = new float[elemCount];
            float[] bLoc = new float[elemCount];
            float[] cLoc = new float[elemCount];

            for (int i = 0; i < elemCount; i++)
            {
                aLoc[i] = (float)rand.NextDouble();
                bLoc[i] = (float)rand.NextDouble();
            }

            a.Write(queue, aLoc);
            b.Write(queue, bLoc);

            kernel.SetArgs(a, b, c);
            Event launchEvt;

            kernel.EnqueueLaunch(queue, elemCount, localSize, null, out launchEvt);
            launchEvt.Wait();
            launchEvt.Dispose();

            c.Read(queue, cLoc);

            for (int i = 0; i < elemCount; i++)
            {
                Assert.That(Math.Abs(aLoc[i] + bLoc[i] - cLoc[i]) < 0.05f);
            }

            c.Dispose();
            b.Dispose();
            a.Dispose();
            kernel.Dispose();
            queue.Dispose();
        }