public void Bind(XIL3Instr xil3i, int cstep, IXILMapping mapping)
        {
            _csteps[xil3i.Index] = cstep;
            _ii[xil3i.Index]     = mapping.InitiationInterval;
            _lat[xil3i.Index]    = mapping.Latency;
            int lat = Math.Max(1, mapping.Latency);

            _maxCStep = Math.Max(cstep + lat - 1, _maxCStep);
        }
Beispiel #2
0
        public IXILMapping TryAllocate(Component host, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes, IProject proj)
        {
            List <IXILMapper> mappers = _mlookup.Get(instr.Name);

            foreach (IXILMapper mapper in mappers)
            {
                IXILMapping mapping = mapper.TryAllocate(host, instr, operandTypes, resultTypes, proj);
                if (mapping != null)
                {
                    return(mapping);
                }
            }
            return(null);
        }
        public IEnumerable <IXILMapping> TryMap(ITransactionSite taSite, XILInstr instr, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes)
        {
            IXILMapping alt0, alt1 = null;

            alt0 = TryMapOne(taSite, instr, operandTypes, resultTypes, false);
            switch (instr.Name)
            {
            case InstructionCodes.Add:
                alt1 = TryMapOne(taSite, instr, new TypeDescriptor[] { operandTypes[1], operandTypes[0] }, resultTypes, true);
                break;
            }

            if (alt0 != null)
            {
                yield return(alt0);
            }
            if (alt1 != null)
            {
                yield return(alt1);
            }
        }
Beispiel #4
0
        public void TellMapping(XIL3Instr instr, long cstep, IXILMapping mapping)
        {
            foreach (int rslot in instr.ResultSlots)
            {
                if (!_interlinks.ContainsKey(rslot))
                {
                    _interlinks[rslot] = new Interlink(rslot);
                }
            }

            var sources = instr.OperandSlots.Select(os => _interlinks[os]).ToArray();
            var sinks   = instr.ResultSlots.Select(rs => _interlinks[rs]).ToArray();

            var  verbs   = mapping.Realize(sources, sinks);
            long curStep = cstep;

            foreach (var verb in verbs)
            {
                var pflow = verb.ToCombFlow();
                foreach (var flow in pflow.Flows)
                {
                    var sflow = flow as SignalFlow;
                    if (sflow == null)
                    {
                        continue;
                    }

                    if (sflow.Target.Desc.HasAttribute <int>())
                    {
                        int index = sflow.Target.Desc.QueryAttribute <int>();
                        _interlinks[index].Driver    = sflow.Source.Desc;
                        _interlinks[index].DriveTime = curStep;
                    }
                    else if (sflow.Source.Desc.HasAttribute <int>())
                    {
                        Dictionary <ISignalOrPortDescriptor, int> fanIn;
                        if (!_fanIn.TryGetValue(sflow.Target.Desc, out fanIn))
                        {
                            fanIn = new Dictionary <ISignalOrPortDescriptor, int>();
                            _fanIn[sflow.Target.Desc] = fanIn;
                        }

                        int index  = sflow.Source.Desc.QueryAttribute <int>();
                        var driver = _interlinks[index].Driver;
                        if (driver == null)
                        {
                            continue;
                        }
                        int slack = (int)(curStep - _interlinks[index].DriveTime);
                        int prevSlack;
                        if (!fanIn.TryGetValue(driver, out prevSlack) ||
                            prevSlack > slack)
                        {
                            fanIn[driver] = slack;
                        }
                    }
                }
            }

            object           iclass = mapping.TASite.Host.GetType();
            HashSet <object> fuSet;

            if (!_fuCount.TryGetValue(iclass, out fuSet))
            {
                fuSet            = new HashSet <object>();
                _fuCount[iclass] = fuSet;
            }
            fuSet.Add(mapping.TASite);
        }
Beispiel #5
0
        public EAllocationDecision SelectBestMapping(XIL3Instr instr, long cstep, IEnumerable <IXILMapping> mappings, out IXILMapping bestMapping)
        {
            foreach (int rslot in instr.ResultSlots)
            {
                _interlinks[rslot] = new Interlink(rslot);
            }

            bestMapping = null;
            double bestCost = double.MaxValue;

            foreach (var mapping in mappings)
            {
                var sources = instr.OperandSlots.Select(os => _interlinks[os]).ToArray();
                var sinks   = instr.ResultSlots.Select(rs => _interlinks[rs]).ToArray();

                var    verbs   = mapping.Realize(sources, sinks);
                long   curStep = cstep;
                double cost    = 0.0;
                foreach (var verb in verbs)
                {
                    var pflow = verb.ToCombFlow();
                    foreach (var flow in pflow.Flows)
                    {
                        var sflow = flow as SignalFlow;
                        if (sflow == null)
                        {
                            continue;
                        }

                        if (sflow.Source.Desc.HasAttribute <int>() &&
                            !sflow.Target.Desc.HasAttribute <int>())
                        {
                            int index  = sflow.Source.Desc.QueryAttribute <int>();
                            var driver = _interlinks[index].Driver;
                            if (driver == null)
                            {
                                continue;
                            }

                            var fanIn = _fanIn[sflow.Target.Desc];
                            foreach (int v in fanIn.Values)
                            {
                                cost += Math.Pow(2.0, -v);
                            }
                            int prevSlack;
                            if (fanIn.TryGetValue(driver, out prevSlack))
                            {
                                cost -= Math.Pow(2.0, -prevSlack);
                            }
                            int slack = (int)(curStep - _interlinks[index].DriveTime);
                            cost += Math.Pow(2.0, -slack);
                        }
                    }

                    curStep++;
                }

                cost /= instr.OperandSlots.Length;

                if (cost < bestCost)
                {
                    bestCost    = cost;
                    bestMapping = mapping;
                }
            }

            object iclass   = mappings.First().TASite.Host.GetType();
            var    fuSet    = _fuCount[iclass];
            int    curCount = fuSet.Count;

            int limit;

            if (!FULimits.TryGetValue(iclass, out limit))
            {
                limit = int.MaxValue;
            }

            if (curCount < limit &&
                bestCost > MaxCost)
            {
                return(EAllocationDecision.AllocateNew);
            }
            else
            {
                return(EAllocationDecision.UseExisting);
            }
        }
Beispiel #6
0
 public void TellMapping(XIL3Instr instr, long cstep, IXILMapping mapping)
 {
 }
Beispiel #7
0
 public EAllocationDecision SelectBestMapping(XIL3Instr instr, long cstep, IEnumerable<IXILMapping> mappings, out IXILMapping bestMapping)
 {
     bestMapping = mappings.First();
     return EAllocationDecision.UseExisting;
 }
Beispiel #8
0
        /// <summary>
        /// Tries to map and bind a given XIL-3 instruction to hardware
        /// </summary>
        /// <param name="instr">XIL-3 instruction to be mapped and bound</param>
        /// <param name="cstep">c-step at which instruction is scheduled</param>
        /// <param name="operandTypes">operand types of instruction</param>
        /// <param name="resultTypes">result types of instruction</param>
        /// <returns>a hardware mapping for the supplied instruction or null if no such exists</returns>
        public IXILMapping TryBind(XIL3Instr instr, long cstep, TypeDescriptor[] operandTypes, TypeDescriptor[] resultTypes)
        {
            ReservationTable rtbl;
            var mappers        = _xmm.LookupMappers(instr.Command);
            var viableMappings = new List <IXILMapping>();

            foreach (IXILMapper mapper in mappers)
            {
                var tas = _taBindLookup.Get(mapper);
                foreach (var ta in tas)
                {
                    var mappings = mapper.TryMap(ta, instr.Command, operandTypes, resultTypes);
                    rtbl = _resTables[ta];
                    foreach (var mapping in mappings)
                    {
                        if (mapping.InitiationInterval > 0)
                        {
                            if (!rtbl.IsReserved(cstep, cstep + mapping.InitiationInterval - 1))
                            {
                                viableMappings.Add(mapping);
                            }
                            else if (mapping.ResourceKind == EMappingKind.ExclusiveResource)
                            {
                                return(null);
                            }
                        }
                        else
                        {
                            viableMappings.Add(mapping);
                        }
                    }
                }
            }
            bool        allocateNew = true;
            IXILMapping bestMapping = null;
            int         lat         = 0;

            if (viableMappings.Count > 0)
            {
                lat = viableMappings.First().Latency;
                if (!viableMappings.All(m => m.Latency == lat))
                {
                    throw new XILSchedulingFailedException("Mappings with different latencies exist for " + instr);
                }

                if (viableMappings.All(m => m.ResourceKind == EMappingKind.ExclusiveResource))
                {
                    allocateNew = false;
                    bestMapping = viableMappings.First();
                }
                else if (viableMappings.All(m => m.ResourceKind == EMappingKind.LightweightResource))
                {
                    allocateNew = true;
                }
                else
                {
                    allocateNew = Policy.SelectBestMapping(instr, cstep, viableMappings, out bestMapping) ==
                                  EAllocationDecision.AllocateNew;
                }
            }
            if (allocateNew)
            {
                foreach (IXILMapper mapper in mappers)
                {
                    bestMapping = mapper.TryAllocate(_host, instr.Command, operandTypes, resultTypes, _targetProject);
                    if (bestMapping != null)
                    {
                        if (viableMappings.Count > 0 && bestMapping.Latency != lat)
                        {
                            throw new XILSchedulingFailedException("Newly allocated mapping for " + instr + " has different latency.");
                        }

                        if (_onAllocation != null)
                        {
                            _onAllocation(bestMapping);
                        }
                        _taBindLookup.Add(mapper, bestMapping.TASite);
                        //bestMapping.TASite.Establish(binder);
                        break;
                    }
                }
            }
            if (bestMapping == null)
            {
                return(null);
            }
            rtbl = _resTables[bestMapping.TASite];
            bool ok = rtbl.TryReserve(cstep, cstep + bestMapping.InitiationInterval - 1, instr);

            Debug.Assert(ok);
            return(bestMapping);
        }
Beispiel #9
0
 public void TellMapping(XIL3Instr instr, long cstep, IXILMapping mapping)
 {
 }
Beispiel #10
0
 public EAllocationDecision SelectBestMapping(XIL3Instr instr, long cstep, IEnumerable <IXILMapping> mappings, out IXILMapping bestMapping)
 {
     bestMapping = mappings.First();
     return(EAllocationDecision.UseExisting);
 }