Skip to content

Commit

Permalink
tests: Add helper to tests that include parallel compiled execution (P…
Browse files Browse the repository at this point in the history
…rincetonUniversity#2591)

Fix typos in comments.

Signed-off-by: Jan Vesely <[email protected]>
  • Loading branch information
jvesely authored Jan 21, 2023
1 parent 5498a46 commit 938de00
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 47 deletions.
11 changes: 10 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,23 @@ def llvm_current_fp_precision():
@pytest.helpers.register
def get_comp_execution_modes():
return [pytest.param(pnlvm.ExecutionMode.Python),
# pytest.param(pnlvm.ExecutionMode.PyTorch, marks=pytest.mark.pytorch),
pytest.param(pnlvm.ExecutionMode.LLVM, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.LLVMExec, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.LLVMRun, marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.PTXExec, marks=[pytest.mark.llvm, pytest.mark.cuda]),
pytest.param(pnlvm.ExecutionMode.PTXRun, marks=[pytest.mark.llvm, pytest.mark.cuda])
]

@pytest.helpers.register
def get_comp_and_ocm_execution_modes():

# The first part converts composition execution mode to (comp_mod, ocm_mode) pair.
# All comp_mode-s other than Python set ocm_mode to None, which is invalid and will
# fail assertion if executed in Python mode, ExecutionMode.Python sets ocm_mode to 'Python'.
return [pytest.param(x.values[0], 'Python' if x.values[0] is pnlvm.ExecutionMode.Python else 'None', id=str(x.values[0]), marks=x.marks) for x in get_comp_execution_modes()] + \
[pytest.param(pnlvm.ExecutionMode.Python, 'LLVM', id='Python-LLVM', marks=pytest.mark.llvm),
pytest.param(pnlvm.ExecutionMode.Python, 'PTX', id='Python-PTX', marks=[pytest.mark.llvm, pytest.mark.cuda])]

@pytest.helpers.register
def cuda_param(val):
return pytest.param(val, marks=[pytest.mark.llvm, pytest.mark.cuda])
Expand Down
44 changes: 10 additions & 34 deletions tests/composition/test_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -2501,8 +2501,8 @@ def test_modulation_of_random_state_DDM(self, comp_mode, benchmark, prng):

@pytest.mark.control
@pytest.mark.composition
# test only OCM modes. we check "saved_values" which are not available in e2e compolation
# FIXME: skip Python since direct ocm modulation of initlizers is not implemetned yet
# test only OCM modes. we check "saved_values" which are not available in e2e compilation
# FIXME: skip Python since direct ocm modulation of initializers is not implemented yet
@pytest.mark.parametrize('ocm_mode', [pytest.param('Python', marks=pytest.mark.skip),
pytest.param('LLVM', marks=pytest.mark.llvm),
pytest.helpers.cuda_param('PTX')])
Expand Down Expand Up @@ -2538,8 +2538,8 @@ def test_modulation_of_initializer(self, ocm_mode):

@pytest.mark.control
@pytest.mark.composition
# test only OCM modes. we check "saved_values" which are not available in e2e compolation
# FIXME: skip Python since direct ocm modulation of initlizers is not implemetned yet
# test only OCM modes. we check "saved_values" which are not available in e2e compilation
# FIXME: skip Python since direct ocm modulation of initializers is not implemented yet
@pytest.mark.parametrize('ocm_mode', [pytest.param('Python', marks=pytest.mark.skip),
pytest.param('LLVM', marks=pytest.mark.llvm),
pytest.helpers.cuda_param('PTX')])
Expand Down Expand Up @@ -2692,16 +2692,8 @@ def test_ocm_default_function(self):

@pytest.mark.parametrize("nested", [True, False])
@pytest.mark.parametrize("format", ["list", "tuple", "SampleIterator", "SampleIteratorArray", "SampleSpec", "ndArray"])
@pytest.mark.parametrize("mode", pytest.helpers.get_comp_execution_modes() +
[pytest.helpers.cuda_param('Python-PTX'),
pytest.param('Python-LLVM', marks=pytest.mark.llvm)])
def test_ocm_searchspace_format_equivalence(self, format, nested, mode):
if str(mode).startswith('Python-'):
ocm_mode = mode.split('-')[1]
mode = pnl.ExecutionMode.Python
else:
# OCM default mode is Python
ocm_mode = 'Python'
@pytest.mark.parametrize("mode, ocm_mode", pytest.helpers.get_comp_and_ocm_execution_modes())
def test_ocm_searchspace_format_equivalence(self, format, nested, mode, ocm_mode):

if format == "list":
search_space = [1, 10]
Expand Down Expand Up @@ -3275,16 +3267,8 @@ def test_stateful_mechanism_in_simulation(self):
)

@pytest.mark.benchmark(group="Model Based OCM")
@pytest.mark.parametrize("mode", pytest.helpers.get_comp_execution_modes() +
[pytest.helpers.cuda_param('Python-PTX'),
pytest.param('Python-LLVM', marks=pytest.mark.llvm)])
def test_model_based_ocm_after(self, benchmark, mode):
if str(mode).startswith('Python-'):
ocm_mode = mode.split('-')[1]
mode = pnl.ExecutionMode.Python
else:
# OCM default mode is Python
ocm_mode = 'Python'
@pytest.mark.parametrize("mode, ocm_mode", pytest.helpers.get_comp_and_ocm_execution_modes())
def test_model_based_ocm_after(self, benchmark, mode, ocm_mode):

A = pnl.ProcessingMechanism(name='A')
B = pnl.ProcessingMechanism(name='B')
Expand Down Expand Up @@ -3324,16 +3308,8 @@ def test_model_based_ocm_after(self, benchmark, mode):
benchmark(comp.run, inputs, execution_mode=mode)

@pytest.mark.benchmark(group="Model Based OCM")
@pytest.mark.parametrize("mode", pytest.helpers.get_comp_execution_modes() +
[pytest.helpers.cuda_param('Python-PTX'),
pytest.param('Python-LLVM', marks=pytest.mark.llvm)])
def test_model_based_ocm_before(self, benchmark, mode):
if str(mode).startswith('Python-'):
ocm_mode = mode.split('-')[1]
mode = pnl.ExecutionMode.Python
else:
# OCM default mode is Python
ocm_mode = 'Python'
@pytest.mark.parametrize("mode, ocm_mode", pytest.helpers.get_comp_and_ocm_execution_modes())
def test_model_based_ocm_before(self, benchmark, mode, ocm_mode):

A = pnl.ProcessingMechanism(name='A')
B = pnl.ProcessingMechanism(name='B')
Expand Down
16 changes: 4 additions & 12 deletions tests/models/test_greedy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,20 @@ def test_simplified_greedy_agent_random(benchmark, comp_mode):

@pytest.mark.model
@pytest.mark.benchmark(group="Predator Prey")
@pytest.mark.parametrize("mode", pytest.helpers.get_comp_execution_modes() +
[pytest.helpers.cuda_param('Python-PTX'),
pytest.param('Python-LLVM', marks=pytest.mark.llvm)])
@pytest.mark.parametrize("mode, ocm_mode", pytest.helpers.get_comp_and_ocm_execution_modes())
@pytest.mark.parametrize("samples", [[0,10],
pytest.param([0,3,6,10], marks=pytest.mark.stress),
pytest.param([0,2,4,6,8,10], marks=pytest.mark.stress),
pytest.param([a / 10.0 for a in range(0, 101)], marks=pytest.mark.stress),
], ids=lambda x: len(x))
@pytest.mark.parametrize('prng', ['Default', 'Philox'])
@pytest.mark.parametrize('fp_type', [pnl.core.llvm.ir.DoubleType, pnl.core.llvm.ir.FloatType])
def test_predator_prey(benchmark, mode, prng, samples, fp_type):
def test_predator_prey(benchmark, mode, ocm_mode, prng, samples, fp_type):
if len(samples) > 10 and mode not in {pnl.ExecutionMode.LLVM,
pnl.ExecutionMode.LLVMExec,
pnl.ExecutionMode.LLVMRun,
"Python-PTX", "Python-LLVM"}:
pnl.ExecutionMode.LLVMRun} and \
ocm_mode not in {'LLVM', 'PTX'}:
pytest.skip("This test takes too long")
if str(mode).startswith('Python-'):
ocm_mode = mode.split('-')[1]
mode = pnl.ExecutionMode.Python
else:
# OCM default mode is Python
ocm_mode = 'Python'

# Instantiate LLVMBuilderContext using the preferred fp type
pnl.core.llvm.builder_context.LLVMBuilderContext(fp_type())
Expand Down

0 comments on commit 938de00

Please sign in to comment.