Esempio n. 1
0
        public void Init()
	    {
            StreamReader sr = new StreamReader("../../data/turing_js_r.rle");
            uint state = 0, n = 0, x = 0, y = 0;
            while (true)
            {
                String line = sr.ReadLine();
                if (line == null) break; // end of file
                int pos = 0;
                if (line[pos] == '#') continue;
                else if (line[pos] == 'x') // header
                {
                    String[] sub = line.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    pw = (UInt32.Parse(sub[1]) + 31) / 32;
                    ph = UInt32.Parse(sub[3]);
                    pattern = new uint[pw * ph];
                    second = new uint[pw * ph];
                }
                else while (pos < line.Length)
                    {
                        Char c = line[pos++];
                        if (state == 0) if (c < '0' || c > '9') { state = 1; n = Math.Max(n, 1); } else n = (uint)(n * 10 + (c - '0'));
                        if (state == 1) // expect other character
                        {
                            if (c == '$') { y += n; x = 0; } // newline
                            else if (c == 'o') for (int i = 0; i < n; i++) BitSet(x++, y); else if (c == 'b') x += n;
                            state = n = 0;
                        }
                    }
                // swap buffers
                for (int i = 0; i < pw * ph; i++) second[i] = pattern[i];
            }
            patternbuffer = new OpenCLBuffer<uint>(ocl,(int)(pw * ph));
            secondbuffer = new OpenCLBuffer<uint>(ocl, second);
        }
Esempio n. 2
0
        // minimalistic .rle file reader for Golly files (see http://golly.sourceforge.net)
        public void Init()
        {
            StreamReader sr = new StreamReader("../../data/turing_js_r.rle");
            uint state = 0, n = 0, x = 0, y = 0;
            while (true)
            {
                String line = sr.ReadLine();
                if (line == null) break; // end of file
                int pos = 0;
                if (line[pos] == '#') continue; /* comment line */
                else if (line[pos] == 'x') // header
                {
                    String[] sub = line.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    pw = (UInt32.Parse(sub[1]) + 31) >> 5;
                    ph = UInt32.Parse(sub[3]);
                    pwph = pw * ph;
                    pattern = new uint[pwph];
                    second = new uint[pwph];
                }
                else while (pos < line.Length)
                    {
                        Char c = line[pos++];
                        if (state == 0) if (c < '0' || c > '9') { state = 1; n = Math.Max(n, 1); } else n = (uint)(n * 10 + (c - '0'));
                        if (state == 1) // expect other character
                        {
                            if (c == '$') { y += n; x = 0; } // newline
                            else if (c == 'o') for (int i = 0; i < n; i++) BitSet(x++, y, second); else if (c == 'b') x += n;
                            state = n = 0;
                        }
                    }
            }
            amountOfCells = pwph << 5;
            levelWidth = pw << 5;
            secondBuffer = new OpenCLBuffer<uint>(ocl, second);
            patternBuffer = new OpenCLBuffer<uint>(ocl, pattern);

            // pass values to the kernel.
            if (GLInterop)
            {
                kernel.SetArgument(0, image);
                kernel.SetArgument(4, patternBuffer);
                kernel.SetArgument(5, secondBuffer);
            }
            else
            {
                kernel.SetArgument(0, buffer);
            }
            kernel.SetArgument(1, levelWidth);
            kernel.SetArgument(2, ph);
            kernel.SetArgument(3, amountOfCells);
            kernel.SetArgument(8, screenWidth);
            kernel.SetArgument(9, screenHeight);

            // pass values to the copy kernel
            copyKernel.SetArgument(0, levelWidth);
            copyKernel.SetArgument(1, amountOfCells);
            copyKernel.SetArgument(2, patternBuffer);
            copyKernel.SetArgument(3, secondBuffer);
        }
Esempio n. 3
0
 public void SetArgument(int i, OpenCLBuffer <uint> v)
 {
     kernel.SetMemoryArgument(i, v._gpubuffer);
 }
Esempio n. 4
0
        // minimalistic .rle file reader for Golly files (see http://golly.sourceforge.net)
        public void Init()
        {
            StreamReader sr = new StreamReader("../../samples/turing_js_r.rle");
            uint         state = 0, n = 0, x = 0, y = 0;

            while (true)
            {
                String line = sr.ReadLine();
                if (line == null)
                {
                    break;               // end of file
                }
                int pos = 0;
                if (line[pos] == '#')
                {
                    continue;              /* comment line */
                }
                else if (line[pos] == 'x') // header
                {
                    String[] sub = line.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    pw      = (UInt32.Parse(sub[1]) + 31) / 32;
                    ph      = UInt32.Parse(sub[3]);
                    pattern = new uint[pw * ph];
                    second  = new uint[pw * ph];
                }
                else
                {
                    while (pos < line.Length)
                    {
                        Char c = line[pos++];
                        if (state == 0)
                        {
                            if (c < '0' || c > '9')
                            {
                                state = 1; n = Math.Max(n, 1);
                            }
                            else
                            {
                                n = (uint)(n * 10 + (c - '0'));
                            }
                        }
                        if (state == 1) // expect other character
                        {
                            if (c == '$')
                            {
                                y += n; x = 0;
                            }                                // newline
                            else if (c == 'o')
                            {
                                for (int i = 0; i < n; i++)
                                {
                                    BitSet(x++, y);
                                }
                            }
                            else if (c == 'b')
                            {
                                x += n;
                            }
                            state = n = 0;
                        }
                    }
                }
            }
            // swap buffers
            for (int i = 0; i < pw * ph; i++)
            {
                second[i] = pattern[i];
            }

            //initiate buffers
            pattern_buffer = new OpenCLBuffer <uint>(program, pattern);
            second_buffer  = new OpenCLBuffer <uint>(program, second);

            //Set Arguments
            empty.SetArgument(0, pattern_buffer);
            swap.SetArgument(0, pattern_buffer);
            swap.SetArgument(1, second_buffer);
            process.SetArgument(0, pattern_buffer);
            process.SetArgument(1, second_buffer);
            process.SetArgument(2, pw);
        }
Esempio n. 5
0
    public void Init()
	{
        StreamReader sr = new StreamReader("../../data/turing_js_r.rle");
        uint state = 0, n = 0, x = 0, y = 0;
        while (true)
        {
            String line = sr.ReadLine();
            if (line == null) break; // end of file
            int pos = 0;
            if (line[pos] == '#') continue; /* comment line */
            else if (line[pos] == 'x') // header
            {
                String[] sub = line.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
                pw = (UInt32.Parse(sub[1]) + 31) / 32;
                ph = UInt32.Parse(sub[3]);
                pattern = new uint[pw * ph];
                second = new uint[pw * ph];
            }
            else while (pos < line.Length)
                {
                    Char c = line[pos++];
                    if (state == 0) if (c < '0' || c > '9') { state = 1; n = Math.Max(n, 1); } else n = (uint)(n * 10 + (c - '0'));
                    if (state == 1) // expect other character
                    {
                        if (c == '$') { y += n; x = 0; } // newline
                        else if (c == 'o') for (int i = 0; i < n; i++) BitSet(x++, y); else if (c == 'b') x += n;
                        state = n = 0;
                    }
                }
        }
            // swap buffers
        for (int i = 0; i < pw * ph; i++) { second[i] = pattern[i]; pattern[i] = 0; }

        secondBuffer = new OpenCLBuffer<uint>(ocl, second);
        patternBuffer = new OpenCLBuffer<uint>(ocl, pattern);

        clearKernel.SetArgument(0, image);

        simulateKernel.SetArgument(0, secondBuffer);
        simulateKernel.SetArgument(1, patternBuffer);
        simulateKernel.SetArgument(2, pw);
        simulateKernel.SetArgument(3, ph);

        copyKernel.SetArgument(0, secondBuffer);
        copyKernel.SetArgument(1, patternBuffer);
        copyKernel.SetArgument(2, pw);

        kernel.SetArgument(0, image);
        kernel.SetArgument(1, pw);
        kernel.SetArgument(4, secondBuffer);
        kernel.SetArgument(5, patternBuffer);
        kernel.SetArgument( 4, secondBuffer );
		kernel.SetArgument( 5, patternBuffer );

        // execute kernel
		long [] workSize = { 512, 512 };
		long [] localSize = { 32, 4 };
        long [] arraySizeExpanded = { pw * 32, ph }; //54 * 32 * 1647
        long [] arraySizeCompressed = { pattern.Length }; //54 * 1647

        // INTEROP PATH:
        // lock the OpenGL texture for use by OpenCL
        kernel.LockOpenGLObject( image.texBuffer );

        // execute the kernels
        //clearKernel.Execute(workSize, localSize);
        simulateKernel.Execute(arraySizeExpanded, null);
        copyKernel.Execute(arraySizeCompressed, null);
        kernel.Execute( workSize, localSize );
            //Thread.Sleep(200);

		// unlock the OpenGL texture so it can be used for drawing a quad
		kernel.UnlockOpenGLObject( image.texBuffer );
        Console.WriteLine("generation " + generation++ + ": " + timer.Elapsed.TotalMilliseconds + "ms");
        
    }
Esempio n. 6
0
        // minimalistic .rle file reader for Golly files (see http://golly.sourceforge.net)
        public void Init()
        {
            StreamReader sr = new StreamReader("../../data/turing_js_r.rle");
            uint         state = 0, n = 0, x = 1, y = 1;

            while (true)
            {
                String line = sr.ReadLine();
                if (line == null)
                {
                    break;               // end of file
                }
                int pos = 0;
                if (line[pos] == '#')
                {
                    continue;              /* comment line */
                }
                else if (line[pos] == 'x') // header
                {
                    String[] sub = line.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    pw      = ((UInt32.Parse(sub[1]) + 33) / 32);
                    ph      = UInt32.Parse(sub[3]) + 2;
                    pattern = new OpenCLBuffer <uint>(ocl, (pw * ph));
                    second  = new OpenCLBuffer <uint>(ocl, (pw * ph));
                    buffer  = new OpenCLBuffer <int>(ocl, 512 * 512);
                    kernel.SetArgument(3, pw);
                    kernel.SetArgument(4, ph);
                }
                else
                {
                    while (pos < line.Length)
                    {
                        Char c = line[pos++];
                        if (state == 0)
                        {
                            if (c < '0' || c > '9')
                            {
                                state = 1; n = Math.Max(n, 1);
                            }
                            else
                            {
                                n = (uint)(n * 10 + (c - '0'));
                            }
                        }
                        if (state == 1) // expect other character
                        {
                            if (c == '$')
                            {
                                y += n; x = 1;
                            }                                // newline
                            else if (c == 'o')
                            {
                                for (int i = 0; i < n; i++)
                                {
                                    BitSet(x++, y);
                                }
                            }
                            else if (c == 'b')
                            {
                                x += n;
                            }
                            state = n = 0;
                        }
                    }
                }
            }
            // swap buffers
            for (int i = 0; i < pw * ph; i++)
            {
                second[i] = pattern[i];
            }
            kernel.SetArgument(1, pattern);
            kernel.SetArgument(2, second);
            secondKernel.SetArgument(0, pattern);
            secondKernel.SetArgument(1, second);
            second.CopyToDevice();
        }
Esempio n. 7
0
        public void ReadGoLFile()
        {
            StreamReader sr = new StreamReader("../../maps/turing_js_r.rle");
            uint         state = 0, n = 0, x = 1, y = 1;

            while (true)
            {
                String line = sr.ReadLine();
                if (line == null)
                {
                    break;               // end of file
                }
                int pos = 0;
                if (line[pos] == '#')
                {
                    continue;                /* comment line */
                }
                else if (line[pos] == 'x')   //Header
                {
                    String[] sub = line.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);

                    size         = new int2(Int32.Parse(sub[1]), Int32.Parse(sub[3]));
                    size_in_ints = new int2((size.x + 31) / 32 + 2, size.y + 2); // Voeg padding toe
                    int lengte_in_ints = size_in_ints.x * size_in_ints.y;

                    // Console.WriteLine("Grootte van arrays: {0}x{1}", size_in_ints.x*32, size_in_ints.y);

                    patroon  = new OpenCLBuffer <uint>(ocl, lengte_in_ints);
                    volgende = new OpenCLBuffer <uint>(ocl, lengte_in_ints);
                    image    = new OpenCLImage <int> (ocl, screen.width, screen.height);
                    buffer   = new OpenCLBuffer <int> (ocl, screen.width * screen.height);

                    werk       = new long[] { size.x, size.y };
                    werk_klein = new long[] { lengte_in_ints };
                }
                else
                {
                    while (pos < line.Length)
                    {
                        Char c = line[pos++];
                        if (state == 0)
                        {
                            if (c < '0' || c > '9')
                            {
                                state = 1; n = Math.Max(n, 1);
                            }
                            else
                            {
                                n = (uint)(n * 10 + (c - '0'));
                            }
                        }
                        if (state == 1) // expect other character
                        {
                            if (c == '$')
                            {
                                y += n; x = 1;
                            }                            // newline
                            else if (c == 'o')
                            {
                                for (int i = 0; i < n; i++)
                                {
                                    patroon[(int)((y) * size_in_ints.x + ((x >> 5)))] |= 1U << (int)(x & 31);
                                    x++;
                                }
                            }
                            else if (c == 'b')
                            {
                                x += n;
                            }
                            state = n = 0;
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        public void Init()
        {
            Console.WriteLine("To turn Wrap on, press y and enter, to turn Wrap off, press n and enter.");
            Console.WriteLine("If an incorrect input is pressed Wrap will be off at default.");
            string input = Console.ReadLine();

            if (input == "y")
            {
                Wrap = 1;
            }
            if (input == "n")
            {
                Wrap = 0;
            }

            StreamReader sr = new StreamReader("../../samples/turing_js_r.rle");
            uint         state = 0, n = 0, x = 0, y = 0;

            while (true)
            {
                String line = sr.ReadLine();
                if (line == null)
                {
                    break;               // end of file
                }
                int pos = 0;
                if (line[pos] == '#')
                {
                    continue;              /* comment line */
                }
                else if (line[pos] == 'x') // header
                {
                    String[] sub = line.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    pw          = (UInt32.Parse(sub[1]) + 31) / 32;
                    breedte     = (UInt32.Parse(sub[1]));
                    ph          = UInt32.Parse(sub[3]);
                    _in         = new uint[pw * ph];
                    _out        = new uint[pw * ph];
                    workSize[0] = pw * 32; //breedte;
                    workSize[1] = ph;
                }
                else
                {
                    while (pos < line.Length)
                    {
                        Char c = line[pos++];
                        if (state == 0)
                        {
                            if (c < '0' || c > '9')
                            {
                                state = 1; n = Math.Max(n, 1);
                            }
                            else
                            {
                                n = (uint)(n * 10 + (c - '0'));
                            }
                        }
                        if (state == 1) // expect other character
                        {
                            if (c == '$')
                            {
                                y += n; x = 0;
                            }                                // newline
                            else if (c == 'o')
                            {
                                for (int i = 0; i < n; i++)
                                {
                                    BitSet(x++, y);
                                }
                            }
                            else if (c == 'b')
                            {
                                x += n;
                            }
                            state = n = 0;
                        }
                    }
                }
            }

            inBuffer  = new OpenCLBuffer <uint>(ocl, _in);
            outBuffer = new OpenCLBuffer <uint>(ocl, _out);

            kernel.SetArgument(0, inBuffer);
            kernel.SetArgument(1, outBuffer);
            kernel.SetArgument(2, pw);
            kernel.SetArgument(3, ph);
            kernel.SetArgument(4, breedte);
            kernel.SetArgument(5, Wrap);

            //BitSet(20, 20);
            //BitSet(21, 20);
            //BitSet(22, 20);
            //BitSet(20, 21);
            //BitSet(21, 22);

            //informatie doorgeven naar de GPU - hele dure operatie. Je kan gaan files loaden op de GPU
            //Kopier de begin state één keer naar de GPU en daarna ga je de array's aanpassen.
        }
        // minimalistic .rle file reader for Golly files (see http://golly.sourceforge.net)
        public void Init()
        {
            timer = new Stopwatch();
            StreamReader sr = new StreamReader("../../data/turing_js_r.rle");
            uint         state = 0, n = 0, x = 0, y = 0;

            while (true)
            {
                String line = sr.ReadLine();
                if (line == null)
                {
                    break;                       // end of file
                }
                int pos = 0;
                if (line[pos] == '#')
                {
                    continue;
                }                                       /* comment line */
                else if (line[pos] == 'x')              // header
                {
                    String[] sub = line.Split(new char[] { '=', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    pw = (UInt32.Parse(sub[1]) + 31) / 32;
                    ph = UInt32.Parse(sub[3]);
                    Console.WriteLine(pw + " " + ph);
                    pattern = new uint[pw * ph];
                    second  = new uint[pw * ph];
                }
                else
                {
                    while (pos < line.Length)
                    {
                        Char c = line[pos++];
                        if (state == 0)
                        {
                            if (c < '0' || c > '9')
                            {
                                state = 1; n = Math.Max(n, 1);
                            }
                            else
                            {
                                n = (uint)(n * 10 + (c - '0'));
                            }
                        }
                        if (state == 1)         // expect other character
                        {
                            if (c == '$')
                            {
                                y += n; x = 0;
                            }                                            // newline
                            else if (c == 'o')
                            {
                                for (int i = 0; i < n; i++)
                                {
                                    BitSet(x++, y);
                                }
                            }
                            else if (c == 'b')
                            {
                                x += n;
                            }
                            state = n = 0;
                        }
                    }
                }
            }
            // swap buffers
            for (int i = 0; i < pw * ph; i++)
            {
                second[i] = pattern[i];
            }

            //    //Initialize buffers
            //    for (int i = 0; i < pw * ph; i++)
            //    {
            //        second[i] = 0;
            //        pattern[i] = 0;
            //    }
            //for(int i = 0; i < 10; i++)
            //    {
            //        second[i] = 1;
            //        pattern[i] = 1;
            //    }
            patternBuffer = new OpenCLBuffer <uint>(ocl, pattern);
            secondBuffer  = new OpenCLBuffer <uint>(ocl, second);
        }