code: def _test_gpu_info(device="cpu"):
      gpu_info = GpuInfo()
  
      # increase code cov
      gpu_info.reset()
      gpu_info.update(None)
  
      t = torch.rand(4, 10, 100, 100).to(device)
      data = gpu_info.compute()
      assert len(data) > 0
      assert "fb_memory_usage" in data[0]
      mem_report = data[0]["fb_memory_usage"]
      assert "used" in mem_report and "total" in mem_report
      assert mem_report["total"] > 0.0
      assert (
          mem_report["used"]
          > t.shape[0]
          * t.shape[1]
          * t.shape[2]
          * t.shape[3]
          / 1024.0
          / 1024.0
      )
  
      assert "utilization" in data[0]
      util_report = data[0]["utilization"]
      assert "gpu_util" in util_report
  
      # with Engine
      engine = Engine(lambda engine, batch: 0.0)
      engine.state = State(metrics={})
  
      gpu_info.completed(engine, name="gpu")
  
      assert "gpu:0 mem(%)" in engine.state.metrics
  
      assert isinstance(engine.state.metrics["gpu:0 mem(%)"], int)
      assert (
          int(mem_report["used"] * 100.0 / mem_report["total"])
          == engine.state.metrics["gpu:0 mem(%)"]
      )
  
      if util_report["gpu_util"] != "N/A":
          assert "gpu:0 util(%)" in engine.state.metrics
          assert isinstance(engine.state.metrics["gpu:0 util(%)"], int)
          assert (
              int(util_report["gpu_util"])
              == engine.state.metrics["gpu:0 util(%)"]
          )
      else:
          assert "gpu:0 util(%)" not in engine.state.metrics
  
file_path: ignite/tests/ignite/contrib/metrics/test_gpu_info.py
imports: from unittest.mock import Mock, patch
  import pytest
  import torch
  from ignite.contrib.metrics import GpuInfo
  from ignite.engine import Engine, State
label_desc: Use image node_id 3 for calling a global function with example usage: _test_gpu_info(device) without return types