示例#1
0
        private static void Main(string[] args)
        {
            if (File.Exists(Path.Combine(System.Environment.CurrentDirectory, @"..\..\log.txt")))
            {
            File.Delete(Path.Combine(System.Environment.CurrentDirectory, @"..\..\log.txt"));
            }

            if (File.Exists(Path.Combine(System.Environment.CurrentDirectory, @"..\..\sortLog.txt")))
            {
                File.Delete(Path.Combine(System.Environment.CurrentDirectory, @"..\..\sortLog.txt"));
            }
            if (File.Exists(Path.Combine(System.Environment.CurrentDirectory, @"..\..\OpenCLDebugLog.txt")))
            {
                File.Delete(Path.Combine(System.Environment.CurrentDirectory, @"..\..\OpenCLDebugLog.txt"));
            }

            numElements--;
            numElements |= numElements >> 1;
            numElements |= numElements >> 2;
            numElements |= numElements >> 4;
            numElements |= numElements >> 8;
            numElements |= numElements >> 16;
            numElements++;

            Random generator = new Random();
            Console.SetWindowSize(Console.LargestWindowWidth/2,Console.LargestWindowHeight/2);
            /*
            ISpatialEntity[] testSpatials = new ISpatialEntity[numElements];
             for (int i = 2; i < testSpatials.Length; i++)
            {
                testSpatials[i] = new TestSpatialEntity(new Vector3(1, 1, 1));
                testSpatials[i].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(generator.Next(1,100), generator.Next(1,100), generator.Next(1,100)), null);
                Console.WriteLine("GUID = "+ testSpatials[i].AgentGuid);
                Console.WriteLine(string.Format("Pos: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.Position.X, testSpatials[i].Shape.Bounds.Position.Y, testSpatials[i].Shape.Bounds.Position.Z));
                Console.WriteLine(string.Format("Min: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.LeftBottomFront.X, testSpatials[i].Shape.Bounds.LeftBottomFront.Y, testSpatials[i].Shape.Bounds.LeftBottomFront.Z, testSpatials[i].AgentGuid));
                Console.WriteLine(string.Format("Max: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.RightTopRear.X, testSpatials[i].Shape.Bounds.RightTopRear.Y, testSpatials[i].Shape.Bounds.RightTopRear.Z, testSpatials[i].AgentGuid));
                Console.WriteLine();
                // Console.Write(" " + testData[i]);#3##2#
            }
             testSpatials[0] = new TestSpatialEntity(new Vector3(1, 1, 1));
             testSpatials[0].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(3, 3, 2), null);

             testSpatials[1] = new TestSpatialEntity(new Vector3(1, 1, 1));
             testSpatials[1].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(3, 2.5, 2), null);

              testSpatials[0] = new TestSpatialEntity(new Vector3(1, 1, 1));
              testSpatials[0].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(2,2,2), null);

              testSpatials[1] = new TestSpatialEntity(new Vector3(1, 1, 1));
              testSpatials[1].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(2,2,2), null);

              testSpatials[2] = new TestSpatialEntity(new Vector3(1, 1, 1));
              testSpatials[2].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(4,4,2), null);

              testSpatials[3] = new TestSpatialEntity(new Vector3(1, 1, 1));
              testSpatials[3].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(4, 4, 2), null);#1#

               for (int i = 0; i < numElements; i++)
            {
                Console.WriteLine("GUID = " + testSpatials[i].AgentGuid);
                Console.WriteLine(string.Format("Pos: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.Position.X, testSpatials[i].Shape.Bounds.Position.Y, testSpatials[i].Shape.Bounds.Position.Z));
                Console.WriteLine(string.Format("Min: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.LeftBottomFront.X, testSpatials[i].Shape.Bounds.LeftBottomFront.Y, testSpatials[i].Shape.Bounds.LeftBottomFront.Z));
                Console.WriteLine(string.Format("Max: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.RightTopRear.X, testSpatials[i].Shape.Bounds.RightTopRear.Y, testSpatials[i].Shape.Bounds.RightTopRear.Z));
                Console.WriteLine();

            }
            #1#
               // compute the next highest power of 2 of 32-bit v

            /*

            #1#
            int[] testData = new int[numElements];
            int[] testResult = new int[numElements];
            for (int i = 0; i < testData.Length; i++)
            {
                testData[i] = generator.Next(1000000);
                // Console.Write(" " + testData[i]);#3#
            }
            Console.WriteLine();
            Program ins = new Program();
            ins.Setup();

            var radix = new GPURadixSort(cqCommandQueue, cxGPUContext, _device);

            Event eve;
            ErrorCode error;
            IMem inputBuff = Cl.CreateBuffer(cxGPUContext, MemFlags.ReadWrite, (IntPtr)(numElements * 4), testData,
                out error);
            ins.CheckErr(error, "Createbuffer");
            IMem outputBuff = Cl.CreateBuffer(cxGPUContext, MemFlags.ReadWrite, (IntPtr)(numElements * 4),
                out error);
            ins.CheckErr(error, "Createbuffer");

            error = Cl.EnqueueWriteBuffer(cqCommandQueue, inputBuff, Bool.True, IntPtr.Zero, (IntPtr)(numElements * 4),
                testData, 0, null,
                out eve);
            ins.CheckErr(error, "EnqBuffer");
            error = Cl.Finish(cqCommandQueue);
            ins.CheckErr(error, "Cl.Finish");
            */

            #region RadixSortTest

            /*            DateTime before = DateTime.Now;
            radix.sortKeysOnly(inputBuff, outputBuff, numElements);

            error = Cl.EnqueueWriteBuffer(cqCommandQueue, inputBuff, Bool.True, IntPtr.Zero, (IntPtr)(numElements * 4),
                testData, 0, null,
                out eve);
            ins.CheckErr(error, "EnqBuffer");

            radix.sortKeysOnly(inputBuff, outputBuff, numElements);*/

                //Collision Detection tests
            /*
            CollisionDetection detec = new CollisionDetection(cqCommandQueue,cxGPUContext,_device,radix,new Point3D(150,150,150),new Vector3(2,2,2) );
            IMem inp;
            IMem outp;
            detec.CreateCellIdArray(testSpatials,out inp, out outp);
            #1#

            */
            #endregion

            /*
               radix.sortKeysOnly(inputBuff, outputBuff, numElements);
            #1#

            error = Cl.EnqueueReadBuffer(cqCommandQueue, outputBuff, Bool.True, IntPtr.Zero, (IntPtr)(numElements * 4),
                testResult, 0, null, out eve);
            ins.CheckErr(error, "Cl.EnqueueReadBuffer");

            //Execute our kernel (OpenCL code)
            error = Cl.Finish(cqCommandQueue);
            ins.CheckErr(error, "Cl.Finish");
            Console.WriteLine("Execution time Gpu ="+( DateTime.Now- before ).TotalMilliseconds);
               /* for (int i = 0; i < numElements; i++)
            {
                Console.Write(" " + testResult[i]);
            }#1#
            before = DateTime.Now;
            Array.Sort(testData);
            Console.WriteLine("Execution time CPU =" + (DateTime.Now - before).TotalMilliseconds);
            int r = 0;

            */

               MovementDelegate moveDel = new MovementDelegate(dele1);
            ExploreDelegate expDel = new ExploreDelegate(dele2);
            generator = new Random();
            Console.SetWindowSize(Console.LargestWindowWidth / 2, Console.LargestWindowHeight / 2);

            ISpatialEntity[] testSpatials = new ISpatialEntity[numElements];

            GpuESC esc = new GpuESC(new Vector3(2, 2, 2), new Vector3(2000000, 8, 8));

            for (int i = 2; i < testSpatials.Length; i++)
            {
                testSpatials[i] = new TestSpatialEntity(new Vector3(0.5, 0.5, 0.5));
                Vector3 actos = new Vector3(i + 0.1, 1.5, 1.5);
                testSpatials[i].Shape = new Cuboid(new Vector3(0.5, 0.5, 0.5), actos, null);
                /*Console.WriteLine("GUID = " + testSpatials[i].AgentGuid);
                Console.WriteLine(string.Format("Pos: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.Position.X, testSpatials[i].Shape.Bounds.Position.Y, testSpatials[i].Shape.Bounds.Position.Z));
                Console.WriteLine(string.Format("Min: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.LeftBottomFront.X, testSpatials[i].Shape.Bounds.LeftBottomFront.Y, testSpatials[i].Shape.Bounds.LeftBottomFront.Z, testSpatials[i].AgentGuid));
                Console.WriteLine(string.Format("Max: x={0} , y ={1}, z={2} ", testSpatials[i].Shape.Bounds.RightTopRear.X, testSpatials[i].Shape.Bounds.RightTopRear.Y, testSpatials[i].Shape.Bounds.RightTopRear.Z, testSpatials[i].AgentGuid));
             */   // Console.WriteLine();
                // Console.Write(" " + testData[i]);#3##2#*/
                esc.Add(testSpatials[i], actos, null, moveDel);
            }
            testSpatials[0] = new TestSpatialEntity(new Vector3(1, 1, 1));
            testSpatials[0].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(3, 3, 2), null);
            esc.Add(testSpatials[0], testSpatials[0].Shape.Position, null, moveDel);

            testSpatials[1] = new TestSpatialEntity(new Vector3(1, 1, 1));
            testSpatials[1].Shape = new Cuboid(new Vector3(1, 1, 1), new Vector3(3, 3, 2), null);
            Console.WriteLine(testSpatials[0].AgentGuid);
            Console.WriteLine(testSpatials[1].AgentGuid);

            esc.Add(testSpatials[1], testSpatials[1].Shape.Position, null, moveDel);
            var before = DateTime.Now;
            for (int i = 0; i <10; i++)
            {
                esc.Commit();
            }

            Console.WriteLine("Execution time Total =" + (DateTime.Now - before).TotalMilliseconds);
            Console.WriteLine(collisionCount);
            int asdcyxcsa = 2;
        }
示例#2
0
        public static void PrintCollisionTuples(GpuESC.CollisionTupel[] collisionTupels, int[] cellIds, long[] cellData, GpuESC.CollisionCell[] debugCellPosList, string caption, int count)
        {
            String output = caption;
            output += "\n";
            output += "\n";
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";

            for (int i = 0; i < count; i++)
            {
                int index1 = collisionTupels[i].obj1;
                int index2 = collisionTupels[i].obj2;
                output += String.Format("CollisionCheck at {0:x}:\n", cellIds[index1]);

                output += String.Format("CollisionTupelElement 1 = {0:x} x={1} y={2} z={3}\n", cellData[index1]&0xFFFFFFFF, debugCellPosList[index1].x, debugCellPosList[index1].y, debugCellPosList[index1].z);
                output += String.Format("CollisionTupelElement 2 = {0:x} x={1} y={2} z={3}\n", cellData[index2]&0xFFFFFFFF, debugCellPosList[index2].x, debugCellPosList[index2].y, debugCellPosList[index2].z);

                output += "\n";
            }

            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";
            using (StreamWriter sw = File.AppendText(log))
            {
                sw.WriteLine(output);
            }
        }
示例#3
0
        /*        public static void PrintCounterBuffer(int[] printData, string caption)
        {
            String output = caption;
            output += "\n";
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";

            output += String.Format("{0,10}", "");
            for (int j = 0; j < numBlocks; j++)
            {
                output += String.Format("{0,29}", "Block " + j);
            }
            output += "\n";
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";
            for (int i = 0; i < num_Radices; i++)
            {
                output += String.Format(" {0,15}    ", "Radix " + i);
                for (int j = 0; j < numBlocks; j++)
                {
                    output += String.Format("{0,5}", "");
                    for (int k = 0; k < NumGroupsPerBlock; k++)
                    {
                        output += String.Format("{0,5:x} ", printData[i * numBlocks * NumGroupsPerBlock + j * NumGroupsPerBlock + k]);

                    }
                }
                output += "\n";
            }
            using (StreamWriter sw = File.AppendText(@"D:\Projects\gpu\GPGPUGpgpuESC\GPGPUGpgpuESC\log.txt"))
            {
                sw.WriteLine(output);
            }
        }*/
        public static void PrintCellIdBufferExtended(long[] cellInput,int[] cellIds, long[] cellData,  GpuESC.CollisionCell[] debugCellPosList,string caption,int count)
        {
            String output = caption;
            output += "\n";
            output += "Data input array\n";
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------";
            for (int i = 0; i < count; i++)
            {
                if (i % 20 == 0) output += "\n";
                output += String.Format("{0,5:x} ", cellInput[i] & 0xFFFFFFFF);

            }
            output += "\n";
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";

            output += "Generated Cell Id Array \n";
            output += "\n";
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";
            output += String.Format("{0,-12}|{1,-12}|{2,-12}|{3,-12}|{4,-12}|{5,-12}|{6,-12}|{7,-12}|{8,-12}|{9,-12}|{10,-12}\n", " CellId", " CellObjId", "CellPos X", "CellPos Y", "CellPos Z", " Home", " Phantom", " New", " Moved", "Explore", "Unused");
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";
            for (int i = 0; i < count * 8; i++)
            {
                output += String.Format("{0,-12:x}|{1,-12:x}|{2,-12}|{3,-12}|{4,-12}|{5,-12}|{6,-12}|{7,-12}|{8,-12}|{9,-12}|{10,-12}\n", cellIds[i], (cellData[i] & ((long)0xFFFFFFFF)), debugCellPosList[i].x, debugCellPosList[i].y, debugCellPosList[i].z,
                    ((cellData[i] & HOMECELL) > 0) ? " Yes" : " No", ((cellData[i] & PHANTOMCELL) > 0) ? " Yes" : " No",
                    ((cellData[i] & NEW) > 0) ? " Yes" : " No", ((cellData[i] & MOVE) > 0) ? " Yes" : " No", ((cellData[i] & EXPLORE) > 0) ? " Yes" : " No", ((cellData[i] & UNUSED) > 0) ? " Yes" : " No");

            }
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";
            using (StreamWriter sw = File.AppendText(log))
            {
                sw.WriteLine(output);
            }
        }
示例#4
0
        public static void PrintCollisionList(long[] collisionList,int[] cellIds, long[] cellData, GpuESC.CollisionCell[] debugCellPosList, string caption, int count)
        {
            String output = caption;
            output += "\n";
            output += "Collision List\n";
            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";

            for (int i = 0; i < count; i++)
            {
                int index = (int)(collisionList[i] & 0xFFFFFFFF);
                int numElements = (int)((collisionList[i] >> 32) & 0xFFFF);
                int homeCnt = (int)((collisionList[i] >> 48) & 0xFFFF);
                output += String.Format("actCellID = {0:x} x={1} y={2} z={3} startIdx= {4} homeCount = {5}\n", cellIds[index], debugCellPosList[index].x, debugCellPosList[index].y, debugCellPosList[index].z,index, homeCnt);
                output += String.Format("Colliding objects:\n");

                for (int j = 0; j < numElements; j++)
                {
                    output += String.Format("objId: {0},", cellData[index+j]&0xFFFFFFFF);
                }
                output += "\n\n";
            }

            output += "----------------------------------------------------------------------------------------------------------------------------------------------------------\n";
            using (StreamWriter sw = File.AppendText(log))
            {
                sw.WriteLine(output);
            }
        }