public override void VisitModuleDefinitionCollection(ModuleDefinitionCollection modules) { for (int i = 0; i < modules.Count; i++) { VisitModuleDefinition(modules[i]); } }
public virtual void VisitModuleDefinitionCollection(ModuleDefinitionCollection modules) { foreach (ModuleDefinition module in modules) { VisitModuleDefinition(module); } }
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 }
public override void VisitModuleDefinitionCollection(ModuleDefinitionCollection modules) { VisitCollection(modules); }