Skip to content

Commit 5ee6976

Browse files
authored
Merge pull request #31227 from loganharbour/31135_remove_devices
Remove `--libtorch-device` and `--device`
2 parents 50dfe9f + f4dfc58 commit 5ee6976

14 files changed

Lines changed: 71 additions & 76 deletions

File tree

framework/include/base/MooseApp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,6 +1519,12 @@ class MooseApp : public ConsoleStreamInterface,
15191519
*/
15201520
bool runInputs();
15211521

1522+
/**
1523+
* Helper that reports an error if the given capability is reserved and
1524+
* should not be added via addCapability().
1525+
*/
1526+
static void checkReservedCapability(const std::string & capability);
1527+
15221528
/// General storage for custom RestartableData that can be added to from outside applications
15231529
std::unordered_map<RestartableDataMapName, std::pair<RestartableDataMap, std::string>>
15241530
_restartable_meta_data;

framework/src/base/MooseApp.C

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,7 @@ MooseApp::validParams()
368368
params.addParam<bool>(
369369
"automatic_automatic_scaling", false, "Whether to turn on automatic scaling by default");
370370

371-
MooseEnum compute_device_type("cpu cuda mps hip ceed-cpu ceed-cuda ceed-hip", "cpu");
372-
params.addCommandLineParam<MooseEnum>("libtorch_device",
373-
"--libtorch-device",
374-
compute_device_type,
375-
"Deprecated. Use --compute-device.");
371+
const MooseEnum compute_device_type("cpu cuda mps hip ceed-cpu ceed-cuda ceed-hip", "cpu");
376372
params.addCommandLineParam<MooseEnum>(
377373
"compute_device",
378374
"--compute-device",
@@ -517,9 +513,7 @@ MooseApp::MooseApp(const InputParameters & parameters)
517513
_initial_backup(getParam<std::unique_ptr<Backup> *>("_initial_backup"))
518514
#ifdef MOOSE_LIBTORCH_ENABLED
519515
,
520-
_libtorch_device(determineLibtorchDeviceType(isParamSetByUser("libtorch_device")
521-
? getParam<MooseEnum>("libtorch_device")
522-
: getParam<MooseEnum>("compute_device")))
516+
_libtorch_device(determineLibtorchDeviceType(getParam<MooseEnum>("compute_device")))
523517
#endif
524518
#ifdef MOOSE_MFEM_ENABLED
525519
,
@@ -533,13 +527,6 @@ MooseApp::MooseApp(const InputParameters & parameters)
533527
: std::set<std::string>{})
534528
#endif
535529
{
536-
if (isParamSetByUser("libtorch_device"))
537-
{
538-
mooseDeprecated("--libtorch-device has been renamed --compute-device.");
539-
if (isParamSetByUser("compute_device"))
540-
mooseError("Remove the redundant --libtorch-device option.");
541-
}
542-
543530
if (&parameters != &_pars)
544531
{
545532
const auto show_trace = Moose::show_trace;
@@ -801,8 +788,6 @@ MooseApp::MooseApp(const InputParameters & parameters)
801788
std::optional<MooseEnum>
802789
MooseApp::getComputeDevice() const
803790
{
804-
if (isParamSetByUser("libtorch_device"))
805-
return getParam<MooseEnum>("libtorch_device");
806791
if (isParamSetByUser("compute_device"))
807792
return getParam<MooseEnum>("compute_device");
808793
return {};
@@ -2371,6 +2356,19 @@ MooseApp::runInputs()
23712356
return false;
23722357
}
23732358

2359+
void
2360+
MooseApp::checkReservedCapability(const std::string & capability)
2361+
{
2362+
// The list of these capabilities should match those within
2363+
// Tester.checkRunnableBase() in the TestHarness
2364+
static const std::set<std::string> reserved{
2365+
"scale_refine", "valgrind", "recover", "heavy", "mpi_procs", "num_threads", "compute_device"};
2366+
if (reserved.count(capability))
2367+
mooseError("MooseApp::addCapability(): The capability \"",
2368+
capability,
2369+
"\" is reserved and may not be registered by an application.");
2370+
}
2371+
23742372
void
23752373
MooseApp::setOutputPosition(const Point & p)
23762374
{
@@ -3530,7 +3528,7 @@ MooseApp::constructingMeshGenerators() const
35303528
torch::DeviceType
35313529
MooseApp::determineLibtorchDeviceType(const MooseEnum & device_enum) const
35323530
{
3533-
const auto pname = isParamSetByUser("libtorch_device") ? "--libtorch-device" : "--compute-device";
3531+
const auto pname = "--compute-device";
35343532
if (device_enum == "cuda")
35353533
{
35363534
#ifdef __linux__
@@ -3592,12 +3590,14 @@ MooseApp::addCapability(const std::string & capability,
35923590
CapabilityUtils::Type value,
35933591
const std::string & doc)
35943592
{
3593+
checkReservedCapability(capability);
35953594
Moose::Capabilities::getCapabilityRegistry().add(capability, value, doc);
35963595
}
35973596

35983597
void
35993598
MooseApp::addCapability(const std::string & capability, const char * value, const std::string & doc)
36003599
{
3600+
checkReservedCapability(capability);
36013601
Moose::Capabilities::getCapabilityRegistry().add(capability, std::string(value), doc);
36023602
}
36033603

python/TestHarness/TestHarness.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,6 @@ def parseCLArgs(self, argv):
11461146
parser.add_argument('--distributed-mesh', action='store_true', dest='distributed_mesh', help='Pass "--distributed-mesh" to executable')
11471147

11481148
parser.add_argument('--compute-device', action='store', dest='compute_device', type=str, choices=TestHarness.validComputeDevices(), default='cpu', help='Run libtorch or MFEM tests with this compute device; device availability depends on library support and compilation settings')
1149-
parser.add_argument('--libtorch-device', action='store', dest='compute_device', type=str, choices=TestHarness.validComputeDevices(), help='Deprecated, use --compute-device instead')
1150-
parser.add_argument('--device', action='store', dest='compute_device', type=str, choices=TestHarness.validComputeDevices(), help='Deprecated, use --compute-device instead')
11511149

11521150
parser.add_argument('--error', action='store_true', help='Run the tests with warnings as errors (Pass "--error" to executable)')
11531151
parser.add_argument('--error-unused', action='store_true', help='Run the tests with errors on unused parameters (Pass "--error-unused" to executable)')

python/TestHarness/testers/RunApp.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ def validParams():
5353
# Valgrind
5454
params.addParam('valgrind', 'NORMAL', "Set to (NONE, NORMAL, HEAVY) to determine which configurations where valgrind will run.")
5555

56-
params.addParam('libtorch_devices', "The devices to use for this libtorch test ('CPU', 'CUDA', 'MPS')")
5756
device_list_str = "', '".join(d.upper() for d in TestHarness.validComputeDevices())
5857
device_param_doc = f"The devices to use for this libtorch or MFEM test ('{device_list_str}'); device availability depends on library support and compilation settings; default ('CPU')"
59-
params.addParam('devices', ['CPU'], device_param_doc)
58+
params.addParam('compute_devices', ['CPU'], device_param_doc)
6059

6160
return params
6261

@@ -79,12 +78,7 @@ def __init__(self, name, params):
7978
if params['no_additional_cli_args']:
8079
raise Exception('The parameters "command_proxy" and "no_additional_cli_args" cannot be supplied together')
8180

82-
if params.isValid('libtorch_devices'):
83-
for value in params['libtorch_devices']:
84-
if value.lower() not in ['cpu', 'cuda', 'mps']:
85-
raise Exception(f'Unknown libtorch_device "{value}"')
86-
87-
for value in params['devices']:
81+
for value in params['compute_devices']:
8882
if value.lower() not in TestHarness.validComputeDevices():
8983
raise Exception(f'Unknown device "{value}"')
9084

@@ -130,12 +124,7 @@ def checkRunnable(self, options):
130124
self.setStatus(self.skip)
131125
return False
132126

133-
if self.specs.isValid('libtorch_devices'):
134-
devices_lower = [x.lower() for x in self.specs['libtorch_devices']]
135-
elif self.specs.isValid('devices'):
136-
devices_lower = [x.lower() for x in self.specs['devices']]
137-
else:
138-
devices_lower = [x.lower() for x in self.specs['compute_devices']]
127+
devices_lower = [x.lower() for x in self.specs['compute_devices']]
139128
if options.compute_device not in devices_lower:
140129
self.addCaveats(f'{options.compute_device} not in compute devices')
141130
self.setStatus(self.skip)

python/TestHarness/testers/Tester.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,8 @@ def augment(key, val_doc):
581581
raise ValueError(f"Capability {key} is defined by the app, but it is a reserved dynamic test harness capability. This is an application bug.")
582582
capabilities[key] = val_doc
583583

584+
# NOTE: If you add to this list, add the capability name as a reserved
585+
# capability within MooseApp::checkReservedCapability()
584586
augment('scale_refine', [options.scaling, 'The number of refinements to do when scaling'])
585587
if options.valgrind_mode == '':
586588
augment('valgrind', [False, 'Not running with valgrind'])

test/tests/mfem/ics/tests

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ignored_items = "root['VTKFile']['@version']"
1010
requirement = 'The system shall have the ability to set initial conditions on a scalar variable.'
1111
capabilities = 'mfem'
12-
devices = 'cpu cuda'
12+
compute_devices = 'cpu cuda'
1313
max_parallel = 1 # schemadiff with multiple ranks
1414
recover = false
1515
[]
@@ -21,7 +21,7 @@
2121
ignored_items = "root['VTKFile']['@version']"
2222
requirement = 'The system shall have the ability to set initial conditions on a vector MFEM variable.'
2323
capabilities = 'mfem'
24-
devices = 'cpu cuda'
24+
compute_devices = 'cpu cuda'
2525
max_parallel = 1 # schemadiff with multiple ranks
2626
recover = false
2727
[]
@@ -34,7 +34,7 @@
3434
ignored_items = "root['VTKFile']['@version']"
3535
requirement = 'The system shall have the ability to set initial conditions on a scalar variable in transient simulations.'
3636
capabilities = 'mfem'
37-
devices = 'cpu cuda'
37+
compute_devices = 'cpu cuda'
3838
max_parallel = 1 # schemadiff with multiple ranks
3939
recover = false
4040
[]

test/tests/mfem/kernels/tests

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ignored_items = "root['VTKFile']['@version']"
1010
requirement = 'The system shall have the ability to solve a definite Maxwell problem with Nedelec elements of the first kind using MFEM.'
1111
capabilities = 'mfem'
12-
devices = 'cpu' # schemadiff with cuda
12+
compute_devices = 'cpu' # schemadiff with cuda
1313
max_parallel = 1 # schemadiff with multiple ranks
1414
recover = false
1515
max_threads = 1
@@ -29,7 +29,7 @@
2929
'Outputs/ParaViewDataCollection/file_base=OutputData/CurlCurlLOR'
3030
requirement = 'The system shall have the ability to solve a LOR definite Maxwell problem with Nedelec elements of the first kind using MFEM.'
3131
capabilities = 'mfem'
32-
devices = 'cpu cuda'
32+
compute_devices = 'cpu cuda'
3333
valgrind = heavy
3434
max_parallel = 1 # schemadiff with multiple ranks
3535
recover = false
@@ -45,7 +45,7 @@
4545
ignored_items = "root['VTKFile']['@version']"
4646
requirement = 'The system shall have the ability to solve a diffusion problem using MFEM.'
4747
capabilities = 'mfem'
48-
devices = 'cpu cuda'
48+
compute_devices = 'cpu cuda'
4949
max_parallel = 1 # schemadiff with multiple ranks
5050
recover = false
5151
expect_out = 'Parallel Type:.*distributed.*Mesh Dimension.*3.*Spatial Dimension.*3.*Elems.*2476.*Num Subdomains.*1.*Solver.*MFEMHypreGMRES'
@@ -60,7 +60,7 @@
6060
ignored_items = "root['VTKFile']['@version']"
6161
requirement = 'The system shall have the ability to solve a diffusion problem with partial assembly using MFEM.'
6262
capabilities = 'mfem'
63-
devices = 'cpu cuda'
63+
compute_devices = 'cpu cuda'
6464
max_parallel = 1 # schemadiff with multiple ranks
6565
recover = false
6666
[]
@@ -72,7 +72,7 @@
7272
cli_args = 'Solver/type=MFEMCGSolver Solver/preconditioner=jacobi '
7373
'Executioner/device=ceed-cpu '
7474
'Executioner/assembly_level=none'
75-
devices = 'ceed-cpu'
75+
compute_devices = 'ceed-cpu'
7676
ignored_items = "root['VTKFile']['@version']"
7777
requirement = 'The system shall have the ability to solve a diffusion problem with matrix-free assembly using MFEM.'
7878
capabilities = 'mfem'
@@ -91,7 +91,7 @@
9191
'Outputs/ParaViewDataCollection/file_base=OutputData/DiffusionLOR'
9292
requirement = 'The system shall have the ability to solve a diffusion problem with Low-Order-Refined preconditioning set up from MOOSE and produce the same result as a native MFEM run.'
9393
capabilities = 'mfem'
94-
devices = 'cpu cuda'
94+
compute_devices = 'cpu cuda'
9595
max_parallel = 1 # schemadiff with multiple ranks
9696
recover = false
9797
abs_zero = 1e-6
@@ -104,7 +104,7 @@
104104
ignored_items = "root['VTKFile']['@version']"
105105
requirement = 'The system shall have the ability to solve a grad-div problem with Raviart-Thomas elements using MFEM.'
106106
capabilities = 'mfem'
107-
devices = 'cpu cuda'
107+
compute_devices = 'cpu cuda'
108108
max_parallel = 1 # schemadiff with multiple ranks
109109
recover = false
110110
errors = 'foobarbaz' # allow cuda errors I guess?
@@ -122,7 +122,7 @@
122122
'Outputs/ParaViewDataCollection/file_base=OutputData/GradDivLOR'
123123
requirement = 'The system shall have the ability to solve a LOR grad-div problem with Raviart-Thomas elements using MFEM.'
124124
capabilities = 'mfem'
125-
devices = 'cpu cuda'
125+
compute_devices = 'cpu cuda'
126126
valgrind = heavy
127127
max_parallel = 1 # schemadiff with multiple ranks
128128
recover = false
@@ -140,7 +140,7 @@
140140
ignored_items = "root['VTKFile']['@version']"
141141
requirement = 'The system shall have the ability to solve a transient heat conduction problem using MFEM.'
142142
capabilities = 'mfem'
143-
devices = 'cpu cuda'
143+
compute_devices = 'cpu cuda'
144144
max_parallel = 1 # schemadiff with multiple ranks
145145
recover = false
146146
[]
@@ -158,7 +158,7 @@
158158
ignored_items = "root['VTKFile']['@version']"
159159
requirement = 'The system shall have the ability to solve a transient heat conduction problem with element assembly using MFEM.'
160160
capabilities = 'mfem'
161-
devices = 'cpu cuda'
161+
compute_devices = 'cpu cuda'
162162
valgrind = none
163163
max_parallel = 1 # schemadiff with multiple ranks
164164
recover = false
@@ -175,7 +175,7 @@
175175
'Solver/type=MFEMCGSolver Solver/preconditioner=jacobi '
176176
'Executioner/assembly_level=none '
177177
'Executioner/device=ceed-cpu'
178-
devices = 'ceed-cpu'
178+
compute_devices = 'ceed-cpu'
179179
ignored_items = "root['VTKFile']['@version']"
180180
requirement = 'The system shall have the ability to solve a transient heat conduction problem with matrix-free assembly using MFEM.'
181181
capabilities = 'mfem'
@@ -198,7 +198,7 @@
198198
'Outputs/ParaViewDataCollection/file_base=OutputData/HeatConductionLOR'
199199
requirement = 'The system shall have the ability to solve a transient heat conduction problem with Low-Order-Refined preconditioning set up from MOOSE and produce the same result as a native MFEM run.'
200200
capabilities = 'mfem'
201-
devices = 'cpu cuda'
201+
compute_devices = 'cpu cuda'
202202
max_parallel = 1 # schemadiff with multiple ranks
203203
recover = false
204204
[]
@@ -210,7 +210,7 @@
210210
ignored_items = "root['VTKFile']['@version']"
211211
requirement = 'The system shall have the ability to solve a transient heat conduction problem with a heat transfer coefficient on one boundary using MFEM.'
212212
capabilities = 'mfem'
213-
devices = 'cpu cuda'
213+
compute_devices = 'cpu cuda'
214214
max_parallel = 1 # schemadiff with multiple ranks
215215
recover = false
216216
[]
@@ -222,7 +222,7 @@
222222
ignored_items = "root['VTKFile']['@version']"
223223
requirement = 'The system shall have the ability to solve a linear elasticity problem using MFEM.'
224224
capabilities = 'mfem'
225-
devices = 'cpu cuda'
225+
compute_devices = 'cpu cuda'
226226
max_parallel = 1 # schemadiff with multiple ranks
227227
recover = false
228228
[]
@@ -234,7 +234,7 @@
234234
ignored_items = "root['VTKFile']['@version']"
235235
requirement = 'The system shall have the ability to solve a linear elasticity problem for a beam deformed under gravitational loads using MFEM.'
236236
capabilities = 'mfem'
237-
devices = 'cpu' # schemadiff with cuda
237+
compute_devices = 'cpu' # schemadiff with cuda
238238
max_parallel = 1 # schemadiff with multiple ranks
239239
recover = false
240240
max_threads = 1
@@ -247,7 +247,7 @@
247247
requirement = 'The system shall have the ability to solve for an irrotational vortex in two dimensions using MFEM.'
248248
abs_zero = 1e-6
249249
capabilities = 'mfem'
250-
devices = 'cpu cuda'
250+
compute_devices = 'cpu cuda'
251251
recover = false
252252
max_parallel = 1 # MOOSE-MFEM-HypreGMRES doesn't appear to work with multiple ranks with cuda
253253
[]
@@ -258,7 +258,7 @@
258258
requirement = 'The system shall have the ability to solve a mixed Darcy problem in two dimensions using MFEM.'
259259
abs_zero = 1e-6
260260
capabilities = 'mfem'
261-
devices = 'cpu cuda'
261+
compute_devices = 'cpu cuda'
262262
recover = false
263263
[]
264264
[]

test/tests/mfem/outputs/tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
requirement = 'The system shall have the ability to write out MFEM solutions to '
1818
'ParaView, VisIt and Conduit data collections.'
1919
capabilities = 'mfem'
20-
devices = 'cpu cuda'
20+
compute_devices = 'cpu cuda'
2121
recover = false
2222
max_parallel = 1 # MOOSE-MFEM-HypreGMRES doesn't appear to work with multiple ranks with cuda
2323
[]

test/tests/mfem/submeshes/tests

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
ignored_items = "root['VTKFile']['@version']"
1010
requirement = 'MOOSE shall have the ability to solve a diffusion problem defined on an MFEM domain restricted submesh.'
1111
capabilities = 'mfem'
12-
devices = 'cpu cuda'
12+
compute_devices = 'cpu cuda'
1313
max_parallel = 1 # schemadiff with multiple ranks
1414
recover = false
1515
[]
@@ -21,7 +21,7 @@
2121
ignored_items = "root['VTKFile']['@version']"
2222
requirement = 'MOOSE shall have the ability to solve an FE problem defined on an MFEM boundary restricted submesh.'
2323
capabilities = 'mfem'
24-
devices = 'cpu cuda'
24+
compute_devices = 'cpu cuda'
2525
max_parallel = 1 # schemadiff with multiple ranks
2626
recover = false
2727
[]
@@ -33,7 +33,7 @@
3333
ignored_items = "root['VTKFile']['@version']"
3434
requirement = 'MOOSE shall have the ability to transfer a domain restricted submesh variable data to a corresponding variable defined on the parent mesh.'
3535
capabilities = 'mfem'
36-
devices = 'cpu cuda'
36+
compute_devices = 'cpu cuda'
3737
max_parallel = 1 # schemadiff with multiple ranks
3838
recover = false
3939
[]

test/tests/mfem/transfers/h1_mfem_parent_mfem_sub/tests

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
type = RunApp
88
input = parent.i
99
capabilities = 'mfem'
10-
devices = 'cpu cuda'
10+
compute_devices = 'cpu cuda'
1111
recover = false
1212
detail = 'running the inputs, and '
1313
[]
@@ -30,7 +30,7 @@
3030
type = RunApp
3131
input = sub.i
3232
capabilities = 'mfem'
33-
devices = 'cpu cuda'
33+
compute_devices = 'cpu cuda'
3434
recover = false
3535
cli_args = 'MultiApps/active=subapp Transfers/active=to_sub '
3636
'subapp:MultiApps/active="" subapp:Transfers/active=""'

0 commit comments

Comments
 (0)