示例#1
0
        public void Schedule(MyProject project, IEnumerable <MyWorkingNode> newNodes = null)
        {
            // If there are any init tasks in the current plan, copy them over to the new one.
            // This is mostly for the first simulation step if there is also a model change.
            MyExecutionBlock oldPlan = null;

            if (ExecutionPlan != null)
            {
                oldPlan = ExecutionPlan.InitStepPlan;
            }

            m_project     = project;
            ExecutionPlan = ExecutionPlanner.CreateExecutionPlan(project, newNodes);

            if (oldPlan != null)
            {
                var newInitPlan = new List <IMyExecutable>();
                newInitPlan.AddRange(oldPlan.Children);
                newInitPlan.AddRange(ExecutionPlan.InitStepPlan.Children);
                ExecutionPlan.InitStepPlan = new MyExecutionBlock(newInitPlan.ToArray())
                {
                    Name = oldPlan.Name
                };
            }

            ExtractAllNodes(m_project);

            // Allow subclasses to react to re-scheduling.
            ScheduleChanged();
        }
示例#2
0
 public virtual MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan)
 {
     switch (LoopType)
     {
         case MyLoopOperation.All:
         {
             var res = new MyLoopBlock(
                 x => x < Iterations,
                 new MyExecutionBlock(
                     m_oneShotTasks,
                     defaultPlan
                 )
             );
             return res;
         }
         case MyLoopOperation.Normal:
         default:
         {
             return new MyLoopBlock(
                 x => x < Iterations,
                 defaultPlan
             );
         }
     }
 }
        /// Executes current IMyExecutable children and moves to next one
        public virtual MyExecutionBlock ExecuteStep()
        {
            if (m_childIterator < m_children.Length)
            {
                IMyExecutable currentChild = m_children[m_childIterator];
                m_childIterator++;

                if (currentChild is MyExecutionBlock)
                {
                    MyExecutionBlock childList = currentChild as MyExecutionBlock;
                    childList.Reset();

                    return(childList);
                }
                else
                {
                    if (currentChild.Enabled)
                    {
                        MyLog.DEBUG.WriteLine("Executing: " + currentChild.Name);
                        currentChild.SimulationStep = SimulationStep;
                        currentChild.Execute();
                    }
                    return(this);
                }
            }
            else
            {
                return(Parent);
            }
        }
示例#4
0
        private void ExecuteCore(int coreNumber)
        {
            try
            {
                if (InDebugMode)
                {
                    MyExecutionBlock currentBlock = CurrentDebuggedBlocks[coreNumber];

                    if (SimulationStep == 0 && currentBlock == null)
                    {
                        ExecutionPlan[coreNumber].InitStepPlan.Reset();
                        currentBlock        = ExecutionPlan[coreNumber].InitStepPlan;
                        m_debugStepComplete = false;
                    }

                    MyExecutionBlock lastBlock = null;

                    do
                    {
                        lastBlock = currentBlock;
                        currentBlock.SimulationStep = SimulationStep;
                        currentBlock = currentBlock.ExecuteStep();
                    }while (currentBlock != null && currentBlock.CurrentChild == null);

                    if (currentBlock == null)
                    {
                        ExecutionPlan[coreNumber].StandardStepPlan.Reset();
                        currentBlock = ExecutionPlan[coreNumber].StandardStepPlan;
                    }
                    else
                    {
                        m_debugStepComplete = false;
                    }

                    CurrentDebuggedBlocks[coreNumber] = currentBlock;
                }
                else //not in debug mode
                {
                    if (SimulationStep == 0)
                    {
                        ExecutionPlan[coreNumber].InitStepPlan.SimulationStep = 0;
                        ExecutionPlan[coreNumber].InitStepPlan.Execute();
                    }

                    //TODO: here should be else! (but some module are not prepared for this)
                    ExecutionPlan[coreNumber].StandardStepPlan.SimulationStep = SimulationStep;
                    ExecutionPlan[coreNumber].StandardStepPlan.Execute();
                }
            }
            catch (Exception e)
            {
                m_errorOccured  = true;
                m_lastException = new MySimulationException(coreNumber, e.Message, e);

                MyKernelFactory.Instance.MarkContextDead(coreNumber);
            }
        }
示例#5
0
 private void CleanExecutionBlockProfilingTimes(MyExecutionBlock plan)
 {
     plan.Iterate(true, executable =>
     {
         var executableBlock = executable as MyExecutionBlock;
         if (executableBlock != null)
         {
             executableBlock.CleanProfilingTimes();
         }
     });
 }
示例#6
0
        private void Iterate(MyExecutionBlock block, bool recursive, IteratorAction action)
        {
            foreach (IMyExecutable executable in block.Children)
            {
                action(executable);

                if (recursive && executable is MyExecutionBlock)
                {
                    Iterate(executable as MyExecutionBlock, recursive, action);
                }
            }
        }
        public MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan)
        {
            //get rid of signal tasks
            IMyExecutable[] content = new IMyExecutable[defaultPlan.Children.Length - 2];
            Array.Copy(defaultPlan.Children, 1, content, 0, defaultPlan.Children.Length - 2);

            //place if block inside
            return new MyExecutionBlock(
                defaultPlan.Children[0],
                new MyIfBlock(IsActive, content),
                defaultPlan.Children.Last()) { Name = defaultPlan.Name };
        }
示例#8
0
        public override void StepOut()
        {
            MyExecutionBlock currentBlock = CurrentDebuggedBlock;

            if (currentBlock != null)
            {
                // This is equivalent to calling StepOver on this node's parent node.
                StopWhenTouchedBlock = currentBlock.Parent;

                // Set this so that the loops knows it should stop when it hits the end of the plan.
                DebugStepMode = DebugStepMode.StepOut;
            }
        }
示例#9
0
        public MyLocalSimulation()
        {
            m_threadPool = new MyThreadPool(MyKernelFactory.Instance.DevCount, InitCore, ExecuteCore);
            m_threadPool.StartThreads();

            try
            {
                ExecutionPlanner = new MyDefaultExecutionPlanner()
                {
                    PlanSignalTasks = true
                };

                PartitioningStrategy  = new MyAllInOneGPUPartitioning(MyKernelFactory.Instance.DevCount, 0);
                CurrentDebuggedBlocks = new MyExecutionBlock[MyKernelFactory.Instance.DevCount];
            }
            catch (Exception e)
            {
                m_threadPool.Finish();
                throw e;
            }
        }
示例#10
0
        public MyLocalSimulation()
        {
            m_threadPool = new MyThreadPool(MyKernelFactory.Instance.DevCount, InitCore, ExecuteCore);
            m_threadPool.StartThreads();

            try
            {
                ExecutionPlanner = new MyDefaultExecutionPlanner()
                {
                    PlanSignalTasks = true
                };

                PartitioningStrategy = new MyAllInOneGPUPartitioning(MyKernelFactory.Instance.DevCount, 0);
                CurrentDebuggedBlocks = new MyExecutionBlock[MyKernelFactory.Instance.DevCount];
            }
            catch (Exception e)
            {
                m_threadPool.Finish();
                throw e;
            }
        }
示例#11
0
        public override void StepOver()
        {
            // HonzaS: Using 0 because the plan will be unified with StarPU anyway.
            MyExecutionBlock currentBlock = CurrentDebuggedBlock;

            if (currentBlock != null)
            {
                // If the current child is a block, pause the simulation when it's next sibling is requested.
                // That happens by visiting this node again.
                var currentChildBlock = currentBlock.CurrentChild as MyExecutionBlock;
                if (currentChildBlock != null)
                {
                    StopWhenTouchedBlock = currentBlock;
                    DebugStepMode        = DebugStepMode.StepOver;
                    return;
                }
            }

            // If the current child is not a block, run for one step.
            // The sim will execute the task and move onto the next.
            DebugStepMode = DebugStepMode.StepInto;
        }
示例#12
0
        public MyExecutionBlock CreateNodeExecutionPlan(MyWorkingNode node, bool initPhase)
        {
            List <IMyExecutable> defaultPlanContent = new List <IMyExecutable>();

            if (!initPhase && PlanSignalTasks)
            {
                defaultPlanContent.Add(new MyIncomingSignalTask(node));
            }

            foreach (var taskPropertyInfo in node.GetInfo().OrderedTasks)
            {
                MyTask task = node.GetTaskByPropertyName(taskPropertyInfo.Name);

                if ((task != null) && !task.DesignTime && (initPhase && task.OneShot || !initPhase && !task.OneShot))
                {
                    defaultPlanContent.Add(task);
                }
            }

            MyNodeGroup nodeGroup = node as MyNodeGroup;

            if (nodeGroup != null)
            {
                foreach (MyNode childNode in nodeGroup.Children.OrderBy(x => x.TopologicalOrder))
                {
                    MyWorkingNode childWorkingNode = childNode as MyWorkingNode;
                    if (childWorkingNode != null)
                    {
                        defaultPlanContent.Add(CreateNodeExecutionPlan(childWorkingNode, initPhase));
                    }
                }
            }

            if (!initPhase && PlanSignalTasks)
            {
                defaultPlanContent.Add(new MyOutgoingSignalTask(node));
            }

            var defaultPlan = new MyExecutionBlock(defaultPlanContent.ToArray())
            {
                Name = node.Name
            };

            MyExecutionBlock resultPlan = defaultPlan;

            IMyCustomExecutionPlanner executionPlannerNode = node as IMyCustomExecutionPlanner;

            if (executionPlannerNode != null)
            {
                resultPlan = initPhase
                    ? executionPlannerNode.CreateCustomInitPhasePlan(defaultPlan)
                    : executionPlannerNode.CreateCustomExecutionPlan(defaultPlan);

                resultPlan.Name = defaultPlan.Name;
            }

            if (resultPlan.Name == null)
            {
                resultPlan.Name = node.GetType().Name;
            }

            if (node is MyNodeGroup)
            {
                resultPlan.Name += " (group)";
            }

            // TODO(HonzaS): Rethink this. It's only used in profiling results.
            node.ExecutionBlock = resultPlan;

            return(resultPlan);
        }
示例#13
0
 private void CleanExecutionBlockProfilingTimes(MyExecutionBlock plan)
 {
     plan.Iterate(true, executable =>
     {
         var executableBlock = executable as MyExecutionBlock;
         if (executableBlock != null)
             executableBlock.CleanProfilingTimes();
     });
 }
示例#14
0
 private void EndChildBlockMeasuring(MyExecutionBlock block)
 {
     EndMeasuring(block);
 }
示例#15
0
        private void Iterate(MyExecutionBlock block, bool recursive, IteratorAction action)
        {
            foreach (IMyExecutable executable in block.Children)
            {
                action(executable);

                if (recursive && executable is MyExecutionBlock)
                {
                    Iterate(executable as MyExecutionBlock, recursive, action);
                }
            }
        }
示例#16
0
        private MyExecutionBlock CreateNodeExecutionPlan(MyWorkingNode node, bool initPhase)
        {
            List <IMyExecutable> defaultPlanContent = new List <IMyExecutable>();

            if (!initPhase && PlanSignalTasks)
            {
                defaultPlanContent.Add(new MyIncomingSignalTask(node));
            }

            foreach (string taskName in node.GetInfo().KnownTasks.Keys)
            {
                MyTask task = node.GetTaskByPropertyName(taskName);

                if (task != null && initPhase && task.OneShot || !initPhase && !task.OneShot)
                {
                    defaultPlanContent.Add(task);
                }
            }

            if (node is MyNodeGroup)
            {
                IEnumerable <MyNode> children = (node as MyNodeGroup).Children.OrderBy(x => x.TopologicalOrder);

                foreach (MyNode childNode in children)
                {
                    if (childNode is MyWorkingNode)
                    {
                        defaultPlanContent.Add(CreateNodeExecutionPlan(childNode as MyWorkingNode, initPhase));
                    }
                }
            }

            if (!initPhase && PlanSignalTasks)
            {
                defaultPlanContent.Add(new MyOutgoingSignalTask(node));
            }

            MyExecutionBlock defaultPlan = new MyExecutionBlock(defaultPlanContent.ToArray());

            defaultPlan.Name = node.Name;

            MyExecutionBlock resultPlan = defaultPlan;

            if (node is IMyCustomExecutionPlanner)
            {
                if (initPhase)
                {
                    resultPlan = (node as IMyCustomExecutionPlanner).CreateCustomInitPhasePlan(defaultPlan);
                }
                else
                {
                    resultPlan = (node as IMyCustomExecutionPlanner).CreateCustomExecutionPlan(defaultPlan);
                }
                resultPlan.Name = defaultPlan.Name;
            }

            if (node is MyNodeGroup)
            {
                resultPlan.Name += " (group)";
            }

            return(resultPlan);
        }
        public virtual MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan)
        {
            List<IMyExecutable> selected = new List<IMyExecutable>();
            List<IMyExecutable> newPlan = new List<IMyExecutable>();

            // copy default plan content to new plan content
            foreach (IMyExecutable groupTask in defaultPlan.Children)
                if (groupTask is MyExecutionBlock)
                    foreach (IMyExecutable nodeTask in (groupTask as MyExecutionBlock).Children)
                        newPlan.Add(nodeTask); // add individual node tasks
                else
                    newPlan.Add(groupTask); // add group tasks

            // remove group backprop tasks (they should be called from the individual layers)
            // DO NOT remove RBM tasks
            // DO NOT remove the currently selected backprop task (it handles batch learning)
            selected = newPlan.Where(task => task is MyAbstractBackpropTask &&  !(task.Enabled) && !(task is MyRBMLearningTask || task is MyRBMReconstructionTask)).ToList();
            newPlan.RemoveAll(selected.Contains);

            // move MyCreateDropoutMaskTask(s) before the first MyForwardTask
            selected = newPlan.Where(task => task is MyCreateDropoutMaskTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.Find(task => task is IMyForwardTask)), selected);

            // move reversed MyOutputDeltaTask(s) after the last MyForwardTask (usually there is only one)
            selected = newPlan.Where(task => task is IMyOutputDeltaTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            if ((selected.Where(task => task.Enabled)).Count() > 1)
                MyLog.WARNING.WriteLine("More than one output tasks are active!");
            if (selected.Count <= 0)
                MyLog.WARNING.WriteLine("No output tasks are active! Planning (of SGD, RMS, Adadelta etc.) might not work properly. Possible cause: no output layer is present.\nIgnore this if RBM task is currently selected.");
            selected.Reverse();
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected);

            // move reversed MyDeltaTask(s) after the last MyOutputDeltaTask
            selected = newPlan.Where(task => task is IMyDeltaTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            selected.Reverse();
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyOutputDeltaTask)) + 1, selected);

            // move MyGradientCheckTask after the last MyDeltaTask
            selected = newPlan.Where(task => task is MyGradientCheckTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyDeltaTask)) + 1, selected);

            // move currently selected backprop task between Delta tasks and UpdateWeights task
            selected = newPlan.Where(task => task is MyAbstractBackpropTask && (task.Enabled)).ToList();
            if (selected.Count > 1)
                MyLog.WARNING.WriteLine("Two or more backprop tasks selected.");
            if (selected.Count <= 0)
                MyLog.WARNING.WriteLine("No backprop task selected.");
            newPlan.RemoveAll(selected.Contains);
            selected.Reverse();
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyDeltaTask)) + 1, selected);

            // move MyUpdateWeightsTask(s) after the last MyGradientCheckTask
            selected = newPlan.Where(task => task is IMyUpdateWeightsTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is MyGradientCheckTask)) + 1, selected);

            // move MyQLearningTask after the last MyForwardTask
            selected = newPlan.Where(task => task is MyQLearningTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected);

            // move MyRestoreValuesTask after the last MyAbstractBackPropTask
            selected = newPlan.Where(task => task is MyRestoreValuesTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyUpdateWeightsTask)) + 1, selected);

            // move MyLSTMPartialDerivativesTask after the last MyForwardTask
            selected = newPlan.Where(task => task is MyLSTMPartialDerivativesTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected);

            // move MySaveActionTask to the end of the task list
            selected = newPlan.Where(task => task is MySaveActionTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.AddRange(selected);

            // return new plan as MyExecutionBlock
            return new MyExecutionBlock(newPlan.ToArray());
        }
示例#18
0
        private MyExecutionBlock GetNextExecutable(MyExecutionBlock executionBlock)
        {
            if (executionBlock.NextChild != null)
                return executionBlock;

            if (executionBlock.Parent != null)
                return GetNextExecutable(executionBlock.Parent);

            // This is the root and it doesn't have a "next" node.
            return null;
        }
        public virtual MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan)
        {
            List<IMyExecutable> selected = new List<IMyExecutable>();
            List<IMyExecutable> newPlan = new List<IMyExecutable>();

            // copy default plan content to new plan content
            foreach (IMyExecutable groupTask in defaultPlan.Children)
                if (groupTask is MyExecutionBlock)
                    foreach (IMyExecutable nodeTask in (groupTask as MyExecutionBlock).Children)
                        newPlan.Add(nodeTask); // add individual node tasks
                else
                    newPlan.Add(groupTask); // add group tasks

            // remove group backprop tasks (they should be called from the individual layers)
            selected = newPlan.Where(task => task is MyAbstractBackpropTask).ToList();
            newPlan.RemoveAll(selected.Contains);

            // move MyCreateDropoutMaskTask(s) before the first MyForwardTask
            selected = newPlan.Where(task => task is MyCreateDropoutMaskTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.Find(task => task is IMyForwardTask)), selected);

            // move reversed MyOutputDeltaTask(s) after the last MyForwardTask (usually there is only one)
            selected = newPlan.Where(task => task is IMyOutputDeltaTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            selected.Reverse();
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected);

            // move reversed MyDeltaTask(s) after the last MyOutputDeltaTask
            selected = newPlan.Where(task => task is IMyDeltaTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            selected.Reverse();
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyOutputDeltaTask)) + 1, selected);

            // move MyGradientCheckTask after the last MyDeltaTask
            selected = newPlan.Where(task => task is MyGradientCheckTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyDeltaTask)) + 1, selected);

            // move MyUpdateWeightsTask(s) after the last MyGradientCheckTask
            selected = newPlan.Where(task => task is IMyUpdateWeightsTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is MyGradientCheckTask)) + 1, selected);

            // move MyQLearningTask after the last MyForwardTask
            selected = newPlan.Where(task => task is MyQLearningTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected);

            // move MyRestoreValuesTask after the last MyAbstractBackPropTask
            selected = newPlan.Where(task => task is MyRestoreValuesTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyUpdateWeightsTask)) + 1, selected);

            // move MySaveActionTask to the end of the task list
            selected = newPlan.Where(task => task is MySaveActionTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.AddRange(selected);

            // return new plan as MyExecutionBlock
            return new MyExecutionBlock(newPlan.ToArray());
        }
        public virtual MyExecutionBlock CreateCustomExecutionPlan(MyExecutionBlock defaultPlan)
        {
            List<IMyExecutable> selected = new List<IMyExecutable>();
            List<IMyExecutable> newPlan = new List<IMyExecutable>();

            List<IMyExecutable> BPTTSingleStep = new List<IMyExecutable>();
            List<IMyExecutable> BPTTAllSteps = new List<IMyExecutable>();

            // copy default plan content to new plan content
            foreach (IMyExecutable groupTask in defaultPlan.Children)
                if (groupTask.GetType() == typeof(MyExecutionBlock))
                    foreach (IMyExecutable nodeTask in (groupTask as MyExecutionBlock).Children)
                        newPlan.Add(nodeTask); // add individual node tasks
                else
                    newPlan.Add(groupTask); // add group tasks

            // remove group backprop tasks (they should be called from the individual layers)
            // DO NOT remove RBM tasks
            // DO NOT remove the currently selected backprop task (it handles batch learning)
            selected = newPlan.Where(task => task is MyAbstractBackpropTask &&  !(task.Enabled) && !(task is MyRBMLearningTask || task is MyRBMReconstructionTask)).ToList();
            newPlan.RemoveAll(selected.Contains);
            // bbpt single step
            BPTTSingleStep.AddRange(newPlan.Where(task => task is IMyDeltaTask).ToList().Reverse<IMyExecutable>());
            BPTTSingleStep.AddRange(newPlan.Where(task => task is MyLSTMPartialDerivativesTask).ToList());
            BPTTSingleStep.AddRange(newPlan.Where(task => task is MyGradientCheckTask).ToList());
            BPTTSingleStep.Add(DecrementTimeStep);

            // backprop until unfolded (timestep=0)
            MyExecutionBlock BPTTLoop = new MyLoopBlock(i => TimeStep != -1,
                BPTTSingleStep.ToArray()
            );

            // if learning is globally disabled, removed update weights tasks
            MyExecutionBlock UpdateWeightsIfNotDisabled = new MyIfBlock(() => GetActiveBackpropTask() != null && GetActiveBackpropTask().DisableLearning == false,
                newPlan.Where(task => task is IMyUpdateWeightsTask).ToArray()
            );
            if (GetActiveBackpropTask() != null && GetActiveBackpropTask().DisableLearning)
            {
                MyLog.WARNING.WriteLine("Learning is globally disabled for the network " + this.Name + " in the " + GetActiveBackpropTask().Name + " backprop task.");
            }

            // bptt architecture
            BPTTAllSteps.Add(BPTTLoop);
            BPTTAllSteps.Add(IncrementTimeStep);
            BPTTAllSteps.Add(RunTemporalBlocksMode);
            BPTTAllSteps.Add(UpdateWeightsIfNotDisabled);
            BPTTAllSteps.Add(DecrementTimeStep);

            // if current time is time for bbp, do it
            MyExecutionBlock BPTTExecuteBPTTIfTimeCountReachedSequenceLength = new MyIfBlock(() => TimeStep == SequenceLength-1,
                BPTTAllSteps.ToArray()
            );

            // remove group backprop tasks (they should be called from the individual layers)
            newPlan.RemoveAll(newPlan.Where(task => task is MyAbstractBackpropTask && !(task is MyRBMLearningTask || task is MyRBMReconstructionTask)).ToList().Contains);
            //TODO - include dropout in the new version of planner
            newPlan.RemoveAll(newPlan.Where(task => task is MyCreateDropoutMaskTask).ToList().Contains);
            //newPlan.RemoveAll(newPlan.Where(task => task is IMyOutputDeltaTask).ToList().Contains);
            newPlan.RemoveAll(newPlan.Where(task => task is IMyDeltaTask).ToList().Contains);
            newPlan.RemoveAll(newPlan.Where(task => task is MyGradientCheckTask).ToList().Contains);
            newPlan.RemoveAll(newPlan.Where(task => task is IMyUpdateWeightsTask).ToList().Contains);
            newPlan.RemoveAll(newPlan.Where(task => task is MyLSTMPartialDerivativesTask).ToList().Contains);
            newPlan.RemoveAll(newPlan.Where(task => task is MyIncrementTimeStepTask).ToList().Contains);
            newPlan.RemoveAll(newPlan.Where(task => task is MyDecrementTimeStepTask).ToList().Contains);
            newPlan.RemoveAll(newPlan.Where(task => task is MyRunTemporalBlocksModeTask).ToList().Contains);

            //selected = newPlan.Where(task => task is IMyOutputDeltaTask).ToList();
            //newPlan.RemoveAll(selected.Contains);

            // after FF add deltaoutput and bptt if needed, then increment one step :)
            newPlan.Insert(0, IncrementTimeStep);

            // Move output delta tasks after all forward tasks.
            selected = newPlan.Where(task => task is IMyOutputDeltaTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected.Reverse<IMyExecutable>());

            // Move Q-learning tasks between forward tasks and output delta tasks.
            selected = newPlan.Where(task => task is MyQLearningTask || task is MyQLearningBatchTask).ToList();
            newPlan.RemoveAll(selected.Contains);
            newPlan.InsertRange(newPlan.IndexOf(newPlan.FindLast(task => task is IMyForwardTask)) + 1, selected.Reverse<IMyExecutable>());

            newPlan.Add(BPTTExecuteBPTTIfTimeCountReachedSequenceLength);

            // return new plan as MyExecutionBlock
            return new MyExecutionBlock(newPlan.ToArray());
        }
        public MyExecutionBlock CreateNodeExecutionPlan(MyWorkingNode node, bool initPhase)
        {
            List<IMyExecutable> defaultPlanContent = new List<IMyExecutable>();

            if (!initPhase && PlanSignalTasks)
            {
                defaultPlanContent.Add(new MyIncomingSignalTask(node));
            }

            foreach (string taskName in node.GetInfo().KnownTasks.Keys)
            {
                MyTask task = node.GetTaskByPropertyName(taskName);

                if (task != null && !task.DesignTime && (initPhase && task.OneShot || !initPhase && !task.OneShot))
                {
                    defaultPlanContent.Add(task);
                }
            }

            MyNodeGroup nodeGroup = node as MyNodeGroup;
            if (nodeGroup != null)
            {
                IEnumerable<MyNode> children = nodeGroup.Children.OrderBy(x => x.TopologicalOrder);

                foreach (MyNode childNode in children)
                {
                    MyWorkingNode childWorkingNode = childNode as MyWorkingNode;
                    if (childWorkingNode != null)
                    {
                        defaultPlanContent.Add(CreateNodeExecutionPlan(childWorkingNode, initPhase));
                    }
                }
            }

            if (!initPhase && PlanSignalTasks)
            {
                defaultPlanContent.Add(new MyOutgoingSignalTask(node));
            }

            MyExecutionBlock defaultPlan = new MyExecutionBlock(defaultPlanContent.ToArray());
            defaultPlan.Name = node.Name;

            MyExecutionBlock resultPlan = defaultPlan;

            IMyCustomExecutionPlanner executionPlannerNode = node as IMyCustomExecutionPlanner;
            if (executionPlannerNode != null)
            {
                if (initPhase)
                {
                    resultPlan = executionPlannerNode.CreateCustomInitPhasePlan(defaultPlan);
                }
                else
                {
                    resultPlan = executionPlannerNode.CreateCustomExecutionPlan(defaultPlan);
                }
                resultPlan.Name = defaultPlan.Name;
            }

            if (resultPlan.Name == null)
                resultPlan.Name = node.GetType().Name;

            if (node is MyNodeGroup)
            {
                resultPlan.Name += " (group)";
            }

            // TODO(HonzaS): Rethink this. It's only used in profiling results.
            node.ExecutionBlock = resultPlan;

            return resultPlan;
        }
示例#22
0
 public virtual MyExecutionBlock CreateCustomInitPhasePlan(MyExecutionBlock defaultInitPhasePlan)
 {
     m_oneShotTasks = defaultInitPhasePlan;
     switch (LoopType)
     {
         case MyLoopOperation.All:
         {
             return new MyExecutionBlock();
         }
         case MyLoopOperation.Normal:
         default:
         {
             return defaultInitPhasePlan;
         }
     }
 }
 public virtual MyExecutionBlock CreateCustomInitPhasePlan(MyExecutionBlock defaultInitPhasePlan)
 {
     return defaultInitPhasePlan;
 }
示例#24
0
 private void EndChildBlockMeasuring(MyExecutionBlock block)
 {
     EndMeasuring(block);
 }
示例#25
0
        private MyExecutionBlock CreateNodeExecutionPlan(MyWorkingNode node, bool initPhase)
        {
            List<IMyExecutable> defaultPlanContent = new List<IMyExecutable>();

            if (!initPhase && PlanSignalTasks)
            {
                defaultPlanContent.Add(new MyIncomingSignalTask(node));
            }

            foreach (string taskName in node.GetInfo().KnownTasks.Keys)
            {
                MyTask task = node.GetTaskByPropertyName(taskName);

                if (task != null && initPhase && task.OneShot || !initPhase && !task.OneShot)
                {
                    defaultPlanContent.Add(task);
                }
            }

            if (node is MyNodeGroup)
            {
                IEnumerable<MyNode> children = (node as MyNodeGroup).Children.OrderBy(x => x.TopologicalOrder);

                foreach (MyNode childNode in children)
                {
                    if (childNode is MyWorkingNode)
                    {
                        defaultPlanContent.Add(CreateNodeExecutionPlan(childNode as MyWorkingNode, initPhase));
                    }
                }
            }

            if (!initPhase && PlanSignalTasks)
            {
                defaultPlanContent.Add(new MyOutgoingSignalTask(node));
            }

            MyExecutionBlock defaultPlan = new MyExecutionBlock(defaultPlanContent.ToArray());
            defaultPlan.Name = node.Name;

            MyExecutionBlock resultPlan = defaultPlan;

            if (node is IMyCustomExecutionPlanner)
            {
                if (initPhase)
                {
                    resultPlan = (node as IMyCustomExecutionPlanner).CreateCustomInitPhasePlan(defaultPlan);
                }
                else
                {
                    resultPlan = (node as IMyCustomExecutionPlanner).CreateCustomExecutionPlan(defaultPlan);
                }
                resultPlan.Name = defaultPlan.Name;
            }

            if (node is MyNodeGroup)
            {
                resultPlan.Name += " (group)";
            }

            return resultPlan;
        }
示例#26
0
        private void ExecuteDebugStep()
        {
            MyExecutionBlock currentBlock = CurrentDebuggedBlock;

            if (currentBlock == null)
            {
                if (m_executionPhase == ExecutionPhase.Initialization)
                {
                    // The next step should be the beginning of the initialization plan.
                    if (ExecutionPlan.InitStepPlan != null)
                    {
                        // There is an initialization plan, take the first step.
                        ExecutionPlan.InitStepPlan.Reset();
                        currentBlock = ExecutionPlan.InitStepPlan;
                    }
                    else
                    {
                        // There is no initialization plan, go to PreStandard and stop because the loading of
                        // block data might be needed.
                        m_executionPhase = ExecutionPhase.PreStandard;
                        return;
                    }
                }
                else if (m_executionPhase == ExecutionPhase.Standard)
                {
                    ExecutionPlan.StandardStepPlan.Reset();
                    currentBlock = ExecutionPlan.StandardStepPlan;
                }
            }

            // This checks if breakpoint was encountered, also used for "stepping".
            bool leavingTargetBlock = false;

            do
            {
                currentBlock.SimulationStep = SimulationStep;
                currentBlock = currentBlock.ExecuteStep();
                if (StopWhenTouchedBlock != null && currentBlock == StopWhenTouchedBlock)
                {
                    leavingTargetBlock = true;
                }
            } while (currentBlock != null && currentBlock.CurrentChild == null);

            if (currentBlock == null)
            {
                // The current plan finished.

                if (m_executionPhase == ExecutionPhase.Initialization)
                {
                    // This means the init plan got finished, not the standard plan.
                    m_stepComplete = false;
                }
                else
                {
                    // This means the standard plan finished, remove the init plan (debug window will reset).
                    ExecutionPlan.InitStepPlan = null;
                }

                // If rescheduling happens, this will be set to "Initialization" again, if not, we need to
                // perform just the standard plan again.
                m_executionPhase   = ExecutionPhase.PreStandard;
                leavingTargetBlock = true;
            }
            else
            {
                m_stepComplete = false;
            }

            CurrentDebuggedBlock = currentBlock;

            if (DebugStepMode != DebugStepMode.None)
            {
                // A step into/over/out is performed.
                if (leavingTargetBlock)
                {
                    // The target block is being left or the sim step is over - step over/out is finished.
                    EmitDebugTargetReached();
                }

                if (DebugStepMode == DebugStepMode.StepInto)
                {
                    // Step into == one step of the simulation.
                    EmitDebugTargetReached();
                }
            }

            if (currentBlock != null && Breakpoints.Contains(currentBlock.CurrentChild))
            {
                // A breakpoint has been reached.
                EmitDebugTargetReached();
            }
        }