Skip to content

Vectorization#294

Merged
jkrajniak merged 24 commits intoespressopp:masterfrom
jnvance:vectorization
Feb 1, 2020
Merged

Vectorization#294
jkrajniak merged 24 commits intoespressopp:masterfrom
jnvance:vectorization

Conversation

@jnvance
Copy link
Copy Markdown
Member

@jnvance jnvance commented Jan 8, 2020

This PR adds a preliminary version of the vectorization submodule which speeds up the calculation of short-range pair interactions targeting Intel CPUs that support AVX2 and AVX-512.

When the espressopp.vectorization.Vectorization class is instantiated, it connects some of its methods to the integrator and storage objects (currently, only VelocityVerlet and DomainDecomposition are supported).

During every time step of integrator.run(), the Vectorization class copies the necessary data from the Particle lists in the cells (currently only position) into ParticleArray, performs the force calculation, and then copies back the forces to the Particle lists. The data in ParticleArray are stored in a structure of arrays (SOA) layout. This enables the vectorization of the neighbor-list construction and force calculation using only #pragma vector directives (no intrinsics), similar to how it is done in the LAMMPS-INTEL package.

Most of the additional source code is contained in the directory src/vectorization, except for two new Boost signals:

  • onCellAdjust - called when the cell structure of the storage class is modified
  • aftCalcFLocal - called from integrator.run after calcForces and just before exchanging ghost forces with neighboring subdomains

Vectorized versions of the VerletList and LennardJones classes are implemented in the vectorization submodule. So to use these on current scripts, one only needs to add the vectorization keyword and pass the correct arguments, e.g.

vec         = espressopp.vectorization.Vectorization(system, integrator)
verletlist  = espressopp.vectorization.VerletList(system, vec, r_cutoff)
potential   = espressopp.vectorization.interaction.LennardJones(...)
interaction = espressopp.vectorization.interaction.VerletListLennardJones(verletlist)

In this version, the energy and virial calculations still rely on the previous VerletList layout, so the Verlet list rebuild has to be manually triggered before calling any analysis functions, e.g.

verletlist.rebuildPairs()
espressopp.tools.analyse.info(system, integrator)

An example script is provided in examples/vectorization/lennard_jones.py which shows the minimal modifications needed for the examples/lennard_jones/lennard_jones.py script to use vectorized versions of the routines (currently only for the equilibration phase since LennardJonesCapped is not yet implemented).

A test was also added in testsuite/vectorization to verify that particle trajectories resulting from the MD integration are almost equal whether the vectorized or the non-vectorized version is used.

Development of the submodule is optimized for the Intel 2018 compiler with -O3 -xHost -restrict flags for Broadwell, and -O3 -xSKYLAKE-AVX512 -qopt-zmm-usage=high for Skylake. Improvements can also be observed with GCC as long as the appropriate optimization flags are used.

@jkrajniak jkrajniak self-requested a review January 8, 2020 16:39
@junghans
Copy link
Copy Markdown
Member

junghans commented Jan 8, 2020

How does this approach compares to https://github.com/ECP-copa/Cabana?

@jnvance
Copy link
Copy Markdown
Member Author

jnvance commented Jan 9, 2020

How does this approach compares to https://github.com/ECP-copa/Cabana?

Cabana seems to provide a more generalized way of representing Struct-of-Arrays and Array-of-Struct-of-Arrays (where attributes are template arguments) similar to how the data are stored in ParticleArray (where the attributes are explicitly listed). Our approach, on the other hand, still uses the original std::vector<Particle> (an extended AOSOA) to store particle information everywhere else but just copies necessary information, like position, to the more compact and aligned SOA or AOSOA layout in ParticleArray.

Comment thread docker/Dockerfile Outdated
@junghans
Copy link
Copy Markdown
Member

junghans commented Jan 9, 2020

How does this approach compares to https://github.com/ECP-copa/Cabana?

Cabana seems to provide a more generalized way of representing Struct-of-Arrays and Array-of-Struct-of-Arrays (where attributes are template arguments) similar to how the data are stored in ParticleArray (where the attributes are explicitly listed). Our approach, on the other hand, still uses the original std::vector<Particle> (an extended AOSOA) to store particle information everywhere else but just copies necessary information, like position, to the more compact and aligned SOA or AOSOA layout in ParticleArray.

Cabana has support for GPU data layouts, too.

jkrajniak
jkrajniak previously approved these changes Jan 24, 2020
Copy link
Copy Markdown
Member

@jkrajniak jkrajniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, however please adjust the copyright years in the file headers. Also, I've pointed out some places where there is room for small adjustments.

Comment thread src/vectorization/ParticleArray.cpp Outdated
Comment thread src/vectorization/Vectorization.py
Comment thread src/vectorization/Vectorization.py Outdated
Comment thread src/vectorization/VerletList.cpp Outdated
Comment thread src/vectorization/VerletList.cpp Outdated
Comment thread src/vectorization/VerletList.cpp Outdated
jkrajniak
jkrajniak previously approved these changes Jan 27, 2020
Comment thread src/vectorization/Vectorization.py Outdated
jkrajniak
jkrajniak previously approved these changes Jan 28, 2020
@jnvance
Copy link
Copy Markdown
Member Author

jnvance commented Jan 28, 2020

It seems the CI failures all result from The job exceeded the maximum log length, and has been terminated. during the make install phase of the test script. Most of the log is from deprecation warnings about std::auto_ptr from the internal Boost library on Ubuntu with GCC. The limit is around 4MB, and even the corresponding logs for the master branch are close to exceeding this limit.

What do you guys think would be the best way to remove or suppress the warnings?

@jkrajniak
Copy link
Copy Markdown
Member

Let's try with -Wdeprecated-declarations

@jnvance
Copy link
Copy Markdown
Member Author

jnvance commented Jan 28, 2020

Let's try with -Wdeprecated-declarations

I placed that flag in the Dockerfile before but reverted it on advice of @junghans

Can we also place that flag directly in .travis.yml just for env: DISTRO=ubuntu EXTERNAL=OFF, DISTRO=ubuntu_rolling EXTERNAL=OFF and DISTRO=ubuntu_mpich EXTERNAL=OFF with compiler: gcc?

@jkrajniak
Copy link
Copy Markdown
Member

Let's try with -Wdeprecated-declarations

I placed that flag in the Dockerfile before but reverted it on advice of @junghans

Can we also place that flag directly in .travis.yml just for env: DISTRO=ubuntu EXTERNAL=OFF, DISTRO=ubuntu_rolling EXTERNAL=OFF and DISTRO=ubuntu_mpich EXTERNAL=OFF with compiler: gcc?

You can try; These warnings are related to boost library, I wouldn't care too much about switching this off.

@junghans
Copy link
Copy Markdown
Member

@jnvance see https://github.com/votca/tools/blob/master/include/votca/tools/eigen.h#L34-L55 for an example on how to disable warning from an included header.

jkrajniak
jkrajniak previously approved these changes Feb 1, 2020
Copy link
Copy Markdown
Member

@jkrajniak jkrajniak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread src/include/python.hpp
@@ -1,4 +1,6 @@
/*
Copyright (C) 2018-2019
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@junghans do you think this copyright of VOTCA team should be placed here?

@jkrajniak jkrajniak self-requested a review February 1, 2020 14:14
@jkrajniak jkrajniak merged commit 6f20e3e into espressopp:master Feb 1, 2020
@jnvance jnvance deleted the vectorization branch February 4, 2020 16:44
@jnvance jnvance restored the vectorization branch February 4, 2020 16:44
@jnvance jnvance deleted the vectorization branch February 4, 2020 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants