Exemple #1
0
 public void Wave_Cpu_2x()
 {
     var kernel = new CpuConfig{Cores = 2}.Configure<WaveKernel>();
     var empty = new Matrix<Cell>(202, 202);
     var after2s = kernel.Execute(empty);
     // todo. validate the result
 }
        private JitCompiler(CpuConfig config, Type t_kernel, TypeBuilder t_xformed)
        {
            _config = config;
            _t_kernel = t_kernel;
            _m_kernel = _t_kernel.GetMethod("RunKernel", BF.All);
            ValidateInputParameters();

            // todo. think how to support multiple methods: *Dims, *Idxes, synchronization points
            // todo. I'd even say that we should embed constants instead of Dims and cache such bodies between calls
            // todo. if some dimension is equal to 1, then strip off corresponding loop
            var lam = _m_kernel.Decompile();
            _hir = lam.Body;
            _params = lam.Sig.Syms;
            _locals = lam.Body.LocalsRecursive();
            _xhir = new Block();
            _tids.Add("x", new Local("tid_x", typeof(int)));
            _tids.Add("y", new Local("tid_y", typeof(int)));
            _tids.Add("z", new Local("tid_z", typeof(int)));
            _xhir.Locals.AddElements(_tids.Values);
            InferLocalAllocationHints();
            ReplicatePrivatelyAllocatedLocals();
            LiftLocallyAllocatedLocals();
            HoistGloballyAllocatedLocals();
            _callsToSyncThreads = _hir.Family().OfType<Eval>().Where(eval =>
            {
                var m1 = eval.InvokedMethod();
                var syncapi_syncThreads = typeof(ISyncApi).GetMethod("SyncThreads");
                return m1.Api() == syncapi_syncThreads;
            }).ToReadOnly(); 
            TransformBlock(_hir, _xhir, false);

            // todo. currently we don't support debuggable IL
            // the latter implies correct PDB-mappings and working watch for replicated vars
            _config.EmitDebuggableIL.AssertFalse();

            _t_xformed = t_xformed;
            _t_xformed.AddInterfaceImplementation(typeof(IBlockRunner));
            _m_xformed = _t_xformed.DefineMethod("RunBlock", MA.Public, typeof(void), typeof(int3).MkArray());
            _m_xformed.DefineParameter(1, ParmA.None, "blockIdx");
            CompileTransformedHir();
        }
 public static void DoCrosscompile(CpuConfig config, Type t_kernel, TypeBuilder t_xformed) { new JitCompiler(config, t_kernel, t_xformed); }
 protected CpuConfig(CpuConfig proto) : base(proto)
 {
 }
 protected CpuConfig(CpuConfig proto) : base(proto) {}
 public void BigTest_Cpu_2x()
 {
     var cfg = new CpuConfig{Cores = 2};
     1.TimesDo(() => BigTest(cfg));
 }
 public void MediumTest_Cpu_1x()
 {
     var cfg = new CpuConfig{Cores = 1};
     1.TimesDo(() => MediumTest(cfg));
 }
 public void SmallTest_Cpu_1x()
 {
     var cfg = new CpuConfig{Cores = 1};
     1.TimesDo(() => SmallTest(cfg));
 }