Add EvalContext tracking to Invocation to prevent silent device switching by jantonguirao · Pull Request #6090 · NVIDIA/DALI

greptile-apps[bot]

greptile-apps[bot]

mzient

greptile-apps[bot]

greptile-apps[bot]

greptile-apps[bot]

greptile-apps[bot]

greptile-apps[bot]

greptile-apps[bot]

…itching

Store the device context when creating an Invocation and validate that
the evaluation context uses the same device. This prevents that operations
created in one device context (e.g., with Device('gpu:1'))
could silently execute on a different device when evaluated with a
different EvalContext.

Changes:
- Invocation now captures Device.current() at creation time
- Invocation.run() validates device match and raises RuntimeError with
  a clear error message if devices don't match
- Added comprehensive tests for device mismatch detection

Fixes issue where:
  with ndd.Device('gpu:1'):
    result = ndd.resize(img, size=[224, 224])
  with ndd.EvalContext(device_id=0):
    result.evaluate()  # Now raises clear error instead of silent failure

Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>
Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>
Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>
…ndling

- Change default EvalContext from global singleton to per-device instances
- Delegate device context management to Device class __enter__/__exit__
- Fix Tensor/Batch.to_device() to use source device context for to-CPU copies
- Relax device validation to only check GPU device mismatches in Invocation.run()
- Simplify test code to work with new context behavior

Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>
Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>

greptile-apps[bot]

@jantonguirao

Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>

greptile-apps[bot]

github-advanced-security[bot]

greptile-apps[bot]

@jantonguirao

…ation was captured, not when it was evaluated

Signed-off-by: Joaquin Anton Guirao <janton@nvidia.com>

greptile-apps[bot]