コード例 #1
0
        public override void Reallocate()
        {
            // This will allocate memory on the device. The CUDA context needs to be set up.
            MyKernelFactory.Instance.SetCurrent(0);

            // TODO(HonzaS): cache the ordered nodes if they have been ordered in model changes.
            foreach (MyNode node in MySimulationHandler.OrderNetworkNodes(m_project.Network))
            {
                node.ReallocateMemoryBlocks();
            }
        }
コード例 #2
0
        private void SetupAfterModelChange(IModelChanges modelChanges, List <MyNode> changersActivated)
        {
            // Clean up memory.
            IterateNodes(modelChanges.RemovedNodes, DestroyNode);

            // This must happen before UpdateMemoryModel() because some nodes touch kernels in UpdateMemoryBlocks().
            MyKernelFactory.Instance.SetCurrent(0);

            // Refresh topological ordering.
            List <MyNode> orderedNodes = MySimulationHandler.OrderNetworkNodes(m_project.Network);

            // Update the whole memory model.
            // TODO(HonzaS): This may break things, check.
            // We'll need to forbid changing of count after the simulation has started with the exception of added nodes.
            // However, the added nodes may lead to reallocation of blocks - deal with it.
            bool updatesNotConverged = UpdateMemoryModel(m_project, orderedNodes);

            Validator.ClearValidation();

            // Validate new nodes.
            IterateNodes(modelChanges.AddedNodes, ValidateNode);

            Validator.AssertError(!updatesNotConverged, m_project.Network, "Possible infinite loop in memory block sizes.");

            if (!Validator.ValidationSucessfull)
            {
                throw new InvalidOperationException("Validation failed for the changed model.");
            }

            // Reschedule.
            Schedule(m_project, modelChanges.AddedNodes);

            // Init nodes
            IterateNodes(modelChanges.AddedNodes, InitNode);

            // Allocate memory
            IEnumerable <MyWorkingNode> nodesToAllocate =
                modelChanges.AddedNodes.Where(node => MyMemoryManager.Instance.IsRegistered(node));

            IterateNodes(nodesToAllocate, AllocateNode);

            foreach (MyNode node in changersActivated)
            {
                EmitModelChanged(node);
            }
        }