33from abc import ABC
44
55import cgen as c
6- import numpy as np
76
87from devito .data import FULL
98from devito .ir import (DummyExpr , Call , Conditional , Expression , List , Prodder ,
1312from devito .passes import is_on_device
1413from devito .passes .iet .engine import iet_pass
1514from devito .symbolics import Byref , CondNe , SizeOf
16- from devito . types . relational import Ge
15+ from sympy import Ge
1716from devito .tools import as_list , is_integer , prod
1817from devito .types import Symbol , QueueID , Wildcard
1918
@@ -63,7 +62,8 @@ def _get_num_devices(cls, platform):
6362 Get the number of accessible devices.
6463 Returns a tuple of (ngpus_symbol, call_to_get_num_devices).
6564 """
66- ngpus = Symbol (name = 'ngpus' , dtype = np .int32 )
65+ from devito .types import Symbol
66+ ngpus = Symbol (name = 'ngpus' , dtype = 'int32' )
6767 devicetype = as_list (cls [platform ])
6868 call_ngpus = cls ['num-devices' ](devicetype , retobj = ngpus )
6969 return ngpus , call_ngpus
@@ -434,22 +434,19 @@ def _make_setdevice_seq(iet, nodes=()):
434434
435435 # Add device validation check
436436 ngpus , call_ngpus = self .langbb ._get_num_devices (self .platform )
437-
438- # Create validation: if deviceid >= num_devices, print error and exit
439- validation_check = Conditional (
437+
438+ validation = Conditional (
440439 Ge (deviceid , ngpus ),
441440 List (body = [
442- Call ('printf' , ['"%s: Error - Requested device ID %d does not exist. '
443- 'Only %d device(s) available. Check CUDA_VISIBLE_DEVICES '
444- 'and container GPU configuration.\\ n"' ,
445- self .langbb ['name' ], deviceid , ngpus ]),
441+ Call ('printf' , ['"%s: Error - device %d >= %d devices\\ n"' ,
442+ self .langbb ['name' ], deviceid , ngpus ]),
446443 Call ('exit' , [1 ])
447444 ])
448445 )
449446
450447 device_setup = List (body = [
451448 call_ngpus ,
452- validation_check ,
449+ validation ,
453450 self .langbb ['set-device' ]([deviceid ] + devicetype )
454451 ])
455452
@@ -468,21 +465,19 @@ def _make_setdevice_mpi(iet, objcomm, nodes=()):
468465
469466 ngpus , call_ngpus = self .langbb ._get_num_devices (self .platform )
470467
471- # Add device validation check for explicit device ID
472- validation_check = Conditional (
468+ # Add device validation for explicit device ID
469+ validation = Conditional (
473470 Ge (deviceid , ngpus ),
474471 List (body = [
475- Call ('printf' , ['"%s: Error - Requested device ID %d does not exist. '
476- 'Only %d device(s) available. Check CUDA_VISIBLE_DEVICES '
477- 'and container GPU configuration.\\ n"' ,
478- self .langbb ['name' ], deviceid , ngpus ]),
472+ Call ('printf' , ['"%s: Error - device %d >= %d devices\\ n"' ,
473+ self .langbb ['name' ], deviceid , ngpus ]),
479474 Call ('exit' , [1 ])
480475 ])
481476 )
482477
483478 osdd_then = List (body = [
484479 call_ngpus ,
485- validation_check ,
480+ validation ,
486481 self .langbb ['set-device' ]([deviceid ] + devicetype )
487482 ])
488483 osdd_else = self .langbb ['set-device' ]([rank % ngpus ] + devicetype )
0 commit comments