Beispiel #1
0
        public void ReadPartTest()
        {
            using (var mem = new StructSimpleMemory <MySimpleStruct>(Context, 100))
            {
                MySimpleStruct[] dat = Enumerable.Range(0, 100)
                                       .Select(n => new MySimpleStruct()
                {
                    X = n, Y = n + 10, Point = n * 2.2f
                })
                                       .ToArray();
                MySimpleStruct[] ans = new MySimpleStruct[25];

                mem.Write(CommandQueue, true, 0, dat.Length, dat).Wait();

                mem.Read(CommandQueue, true, 0, 25, ans).Wait();
                Assert.AreEqual(dat.Skip(0).Take(25), ans);

                mem.Read(CommandQueue, true, 25, 25, ans).Wait();
                Assert.AreEqual(dat.Skip(25).Take(25), ans);

                mem.Read(CommandQueue, true, 50, 25, ans).Wait();
                Assert.AreEqual(dat.Skip(50).Take(25), ans);

                mem.Read(CommandQueue, true, 75, 25, ans).Wait();
                Assert.AreEqual(dat.Skip(75).Take(25), ans);
            }
        }
Beispiel #2
0
        public void ReadWriteTest()
        {
            using (var mem = new StructSimpleMemory <MySimpleStruct>(Context, 100))
            {
                MySimpleStruct[] dat = Enumerable.Range(0, 100)
                                       .Select(n => new MySimpleStruct()
                {
                    X = n, Y = n + 10, Point = n * 2.2f
                })
                                       .ToArray();
                MySimpleStruct[] ans = new MySimpleStruct[100];

                mem.WriteDirect(CommandQueue, true, 0, dat.Length, dat, 0).Wait();
                mem.ReadDirect(CommandQueue, true, 0, ans.Length, ans, 0).Wait();
                Assert.AreEqual(dat, ans);


                mem.Write(CommandQueue, true, 0, dat.Length, dat, 0).Wait();
                Assert.AreEqual(dat, ans);

                mem.Write(CommandQueue, true, 0, dat.Length, dat).Wait();
                Assert.AreEqual(dat, ans);

                mem.Write(CommandQueue, true, dat.Length, dat).Wait();
                Assert.AreEqual(dat, ans);

                mem.Write(CommandQueue, true, dat).Wait();
                Assert.AreEqual(dat, ans);



                mem.Read(CommandQueue, true, 0, ans.Length, ans, 0).Wait();
                Assert.AreEqual(dat, ans);

                mem.Read(CommandQueue, true, 0, ans.Length, ans).Wait();
                Assert.AreEqual(dat, ans);

                mem.Read(CommandQueue, true, ans.Length, ans).Wait();
                Assert.AreEqual(dat, ans);

                mem.Read(CommandQueue, true, ans).Wait();
                Assert.AreEqual(dat, ans);
            }
        }
Beispiel #3
0
        public ScoredPoint[] Find()
        {
            ulong rangeLimit  = Device.Info.Get(ClDeviceInfo.DeviceMaxWorkGroupSize);
            int   rangeLimitI = (int)Math.Sqrt((int)rangeLimit);
            int   rangeLimitJ = (int)rangeLimitI;

            int heiAdding = rangeLimitI - (Source.Height - Template.Height + 1) % rangeLimitI;
            int widAdding = rangeLimitJ - (Source.Width - Template.Width + 1) % rangeLimitJ;

            if (heiAdding == rangeLimitI)
            {
                heiAdding = 0;
            }
            if (widAdding == rangeLimitJ)
            {
                widAdding = 0;
            }

            var sourceSource   = ImageSource.Create(Source, widAdding, heiAdding);
            var templateSource = new ImageSource(Template);

            int rangeI = sourceSource.Height - Template.Height + 1;
            int rangeJ = sourceSource.Width - Template.Width + 1;

            var ans = new ScoredPoint[rangeI * rangeJ];

            using (var imgMem = Context.CreateSimpleMemory(sourceSource.Data))
                using (var tmpMem = Context.CreateSimpleMemory(templateSource.Data))
                    using (var pntAryMem = new StructSimpleMemory <ScoredPoint>(Context, rangeI * rangeJ))
                    {
                        PgKernel.SetWorkSize(rangeI, rangeJ);
                        PgKernel.SetLocalSize(rangeLimitI, rangeLimitJ);
                        PgKernel.SetArgs(
                            rangeJ,
                            imgMem, sourceSource.Width,
                            tmpMem, templateSource.Width, templateSource.Height,
                            pntAryMem);
                        PgKernel.NDRange(CommandQueue).Wait();

                        pntAryMem.Read(CommandQueue, true, ans);
                    }

            return(ans.Where(pnt => pnt.Score >= Threashold)
                   .OrderByDescending(pnt => pnt.Score)
                   .Take(100)
                   .ToArray());
        }
Beispiel #4
0
        public void ShaderTest()
        {
            const int WorkSize = 100;
            const int Adding   = 53;

            using (var program = Context.CreateProgram(Source))
                using (var kernel = program.CreateKernel("testKernel"))
                {
                    var input = Enumerable.Range(0, 100)
                                .Select(n => new MySimpleStruct()
                    {
                        X     = n,
                        Y     = n + 10,
                        Point = n * 2.2f
                    })
                                .ToArray();

                    var output   = new MySimpleStruct[WorkSize];
                    var expected = input
                                   .Select(v => new MySimpleStruct()
                    {
                        X     = v.X + Adding,
                        Y     = v.Y + Adding,
                        Point = v.Point + Adding,
                    })
                                   .ToArray();

                    kernel.SetWorkSize(WorkSize);
                    using (var mem = new StructSimpleMemory <MySimpleStruct>(Context, 100))
                    {
                        mem.Write(CommandQueue, true, 0, 50, input);
                        mem.Write(CommandQueue, true, 50, WorkSize - 50, input, 50);

                        kernel.SetArgs(mem, (int)Adding);
                        kernel.NDRange(CommandQueue).Wait();

                        mem.Read(CommandQueue, true, output);

                        Assert.AreEqual(expected, output);
                    }
                }
        }