Exemplo n.º 1
0
        static public void For(Accelerator_View view, Tiled_Extent extent, _Kernel_tiled_type _kernel)
        {
            // Compile and link any "to do" work before any DLL loading.
            builder.Make();

            Structure structure = Analysis.Singleton().FindAllTargets(_kernel);

            // Get corresponding Campy code for C# kernel.
            Type thunk = GetThunk(_kernel, extent, structure);

            // Create thunk object.
            object obj = Activator.CreateInstance(thunk);

            // Set fields of thunk based on lambda.
            CopyFieldsFromHostToStaging(_kernel, structure, ref obj);

            // Set extent.
            CopyExtentToStaging(extent, ref obj);

            // Set extent.
            CopyViewToStaging(view, ref obj);

            // Get address of thunk method.
            SR.MethodInfo mi2 = thunk.GetMethod(Campy.Utils.Utility.NormalizeSystemReflectionName(_kernel.Method.Name));

            // Call thunk method.
            mi2.Invoke(obj, new object[] { });
        }
Exemplo n.º 2
0
        static public void AnalyzeThisAssembly()
        {
            Options.Singleton.Set(Options.OptionType.DisplayFinalGraph, true);
            Options.Singleton.Set(Options.OptionType.DoNotAnalyzeCampyAssemblies, true);

            if (Environment.Is64BitProcess)
            {
                System.Console.WriteLine("Thunk between 64-bit C# and C++ AMP unimplemented.");
                throw new Exception("Thunk between 64-bit C# and C++ AMP unimplemented.");
            }
            builder = new Build();
            System.Diagnostics.StackTrace stack_trace = new System.Diagnostics.StackTrace(true);
            System.Diagnostics.StackFrame stack_frame = stack_trace.GetFrame(1);
            System.Reflection.Assembly    assembly    = stack_frame.GetMethod().DeclaringType.Assembly;
            CFG control_flow_graph = CFG.Singleton(Analysis.Singleton());

            // Handle the following code:
            //    delegate int fun(int xxx);
            //    fun x = (int y) => { return y + 1; };
            //
            // I don't really understand, but when a delegate type is created,
            // it seems to call the function System.MulticastDelegate.CtorClosed(Object, IntPtr).
            // There is no body for the constructor of the delegate "fun"
            // which does this--at least, I can't find it anywhere. So, when we see a newobj
            // of an object derived from MulticastDelegate, make SSA match this function.
            // This function DOES hava a method body which does seem to do what is
            // necessary.
            SR.MethodInfo delegate_constructor = ReflectionCecilInterop.FindMethod("System.MulticastDelegate.CtorClosed(Object, IntPtr)");
            control_flow_graph.Add(delegate_constructor);
            control_flow_graph.ExtractBasicBlocks();

            control_flow_graph.AddAssembly(assembly);
            control_flow_graph.ExtractBasicBlocks();

            control_flow_graph.FindNewBlocks(assembly);

            if (Options.Singleton.Get(Options.OptionType.DisplayFinalGraph))
            {
                System.Console.WriteLine("Final graph:");
                control_flow_graph.OutputEntireGraph();
            }
        }