code: def _get_window_grid_kernel3d(
      d: int, h: int, w: int, device: torch.device = torch.device("cpu")
  ) -> Tensor:
      r"""Helper function, which generates a kernel to return coordinates, residual to window center.
  
      Args:
          d: kernel depth.
          h: kernel height.
          w: kernel width.
          device: device, on which generate.
  
      Returns:
          conv_kernel [3x1xdxhxw]
      """
      grid2d = create_meshgrid(h, w, True, device=device)
      if d > 1:
          z = torch.linspace(-1, 1, d, device=device).view(d, 1, 1, 1)
      else:  # only onr channel with index == 0
          z = zeros(1, 1, 1, 1, device=device)
      grid3d = concatenate(
          [
              z.repeat(1, h, w, 1).contiguous(),
              grid2d.repeat(d, 1, 1, 1),
          ],
          3,
      )
      conv_kernel = grid3d.permute(3, 0, 1, 2).unsqueeze(1)
      return conv_kernel
  
imports: from __future__ import annotations
  import torch
  import torch.nn.functional
  from kornia.core import Module, Tensor, concatenate, rand, stack, tensor, where, zeros, zeros_like
  from kornia.filters.sobel import spatial_gradient3d
  from kornia.geometry.conversions import normalize_pixel_coordinates, normalize_pixel_coordinates3d
  from kornia.utils import create_meshgrid, create_meshgrid3d
  from kornia.utils._compat import torch_version_ge
  from kornia.utils.helpers import safe_solve_with_mask
  from .dsnt import spatial_expectation2d, spatial_softmax2d
  from .nms import nms3d
label_desc: Use image node_id 4 for calling a global function with example usage: _get_window_grid_kernel3d(d, h, w, device) and returns: conv_kernel