Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8.1.1 #14

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,7 @@ ENDFOREACH(subdir)
LIST(APPEND CMAKE_PREFIX_PATH $ENV{ROCM_PATH} /opt/rocm)

FIND_PACKAGE(HIP CONFIG REQUIRED)
FIND_PACKAGE(HIPFFT CONFIG REQUIRED)

IF(${HIP_COMPILER} STREQUAL "clang")
MESSAGE(STATUS "Using HIP-Clang compiler")
ELSE()
MESSAGE(FATAL_ERROR "HIP compiler ${HIP_COMPILER} not recognized!")
ENDIF()
FIND_PACKAGE(HIPFFT CONFIG)

ADD_SUBDIRECTORY(platforms/hip)

Expand Down
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,6 @@ AMD GPUs on [AMD ROCm™ open software platform](https://rocmdocs.amd.com).

## Installing with Conda

This plugin requires hipFFT and rocFFT, install them from ROCm repositories:

```sh
apt install hipfft rocfft
```

```sh
conda create -n openmm-env -c streamhpc -c conda-forge --strict-channel-priority openmm-hip
conda activate openmm-env
Expand Down Expand Up @@ -69,7 +63,7 @@ The plugin requires source code of OpenMM, it can be downloaded as an archive
[here](https://github.com/openmm/openmm/releases) or as a Git repository:

```sh
git clone https://github.com/openmm/openmm.git -b 8.0.0
git clone https://github.com/openmm/openmm.git -b 8.1.1
```

To build the plugin, follow these steps:
Expand Down Expand Up @@ -100,7 +94,7 @@ source code:
```sh
mkdir build build-hip install

git clone https://github.com/openmm/openmm.git -b 8.0.0
git clone https://github.com/openmm/openmm.git -b 8.1.1
cd build
cmake ../openmm/ -D CMAKE_INSTALL_PREFIX=../install -D OPENMM_BUILD_COMMON=ON -D OPENMM_PYTHON_USER_INSTALL=ON
make
Expand Down Expand Up @@ -138,22 +132,36 @@ please try different backends:
* the hipFFT/rocFFT-based implementation (`export OPENMM_FFT_BACKEND=1`);
* the VkFFT-based implementation (`export OPENMM_FFT_BACKEND=2`);

### The kernel compilation: hipcc and hipRTC
The hipFFT/rocFFT-based implementation requires hipFFT and rocFFT libraries, otherwise it will be
disabled, install them from ROCm repositories before running cmake:

```sh
apt install hipfft rocfft
```

By default, the HIP Platform builds kernels with the hipcc compiler. To run the compiler, paths
in the following order are used:
If you see "libhipfft.so.0: cannot open shared object file: No such file or directory", run
`ldconfig`.

### The kernel compilation: amdclang++ and hipRTC

By default, the HIP Platform builds kernels with the amdclang++ compiler. To run the compiler,
paths in the following order are used:

* `properties['HipCompiler']`, if it is passed to Context constructor;
* `OPENMM_HIP_COMPILER` environment variable, if it is set;
* `${ROCM_PATH}/bin/hipcc`, if `ROCM_PATH` environment variable is set;
* `/opt/rocm/bin/hipcc` otherwise.
* `${ROCM_PATH}/bin/amdclang++`, if `ROCM_PATH` environment variable is set;
* `/opt/rocm/bin/amdclang++` otherwise.

There is an alternative way to compile kernels: hipRTC, it is implemented by
`plugins/hipcompiler`. To enable this way:

* set `properties['HipAllowRuntimeCompiler'] = 'true'`;
* set `OPENMM_USE_HIPRTC` environment variable to 1 (`export OPENMM_USE_HIPRTC=1`).

**Warning:** hipRTC from ROCm 6.0.0 has issues with ambiguous operators for vector and complex
types. It seems that they have been fixed in ROCm/clr's `develop` branch and likely OpenMM+hipRTC
will be usable with the next ROCm release.

## License

The HIP Platform uses OpenMM API under the terms of the MIT License. A copy of this license may
Expand Down
12 changes: 10 additions & 2 deletions platforms/hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,17 @@ IF (OPENMM_BUILD_SHARED_LIB)
ADD_LIBRARY(${SHARED_TARGET} SHARED ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
ADD_DEPENDENCIES(${SHARED_TARGET} CommonKernels HipKernels)

TARGET_LINK_LIBRARIES(${SHARED_TARGET} PUBLIC ${OPENMM_LIBRARY_NAME} ${PTHREADS_LIB} hip::host hip::hipfft)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} PUBLIC ${OPENMM_LIBRARY_NAME} ${PTHREADS_LIB} hip::host)
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_COMMON_BUILDING_SHARED_LIBRARY")
IF (APPLE)
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS} -F/Library/Frameworks -framework HIP")
ELSE (APPLE)
SET_TARGET_PROPERTIES(${SHARED_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_LINK_FLAGS}")
ENDIF (APPLE)
IF(HIPFFT_FOUND)
TARGET_LINK_LIBRARIES(${SHARED_TARGET} PUBLIC hip::hipfft)
TARGET_COMPILE_OPTIONS(${SHARED_TARGET} PUBLIC "-DOPENMM_HIP_WITH_HIPFFT")
ENDIF(HIPFFT_FOUND)

INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${SHARED_TARGET})
ENDIF (OPENMM_BUILD_SHARED_LIB)
Expand All @@ -127,13 +131,17 @@ IF(OPENMM_BUILD_STATIC_LIB)
ADD_LIBRARY(${STATIC_TARGET} STATIC ${SOURCE_FILES} ${SOURCE_INCLUDE_FILES} ${API_ABS_INCLUDE_FILES})
ADD_DEPENDENCIES(${STATIC_TARGET} CommonKernels HipKernels)

TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${OPENMM_LIBRARY_NAME} ${PTHREADS_LIB_STATIC} hip::host hip::hipfft)
TARGET_LINK_LIBRARIES(${STATIC_TARGET} ${OPENMM_LIBRARY_NAME} ${PTHREADS_LIB_STATIC} hip::host)
SET_TARGET_PROPERTIES(${STATIC_TARGET} PROPERTIES COMPILE_FLAGS "${EXTRA_COMPILE_FLAGS} -DOPENMM_COMMON_BUILDING_STATIC_LIBRARY")
IF (APPLE)
SET_TARGET_PROPERTIES(${STATIC_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_COMPILE_FLAGS} -F/Library/Frameworks -framework HIP")
ELSE (APPLE)
SET_TARGET_PROPERTIES(${STATIC_TARGET} PROPERTIES LINK_FLAGS "${EXTRA_LINK_FLAGS}")
ENDIF (APPLE)
IF(HIPFFT_FOUND)
TARGET_LINK_LIBRARIES(${STATIC_TARGET} PUBLIC hip::hipfft)
TARGET_COMPILE_OPTIONS(${STATIC_TARGET} PUBLIC "-DOPENMM_HIP_WITH_HIPFFT")
ENDIF(HIPFFT_FOUND)

INSTALL_TARGETS(/lib/plugins RUNTIME_DIRECTORY /lib/plugins ${STATIC_TARGET})
ENDIF(OPENMM_BUILD_STATIC_LIB)
Expand Down
12 changes: 12 additions & 0 deletions platforms/hip/include/HipKernels.h
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@ class HipCalcCustomCVForceKernel : public CommonCalcCustomCVForceKernel {
}
};

/**
* This kernel is invoked by ATMForce to calculate the forces acting on the system and the energy of the system.
*/
class HipCalcATMForceKernel : public CommonCalcATMForceKernel {
public:
HipCalcATMForceKernel(std::string name, const Platform& platform, ComputeContext& cc) : CommonCalcATMForceKernel(name, platform, cc) {
}
ComputeContext& getInnerComputeContext(ContextImpl& innerContext) {
return *reinterpret_cast<HipPlatform::PlatformData*>(innerContext.getPlatformData())->contexts[0];
}
};

} // namespace OpenMM

#endif /*OPENMM_HIPKERNELS_H_*/
18 changes: 13 additions & 5 deletions platforms/hip/include/HipNonbondedUtilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2009-2022 Stanford University and the Authors. *
* Portions copyright (c) 2009-2023 Stanford University and the Authors. *
* Portions copyright (C) 2020-2023 Advanced Micro Devices, Inc. All Rights *
* Reserved. *
* Authors: Peter Eastman, Nicholas Curtis *
Expand Down Expand Up @@ -83,8 +83,10 @@ class OPENMM_EXPORT_COMMON HipNonbondedUtilities : public NonbondedUtilities {
* @param exclusionList for each atom, specifies the list of other atoms whose interactions should be excluded
* @param kernel the code to evaluate the interaction
* @param forceGroup the force group in which the interaction should be calculated
* @param usesNeighborList specifies whether a neighbor list should be used to optimize this interaction. This should
* be viewed as only a suggestion. Even when it is false, a neighbor list may be used anyway.
*/
void addInteraction(bool usesCutoff, bool usesPeriodic, bool usesExclusions, double cutoffDistance, const std::vector<std::vector<int> >& exclusionList, const std::string& kernel, int forceGroup);
void addInteraction(bool usesCutoff, bool usesPeriodic, bool usesExclusions, double cutoffDistance, const std::vector<std::vector<int> >& exclusionList, const std::string& kernel, int forceGroup, bool usesNeighborList = true);
/**
* Add a nonbonded interaction to be evaluated by the default interaction kernel.
*
Expand All @@ -95,9 +97,11 @@ class OPENMM_EXPORT_COMMON HipNonbondedUtilities : public NonbondedUtilities {
* @param exclusionList for each atom, specifies the list of other atoms whose interactions should be excluded
* @param kernel the code to evaluate the interaction
* @param forceGroup the force group in which the interaction should be calculated
* @param usesNeighborList specifies whether a neighbor list should be used to optimize this interaction. This should
* be viewed as only a suggestion. Even when it is false, a neighbor list may be used anyway.
* @param supportsPairList specifies whether this interaction can work with a neighbor list that uses a separate pair list
*/
void addInteraction(bool usesCutoff, bool usesPeriodic, bool usesExclusions, double cutoffDistance, const std::vector<std::vector<int> >& exclusionList, const std::string& kernel, int forceGroup, bool supportsPairList);
void addInteraction(bool usesCutoff, bool usesPeriodic, bool usesExclusions, double cutoffDistance, const std::vector<std::vector<int> >& exclusionList, const std::string& kernel, int forceGroup, bool usesNeighborList, bool supportsPairList);
/**
* Add a per-atom parameter that the default interaction kernel may depend on.
*/
Expand Down Expand Up @@ -336,20 +340,23 @@ class OPENMM_EXPORT_COMMON HipNonbondedUtilities : public NonbondedUtilities {
HipArray sortedBlocks;
HipArray sortedBlockCenter;
HipArray sortedBlockBoundingBox;
HipArray blockSizeRange;
HipArray largeBlockCenter;
HipArray largeBlockBoundingBox;
HipArray oldPositions;
HipArray rebuildNeighborList;
HipSort* blockSorter;
hipEvent_t downloadCountEvent;
unsigned int* pinnedCountBuffer;
std::vector<void*> forceArgs, findBlockBoundsArgs, sortBoxDataArgs, findInteractingBlocksArgs, copyInteractionCountsArgs;
std::vector<void*> forceArgs, findBlockBoundsArgs, computeSortKeysArgs, sortBoxDataArgs, findInteractingBlocksArgs, copyInteractionCountsArgs;
std::vector<std::vector<int> > atomExclusions;
std::vector<ParameterInfo> parameters;
std::vector<ParameterInfo> arguments;
std::vector<std::string> energyParameterDerivatives;
std::map<int, double> groupCutoff;
std::map<int, std::string> groupKernelSource;
double lastCutoff;
bool useCutoff, usePeriodic, anyExclusions, usePadding, forceRebuildNeighborList, canUsePairList;
bool useCutoff, usePeriodic, anyExclusions, usePadding, useNeighborList, forceRebuildNeighborList, canUsePairList, useLargeBlocks;
int startTileIndex, startBlockIndex, numBlocks, numTilesInBatch, maxExclusions;
int numForceThreadBlocks, forceThreadBlockSize, findInteractingBlocksThreadBlockSize, numAtoms, groupFlags;
unsigned int maxTiles, maxSinglePairs, tilesAfterReorder;
Expand All @@ -368,6 +375,7 @@ class HipNonbondedUtilities::KernelSet {
std::string source;
hipFunction_t forceKernel, energyKernel, forceEnergyKernel;
hipFunction_t findBlockBoundsKernel;
hipFunction_t computeSortKeysKernel;
hipFunction_t sortBoxDataKernel;
hipFunction_t findInteractingBlocksKernel;
hipFunction_t copyInteractionCountsKernel;
Expand Down
Loading