Beispiel #1
0
        public void StopMusic()
        {
            IsPlaying = false;
            Dim1.SetActive(false);
            Dim2.SetActive(false);
            Dim3.SetActive(false);
            MusicSource.Stop();

            //beforeY = -1;
        }
Beispiel #2
0
 public void PlayMusic()
 {
     if (Table.BlockCount() > 0 && CurrentBlockTime <= 0)
     {
         CurrentBlockTime = Table.GetBlock(CurrentBlockIndex).BlockTime;
     }
     IsPlaying = true;
     Dim1.SetActive(true);
     Dim2.SetActive(true);
     Dim3.SetActive(true);
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            Assembly ass = Assembly.LoadFrom(@"D:\Nick Personal\Programming\GPU\Projects\Cudafy\Cudafy\bin\Debug\ESA.Dataflow.dll"); //(typeof(Program));
            //  ass.
            ////AssemblyDefinition.
            AssemblyDefinition         ad  = AssemblyFactory.GetAssembly(ass.Location);
            ModuleDefinitionCollection mdc = ad.Modules;
            StringBuilder sb           = new StringBuilder();
            StringWriter  streamWriter = new StringWriter(sb);

            foreach (ModuleDefinition mod in mdc)
            {
                Console.WriteLine(mod.Name);
                foreach (TypeDefinition type in mod.Types)
                {
                    Console.WriteLine(type.FullName);
                    if (type.Name == "ControlVector")
                    {
                        foreach (MethodDefinition md in type.Methods)
                        {
                            //foreach (CustomAttribute ca in md.CustomAttributes)
                            //{
                            //    if (ca.Constructor.DeclaringType.Name == "GPUFunctionAttribute")
                            //    {
                            if (md.Name == "Add")
                            {
                                Console.WriteLine(md.Name);
                                ILanguage       lan       = Cecil.Decompiler.Languages.CSharp.GetLanguage(Cecil.Decompiler.Languages.CSharpVersion.V3);
                                ILanguageWriter lanWriter = lan.GetWriter(new PlainTextFormatter(streamWriter));
                                lanWriter.Write(md);

                                Console.WriteLine(sb.ToString());
                            }
                            // }
                            //}
                        }
                    }
                }
            }

            int size = 4;

            int[]   myArray = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
            int[][] inputA  = new int[size][];
            int[][] inputB  = new int[size][];
            int[][] outputC = new int[size][];
            for (int i = 0; i < size; i++)
            {
                inputB[i]  = new int[size];
                outputC[i] = new int[size];
                inputA[i]  = new int[size];
                int cnt = i;
                for (int x = 0; x < size; x++)
                {
                    inputA[i][x] = cnt;
                    inputB[i][x] = cnt++;
                }
            }

            HCudafy cuda = new HCudafy();

            cuda.Cudafy(typeof(Program));

            Stopwatch sw = new Stopwatch();

            sw.Start();
            int[]   devMyArray = cuda.CopyToDevice(myArray);
            int[][] devA       = cuda.CopyToDevice(inputA);
            int[][] devB       = cuda.CopyToDevice(inputB);
            int[][] devC       = cuda.Allocate(outputC);
            Dim3    grid       = new Dim3(1);
            Dim3    block      = new Dim3(size / 1);

            cuda.Launch(grid, block, "doVecAdd", devA, devB, devC, 42, devMyArray);

            cuda.CopyFromDevice(devC, outputC);
            sw.Stop();
            for (int i = 0; i < 4; i++)
            {
                for (int x = 0; x < 4; x++)
                {
                    Console.Write("{0}\t", outputC[i][x]);
                }
                Console.WriteLine();
            }

            int[] somestuff = new int[512];
            for (int y = 0; y < 512; y++)
            {
                somestuff[y] = y * 10;
            }
            int[] data = cuda.CopyToDevice(somestuff);
            int[] res  = new int[512];
            cuda.CopyFromDevice(data, res);
            for (int y = 0; y < 512; y++)
            {
                if (res[y] != somestuff[y])
                {
                    throw new Exception();
                }
            }


            int[][] deviceArray2D = cuda.Allocate <int>(4, 8);
            int[]   deviceArray   = cuda.Allocate <int>(7);

            Console.WriteLine(sw.ElapsedMilliseconds + "ms");
            Console.WriteLine("Done");
            Console.ReadKey();
            return;

            #region scrap
            //Action<object> action = (object obj) =>
            //{
            //    Console.WriteLine("Task={0}, obj={1}, Thread={2}", Task.CurrentId, obj.ToString(), Thread.CurrentThread.ManagedThreadId);
            //};
            //Task t = new Task(action, "hello");
            //HThread ht = new HThread(action, "hello");

            //HGrid grid = new HGrid(
            //HCudafy.Launch(
            int     side          = 1024;
            int[][] myJaggedArray = new int[side][];
            for (int i = 0; i < side; i++)
            {
                myJaggedArray[i] = new int[side];
                int cnt = i;
                for (int x = 0; x < side; x++)
                {
                    myJaggedArray[i][x] = cnt++;
                }
            }

            int threads = Environment.ProcessorCount / 1;
            //  _barrier = new Barrier(threads);

            //Console.WriteLine("Before");
            //var po = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount };
            //Parallel.For(0, side, po, i => Process(myJaggedArray[i]));
            myJaggedArray.AsParallel().WithDegreeOfParallelism(threads).ForAll(x => Process(x));
            //myJaggedArray.ToList().ForEach(x => Process(x));
            //Console.WriteLine("Between");
            //myJaggedArray.AsParallel().WithDegreeOfParallelism(threads).ForAll(x => Process(x));
            sw.Stop();
            // _barrier.Dispose();
            Console.WriteLine(sw.ElapsedMilliseconds + "ms");
            Console.WriteLine("Done");
            Console.ReadKey();
            #endregion
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            Assembly ass = Assembly.LoadFrom(@"D:\Nick Personal\Programming\GPU\Projects\Cudafy\Cudafy\bin\Debug\ESA.Dataflow.dll"); //(typeof(Program));
          //  ass.
            ////AssemblyDefinition.
            AssemblyDefinition ad = AssemblyFactory.GetAssembly(ass.Location);
            ModuleDefinitionCollection mdc = ad.Modules;
            StringBuilder sb = new StringBuilder();
            StringWriter streamWriter = new StringWriter(sb);
            foreach (ModuleDefinition mod in mdc)
            {
                Console.WriteLine(mod.Name);
                foreach (TypeDefinition type in mod.Types)
                {
                    Console.WriteLine(type.FullName);
                    if (type.Name == "ControlVector")
                    foreach (MethodDefinition md in type.Methods)
                    {

                        //foreach (CustomAttribute ca in md.CustomAttributes)
                        //{
                        //    if (ca.Constructor.DeclaringType.Name == "GPUFunctionAttribute")
                        //    {
                        if (md.Name == "Add")
                        {
                            Console.WriteLine(md.Name);
                            ILanguage lan = Cecil.Decompiler.Languages.CSharp.GetLanguage(Cecil.Decompiler.Languages.CSharpVersion.V3);
                            ILanguageWriter lanWriter = lan.GetWriter(new PlainTextFormatter(streamWriter));
                            lanWriter.Write(md);
                         
                            Console.WriteLine(sb.ToString());
                        }
                           // }
                        //}
                    }
                }
            }

            int size = 4;
            int[] myArray = new int[] { 0,1,2,3,4,5,6,7 };
            int[][] inputA = new int[size][];
            int[][] inputB = new int[size][];
            int[][] outputC = new int[size][];
            for (int i = 0; i < size; i++)
            {
                inputB[i] = new int[size];
                outputC[i] = new int[size];
                inputA[i] = new int[size];
                int cnt = i;
                for (int x = 0; x < size; x++)
                {
                    inputA[i][x] = cnt;
                    inputB[i][x] = cnt++;
                }
            }

            HCudafy cuda = new HCudafy();
            cuda.Cudafy(typeof(Program));

            Stopwatch sw = new Stopwatch();
            sw.Start();  
            int[] devMyArray = cuda.CopyToDevice(myArray);
            int[][] devA = cuda.CopyToDevice(inputA);
            int[][] devB = cuda.CopyToDevice(inputB);
            int[][] devC = cuda.Allocate(outputC);
            Dim3 grid = new Dim3(1);
            Dim3 block = new Dim3(size/1);
            cuda.Launch(grid, block, "doVecAdd", devA, devB, devC, 42, devMyArray);     
           
            cuda.CopyFromDevice(devC, outputC);
            sw.Stop();
            for (int i = 0; i < 4; i++)
            {
                for (int x = 0; x < 4; x++)
                    Console.Write("{0}\t", outputC[i][x]);
                Console.WriteLine();
            }

            int[] somestuff = new int[512];
            for (int y = 0; y < 512; y++)
                somestuff[y] = y * 10;
            int[] data = cuda.CopyToDevice(somestuff);
            int[] res = new int[512];
            cuda.CopyFromDevice(data, res);
            for (int y = 0; y < 512; y++)
                if (res[y] != somestuff[y])
                    throw new Exception();


            int[][] deviceArray2D = cuda.Allocate<int>(4, 8);
            int[] deviceArray = cuda.Allocate<int>(7);

            Console.WriteLine(sw.ElapsedMilliseconds + "ms");
            Console.WriteLine("Done");
            Console.ReadKey();
            return;
            #region scrap
            //Action<object> action = (object obj) =>
            //{
            //    Console.WriteLine("Task={0}, obj={1}, Thread={2}", Task.CurrentId, obj.ToString(), Thread.CurrentThread.ManagedThreadId);
            //};
            //Task t = new Task(action, "hello");
            //HThread ht = new HThread(action, "hello");
            
            //HGrid grid = new HGrid(
            //HCudafy.Launch(
            int side = 1024;
            int[][] myJaggedArray = new int[side][];
            for (int i = 0; i < side; i++)
            {
                myJaggedArray[i] = new int[side];
                int cnt = i;
                for (int x = 0; x < side; x++)
                    myJaggedArray[i][x] = cnt++;
            }

            int threads = Environment.ProcessorCount / 1;
          //  _barrier = new Barrier(threads);

            //Console.WriteLine("Before");
            //var po = new ParallelOptions() { MaxDegreeOfParallelism = Environment.ProcessorCount };
            //Parallel.For(0, side, po, i => Process(myJaggedArray[i]));
            myJaggedArray.AsParallel().WithDegreeOfParallelism(threads).ForAll(x => Process(x));
            //myJaggedArray.ToList().ForEach(x => Process(x));
            //Console.WriteLine("Between");
            //myJaggedArray.AsParallel().WithDegreeOfParallelism(threads).ForAll(x => Process(x));
            sw.Stop();
           // _barrier.Dispose();
            Console.WriteLine(sw.ElapsedMilliseconds+"ms");
            Console.WriteLine("Done");
            Console.ReadKey();
            #endregion
        }
Beispiel #5
0
        private void Read()
        {
            if (_read)
                return;
            try
            {
                using (StreamReader sr = new StreamReader(_fileName))
                {
                    string line;

                    while ((line = sr.ReadLine()) != null)
                    {
                        if(line.Contains("Resolution")) {
                            string[] split = line.Split(null);
                            _dim = new Dim3(Convert.ToInt32(split[1]), Convert.ToInt32(split[2]), Convert.ToInt32(split[3]));
                        }
                        if (line.Contains("SliceThickness"))
                        {
                            CultureInfo culture = CultureInfo.GetCultureInfo("en-US");
                            string[] split = line.Split(null);
                            _sliceThickness = new Vector3(float.Parse(split[1], culture), float.Parse(split[2], culture), float.Parse(split[3], culture));
                        }
                    }
                }

                string rawFile = _fileName.Substring(0, _fileName.Length - 3) + "raw";
                FileStream fs = new FileStream(rawFile, FileMode.Open, FileAccess.Read);
                BinaryReader binReader = new BinaryReader(fs);
                _data = binReader.ReadBytes(_dim.Width * _dim.Height * _dim.Depth);
                binReader.Close();
                fs.Close();
                _read = true;
            }
            catch (Exception e)
            {
                // Let the user know what went wrong.
                Console.WriteLine("The file could not be read:");
                Console.WriteLine(e.Message);
            }
        }