public void TestThrowExceptionOnNonExistingMethod() { MethodInfo info = typeof(PartialManaged).GetMethod("NonExistingMethod"); JitCompiler compiler = new JitCompiler(new PortablePdbCache()); Assert.Throws <ArgumentNullException>(() => compiler.CompileMethod(info)); }
protected void TestKernelCrosscompilation(Type t_kernel) { var cfg = new CudaConfig { BlockDim = new dim3(16, 16, 1) }; cfg.Codebase.OptIn(t => t.Assembly.GetName().Name == "Conflux.Playground"); using (Runtimes.Activate(new CudaRuntime(cfg, t_kernel))) { var result = JitCompiler.DoCompile(cfg, t_kernel); var s_ptx_actual = result.Ptx; var s_hir_actual = result.Hir.DumpAsText(); var asm = MethodInfo.GetCurrentMethod().DeclaringType.Assembly; var @namespace = MethodInfo.GetCurrentMethod().DeclaringType.Namespace; @namespace += ".Reference."; var ptx_fileName = asm.GetManifestResourceNames().SingleOrDefault2( n => String.Compare(n, @namespace + t_kernel.Name + ".ptx", true) == 0); var hir_fileName = asm.GetManifestResourceNames().SingleOrDefault2( n => String.Compare(n, @namespace + t_kernel.Name + ".hir", true) == 0); Verify(s_ptx_actual, ptx_fileName, "crosscompiled PTX", t_kernel); Verify(s_hir_actual, hir_fileName, "crosscompiled HIR", t_kernel); } }
/// <summary> /// Compiles the specified expression with support for Just In Time (JIT) compilation. /// </summary> /// <param name="expression">The lambda expression to compile.</param> /// <param name="options">Compilation options to influence compilation behavior.</param> /// <returns>Delegate that can be used to evaluate the expression tree.</returns> private static Delegate JitCompile(LambdaExpression expression, CompilationOptions options) { // // Check if we want compilation or interpretation. // var preferInterpretation = (options & CompilationOptions.PreferInterpretation) != 0; var tieredCompilation = (options & CompilationOptions.TieredCompilation) != 0; // // First, reduce the expression in order to get rid of nested lambda // expressions in positions where JIT compilation is not supported. // var reduced = Reducer.Reduce(expression); // // Create the root parameter of the top-level lambda, representing // the method table. Entries in the method table are retrieved to // obtain thunks for inner lambdas at runtime. // var methodTable = Expression.Parameter(typeof(MethodTable), "__mt"); // // Analyze the expression tree to obtain information about scopes // which are used to build closures. // var analysis = Analyzer.Analyze(reduced, methodTable); // // Create the expression rewriter to prepare the expression tree for // JIT compilation support. // var thunkFactory = tieredCompilation ? ThunkFactory.TieredCompilation : preferInterpretation ? ThunkFactory.Interpreted : ThunkFactory.Compiled; var result = JitCompiler.Prepare(methodTable, analysis, reduced, thunkFactory); // // Build the top-level lambda which is parameterized by the method // table to access thunks for inner lambdas. This will return a // lambda expression whose return type is a delegate. // var lambda = Expression.Lambda(result.Expression, result.MethodTableParameter); Debug.Assert(lambda.Body.Type == expression.Type, "Expected compatible delegate type."); // // Compile the top-level lambda and invoke the resulting delegate with // the method table instance. This will prepare the inner lambda(s) for // later invocation. Effectively, we've curried the original expression // to take an explicit method table parameter, and we're applying the // outer lambda here. // var compiled = lambda.Compile(preferInterpretation); return((Delegate)compiled.DynamicInvoke(result.MethodTable)); }
protected override void CoreRunKernel(IGrid grid, IKernel kernel) { (Config.Target <= CudaVersions.HardwareIsa).AssertTrue(); (Config.Version <= CudaVersions.SoftwareIsa).AssertTrue(); var t_kernel = kernel.GetType().BaseType.BaseType; var jitted_kernel = JitCompiler.DoCompile(Config, t_kernel); jitted_kernel.Run(grid.GridDim, grid.BlockDim, kernel); }
public static JittedKernel JitKernel(this String ptx, JitTuning tuning, HardwareIsa target) { ptx.AssertNotNull(); CudaDriver.Ensure(); var compiler = new JitCompiler(); compiler.Target = target; compiler.Tuning = tuning; var result = compiler.Compile(ptx); return(new JittedKernel(result)); }
public static JittedKernel JitKernel(this String ptx, JitTuning tuning) { ptx.AssertNotNull(); CudaDriver.Ensure(); var compiler = new JitCompiler(); compiler.TargetFromContext = true; compiler.Tuning = tuning; var result = compiler.Compile(ptx); return(new JittedKernel(result)); }
public void TestList() { var lst = new List <int> { 1, 2, 3 }; var jit = MetaGen.GenerateJit(ManglingCode).Invoke(Schema); var fnDescs = jit.First(_ => _.Item1.TypeName.StartsWith("List")) .By(type_and_fields => type_and_fields.Item2); var get_from_lst_int = fnDescs .First(v => v.Verb.Equals(Verbs.Verb.NewComposedVerb(Verbs.Verb.LGet, Verbs.Verb.BGet))) .By(_ => { Output.WriteLine(_.Verb.ToString()); return(JitCompiler.CompileFunction(_)); }) .By(native => Marshal.GetDelegateForFunctionPointer( native.CallSite, typeof(LBGet))); var count_lst_int = fnDescs .First(v => v.Verb.Equals(Verbs.Verb.LCount)) .By(_ => { Output.WriteLine(_.Verb.ToString()); return(JitCompiler.CompileFunction(_)); }) .By(native => Marshal.GetDelegateForFunctionPointer( native.CallSite, typeof(LCount))); Helper.ListToNativeAndThen( lst, subject => { var list_1 = (int)get_from_lst_int.DynamicInvoke(subject, 1); var list_len = (int)count_lst_int.DynamicInvoke(subject); Output.WriteLine("list[1]=" + list_1.ToString()); Output.WriteLine("list length =" + list_len.ToString()); Assert.Equal(list_1, lst[1]); Assert.Equal(list_len, lst.Count()); return(0); }); }
protected override void CustomCompile(Type t_kernel, TypeBuilder t) { JitCompiler.DoCrosscompile(Config, t_kernel, t); }