示例#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 void Explore(IShape shape, ExploreDelegate exploreDelegate, Enum collisionType = null)
        {
            IEnumerable<ISpatialEntity> res;
            if (gpuActive) gpuActiveWait.WaitOne();
            Interlocked.Increment(ref m_ActiveOperationCount);
            int objId = Interlocked.Increment(ref exploreIdGenBase);
            long objData = objId | FLAG_EXLORE;
            objIdList.Add(objId);
            m_ExploreDelegates.Add(new Tuple<long, ExploreDelegate>(objData,exploreDelegate));
            /*spatialObjIdMap.Add(entity, objId);
            objIdSpatialMap.Add(objId, entity);
            */
            clShapeObject act;
            clPoint center;
            center.x = (float)shape.Bounds.Position.X;
            center.y = (float)shape.Bounds.Position.Y;
            center.z = (float)shape.Bounds.Position.Z;
            clPoint front;
            front.x = (float)shape.Bounds.LeftBottomFront.X;
            front.y = (float)shape.Bounds.LeftBottomFront.Y;
            front.z = (float)shape.Bounds.LeftBottomFront.Z;
            clPoint rear;
            rear.x = (float)shape.Bounds.RightTopRear.X;
            rear.y = (float)shape.Bounds.RightTopRear.Y;
            rear.z = (float)shape.Bounds.RightTopRear.Z;
            act.center = center;
            act.leftBottomFront = front;
            act.rigthTopRear = rear;

            envExploreObjs.Add(objData, act);
            /*
                        shapeList.Add(act);
                        objIdClShapeMap.Add(objId, act);
                        */

            Interlocked.Decrement(ref m_ActiveOperationCount);
        }