Ejemplo n.º 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);
            }
        }
Ejemplo n.º 2
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 StructMappingMemory <MySimpleStruct>(Context, 100))
                    {
                        mem.Write(CommandQueue, true, 0, 50, input);
                        using (var memMap = mem.Mapping(CommandQueue, true, 50, WorkSize - 50))
                        {
                            for (int i = 0; i < memMap.Length; ++i)
                            {
                                memMap[i] = input[i + 50];
                            }
                        }

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

                        mem.Read(CommandQueue, true, output);

                        Assert.AreEqual(expected, output);
                    }
                }
        }
Ejemplo n.º 3
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);
            }
        }