Skip to content

Commit

Permalink
training for half billion steps
Browse files Browse the repository at this point in the history
also fixed dead lock iteration over contact array during concurrent rendering
  • Loading branch information
JulioJerez committed Sep 1, 2024
1 parent 9a3d573 commit 4903a2a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ namespace ndAdvancedRobot
,m_discountFactor(0.99f)
,m_horizon(ndFloat32(1.0f) / (ndFloat32(1.0f) - m_discountFactor))
,m_lastEpisode(-1)
,m_stopTraining(300 * 1000000)
,m_stopTraining(500 * 1000000)
,m_modelIsTrained(false)
{
//ndWorld* const world = scene->GetWorld();
Expand Down
3 changes: 3 additions & 0 deletions newton-4.00/applications/ndSandbox/toolbox/ndDebugDisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,7 @@ void ndDebugDisplay::ndContactPoints::UpdateBuffers(ndDemoEntityManager* const s
m_points.SetCount(0);
ndWorld* const world = scene->GetWorld();
const ndContactArray& contactList = world->GetContactList();
ndScopeSpinLock contactLock(contactList.GetLock());

glVector3 color(GLfloat(1.0f), GLfloat(0.0f), GLfloat(0.0f));
for (ndInt32 i = 0; i < contactList.GetCount(); ++i)
Expand Down Expand Up @@ -722,6 +723,8 @@ void ndDebugDisplay::ndNormalForces::UpdateBuffers(ndDemoEntityManager* const sc

ndWorld* const world = scene->GetWorld();
const ndContactArray& contactList = world->GetContactList();
ndScopeSpinLock contactLock(contactList.GetLock());

for (ndInt32 i = 0; i < contactList.GetCount(); ++i)
{
const ndContact* const contact = contactList[i];
Expand Down
2 changes: 2 additions & 0 deletions newton-4.00/sdk/dCollision/ndContactArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ndContact* ndContactArray::CreateContact(ndBodyKinematic* const body0, ndBodyKin
ndContact* const contact = new ndContact;
contact->SetBodies(body0, body1);
contact->AttachToBodies();

ndScopeSpinLock lock(m_lock);
PushBack(contact);
return contact;
Expand All @@ -76,6 +77,7 @@ void ndContactArray::DetachContact(ndContact* const contact)

void ndContactArray::DeleteAllContacts()
{
ndScopeSpinLock lock(m_lock);
for (ndInt32 i = ndInt32(GetCount()) - 1; i >= 0; --i)
{
ndContact* const contact = m_array[i];
Expand Down
6 changes: 6 additions & 0 deletions newton-4.00/sdk/dCollision/ndContactArray.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,16 @@ class ndContactArray : public ndArray<ndContact*>
void DetachContact(ndContact* const contact);
ndContact* CreateContact(ndBodyKinematic* const body0, ndBodyKinematic* const body1);

ndSpinLock& GetLock() const;
D_COLLISION_API ndInt32 GetActiveContacts() const;

private:
mutable ndSpinLock m_lock;
};

inline ndSpinLock& ndContactArray::GetLock() const
{
return m_lock;
}

#endif
5 changes: 3 additions & 2 deletions newton-4.00/sdk/dCollision/ndScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ bool ndScene::RemoveBody(const ndSharedPtr<ndBody>& body)
m_forceBalanceSceneCounter = 0;
m_bvhSceneManager.RemoveBody(kinematicBody);

//ndAssert(0);
ndBodyKinematic::ndContactMap& contactMap = kinematicBody->GetContactMap();
while (contactMap.GetRoot())
{
Expand Down Expand Up @@ -1201,12 +1202,10 @@ void ndScene::Cleanup()
m_contactArray.DeleteAllContacts();

ndFreeListAlloc::Flush();
m_contactArray.Resize(1024);
m_sceneBodyArray.Resize(1024);
m_activeConstraintArray.Resize(1024);
m_scratchBuffer.Resize(1024 * sizeof(void*));

m_contactArray.SetCount(0);
m_scratchBuffer.SetCount(0);
m_sceneBodyArray.SetCount(0);
m_activeConstraintArray.SetCount(0);
Expand Down Expand Up @@ -1592,6 +1591,7 @@ void ndScene::CalculateContacts()
{
D_TRACKTIME();
m_activeConstraintArray.SetCount(0);
ndScopeSpinLock lock(m_contactArray.GetLock());
const ndInt32 contactCount = ndInt32(m_contactArray.GetCount() + m_newPairs.GetCount());
m_contactArray.SetCount(contactCount);
if (contactCount)
Expand Down Expand Up @@ -1653,6 +1653,7 @@ void ndScene::DeleteDeadContacts()
};
ndUnsigned32 prefixScan[5];

ndScopeSpinLock lock(m_contactArray.GetLock());
if (m_contactArray.GetCount())
{
D_TRACKTIME();
Expand Down

0 comments on commit 4903a2a

Please sign in to comment.