-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1068 from Libensemble/feature/gen_procs_gpus
Add gen options for num_procs and num_gpus
- Loading branch information
Showing
11 changed files
with
334 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ apoints | |
numer | ||
hist | ||
inout | ||
slac |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
libensemble/tests/functionality_tests/test_GPU_gen_resources.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
""" | ||
Tests variable resource detection and automatic GPU assignment in both | ||
generator and simulators. | ||
The persistent generator creates simulations with variable resource requirements, | ||
while also requiring resources itself. The resources required by a sim must | ||
not be larger than what remains once the generator resources are assigned. | ||
The sim_f (gpu_variable_resources_from_gen) asserts that GPUs assignment | ||
is correct for the default method for the MPI runner. GPUs are not actually | ||
used for default application. Four GPUs per node is mocked up below (if this line | ||
is removed, libEnsemble will detect any GPUs available). | ||
A dry_run option is provided. This can be set in the calling script, and will | ||
just print run-lines and GPU settings. This may be used for testing run-lines | ||
produced and GPU settings for different MPI runners. | ||
Execute via one of the following commands (e.g. 4 workers): | ||
mpiexec -np 5 python test_GPU_gen_resources.py | ||
python test_GPU_gen_resources.py --comms local --nworkers 4 | ||
When running with the above command, the number of concurrent evaluations of | ||
the objective function will be 4, as one of the five workers will be the | ||
persistent generator. | ||
""" | ||
|
||
# Do not change these lines - they are parsed by run-tests.sh | ||
# TESTSUITE_COMMS: mpi local | ||
# TESTSUITE_NPROCS: 5 | ||
|
||
import sys | ||
|
||
import numpy as np | ||
|
||
from libensemble.alloc_funcs.start_only_persistent import only_persistent_gens as alloc_f | ||
from libensemble.executors.mpi_executor import MPIExecutor | ||
from libensemble.gen_funcs.persistent_sampling_var_resources import uniform_sample_with_sim_gen_resources as gen_f | ||
|
||
# Import libEnsemble items for this test | ||
from libensemble.libE import libE | ||
from libensemble.sim_funcs import six_hump_camel | ||
from libensemble.sim_funcs.var_resources import gpu_variable_resources_from_gen as sim_f | ||
from libensemble.tools import add_unique_random_streams, parse_args | ||
|
||
# from libensemble import logger | ||
# logger.set_level("DEBUG") # For testing the test | ||
|
||
|
||
# Main block is necessary only when using local comms with spawn start method (default on macOS and Windows). | ||
if __name__ == "__main__": | ||
nworkers, is_manager, libE_specs, _ = parse_args() | ||
|
||
libE_specs["num_resource_sets"] = nworkers # Persistent gen DOES need resources | ||
|
||
# Mock GPU system / uncomment to detect GPUs | ||
libE_specs["sim_dirs_make"] = True # Will only contain files if dry_run is False | ||
libE_specs["gen_dirs_make"] = True # Will only contain files if dry_run is False | ||
libE_specs["ensemble_dir_path"] = "./ensemble_GPU_gen_resources_w" + str(nworkers) | ||
libE_specs["reuse_output_dir"] = True | ||
dry_run = True | ||
|
||
if libE_specs["comms"] == "tcp": | ||
sys.exit("This test only runs with MPI or local -- aborting...") | ||
|
||
# Get paths for applications to run | ||
six_hump_camel_app = six_hump_camel.__file__ | ||
exctr = MPIExecutor() | ||
exctr.register_app(full_path=six_hump_camel_app, app_name="six_hump_camel") | ||
|
||
n = 2 | ||
sim_specs = { | ||
"sim_f": sim_f, | ||
"in": ["x"], | ||
"out": [("f", float)], | ||
"user": {"dry_run": dry_run}, | ||
} | ||
|
||
gen_specs = { | ||
"gen_f": gen_f, | ||
"persis_in": ["f", "x", "sim_id"], | ||
"out": [("num_procs", int), ("num_gpus", int), ("x", float, n)], | ||
"user": { | ||
"initial_batch_size": nworkers - 1, | ||
"max_procs": nworkers - 1, # Any sim created can req. 1 worker up to all. | ||
"lb": np.array([-3, -2]), | ||
"ub": np.array([3, 2]), | ||
"dry_run": dry_run, | ||
}, | ||
} | ||
|
||
alloc_specs = { | ||
"alloc_f": alloc_f, | ||
"user": { | ||
"give_all_with_same_priority": False, | ||
"async_return": False, # False batch returns | ||
}, | ||
} | ||
|
||
exit_criteria = {"sim_max": 20} | ||
libE_specs["resource_info"] = {"cores_on_node": (nworkers * 2, nworkers * 4), "gpus_on_node": nworkers} | ||
|
||
base_libE_specs = libE_specs.copy() | ||
for run in range(5): | ||
|
||
# reset | ||
libE_specs = base_libE_specs.copy() | ||
persis_info = add_unique_random_streams({}, nworkers + 1) | ||
|
||
if run == 0: | ||
libE_specs["gen_num_procs"] = 2 | ||
elif run == 1: | ||
libE_specs["gen_num_gpus"] = 1 | ||
elif run == 2: | ||
persis_info["gen_num_gpus"] = 1 | ||
elif run == 3: | ||
# Two GPUs per resource set | ||
libE_specs["resource_info"]["gpus_on_node"] = nworkers * 2 | ||
persis_info["gen_num_gpus"] = 1 | ||
elif run == 4: | ||
# Two GPUs requested for gen | ||
persis_info["gen_num_procs"] = 2 | ||
persis_info["gen_num_gpus"] = 2 | ||
gen_specs["user"]["max_procs"] = max(nworkers - 2, 1) | ||
|
||
# Perform the run | ||
H, persis_info, flag = libE( | ||
sim_specs, gen_specs, exit_criteria, persis_info, libE_specs=libE_specs, alloc_specs=alloc_specs | ||
) | ||
|
||
# All asserts are in gen and sim funcs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.