code: def BlackHoleCUDA(zImage, fImage, InputCL):
      Device = InputCL["Device"]
      Mass = InputCL["Mass"]
      InternalRadius = InputCL["InternalRadius"]
      ExternalRadius = InputCL["ExternalRadius"]
      Angle = InputCL["Angle"]
      Method = InputCL["Method"]
      TrackPoints = InputCL["TrackPoints"]
      Physics = InputCL["Physics"]
      Threads = InputCL["Threads"]
  
      PhysicsList = DictionariesAPI()
  
      if InputCL["BlackBody"]:
          # Spectrum is Black Body one
          Line = 0
      else:
          # Spectrum is Monochromatic Line one
          Line = 1
  
      Trajectories = numpy.zeros(
          (int(InputCL["Size"] / 2), InputCL["TrackPoints"]),
          dtype=numpy.float32,
      )
      IdLast = numpy.zeros(int(InputCL["Size"] / 2), dtype=numpy.int32)
  
      try:
          # For PyCUDA import
          import pycuda.driver as cuda
          from pycuda.compiler import SourceModule
  
          cuda.init()
          for Id in range(cuda.Device.count()):
              if Id == Device:
                  XPU = cuda.Device(Id)
                  print("GPU selected %s" % XPU.name())
          print
  
      except ImportError:
          print("Platform does not seem to support CUDA")
  
      Context = XPU.make_context()
  
      try:
          mod = SourceModule(
              KernelCodeCuda(),
              options=[
                  "--compiler-options",
                  "-DPHYSICS=%i -DSETTRACKPOINTS=%i"
                  % (PhysicsList[Physics], TrackPoints),
              ],
          )
          print("Compilation seems to be OK")
      except Exception:
          print("Compilation seems to break")
  
      EachPixelCU = mod.get_function("EachPixel")
      OriginalCU = mod.get_function("Original")
      EachCircleCU = mod.get_function("EachCircle")
      TrajectoryCU = mod.get_function("Trajectory")
      PixelCU = mod.get_function("Pixel")
      CircleCU = mod.get_function("Circle")
  
      TrajectoriesCU = cuda.mem_alloc(
          Trajectories.size * Trajectories.dtype.itemsize
      )
      cuda.memcpy_htod(TrajectoriesCU, Trajectories)
      zImageCU = cuda.mem_alloc(zImage.size * zImage.dtype.itemsize)
      cuda.memcpy_htod(zImageCU, zImage)
      fImageCU = cuda.mem_alloc(fImage.size * fImage.dtype.itemsize)
      cuda.memcpy_htod(zImageCU, fImage)
      IdLastCU = cuda.mem_alloc(IdLast.size * IdLast.dtype.itemsize)
      cuda.memcpy_htod(IdLastCU, IdLast)
  
      start_time = time.time()
  
      if Method == "EachPixel":
          EachPixelCU(
              zImageCU,
              fImageCU,
              numpy.float32(Mass),
              numpy.float32(InternalRadius),
              numpy.float32(ExternalRadius),
              numpy.float32(Angle),
              numpy.int32(Line),
              grid=(
                  int(zImage.shape[0] / Threads),
                  int(zImage.shape[1] / Threads),
              ),
              block=(Threads, Threads, 1),
          )
      elif Method == "EachCircle":
          EachCircleCU(
              zImageCU,
              fImageCU,
              numpy.float32(Mass),
              numpy.float32(InternalRadius),
              numpy.float32(ExternalRadius),
              numpy.float32(Angle),
              numpy.int32(Line),
              grid=(int(zImage.shape[0] / Threads / 2), 1),
              block=(Threads, 1, 1),
          )
      elif Method == "Original":
          OriginalCU(
              zImageCU,
              fImageCU,
              numpy.uint32(zImage.shape[0] / 2),
              numpy.float32(Mass),
              numpy.float32(InternalRadius),
              numpy.float32(ExternalRadius),
              numpy.float32(Angle),
              numpy.int32(Line),
              grid=(1, 1),
              block=(1, 1, 1),
          )
      elif Method == "TrajectoCircle":
          TrajectoryCU(
              TrajectoriesCU,
              IdLastCU,
              numpy.float32(Mass),
              numpy.float32(InternalRadius),
              numpy.float32(ExternalRadius),
              numpy.float32(Angle),
              numpy.int32(Line),
              grid=(int(Trajectories.shape[0] / Threads), 1),
              block=(Threads, 1, 1),
          )
  
          CircleCU(
              TrajectoriesCU,
              IdLastCU,
              zImageCU,
              fImageCU,
              numpy.float32(Mass),
              numpy.float32(InternalRadius),
              numpy.float32(ExternalRadius),
              numpy.float32(Angle),
              numpy.int32(Line),
              grid=(
                  int(Trajectories.shape[0] / Threads),
                  int(zImage.shape[0] * 4 / Threads),
              ),
              block=(Threads, Threads, 1),
          )
      else:
          # Default method: TrajectoPixel
          TrajectoryCU(
              TrajectoriesCU,
              IdLastCU,
              numpy.float32(Mass),
              numpy.float32(InternalRadius),
              numpy.float32(ExternalRadius),
              numpy.float32(Angle),
              numpy.int32(Line),
              grid=(int(Trajectories.shape[0] / Threads), 1),
              block=(Threads, 1, 1),
          )
  
          PixelCU(
              zImageCU,
              fImageCU,
              TrajectoriesCU,
              IdLastCU,
              numpy.uint32(Trajectories.shape[0]),
              numpy.float32(Mass),
              numpy.float32(InternalRadius),
              numpy.float32(ExternalRadius),
              numpy.float32(Angle),
              numpy.int32(Line),
              grid=(
                  int(zImage.shape[0] / Threads),
                  int(zImage.shape[1] / Threads),
                  1,
              ),
              block=(Threads, Threads, 1),
          )
  
      Context.synchronize()
  
      compute = time.time() - start_time
  
      cuda.memcpy_dtoh(zImage, zImageCU)
      cuda.memcpy_dtoh(fImage, fImageCU)
      if Method == "TrajectoPixel" or Method == "TrajectoCircle":
          cuda.memcpy_dtoh(Trajectories, TrajectoriesCU)
      elapsed = time.time() - start_time
      print("\nCompute Time : %f" % compute)
      print("Elapsed Time : %f\n" % elapsed)
  
      zMaxPosition = numpy.where(zImage[:, :] == zImage.max())
      fMaxPosition = numpy.where(fImage[:, :] == fImage.max())
      print(
          "Z max @(%f,%f) : %f"
          % (
              (
                  1.0 * zMaxPosition[1][0] / zImage.shape[1] - 0.5,
                  1.0 * zMaxPosition[0][0] / zImage.shape[0] - 0.5,
                  zImage.max(),
              )
          )
      )
      print(
          "Flux max @(%f,%f) : %f"
          % (
              (
                  1.0 * fMaxPosition[1][0] / fImage.shape[1] - 0.5,
                  1.0 * fMaxPosition[0][0] / fImage.shape[0] - 0.5,
                  fImage.max(),
              )
          )
      )
  
      Context.pop()
  
      Context.detach()
  
      if Method == "TrajectoPixel" or Method == "TrajectoCircle":
          if not NoImage:
              AngleStep = 4 * numpy.pi / TrackPoints
              Angles = numpy.arange(0.0, 4 * numpy.pi, AngleStep)
              Angles.shape = (1, TrackPoints)
  
              # numpy.savetxt("TrouNoirTrajectories_%s.csv" % ImageInfo,
              #               numpy.transpose(numpy.concatenate((Angles,Trajectories),axis=0)),
              #               delimiter=' ', fmt='%.2e')
              numpy.savetxt(
                  "TrouNoirTrajectories.csv",
                  numpy.transpose(
                      numpy.concatenate((Angles, Trajectories), axis=0)
                  ),
                  delimiter=" ",
                  fmt="%.2e",
              )
  
      return elapsed
  
file_path: pyopencl/examples/black-hole-accretion.py
imports: import pyopencl
  import numpy
  import time
  import sys
  import getopt
  from socket import gethostname
label_desc: Use image node_id 5 for calling a global function with example usage: BlackHoleCUDA(zImage, fImage, InputCL) and returns: elapsed