public InterpreterProperties(InterpreterProperties rhs) { executingGraphNode = rhs.executingGraphNode; nodeIterations = rhs.nodeIterations; functionCallArguments = rhs.functionCallArguments; functionCallDotCallDimensions = rhs.functionCallDotCallDimensions; DominantStructure = rhs.DominantStructure; }
/// <summary> /// Return arguments at the corresponding levles and dominant list structure. /// </summary> /// <param name="arguments"></param> /// <param name="atLevels"></param> /// <param name="runtimeCore"></param> /// <returns></returns> public static ArgumentAtLevelStructure GetArgumentAtLevelStructure(List <StackValue> arguments, List <AtLevel> atLevels, RuntimeCore runtimeCore) { var argumentAtLevels = GetArgumentsAtLevels(arguments, atLevels, runtimeCore); arguments = argumentAtLevels.Select(a => a.Argument).ToList(); int domListIndex = argumentAtLevels.FindIndex(x => x.IsDominant); if (domListIndex < 0) { return(new ArgumentAtLevelStructure(arguments, null)); } if (runtimeCore != null && argumentAtLevels.Count(x => x.IsDominant) > 1) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.MoreThanOneDominantList, Resources.MoreThanOneDominantList); return(new ArgumentAtLevelStructure(arguments, null)); } var indices = argumentAtLevels[domListIndex].Indices; var dominantStructure = new DominantListStructure(indices, domListIndex); return(new ArgumentAtLevelStructure(arguments, dominantStructure)); }
public ArgumentAtLevelStructure(List <StackValue> arguments, DominantListStructure dominantStructure) { Arguments = arguments; DominantStructure = dominantStructure; }
/// <summary> /// If an input is a dominant list, restructure the result based on the /// structure of dominant list. /// /// Note the dominant structure will be restored only if the dominant /// list is zipped with other arguments, or the replication is applied /// to the dominant list firstly. /// </summary> /// <param name="ret"></param> /// <param name="domStructure"></param> /// <param name="instructions"></param> /// <param name="runtimeCore"></param> /// <returns></returns> public static StackValue RestoreDominantStructure( StackValue ret, DominantListStructure domStructure, List <ReplicationInstruction> instructions, RuntimeCore runtimeCore) { if (domStructure == null) { return(ret); } var domListIndex = domStructure.ArgumentIndex; var indicesList = domStructure.Indices; // If there is replication on the dominant list, it should be the // topest replicaiton. if (instructions != null && instructions.Any()) { var firstInstruciton = instructions.First(); if (firstInstruciton.Zipped) { if (!firstInstruciton.ZipIndecies.Contains(domListIndex)) { return(ret); } } else { if (firstInstruciton.CartesianIndex != domListIndex) { return(ret); } } } // Allocate an empty array to hold the value StackValue newRet; try { newRet = runtimeCore.RuntimeMemory.Heap.AllocateArray(new StackValue[] { }); } catch (RunOutOfMemoryException) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.RunOutOfMemory, Resources.RunOutOfMemory); return(StackValue.Null); } var array = runtimeCore.Heap.ToHeapObject <DSArray>(newRet); // Write the result back var values = ret.IsArray ? runtimeCore.Heap.ToHeapObject <DSArray>(ret).Values : Enumerable.Repeat(ret, 1); var valueIndicePairs = values.Zip(indicesList, (val, idx) => new { Value = val, Indices = idx }); foreach (var item in valueIndicePairs) { var value = item.Value; var indices = item.Indices.Select(x => StackValue.BuildInt(x)).ToArray(); array.SetValueForIndices(indices, value, runtimeCore); } return(newRet); }
//Dispatch private StackValue DispatchNew( Context context, List<StackValue> arguments, List<List<ReplicationGuide>> partialReplicationGuides, DominantListStructure domintListStructure, StackFrame stackFrame, RuntimeCore runtimeCore) { // Update the CallsiteExecutionState with // TODO: Replace this with the real data UpdateCallsiteExecutionState(null, runtimeCore); Stopwatch sw = new Stopwatch(); sw.Start(); StringBuilder log = new StringBuilder(); log.AppendLine("Method name: " + methodName); #region Get Function Group //@PERF: Possible optimisation point here, to deal with static dispatches that don't need replication analysis //Handle resolution Pass 1: Name -> Method Group FunctionGroup funcGroup = GetFuncGroup(runtimeCore); if (funcGroup == null) { log.AppendLine("Function group not located"); log.AppendLine("Resolution failed in: " + sw.ElapsedMilliseconds); if (runtimeCore.Options.DumpFunctionResolverLogic) runtimeCore.DSExecutable.EventSink.PrintMessage(log.ToString()); return ReportFunctionGroupNotFound(runtimeCore, arguments); } //check accesibility of function group bool methodAccessible = IsFunctionGroupAccessible(runtimeCore, ref funcGroup); if (!methodAccessible) { return ReportMethodNotAccessible(runtimeCore); } //If we got here then the function group got resolved log.AppendLine("Function group resolved: " + funcGroup); #endregion partialReplicationGuides = PerformRepGuideDemotion(arguments, partialReplicationGuides, runtimeCore); //Replication Control is an ordered list of the elements that we have to replicate over //Ordering implies containment, so element 0 is the outer most forloop, element 1 is nested within it etc. //Take the explicit replication guides and build the replication structure //Turn the replication guides into a guide -> List args data structure var partialInstructions = Replicator.BuildPartialReplicationInstructions(partialReplicationGuides); //Get the fep that are resolved List<FunctionEndPoint> resolvesFeps; List<ReplicationInstruction> replicationInstructions; arguments = PerformRepGuideForcedPromotion(arguments, partialReplicationGuides, runtimeCore); ComputeFeps(log, context, arguments, funcGroup, partialInstructions, partialReplicationGuides, stackFrame, runtimeCore, out resolvesFeps, out replicationInstructions); if (resolvesFeps.Count == 0) { log.AppendLine("Resolution Failed"); if (runtimeCore.Options.DumpFunctionResolverLogic) runtimeCore.DSExecutable.EventSink.PrintMessage(log.ToString()); return ReportMethodNotFoundForArguments(runtimeCore, arguments); } arguments.ForEach(x => runtimeCore.AddCallSiteGCRoot(CallSiteID, x)); StackValue ret = Execute(resolvesFeps, context, arguments, replicationInstructions, stackFrame, runtimeCore, funcGroup); if (!ret.IsExplicitCall) { ret = AtLevelHandler.RestoreDominantStructure(ret, domintListStructure, replicationInstructions, runtimeCore); } runtimeCore.RemoveCallSiteGCRoot(CallSiteID); return ret; }
public StackValue JILDispatch( List<StackValue> arguments, List<List<ReplicationGuide>> replicationGuides, DominantListStructure domintListStructure, StackFrame stackFrame, RuntimeCore runtimeCore, Context context) { #if DEBUG ArgumentSanityCheck(arguments); #endif // Dispatch method return DispatchNew(context, arguments, replicationGuides, domintListStructure, stackFrame, runtimeCore); }
//Inbound methods public StackValue JILDispatchViaNewInterpreter( Context context, List<StackValue> arguments, List<List<ReplicationGuide>> replicationGuides, DominantListStructure domintListStructure, StackFrame stackFrame, RuntimeCore runtimeCore) { #if DEBUG ArgumentSanityCheck(arguments); #endif // Dispatch method context.IsImplicitCall = true; return DispatchNew(context, arguments, replicationGuides, domintListStructure, stackFrame, runtimeCore); }
public ArgumentAtLevelStructure(List<StackValue> arguments, DominantListStructure dominantStructure) { Arguments = arguments; DominantStructure = dominantStructure; }
/// <summary> /// If an input is a dominant list, restructure the result based on the /// structure of dominant list. /// /// Note the dominant structure will be restored only if the dominant /// list is zipped with other arguments, or the replication is applied /// to the dominant list firstly. /// </summary> /// <param name="ret"></param> /// <param name="domStructure"></param> /// <param name="instructions"></param> /// <param name="runtimeCore"></param> /// <returns></returns> public static StackValue RestoreDominantStructure( StackValue ret, DominantListStructure domStructure, List<ReplicationInstruction> instructions, RuntimeCore runtimeCore) { if (domStructure == null) { return ret; } var domListIndex = domStructure.ArgumentIndex; var indicesList = domStructure.Indices; // If there is replication on the dominant list, it should be the // topest replicaiton. if (instructions != null && instructions.Any()) { var firstInstruciton = instructions.First(); if (firstInstruciton.Zipped) { if (!firstInstruciton.ZipIndecies.Contains(domListIndex)) { return ret; } } else { if (firstInstruciton.CartesianIndex != domListIndex) { return ret; } } } // Allocate an empty array to hold the value var newRet = runtimeCore.RuntimeMemory.Heap.AllocateArray(new StackValue[] { }); var array = runtimeCore.Heap.ToHeapObject<DSArray>(newRet); // Write the result back var values = ret.IsArray ? runtimeCore.Heap.ToHeapObject<DSArray>(ret).Values : Enumerable.Repeat(ret, 1); var valueIndicePairs = values.Zip(indicesList, (val, idx) => new { Value = val, Indices = idx }); foreach (var item in valueIndicePairs) { var value = item.Value; var indices = item.Indices.Select(x => StackValue.BuildInt(x)).ToArray(); array.SetValueForIndices(indices, value, runtimeCore); } return newRet; }
/// <summary> /// Return arguments at the corresponding levles and dominant list structure. /// </summary> /// <param name="arguments"></param> /// <param name="atLevels"></param> /// <param name="runtimeCore"></param> /// <returns></returns> public static ArgumentAtLevelStructure GetArgumentAtLevelStructure(List<StackValue> arguments, List<AtLevel> atLevels, RuntimeCore runtimeCore) { var argumentAtLevels = GetArgumentsAtLevels(arguments, atLevels, runtimeCore); arguments = argumentAtLevels.Select(a => a.Argument).ToList(); int domListIndex = argumentAtLevels.FindIndex(x => x.IsDominant); if (domListIndex < 0) { return new ArgumentAtLevelStructure(arguments, null); } if (runtimeCore != null && argumentAtLevels.Count(x => x.IsDominant) > 1) { runtimeCore.RuntimeStatus.LogWarning(Runtime.WarningID.MoreThanOneDominantList, Resources.MoreThanOneDominantList); return new ArgumentAtLevelStructure(arguments, null); } var indices = argumentAtLevels[domListIndex].Indices; var dominantStructure = new DominantListStructure(indices, domListIndex); return new ArgumentAtLevelStructure(arguments, dominantStructure); }