浏览代码

Better memory allocation for Heuristic (#3785)

* Fixing some issues with previous action and better memory allocation in the Heuristic Policy

* Copying the data rather than using references

* [skip ci]Update com.unity.ml-agents/Runtime/Agent.cs

Co-Authored-By: Chris Elion <chris.elion@unity3d.com>

* Addressing comments

Co-authored-by: Chris Elion <chris.elion@unity3d.com>
/develop/no-threading
GitHub 4 年前
当前提交
3fb490f6
共有 2 个文件被更改,包括 30 次插入8 次删除
  1. 21
      com.unity.ml-agents/Runtime/Agent.cs
  2. 17
      com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs

21
com.unity.ml-agents/Runtime/Agent.cs


m_CumulativeReward = 0f;
m_RequestAction = false;
m_RequestDecision = false;
Array.Clear(m_Info.storedVectorActions, 0, m_Info.storedVectorActions.Length);
}
/// <summary>

return;
}
m_Info.storedVectorActions = m_Action.vectorActions;
if (m_Info.done)
{
Array.Clear(m_Info.storedVectorActions, 0, m_Info.storedVectorActions.Length);
}
else
{
Array.Copy(m_Action.vectorActions, m_Info.storedVectorActions, m_Action.vectorActions.Length);
}
m_ActionMasker.ResetMask();
UpdateSensors();
using (TimerStack.Instance.Scoped("CollectObservations"))

void DecideAction()
{
m_Action.vectorActions = m_Brain?.DecideAction();
}
var action = m_Brain?.DecideAction();
if (action == null)
{
Array.Clear(m_Action.vectorActions, 0, m_Action.vectorActions.Length);
}
else
{
Array.Copy(action, m_Action.vectorActions, action.Length);
}
}
}

17
com.unity.ml-agents/Runtime/Policies/HeuristicPolicy.cs


ActionGenerator m_Heuristic;
float[] m_LastDecision;
int m_numActions;
bool m_Done;
bool m_DecisionRequested;
WriteAdapter m_WriteAdapter = new WriteAdapter();
NullList m_NullList = new NullList();

{
m_Heuristic = heuristic;
m_numActions = numActions;
m_LastDecision = new float[m_numActions];
}
/// <inheritdoc />

if (!info.done)
{
// Reset m_LastDecision each time.
m_LastDecision = new float[m_numActions];
m_Heuristic.Invoke(m_LastDecision);
}
m_Done = info.done;
m_DecisionRequested = true;
if (!m_Done && m_DecisionRequested)
{
m_Heuristic.Invoke(m_LastDecision);
}
m_DecisionRequested = false;
return m_LastDecision;
}

正在加载...
取消
保存