コード例 #1
0
ファイル: test_sequence.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            DVVector vec = new DVVector("int32_t", 10);

            TRTC.Sequence(vec);
            print_array((int[])vec.to_host());

            TRTC.Sequence(vec, new DVInt32(1));
            print_array((int[])vec.to_host());

            TRTC.Sequence(vec, new DVInt32(1), new DVInt32(3));
            print_array((int[])vec.to_host());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            {
                DVVector d_values = new DVVector(new int[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 });
                DVVector d_map    = new DVVector(new int[] { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 });
                DVVector d_output = new DVVector("int32_t", 10);
                TRTC.Gather(d_map, d_values, d_output);
                print_array((int[])d_output.to_host());
            }

            {
                DVVector d_values  = new DVVector(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
                DVVector d_stencil = new DVVector(new int[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 });
                DVVector d_map     = new DVVector(new int[] { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 });
                DVVector d_output  = new DVVector("int32_t", 10);
                TRTC.Fill(d_output, new DVInt32(7));
                TRTC.Gather_If(d_map, d_stencil, d_values, d_output);
                print_array((int[])d_output.to_host());
            }

            Functor is_even = new Functor(new string[] { "x" }, "        return ((x % 2) == 0);\n");
            {
                DVVector d_values  = new DVVector(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });
                DVVector d_stencil = new DVVector(new int[] { 0, 3, 4, 1, 4, 1, 2, 7, 8, 9 });
                DVVector d_map     = new DVVector(new int[] { 0, 2, 4, 6, 8, 1, 3, 5, 7, 9 });
                DVVector d_output  = new DVVector("int32_t", 10);
                TRTC.Fill(d_output, new DVInt32(7));
                TRTC.Gather_If(d_map, d_stencil, d_values, d_output, is_even);
                print_array((int[])d_output.to_host());
            }
        }
コード例 #3
0
ファイル: test_fill.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            DVVector vec_to_fill = new DVVector("int32_t", 5);

            TRTC.Fill(vec_to_fill, new DVInt32(123));
            print_array((int[])vec_to_fill.to_host());
        }
コード例 #4
0
        static void Main(string[] args)
        {
            {
                DVVector dIn  = new DVVector(new int[] { 10, 20, 30, 40, 50, 60, 70, 80 });
                DVVector dOut = new DVVector("int32_t", 8);
                TRTC.Copy(dIn, dOut);
                print_array((int[])dOut.to_host());
            }

            Functor is_even = new Functor(new string[] { "x" }, "        return x % 2 == 0;\n");

            {
                DVVector dIn   = new DVVector(new int[] { -2, 0, -1, 0, 1, 2 });
                DVVector dOut  = new DVVector("int32_t", 6);
                long     count = TRTC.Copy_If(dIn, dOut, is_even);
                print_array((int[])dOut.to_host(0, count));
            }

            {
                DVVector dIn      = new DVVector(new int[] { 0, 1, 2, 3, 4, 5 });
                DVVector dStencil = new DVVector(new int[] { -2, 0, -1, 0, 1, 2 });
                DVVector dOut     = new DVVector("int32_t", 6);
                long     count    = TRTC.Copy_If_Stencil(dIn, dStencil, dOut, is_even);
                print_array((int[])dOut.to_host(0, count));
            }
        }
コード例 #5
0
ファイル: test_scatter.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            {
                DVVector d_values = new DVVector(new int[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 });
                DVVector d_map    = new DVVector(new int[] { 0, 5, 1, 6, 2, 7, 3, 8, 4, 9 });
                DVVector d_output = new DVVector("int32_t", 10);
                TRTC.Scatter(d_values, d_map, d_output);
                print_array((int[])d_output.to_host());
            }

            {
                DVVector d_V = new DVVector(new int[] { 10, 20, 30, 40, 50, 60, 70, 80 });
                DVVector d_M = new DVVector(new int[] { 0, 5, 1, 6, 2, 7, 3, 4 });
                DVVector d_S = new DVVector(new int[] { 1, 0, 1, 0, 1, 0, 1, 0 });
                DVVector d_D = new DVVector(new int[] { 0, 0, 0, 0, 0, 0, 0, 0 });
                TRTC.Scatter_If(d_V, d_M, d_S, d_D);
                print_array((int[])d_D.to_host());
            }

            Functor is_even = new Functor(new string[] { "x" }, "        return ((x % 2) == 0);\n");
            {
                DVVector d_V = new DVVector(new int[] { 10, 20, 30, 40, 50, 60, 70, 80 });
                DVVector d_M = new DVVector(new int[] { 0, 5, 1, 6, 2, 7, 3, 4 });
                DVVector d_S = new DVVector(new int[] { 2, 1, 2, 1, 2, 1, 2, 1 });
                DVVector d_D = new DVVector(new int[] { 0, 0, 0, 0, 0, 0, 0, 0 });
                TRTC.Scatter_If(d_V, d_M, d_S, d_D, is_even);
                print_array((int[])d_D.to_host());
            }
        }
コード例 #6
0
ファイル: test_scan.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            {
                DVVector darr = new DVVector(new int[] { 1, 0, 2, 2, 1, 3 });
                TRTC.Inclusive_Scan(darr, darr);
                print_array((int[])darr.to_host());
            }

            {
                DVVector darr = new DVVector(new int[] { -5, 0, 2, -3, 2, 4, 0, -1, 2, 8 });
                TRTC.Inclusive_Scan(darr, darr, new Functor("Maximum"));
                print_array((int[])darr.to_host());
            }

            {
                DVVector darr = new DVVector(new int[] { 1, 0, 2, 2, 1, 3 });
                TRTC.Exclusive_Scan(darr, darr);
                print_array((int[])darr.to_host());
            }

            {
                DVVector darr = new DVVector(new int[] { 1, 0, 2, 2, 1, 3 });
                TRTC.Exclusive_Scan(darr, darr, new DVInt32(4));
                print_array((int[])darr.to_host());
            }

            {
                DVVector darr = new DVVector(new int[] { -5, 0, 2, -3, 2, 4, 0, -1, 2, 8 });
                TRTC.Exclusive_Scan(darr, darr, new DVInt32(1), new Functor("Maximum"));
                print_array((int[])darr.to_host());
            }
        }
コード例 #7
0
ファイル: test_replace.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            Functor is_less_than_zero = new Functor(new string[] { "x" }, "        return x<0;\n");

            {
                DVVector vec = new DVVector(new int[] { 1, 2, 3, 1, 2 });
                TRTC.Replace(vec, new DVInt32(1), new DVInt32(99));
                print_array((int[])vec.to_host());
            }

            {
                DVVector vec = new DVVector(new int[] { 1, -2, 3, -4, 5 });
                TRTC.Replace_If(vec, is_less_than_zero, new DVInt32(99));
                print_array((int[])vec.to_host());
            }

            {
                DVVector vec_in  = new DVVector(new int[] { 1, 2, 3, 1, 2 });
                DVVector vec_out = new DVVector("int32_t", 5);
                TRTC.Replace_Copy(vec_in, vec_out, new DVInt32(1), new DVInt32(99));
                print_array((int[])vec_out.to_host());
            }

            {
                DVVector vec_in  = new DVVector(new int[] { 1, -2, 3, -4, 5 });
                DVVector vec_out = new DVVector("int32_t", 5);
                TRTC.Replace_Copy_If(vec_in, vec_out, is_less_than_zero, new DVInt32(99));
                print_array((int[])vec_out.to_host());
            }
        }
コード例 #8
0
ファイル: test_tabulate.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            DVVector vec = new DVVector("int32_t", 10);

            TRTC.Sequence(vec);
            TRTC.Tabulate(vec, new Functor("Negate"));
            print_array((int[])vec.to_host());
        }
コード例 #9
0
        static void Main(string[] args)
        {
            DVCounter src = new DVCounter(new DVInt32(1), 10);
            DVVector  dst = new DVVector("int32_t", 10);

            TRTC.Copy(src, dst);
            print_array((int[])dst.to_host());
        }
コード例 #10
0
        static void Main(string[] args)
        {
            DVVector darr1 = new DVVector(new int[] { 10, 20, 30, 40, 50, 60, 70, 80 });
            DVVector darr2 = new DVVector(new int[] { 1000, 900, 800, 700, 600, 500, 400, 300 });

            TRTC.Swap(darr1, darr2);
            print_array((int[])darr1.to_host());
            print_array((int[])darr2.to_host());
        }
コード例 #11
0
        static void Main(string[] args)
        {
            DVVector  dvalues = new DVVector(new int[] { 3, 7, 2, 5 });
            DVReverse src     = new DVReverse(dvalues);
            DVVector  dst     = new DVVector("int32_t", 4);

            TRTC.Copy(src, dst);
            print_array((int[])dst.to_host());
        }
コード例 #12
0
        static void Main(string[] args)
        {
            DVVector d_input = new DVVector(new int[] { 0, 2, 5, 7, 8 });

            {
                Console.WriteLine(TRTC.Lower_Bound(d_input, new DVInt32(0)));
                Console.WriteLine(TRTC.Lower_Bound(d_input, new DVInt32(1)));
                Console.WriteLine(TRTC.Lower_Bound(d_input, new DVInt32(2)));
                Console.WriteLine(TRTC.Lower_Bound(d_input, new DVInt32(3)));
                Console.WriteLine(TRTC.Lower_Bound(d_input, new DVInt32(8)));
                Console.WriteLine(TRTC.Lower_Bound(d_input, new DVInt32(9)));
            }
            Console.WriteLine("");
            {
                Console.WriteLine(TRTC.Upper_Bound(d_input, new DVInt32(0)));
                Console.WriteLine(TRTC.Upper_Bound(d_input, new DVInt32(1)));
                Console.WriteLine(TRTC.Upper_Bound(d_input, new DVInt32(2)));
                Console.WriteLine(TRTC.Upper_Bound(d_input, new DVInt32(3)));
                Console.WriteLine(TRTC.Upper_Bound(d_input, new DVInt32(8)));
                Console.WriteLine(TRTC.Upper_Bound(d_input, new DVInt32(9)));
            }
            Console.WriteLine("");
            {
                Console.WriteLine(TRTC.Binary_Search(d_input, new DVInt32(0)));
                Console.WriteLine(TRTC.Binary_Search(d_input, new DVInt32(1)));
                Console.WriteLine(TRTC.Binary_Search(d_input, new DVInt32(2)));
                Console.WriteLine(TRTC.Binary_Search(d_input, new DVInt32(3)));
                Console.WriteLine(TRTC.Binary_Search(d_input, new DVInt32(8)));
                Console.WriteLine(TRTC.Binary_Search(d_input, new DVInt32(9)));
            }
            Console.WriteLine("");

            DVVector d_values = new DVVector(new int[] { 0, 1, 2, 3, 8, 9 });
            DVVector d_output = new DVVector("int32_t", 6);

            TRTC.Lower_Bound_V(d_input, d_values, d_output);
            print_array((int[])d_output.to_host());

            TRTC.Upper_Bound_V(d_input, d_values, d_output);
            print_array((int[])d_output.to_host());

            TRTC.Binary_Search_V(d_input, d_values, d_output);
            print_array((int[])d_output.to_host());
        }
コード例 #13
0
        static void Main(string[] args)
        {
            DVVector       d_in = new DVVector(new int[] { 0, 1, 2, 3, 4 });
            DVCustomVector src  = new DVCustomVector(new DeviceViewable[] { d_in }, new string[] { "src" }, "idx",
                                                     "        return src[idx % src.size()];\n", "int32_t", d_in.size() * 5);
            DVVector dst = new DVVector("int32_t", 25);

            TRTC.Copy(src, dst);
            print_array((int[])dst.to_host());
        }
コード例 #14
0
        static void Main(string[] args)
        {
            DVVector      dvalues  = new DVVector(new float[] { 10.0f, 20.0f, 30.0f, 40.0f, 50.0f, 60.0f, 70.0f, 80.0f });
            DVVector      dindices = new DVVector(new int[] { 2, 6, 1, 3 });
            DVPermutation src      = new DVPermutation(dvalues, dindices);
            DVVector      dst      = new DVVector("float", 4);

            TRTC.Copy(src, dst);
            print_array((float[])dst.to_host());
        }
コード例 #15
0
        static void Main(string[] args)
        {
            DVVector    dvalues     = new DVVector(new float[] { 1.0f, 4.0f, 9.0f, 16.0f });
            Functor     square_root = new Functor(new string[] { "x" }, "        return sqrtf(x);\n");
            DVTransform src         = new DVTransform(dvalues, "float", square_root);
            DVVector    dst         = new DVVector("float", 4);

            TRTC.Copy(src, dst);
            print_array((float[])dst.to_host());
        }
コード例 #16
0
        static void Main(string[] args)
        {
            Functor is_even = new Functor(new string[] { "x" }, "        return x % 2 == 0;\n");

            {
                DVVector d_value = new DVVector(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
                TRTC.Partition(d_value, is_even);
                print_array((int[])d_value.to_host());
            }

            {
                DVVector d_value   = new DVVector(new int[] { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 });
                DVVector d_stencil = new DVVector(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
                TRTC.Partition_Stencil(d_value, d_stencil, is_even);
                print_array((int[])d_value.to_host());
            }

            {
                DVVector d_value = new DVVector(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
                DVVector d_evens = new DVVector("int32_t", 10);
                DVVector d_odds  = new DVVector("int32_t", 10);
                long     count   = TRTC.Partition_Copy(d_value, d_evens, d_odds, is_even);
                print_array((int[])d_evens.to_host(0, count));
                print_array((int[])d_odds.to_host(0, 10 - count));
            }

            {
                DVVector d_value   = new DVVector(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
                DVVector d_stencil = new DVVector(new int[] { 0, 1, 0, 1, 0, 1, 0, 1, 0, 1 });
                DVVector d_evens   = new DVVector("int32_t", 10);
                DVVector d_odds    = new DVVector("int32_t", 10);
                long     count     = TRTC.Partition_Copy_Stencil(d_value, d_stencil, d_evens, d_odds, new Functor("Identity"));
                print_array((int[])d_evens.to_host(0, count));
                print_array((int[])d_odds.to_host(0, 10 - count));
            }

            {
                DVVector d_value = new DVVector(new int[] { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 });
                Console.WriteLine(TRTC.Partition_Point(d_value, is_even));
            }

            {
                DVVector d_value = new DVVector(new int[] { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 });
                Console.WriteLine(TRTC.Is_Partitioned(d_value, is_even));
            }

            {
                DVVector d_value = new DVVector(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
                Console.WriteLine(TRTC.Is_Partitioned(d_value, is_even));
            }
        }
コード例 #17
0
        static void Main(string[] args)
        {
            {
                DVVector d_data = new DVVector(new int[] { 1, 0, 2, 2, 1, 3 });
                TRTC.Transform_Inclusive_Scan(d_data, d_data, new Functor("Negate"), new Functor("Plus"));
                print_array((int[])d_data.to_host());
            }

            {
                DVVector d_data = new DVVector(new int[] { 1, 0, 2, 2, 1, 3 });
                TRTC.Transform_Exclusive_Scan(d_data, d_data, new Functor("Negate"), new DVInt32(4), new Functor("Plus"));
                print_array((int[])d_data.to_host());
            }
        }
コード例 #18
0
ファイル: test_rand.cs プロジェクト: fynv/CURandRTC
        static void Main(string[] args)
        {
            DVRNG rng = new DVRNG();
            For   ker = new For(new string[] { "rng", "vec_rnd" }, "idx",
                                @"
    RNGState state;
    rng.state_init(1234, idx, 0, state);
    vec_rnd[idx]=(float)state.rand01();");

            DVVector d_vec_rnd = new DVVector("float", 1024);

            DeviceViewable[] kargs = new DeviceViewable[] { rng, d_vec_rnd };
            ker.launch_n(1024, kargs);
            print_array((float[])d_vec_rnd.to_host());
        }
コード例 #19
0
        static void Main(string[] args)
        {
            {
                DVVector vec_in  = new DVVector(new int[] { 1, 2, 1, 2, 1, 2, 1, 2 });
                DVVector vec_out = new DVVector("int32_t", 8);
                TRTC.Adjacent_Difference(vec_in, vec_out);
                print_array((int[])vec_out.to_host());
            }

            {
                DVVector vec_in  = new DVVector(new int[] { 1, 2, 1, 2, 1, 2, 1, 2 });
                DVVector vec_out = new DVVector("int32_t", 8);
                TRTC.Adjacent_Difference(vec_in, vec_out, new Functor("Plus"));
                print_array((int[])vec_out.to_host());
            }
        }
コード例 #20
0
        static void Main(string[] args)
        {
            DVVector d_int_in   = new DVVector(new int[] { 0, 1, 2, 3, 4 });
            DVVector d_float_in = new DVVector(new float[] { 0.0f, 10.0f, 20.0f, 30.0f, 40.0f });

            DVVector d_int_out   = new DVVector("int32_t", 5);
            DVVector d_float_out = new DVVector("float", 5);

            DVZipped src = new DVZipped(new DVVectorLike[] { d_int_in, d_float_in }, new string[] { "a", "b" });
            DVZipped dst = new DVZipped(new DVVectorLike[] { d_int_out, d_float_out }, new string[] { "a", "b" });

            TRTC.Copy(src, dst);

            print_array((int[])d_int_out.to_host());
            print_array((float[])d_float_out.to_host());
        }
コード例 #21
0
        static void Main(string[] args)
        {
            {
                DVVector d_value = new DVVector(new int[] { 3, 1, 4, 1, 5, 9 });
                long     count   = TRTC.Remove(d_value, new DVInt32(1));
                print_array((int[])d_value.to_host(0, count));
            }

            {
                DVVector d_in  = new DVVector(new int[] { -2, 0, -1, 0, 1, 2 });
                DVVector d_out = new DVVector("int32_t", 6);
                long     count = TRTC.Remove_Copy(d_in, d_out, new DVInt32(0));
                print_array((int[])d_out.to_host(0, count));
            }

            Functor is_even = new Functor(new string[] { "x" }, "        return x % 2 == 0;\n");

            {
                DVVector d_value = new DVVector(new int[] { 1, 4, 2, 8, 5, 7 });
                long     count   = TRTC.Remove_If(d_value, is_even);
                print_array((int[])d_value.to_host(0, count));
            }

            {
                DVVector d_in  = new DVVector(new int[] { -2, 0, -1, 0, 1, 2 });
                DVVector d_out = new DVVector("int32_t", 6);
                long     count = TRTC.Remove_Copy_If(d_in, d_out, is_even);
                print_array((int[])d_out.to_host(0, count));
            }

            Functor identity = new Functor("Identity");

            {
                DVVector d_value   = new DVVector(new int[] { 1, 4, 2, 8, 5, 7 });
                DVVector d_stencil = new DVVector(new int[] { 0, 1, 1, 1, 0, 0 });
                long     count     = TRTC.Remove_If_Stencil(d_value, d_stencil, identity);
                print_array((int[])d_value.to_host(0, count));
            }

            {
                DVVector d_in      = new DVVector(new int[] { -2, 0, -1, 0, 1, 2 });
                DVVector d_stencil = new DVVector(new int[] { 1, 1, 0, 1, 0, 1 });
                DVVector d_out     = new DVVector("int32_t", 6);
                long     count     = TRTC.Remove_Copy_If_Stencil(d_in, d_stencil, d_out, identity);
                print_array((int[])d_out.to_host(0, count));
            }
        }
コード例 #22
0
        static void Main(string[] args)
        {
            {
                DVVector dvalues = new DVVector(new int[] { 1, 4, 2, 8, 5, 7 });
                Console.WriteLine(TRTC.Is_Sorted(dvalues));
                TRTC.Sort(dvalues);
                print_array((int[])dvalues.to_host());
                Console.WriteLine(TRTC.Is_Sorted(dvalues));
            }

            {
                Functor  comp    = new Functor("Greater");
                DVVector dvalues = new DVVector(new int[] { 1, 4, 2, 8, 5, 7 });
                Console.WriteLine(TRTC.Is_Sorted(dvalues, comp));
                TRTC.Sort(dvalues, comp);
                print_array((int[])dvalues.to_host());
                Console.WriteLine(TRTC.Is_Sorted(dvalues, comp));
            }

            {
                DVVector dkeys   = new DVVector(new int[] { 1, 4, 2, 8, 5, 7 });
                DVVector dvalues = new DVVector(new int[] { 1, 2, 3, 4, 5, 6 });
                TRTC.Sort_By_Key(dkeys, dvalues);
                print_array((int[])dkeys.to_host());
                print_array((int[])dvalues.to_host());
            }

            {
                Functor  comp    = new Functor("Greater");
                DVVector dkeys   = new DVVector(new int[] { 1, 4, 2, 8, 5, 7 });
                DVVector dvalues = new DVVector(new int[] { 1, 2, 3, 4, 5, 6 });
                TRTC.Sort_By_Key(dkeys, dvalues, comp);
                print_array((int[])dkeys.to_host());
                print_array((int[])dvalues.to_host());
            }

            {
                DVVector dvalues = new DVVector(new int[] { 0, 1, 2, 3, 0, 1, 2, 3 });
                Console.WriteLine(TRTC.Is_Sorted_Until(dvalues));
            }

            {
                DVVector dvalues = new DVVector(new int[] { 3, 2, 1, 0, 3, 2, 1, 0 });
                Console.WriteLine(TRTC.Is_Sorted_Until(dvalues, new Functor("Greater")));
            }
        }
コード例 #23
0
ファイル: test_merge.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            {
                DVVector dIn1 = new DVVector(new int[] { 1, 3, 5, 7, 9, 11 });
                DVVector dIn2 = new DVVector(new int[] { 1, 1, 2, 3, 5, 8, 13 });
                DVVector dOut = new DVVector("int32_t", 13);
                TRTC.Merge(dIn1, dIn2, dOut);
                print_array((int[])dOut.to_host());
            }

            {
                DVVector dIn1 = new DVVector(new int[] { 11, 9, 7, 5, 3, 1 });
                DVVector dIn2 = new DVVector(new int[] { 13, 8, 5, 3, 2, 1, 1 });
                DVVector dOut = new DVVector("int32_t", 13);
                TRTC.Merge(dIn1, dIn2, dOut, new Functor("Greater"));
                print_array((int[])dOut.to_host());
            }

            {
                DVVector dKeys1   = new DVVector(new int[] { 1, 3, 5, 7, 9, 11 });
                DVVector dVals1   = new DVVector(new int[] { 0, 0, 0, 0, 0, 0 });
                DVVector dKeys2   = new DVVector(new int[] { 1, 1, 2, 3, 5, 8, 13 });
                DVVector dVals2   = new DVVector(new int[] { 1, 1, 1, 1, 1, 1, 1 });
                DVVector dKeysOut = new DVVector("int32_t", 13);
                DVVector dValsOut = new DVVector("int32_t", 13);
                TRTC.Merge_By_Key(dKeys1, dKeys2, dVals1, dVals2, dKeysOut, dValsOut);
                print_array((int[])dKeysOut.to_host());
                print_array((int[])dValsOut.to_host());
            }

            {
                DVVector dKeys1   = new DVVector(new int[] { 11, 9, 7, 5, 3, 1 });
                DVVector dVals1   = new DVVector(new int[] { 0, 0, 0, 0, 0, 0 });
                DVVector dKeys2   = new DVVector(new int[] { 13, 8, 5, 3, 2, 1, 1 });
                DVVector dVals2   = new DVVector(new int[] { 1, 1, 1, 1, 1, 1, 1 });
                DVVector dKeysOut = new DVVector("int32_t", 13);
                DVVector dValsOut = new DVVector("int32_t", 13);
                TRTC.Merge_By_Key(dKeys1, dKeys2, dVals1, dVals2, dKeysOut, dValsOut, new Functor("Greater"));
                print_array((int[])dKeysOut.to_host());
                print_array((int[])dValsOut.to_host());
            }
        }
コード例 #24
0
ファイル: test_for.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            For ker = new For(new string[] { "arr_in", "arr_out", "k" }, "idx",
                              "    arr_out[idx] = arr_in[idx]*k;\n");

            DVVector dvec_in_f  = new DVVector(new float[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f });
            DVVector dvec_out_f = new DVVector("float", 5);
            DVFloat  k1         = new DVFloat(10.0f);

            DeviceViewable[] args_f = new DeviceViewable[] { dvec_in_f, dvec_out_f, k1 };
            ker.launch_n(5, args_f);
            print_array((float[])dvec_out_f.to_host());

            DVVector dvec_in_i  = new DVVector(new int[] { 6, 7, 8, 9, 10 });
            DVVector dvec_out_i = new DVVector("int32_t", 5);
            DVInt32  k2         = new DVInt32(5);

            DeviceViewable[] args_i = new DeviceViewable[] { dvec_in_i, dvec_out_i, k2 };
            ker.launch_n(5, args_i);
            print_array((int[])dvec_out_i.to_host());
        }
コード例 #25
0
        static void Main(string[] args)
        {
            Functor is_odd = new Functor(new string[] { "x" }, "        return x % 2;\n");

            {
                DVVector vec = new DVVector(new int[] { -5, 0, 2, -3, 2, 4, 0, -1, 2, 8 });
                TRTC.Transform(vec, vec, new Functor("Negate")); // in place
                print_array((int[])vec.to_host());
            }

            {
                DVVector d_in1 = new DVVector(new int[] { -5, 0, 2, 3, 2, 4 });
                DVVector d_in2 = new DVVector(new int[] { 3, 6, -2, 1, 2, 3 });
                DVVector d_out = new DVVector("int32_t", 6);
                TRTC.Transform_Binary(d_in1, d_in2, d_out, new Functor("Plus"));
                print_array((int[])d_out.to_host());
            }

            {
                DVVector vec = new DVVector(new int[] { -5, 0, 2, -3, 2, 4, 0, -1, 2, 8 });
                TRTC.Transform_If(vec, vec, new Functor("Negate"), is_odd); // in place
                print_array((int[])vec.to_host());
            }

            {
                DVVector d_data    = new DVVector(new int[] { -5, 0, 2, -3, 2, 4, 0, -1, 2, 8 });
                DVVector d_stencil = new DVVector(new int[] { 1, 0, 1, 0, 1, 0, 1, 0, 1, 0 });
                TRTC.Transform_If_Stencil(d_data, d_stencil, d_data, new Functor("Negate"), new Functor("Identity")); // in place
                print_array((int[])d_data.to_host());
            }

            {
                DVVector d_in1     = new DVVector(new int[] { -5, 0, 2, 3, 2, 4 });
                DVVector d_in2     = new DVVector(new int[] { 3, 6, -2, 1, 2, 3 });
                DVVector d_stencil = new DVVector(new int[] { 1, 0, 1, 0, 1, 0 });
                DVVector d_output  = new DVVector("int32_t", 6);
                TRTC.Transform_Binary_If_Stencil(d_in1, d_in2, d_stencil, d_output, new Functor("Plus"), new Functor("Identity")); // in place
                print_array((int[])d_output.to_host());
            }
        }
コード例 #26
0
ファイル: test_reduce.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            {
                DVVector darr = new DVVector(new int[] { 1, 0, 2, 2, 1, 3 });
                Console.WriteLine(TRTC.Reduce(darr));
                Console.WriteLine(TRTC.Reduce(darr, new DVInt32(1)));
                Console.WriteLine(TRTC.Reduce(darr, new DVInt32(-1), new Functor("Maximum")));
            }

            {
                DVVector d_keys_in    = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_values_in  = new DVVector(new int[] { 9, 8, 7, 6, 5, 4, 3 });
                DVVector d_keys_out   = new DVVector("int32_t", 7);
                DVVector d_values_out = new DVVector("int32_t", 7);
                long     count        = TRTC.Reduce_By_Key(d_keys_in, d_values_in, d_keys_out, d_values_out);
                print_array((int[])d_keys_out.to_host(0, count));
                print_array((int[])d_values_out.to_host(0, count));
            }

            {
                DVVector d_keys_in    = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_values_in  = new DVVector(new int[] { 9, 8, 7, 6, 5, 4, 3 });
                DVVector d_keys_out   = new DVVector("int32_t", 7);
                DVVector d_values_out = new DVVector("int32_t", 7);
                long     count        = TRTC.Reduce_By_Key(d_keys_in, d_values_in, d_keys_out, d_values_out, new Functor("EqualTo"));
                print_array((int[])d_keys_out.to_host(0, count));
                print_array((int[])d_values_out.to_host(0, count));
            }

            {
                DVVector d_keys_in    = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_values_in  = new DVVector(new int[] { 9, 8, 7, 6, 5, 4, 3 });
                DVVector d_keys_out   = new DVVector("int32_t", 7);
                DVVector d_values_out = new DVVector("int32_t", 7);
                long     count        = TRTC.Reduce_By_Key(d_keys_in, d_values_in, d_keys_out, d_values_out, new Functor("EqualTo"), new Functor("Plus"));
                print_array((int[])d_keys_out.to_host(0, count));
                print_array((int[])d_values_out.to_host(0, count));
            }
        }
コード例 #27
0
        static void Main(string[] args)
        {
            {
                DVVector d_keys   = new DVVector(new int[] { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
                DVVector d_values = new DVVector(new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
                TRTC.Inclusive_Scan_By_Key(d_keys, d_values, d_values);
                print_array((int[])d_values.to_host());
            }

            {
                DVVector d_keys   = new DVVector(new int[] { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
                DVVector d_values = new DVVector(new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
                TRTC.Exclusive_Scan_By_Key(d_keys, d_values, d_values);
                print_array((int[])d_values.to_host());
            }

            {
                DVVector d_keys   = new DVVector(new int[] { 0, 0, 0, 1, 1, 2, 3, 3, 3, 3 });
                DVVector d_values = new DVVector(new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 });
                TRTC.Exclusive_Scan_By_Key(d_keys, d_values, d_values, new DVInt32(5));
                print_array((int[])d_values.to_host());
            }
        }
コード例 #28
0
ファイル: test_trtc.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            Kernel ker = new Kernel(new string[] { "arr_in", "arr_out", "k" },
                                    @"
    size_t idx = blockIdx.x * blockDim.x + threadIdx.x;
    if (idx >= arr_in.size()) return;
    arr_out[idx] = arr_in[idx]*k;");

            DVVector dvec_in_f  = new DVVector(new float[] { 1.0f, 2.0f, 3.0f, 4.0f, 5.0f });
            DVVector dvec_out_f = new DVVector("float", 5);
            DVFloat  k1         = new DVFloat(10.0f);

            DeviceViewable[] args_f = new DeviceViewable[] { dvec_in_f, dvec_out_f, k1 };
            ker.launch(1, 128, args_f);
            print_array((float[])dvec_out_f.to_host());

            DVVector dvec_in_i  = new DVVector(new int[] { 6, 7, 8, 9, 10 });
            DVVector dvec_out_i = new DVVector("int32_t", 5);
            DVInt32  k2         = new DVInt32(5);

            DeviceViewable[] args_i = new DeviceViewable[] { dvec_in_i, dvec_out_i, k2 };
            ker.launch(1, 128, args_i);
            print_array((int[])dvec_out_i.to_host());
        }
コード例 #29
0
ファイル: test_unique.cs プロジェクト: sumit-byte/ThrustRTC
        static void Main(string[] args)
        {
            {
                DVVector d_value = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                long     count   = TRTC.Unique(d_value);
                print_array((int[])d_value.to_host(0, count));
            }

            {
                DVVector d_value = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                long     count   = TRTC.Unique(d_value, new Functor("EqualTo"));
                print_array((int[])d_value.to_host(0, count));
            }

            {
                DVVector d_in  = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_out = new DVVector("int32_t", 7);
                long     count = TRTC.Unique_Copy(d_in, d_out);
                print_array((int[])d_out.to_host(0, count));
            }

            {
                DVVector d_in  = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_out = new DVVector("int32_t", 7);
                long     count = TRTC.Unique_Copy(d_in, d_out, new Functor("EqualTo"));
                print_array((int[])d_out.to_host(0, count));
            }

            {
                DVVector d_keys   = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_values = new DVVector(new int[] { 9, 8, 7, 6, 5, 4, 3 });
                long     count    = TRTC.Unique_By_Key(d_keys, d_values);
                print_array((int[])d_keys.to_host(0, count));
                print_array((int[])d_values.to_host(0, count));
            }

            {
                DVVector d_keys   = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_values = new DVVector(new int[] { 9, 8, 7, 6, 5, 4, 3 });
                long     count    = TRTC.Unique_By_Key(d_keys, d_values, new Functor("EqualTo"));
                print_array((int[])d_keys.to_host(0, count));
                print_array((int[])d_values.to_host(0, count));
            }

            {
                DVVector d_keys_in    = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_values_in  = new DVVector(new int[] { 9, 8, 7, 6, 5, 4, 3 });
                DVVector d_keys_out   = new DVVector("int32_t", 7);
                DVVector d_values_out = new DVVector("int32_t", 7);
                long     count        = TRTC.Unique_By_Key_Copy(d_keys_in, d_values_in, d_keys_out, d_values_out);
                print_array((int[])d_keys_out.to_host(0, count));
                print_array((int[])d_values_out.to_host(0, count));
            }

            {
                DVVector d_keys_in    = new DVVector(new int[] { 1, 3, 3, 3, 2, 2, 1 });
                DVVector d_values_in  = new DVVector(new int[] { 9, 8, 7, 6, 5, 4, 3 });
                DVVector d_keys_out   = new DVVector("int32_t", 7);
                DVVector d_values_out = new DVVector("int32_t", 7);
                long     count        = TRTC.Unique_By_Key_Copy(d_keys_in, d_values_in, d_keys_out, d_values_out, new Functor("EqualTo"));
                print_array((int[])d_keys_out.to_host(0, count));
                print_array((int[])d_values_out.to_host(0, count));
            }
        }