Skip to content

Commit

Permalink
GPU batching (#473)
Browse files Browse the repository at this point in the history
* remove GPU keyword

* Add GPU check and include it in the memory_manager

Co-authored-by: Samuel Tovey <tovey.samuel@gmail.com>
  • Loading branch information
PythonFZ and SamTov authored Jan 25, 2022
1 parent 824af77 commit 8f55d26
Show file tree
Hide file tree
Showing 18 changed files with 18 additions and 73 deletions.
10 changes: 10 additions & 0 deletions CI/unit_tests/utils/test_meta_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
import unittest

import numpy as np
import tensorflow as tf

from mdsuite.utils.meta_functions import (
find_item,
get_dimensionality,
get_machine_properties,
golden_section_search,
gpu_available,
join_path,
line_counter,
linear_fitting_function,
Expand All @@ -45,6 +47,14 @@
)


def test_gpu_available():
"""
Ideally this should be checked against something else than tf.config
but I don't have any better measure.
"""
assert gpu_available() == (len(tf.config.list_physical_devices("GPU")) > 1)


class TestMetaFunction(unittest.TestCase):
"""
A test class for the meta functions module.
Expand Down
5 changes: 0 additions & 5 deletions mdsuite/calculators/angular_distribution_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ def __call__(
species: list = None,
use_tf_function: bool = False,
molecules: bool = False,
gpu: bool = False,
plot: bool = True,
norm_power: int = 4,
**kwargs,
Expand Down Expand Up @@ -188,9 +187,6 @@ def __call__(
If set to zero no distance normalization will be applied.
molecules : bool
if true, perform the analysis on molecules.
gpu : bool
if true, scale the memory requirements to that of the biggest
GPU on the machine.
plot : bool
If true, plot the result of the analysis.
"""
Expand All @@ -212,7 +208,6 @@ def __call__(
# Parse the user arguments.
self.use_tf_function = use_tf_function
self.cutoff = cutoff
self.gpu = gpu
self.plot = plot
self._batch_size = batch_size # memory management for all batches
self.adf_minibatch = (
Expand Down
3 changes: 0 additions & 3 deletions mdsuite/calculators/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ class Calculator(CalculatorDatabase):
List of experiments on which to run the calculator.
plot : bool
If true, the results will be plotted.
gpu : bool
If true, the memory will be scaled down to the best GPU on the system.
system_property: bool (default = False)
If the calculator returns a value for the whole system such as ionic
conductivity or viscosity as opposed to a species-specific number.
Expand Down Expand Up @@ -219,7 +217,6 @@ def __init__(
self.experiments = [self.experiment]

self.plot = False
self.gpu = False

# SQL data attributes.
self.result_keys = None
Expand Down
5 changes: 0 additions & 5 deletions mdsuite/calculators/einstein_diffusion_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ def __call__(
atom_selection: np.s_ = np.s_[:],
molecules: bool = False,
tau_values: Union[int, List, Any] = np.s_[:],
gpu: bool = False,
):
"""
Expand All @@ -132,9 +131,6 @@ def __call__(
If true, molecules are used instead of atoms.
tau_values : Union[int, list, np.s_]
Selection of tau values to use in the window sliding.
gpu : bool
If true, scale the memory requirement down to the amount of
the biggest GPU in the system.
Returns
-------
Expand All @@ -154,7 +150,6 @@ def __call__(
molecules=molecules,
species=species,
)
self.gpu = gpu
self.plot = plot
self.system_property = False
self.time = self._handle_tau_values()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def __call__(
molecules: bool = False,
export: bool = False,
atom_selection: dict = np.s_[:],
gpu: bool = False,
):
"""
Parameters
Expand All @@ -143,9 +142,6 @@ def __call__(
Selection of atoms to use within the HDF5 database.
export : bool
If true, export the data directly into a csv file.
gpu : bool
If true, scale the memory requirement down to the amount of
the biggest GPU in the system.
Returns
-------
Expand All @@ -157,7 +153,6 @@ def __call__(
species = list(self.experiment.species)
self.combinations = list(itertools.combinations_with_replacement(species, 2))

self.gpu = gpu
self.plot = plot

# set args that will affect the computation result
Expand Down
5 changes: 0 additions & 5 deletions mdsuite/calculators/einstein_helfand_ionic_conductivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def __call__(
data_range=500,
correlation_time=1,
tau_values: np.s_ = np.s_[:],
gpu: bool = False,
):
"""
Python constructor
Expand All @@ -113,9 +112,6 @@ def __call__(
Number of configurations to use in each ensemble
correlation_time : int
Correlation time to use in the analysis.
gpu : bool
If true, reduce memory usage to the maximum GPU capability.
"""

# set args that will affect the computation result
Expand All @@ -126,7 +122,6 @@ def __call__(
atom_selection=np.s_[:],
)

self.gpu = gpu
self.plot = plot
self.time = self._handle_tau_values()
self.msd_array = np.zeros(self.data_resolution)
Expand Down
6 changes: 0 additions & 6 deletions mdsuite/calculators/einstein_helfand_thermal_conductivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ def __call__(
data_range=500,
correlation_time=1,
tau_values: np.s_ = np.s_[:],
gpu: bool = False,
):
"""
Python constructor
Expand All @@ -123,9 +122,6 @@ def __call__(
Data range to use in the analysis.
correlation_time : int
Correlation time to use in the window sampling.
gpu : bool
If true, scale the memory requirement down to the amount of
the biggest GPU in the system.
"""
# set args that will affect the computation result
self.args = Args(
Expand All @@ -134,8 +130,6 @@ def __call__(
tau_values=tau_values,
atom_selection=np.s_[:],
)

self.gpu = gpu
self.plot = plot
self.time = self._handle_tau_values()
self.msd_array = np.zeros(self.data_resolution)
Expand Down
5 changes: 0 additions & 5 deletions mdsuite/calculators/einstein_helfand_thermal_kinaci.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ def __call__(
data_range=500,
correlation_time=1,
tau_values: np.s_ = np.s_[:],
gpu: bool = False,
):
"""
Python constructor
Expand All @@ -127,9 +126,6 @@ def __call__(
correlation_time : int
Correlation time to use in the window sampling.
gpu : bool
If true, scale the memory requirement down to the amount of
the biggest GPU in the system.
"""
# set args that will affect the computation result
self.args = Args(
Expand All @@ -140,7 +136,6 @@ def __call__(
)

self.plot = plot
self.gpu = gpu
self.time = self._handle_tau_values()
self.msd_array = np.zeros(self.data_resolution)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def __call__(
molecules: bool = False,
export: bool = False,
atom_selection: dict = np.s_[:],
gpu: bool = False,
integration_range: int = None,
):
"""
Expand All @@ -142,9 +141,6 @@ def __call__(
Selection of atoms to use within the HDF5 database.
export : bool
If true, export the data directly into a csv file.
gpu : bool
If true, scale the memory requirement down to the amount of
the biggest GPU in the system.
integration_range : int
Range over which to perform the integration.
"""
Expand All @@ -162,7 +158,6 @@ def __call__(
integration_range=integration_range,
)

self.gpu = gpu
self.plot = plot
self.time = self._handle_tau_values()

Expand Down
5 changes: 0 additions & 5 deletions mdsuite/calculators/green_kubo_ionic_conductivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ def __call__(
data_range=500,
correlation_time=1,
tau_values: np.s_ = np.s_[:],
gpu: bool = False,
integration_range: int = None,
):
"""
Expand All @@ -129,14 +128,10 @@ def __call__(
Data range to use in the analysis.
correlation_time : int
Correlation time to use in the window sampling.
gpu : bool
If true, scale the memory requirement down to the amount of
the biggest GPU in the system.
integration_range : int
Range over which integration should be performed.
"""

self.gpu = gpu
self.plot = plot
self.jacf: np.ndarray
self.sigma = []
Expand Down
5 changes: 0 additions & 5 deletions mdsuite/calculators/green_kubo_self_diffusion_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ def __call__(
correlation_time: int = 1,
atom_selection=np.s_[:],
molecules: bool = False,
gpu: bool = False,
tau_values: Union[int, List, Any] = np.s_[:],
integration_range: int = None,
):
Expand All @@ -139,9 +138,6 @@ def __call__(
Selection of atoms to use within the HDF5 database.
molecules : bool
If true, molecules are used instead of atoms.
gpu : bool
If true, scale the memory requirement down to the amount of
the biggest GPU in the system.
integration_range : int
Range over which to integrate. Default is to integrate over
the full data range.
Expand All @@ -165,7 +161,6 @@ def __call__(
integration_range=integration_range,
)

self.gpu = gpu
self.plot = plot
self.time = self._handle_tau_values()
self.vacf = np.zeros(self.data_resolution)
Expand Down
5 changes: 0 additions & 5 deletions mdsuite/calculators/green_kubo_thermal_conductivity.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ def __call__(
data_range=500,
tau_values: np.s_ = np.s_[:],
correlation_time: int = 1,
gpu: bool = False,
integration_range: int = None,
):
"""
Expand All @@ -119,13 +118,9 @@ def __call__(
Data range to use in the analysis.
correlation_time : int
Correlation time to use in the window sampling.
gpu : bool
If true, scale the memory requirement down to the amount of
the biggest GPU in the system.
integration_range : int
Range over which the integration should be performed.
"""
self.gpu = gpu
self.plot = plot
self.jacf: np.ndarray
self.prefactor: float
Expand Down
3 changes: 0 additions & 3 deletions mdsuite/calculators/green_kubo_viscosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ def __call__(
data_range=500,
tau_values: np.s_ = np.s_[:],
correlation_time: int = 1,
gpu: bool = False,
integration_range: int = None,
):
"""
Expand All @@ -118,8 +117,6 @@ def __call__(
data_range :
Number of configurations to use in each ensemble
"""

self.gpu = gpu
self.plot = plot
self.sigma = []

Expand Down
3 changes: 0 additions & 3 deletions mdsuite/calculators/green_kubo_viscosity_flux.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def __call__(
data_range=500,
correlation_time=1,
tau_values: np.s_ = np.s_[:],
gpu: bool = False,
integration_range: int = None,
):
"""
Expand All @@ -117,8 +116,6 @@ def __call__(
data_range : int
Number of configurations to include in each ensemble
"""

self.gpu = gpu
self.plot = plot
self.sigma = []

Expand Down
10 changes: 0 additions & 10 deletions mdsuite/calculators/radial_distribution_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ def __init__(self, **kwargs):
self.key_list = None
self.rdf = None

self.correct_minibatch_batching = None

@call
def __call__(
self,
Expand All @@ -151,7 +149,6 @@ def __call__(
minibatch: int = -1,
species: list = None,
molecules: bool = False,
gpu: bool = False,
**kwargs,
):
"""
Expand Down Expand Up @@ -184,8 +181,6 @@ def __call__(
issues. Increase this value for better performance.
molecules: bool
If true, the molecules will be analyzed rather than the atoms.
gpu: bool
Calculate batch size based on GPU memory instead of CPU memory
kwargs:
overide_n_batches: int
override the automatic batch size calculation
Expand All @@ -209,7 +204,6 @@ def __call__(
# usually performance or plotting
self.rdf_minibatch = minibatch
self.plot = plot
self.gpu = gpu

# kwargs parsing
self.use_tf_function = kwargs.pop("use_tf_function", False)
Expand Down Expand Up @@ -252,10 +246,6 @@ def check_input(self):
else:
self.args.species = list(self.experiment.species)

if self.gpu:
self.correct_minibatch_batching = 100
# 100 seems to be a good value for most systems

self._initialize_rdf_parameters()

def _initialize_rdf_parameters(self):
Expand Down
1 change: 0 additions & 1 deletion mdsuite/calculators/trajectory_calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def _prepare_managers(self, data_path: list, correct: bool = False):
database=self.database,
memory_fraction=0.8,
scale_function=self.scale_function,
gpu=self.gpu,
)
(
self.batch_size,
Expand Down
Loading

0 comments on commit 8f55d26

Please sign in to comment.