40. Performance

This section will describe different methods and techniques that can be applied to simulations in AGX to increase the runtime performance.

Some methods have already been described in previous sections:

40.1. Contact viscosity

If you are using the DIRECT solver for contact friction (see Section 12.15.4) you can sometimes achieve improved performance by increasing the viscosity in the contact material.

40.2. Contact Warmstarting

In Section 12, friction models were explained. Which friction model(s) that are in use can affect the runtime performance in a large way. Scale-box-friction for example provides a more realistic model than box-friction at the expense of a higher runtime cost due to more numeric work in the solver.

The cost of scale-box-friction can in some scenarios be reduced by enabling contact warmstarting via

agx::DynamicsSystem::setEnableContactWarmstarting( bool enable )

This feature will map internal solver states from the previous timestep to the current one by matching the previous contact point positions and normals to the current ones. The sovler is then warmstarted and have the possibility to reduce the amount of work needed to solve the system.

When the default friction model is used and no special handling is setup via contact materials, enabling contact warmstarting will just add overhead since extra steps are enabled that checks if data should be cached and if contact points should be matched from timestep to timestep.

Attention

The internal states used for warmstarting contacts are not part of the data that is serialized. Creating a simulation and simulating for e.g. 10 seconds can have slightly different trajectories compared to a different simulation with the same initial state that was simulated for 5 seconds, stored, restored and then simulated an additional 5 seconds.

40.3. Using Iterative contact solver

In Section 3.4 the different solvers available in AGX Dynamics where described. If you have performance challenges and you are willing to sacrifice precision for performance, the Iterative solver can be used for solving contact friction. As described in Section 12.15.4 we can control solve type for each ContactMaterial by creating a Friction model.

Assume for example you have a scenario where you are using a machine (wheel loader, excavator) and you want to interact with many (hundreds) of rocks, the performance might be an issue when using the default (SPLIT) contact model.

Assume you have a Material for the rocks and you want to use the ITERATIVE solve model for anytime two rocks interact:

// Create a material for the rocks
// Then (not shown) you need to assign each "rock" geometry the new material
agx::MaterialRef rockMaterial = new agx::Material("Rock")

// Get (or create if not already created) the ContactMaterial for the Rock/Rock material interaction
agx::ContactMaterialRef rock_rock_cm = simulation->getMaterialManager()->getOrCreateContactMaterial(rockMaterial, rockMaterial);

// Create a new FrictionModel, we will use the friction model which is default in AGX:
agx::FrictionModelRef fm = new agx::IterativeProjectedConeFriction();
fm->setSolveType( agx::FrictionModel::ITERATIVE );

// Assign the friction model to the contact material
rock_rock_cm->setFrictionModel(fm);

By using the code above, AGX will now use the fast ITERATIVE solver for any contacts between two geometries using the “Rock” material.

Section 22.8 show an example in how to combine the ITERATIVE and the DIRECT solver in the same scene.

40.4. AGX Sabre

The overview in Table 3.1 mentioned that agxSabre contains a sparse matrix solver. The sparse matrix is blocked so that BLAS-like kernels can be used to achieve better performance.

By default AGX will select which kernels to use and this default value should be left alone for best performance. But if the user really wants to, the setting can also be changed by the function

bool agxSabre::SabreKernels::setPreferredVectorInstructionSet( bitmask )

AGX Sabre will check which hardware features that are supported during library initialization. Unsupported features in the input value to setPreferredVectorInstructionSet will then be masked away.

The bit in the instruction set bitmask which has the largest effect is AVX2_BIT which enables fused-multiply-add instructions.

Which kernels to use can also be configured via the environment variable AGXSABRE_KERNELS and that variable accepts the same values as setPreferredVectorInstructionSet. For verification, the environment variable AGXSABRE_VERBOSE_KERNELS can be set to recieve a printout on stdout such as [agxSabre] Detected "GenuineIntel" CPU with HW features 7, preferred features set to 7 to see how the hardware was identified. Additionally, if AGXSABRE_KERNELS is also set, two lines will be displayed, e.g.:

[agxSabre] Environment set preferred vector instruction set to 15
[agxSabre] Detected "AuthenticAMD" CPU with HW features 15, preferred features set to 15