Skip to content

Commit 1e7497a

Browse files
committed
Improve error message for invalid accelerator resource
Signed-off-by: Ben Sherman <[email protected]>
1 parent 064ef34 commit 1e7497a

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

docs/reference/process.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ The following options are available for all process outputs:
290290

291291
### accelerator
292292

293-
:::{versionadded} 19.09.0-edge
294-
:::
295-
296293
The `accelerator` directive allows you to request hardware accelerators (e.g. GPUs) for the task execution. For example:
297294

298295
```nextflow
@@ -313,17 +310,23 @@ This directive is only used by certain executors. Refer to the {ref}`executor-pa
313310
:::
314311

315312
:::{note}
316-
Additional options may be required to fully enable the use of accelerators. When using containers with GPUs, you must pass the GPU drivers through to the container. For Docker, this requires the option `--gpus all` in the docker run command. For Apptainer/Singularity, this requires the option `--nv`. The specific implementation details depend on the accelerator and container type being used.
313+
Additional options may be required to fully enable the use of accelerators. When using containers with GPUs, you must pass the GPU drivers through to the container. For Docker, this requires the option `--gpus all` in the `docker run` command. For Apptainer/Singularity, this requires the option `--nv`. The specific implementation details depend on the accelerator and container type being used.
317314
:::
318315

319-
:::{note}
320-
The accelerator `type` option depends on the target execution platform. Refer to the platform-specific documentation for details on the available accelerators:
316+
The following options are available:
321317

322-
- [Google Cloud](https://cloud.google.com/compute/docs/gpus/)
323-
- [Kubernetes](https://kubernetes.io/docs/tasks/manage-gpus/scheduling-gpus/#clusters-containing-different-types-of-gpus)
318+
`request: Integer`
319+
: The number of requested accelerators.
320+
: Specifying this directive with a number (e.g. `accelerator 4`) is equivalent to the `request` option (e.g. `accelerator request: 4`).
324321

325-
The accelerator `type` option is not supported for AWS Batch. You can control the accelerator type indirectly through the allowed instance types in your Compute Environment. See the [AWS Batch FAQs](https://aws.amazon.com/batch/faqs/?#GPU_Scheduling_) for more information.
326-
:::
322+
`type: String`
323+
: The accelerator type.
324+
: The meaning of this option depends on the target execution platform. Refer to the platform-specific documentation for details on the available accelerators:
325+
326+
- [Google Cloud](https://cloud.google.com/compute/docs/gpus/)
327+
- [Kubernetes](https://kubernetes.io/docs/tasks/manage-gpus/scheduling-gpus/#clusters-containing-different-types-of-gpus)
328+
329+
: This option is not supported for AWS Batch. You can control the accelerator type indirectly through the allowed instance types in your Compute Environment. See the [AWS Batch FAQs](https://aws.amazon.com/batch/faqs/?#GPU_Scheduling_) for more information.
327330

328331
(process-afterscript)=
329332

modules/nextflow/src/main/groovy/nextflow/executor/res/AcceleratorResource.groovy

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,20 @@ class AcceleratorResource {
4040
}
4141

4242
AcceleratorResource( Map res ) {
43-
if( res.limit!=null && res.request!=null ) {
43+
if( res.limit != null && res.request != null ) {
4444
this.limit = res.limit as int
4545
this.request = res.request as int
4646
}
47-
else if( res.limit!=null ) {
47+
else if( res.limit != null ) {
4848
this.limit = res.limit as int
4949
this.request = res.limit as int
5050
}
5151
else if( res.request != null ) {
5252
this.request = res.request as int
5353
}
54+
else {
55+
throw new IllegalArgumentException("Invalid `accelerator` directive value -- `request` or `limit` is required: $res")
56+
}
5457

5558
if( res.type )
5659
this.type = res.type as String

modules/nextflow/src/test/groovy/nextflow/executor/res/AcceleratorResourceTest.groovy

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import spock.lang.Specification
2424
*/
2525
class AcceleratorResourceTest extends Specification {
2626

27-
def 'should create a gpu resource' () {
27+
def 'should create an accelerator resource' () {
2828

2929
when:
3030
def acc = new AcceleratorResource(VALUE)
@@ -46,4 +46,12 @@ class AcceleratorResourceTest extends Specification {
4646
[limit: 3, type: 'nvidia'] | 3 | 3 | 'nvidia' | null
4747
[limit: 3, runtime: 'foo'] | 3 | 3 | null | 'foo'
4848
}
49+
50+
def 'should throw error for invalid resource' () {
51+
when:
52+
def acc = new AcceleratorResource([count: 1, type: 'nvidia-tesla-t4'])
53+
then:
54+
def err = thrown(IllegalArgumentException)
55+
err.message.contains('Invalid `accelerator` directive value -- `request` or `limit` is required')
56+
}
4957
}

0 commit comments

Comments
 (0)