Module tornado.api

Class TaskGraph

java.lang.Object
uk.ac.manchester.tornado.api.TaskGraph
All Implemented Interfaces:
TaskGraphInterface

public class TaskGraph extends Object implements TaskGraphInterface
Tornado Task Graph API.

Task-based parallel API to express methods to be accelerated on any OpenCL, PTX and/or SPIR-V compatible device.

Since:
v0.15
  • Field Details

  • Constructor Details

    • TaskGraph

      public TaskGraph(String name)
  • Method Details

    • addTask

      public TaskGraph addTask(TaskPackage taskPackage)
      It adds a task by using a TaskPackage.
      Specified by:
      addTask in interface TaskGraphInterface
      Parameters:
      taskPackage - TaskPackage
      Returns:
      invalid @link
      {@link @TaskGraph
      }
    • task

      public TaskGraph task(String id, TornadoFunctions.Task code)
      Adds task with no parameter.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with one argument
      Returns:
      TaskGraph
    • task

      public <T1> TaskGraph task(String id, TornadoFunctions.Task1<T1> code, T1 arg)
      Adds task with one parameter.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with one argument
      arg - Argument to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2> TaskGraph task(String id, TornadoFunctions.Task2<T1,T2> code, T1 arg1, T2 arg2)
      Adds task with two parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with two arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3> TaskGraph task(String id, TornadoFunctions.Task3<T1,T2,T3> code, T1 arg1, T2 arg2, T3 arg3)
      Add task with three parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with three arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4> TaskGraph task(String id, TornadoFunctions.Task4<T1,T2,T3,T4> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
      Adds task with four parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with four arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5> TaskGraph task(String id, TornadoFunctions.Task5<T1,T2,T3,T4,T5> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
      Adds task with five parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with five arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6> TaskGraph task(String id, TornadoFunctions.Task6<T1,T2,T3,T4,T5,T6> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
      Adds task with six parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with six arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7> TaskGraph task(String id, TornadoFunctions.Task7<T1,T2,T3,T4,T5,T6,T7> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7)
      Adds task with seven parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with seven arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7, T8> TaskGraph task(String id, TornadoFunctions.Task8<T1,T2,T3,T4,T5,T6,T7,T8> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8)
      Adds task with eight parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with eight arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      arg8 - Argument 8 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7, T8, T9> TaskGraph task(String id, TornadoFunctions.Task9<T1,T2,T3,T4,T5,T6,T7,T8,T9> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9)
      Adds task with nine parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with nine arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      arg8 - Argument 8 to the method
      arg9 - Argument 9 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> TaskGraph task(String id, TornadoFunctions.Task10<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10)
      Adds task with 10 parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with 10 arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      arg8 - Argument 8 to the method
      arg9 - Argument 9 to the method
      arg10 - Argument 10 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> TaskGraph task(String id, TornadoFunctions.Task11<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11)
      It creates a task with 11 parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with 10 arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      arg8 - Argument 8 to the method
      arg9 - Argument 9 to the method
      arg10 - Argument 10 to the method
      arg11 - Argument 11 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12> TaskGraph task(String id, TornadoFunctions.Task12<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12)
      It creates a task with 12 parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with 10 arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      arg8 - Argument 8 to the method
      arg9 - Argument 9 to the method
      arg10 - Argument 10 to the method
      arg11 - Argument 11 to the method
      arg12 - Argument 12 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13> TaskGraph task(String id, TornadoFunctions.Task13<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13)
      It creates a task with 13 parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with 10 arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      arg8 - Argument 8 to the method
      arg9 - Argument 9 to the method
      arg10 - Argument 10 to the method
      arg11 - Argument 11 to the method
      arg12 - Argument 12 to the method
      arg13 - Argument 13 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14> TaskGraph task(String id, TornadoFunctions.Task14<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14)
      It creates a task with 14 parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with 10 arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      arg8 - Argument 8 to the method
      arg9 - Argument 9 to the method
      arg10 - Argument 10 to the method
      arg11 - Argument 11 to the method
      arg12 - Argument 12 to the method
      arg13 - Argument 13 to the method
      arg14 - Argument 14 to the method
      Returns:
      TaskGraph
    • task

      public <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15> TaskGraph task(String id, TornadoFunctions.Task15<T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15> code, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6, T7 arg7, T8 arg8, T9 arg9, T10 arg10, T11 arg11, T12 arg12, T13 arg13, T14 arg14, T15 arg15)
      It creates a task with 15 parameters.
      Specified by:
      task in interface TaskGraphInterface
      Parameters:
      id - Task-id
      code - Reference to an existing Java method with 15 arguments
      arg1 - Argument 1 to the method
      arg2 - Argument 2 to the method
      arg3 - Argument 3 to the method
      arg4 - Argument 4 to the method
      arg5 - Argument 5 to the method
      arg6 - Argument 6 to the method
      arg7 - Argument 7 to the method
      arg8 - Argument 8 to the method
      arg9 - Argument 9 to the method
      arg10 - Argument 10 to the method
      arg11 - Argument 11 to the method
      arg12 - Argument 12 to the method
      arg13 - Argument 13 to the method
      arg14 - Argument 14 to the method
      arg15 - Argument 15 to the method
      Returns:
      TaskGraph
    • prebuiltTask

      public TaskGraph prebuiltTask(String id, String entryPoint, String filename, AccessorParameters accessorParameters)
      Specified by:
      prebuiltTask in interface TaskGraphInterface
      Parameters:
      id - String that represents the task-id.
      entryPoint - Name of the kernel to be launched on the target device.
      filename - String that represents the path to the native source (e.g., the OpenCL C kernel).
      accessorParameters - AccessorParameters with the type of accessor for each of the input parameters to the low-level kernel.
      Returns:
      TaskGraph
    • prebuiltTask

      public TaskGraph prebuiltTask(String id, String entryPoint, String filename, AccessorParameters accessorParameters, int[] atomics)
      Add a pre-built OpenCL task into a task-schedule with atomics region.
      Specified by:
      prebuiltTask in interface TaskGraphInterface
      Parameters:
      id - Task-id
      entryPoint - Kernel's name of the entry point
      filename - Input OpenCL C Kernel
      accessorParameters - AccessorParameters with the type of accessor for each of the input parameters to the low-level kernel.
      atomics - Atomics region.
      Returns:
      TaskGraph
    • getTaskGraphName

      public String getTaskGraphName()
      Obtains the task-schedule name that was assigned.
      Specified by:
      getTaskGraphName in interface TaskGraphInterface
      Returns:
      String
    • transferToDevice

      public TaskGraph transferToDevice(int mode, Object... objects)
      Tag a set of objects (Java objects) to be transferred to the device. There are three modes:

      DataTransferMode.FIRST_EXECUTION: it transfers data only the first execution of the task-graph (READ ONLY)

      DataTransferMode.EVERY_EXECUTION: it transfers data for every execution of the task-graph (READ/WRITE)

      Specified by:
      transferToDevice in interface TaskGraphInterface
      Parameters:
      mode - A mode from DataTransferMode
      objects - List of Java objects (usually arrays) to be transferred to the device.
      Returns:
      TaskGraph
    • consumeFromDevice

      public TaskGraph consumeFromDevice(String uniqueTaskGraphName, Object... objects)
      Tag a set of objects to be used directly from the device. It requires objects to be tagged as persisted objects from a previous taskgraph. This method ensures that the specified objects are consumed from the device and are not copied from the host.
      Specified by:
      consumeFromDevice in interface TaskGraphInterface
      Parameters:
      uniqueTaskGraphName - A unique identifier for the task graph.
      objects - List of Java objects (usually arrays) to be consumed from the device.
      Returns:
      TaskGraph
    • consumeFromDevice

      public TaskGraph consumeFromDevice(Object... objects)
      Specified by:
      consumeFromDevice in interface TaskGraphInterface
    • transferToHost

      public TaskGraph transferToHost(int mode, Object... objects)
      Tag a set of objects (Java objects) to be transferred from the device to the host after the execution completes. There are two modes:

      DataTransferMode.EVERY_EXECUTION: transfers data for every execution of the task-graph (WRITE only)

      DataTransferMode.UNDER_DEMAND: it transfers data only under demand. Data are not transferred unless the execution-plan, an TornadoExecutionPlan object, invokes the `transferToHost` function. This is used for optimization of data transfers.

      Specified by:
      transferToHost in interface TaskGraphInterface
      Parameters:
      mode - A mode from DataTransferMode
      objects - List of Java objects (usually arrays) to be transferred to the device.
      Returns:
      TaskGraph
    • persistOnDevice

      public TaskGraph persistOnDevice(Object... objects)
      Tags a set of objects to persist on the device without transferring them back to the host after execution.

      This method marks the objects as available on the device for future taskGraph executions without redundant data transfers. Data is not transferred to the host unless explicitly requested via the execution plan.

      Specified by:
      persistOnDevice in interface TaskGraphInterface
      Parameters:
      objects - List of Java objects (usually arrays) to persist on the device.
      Returns:
      TaskGraph
    • snapshot

      public ImmutableTaskGraph snapshot()
      Function that closes a task-graph definition and creates an immutable task-graph ready for execution.
      Specified by:
      snapshot in interface TaskGraphInterface
      Returns:
      ImmutableTaskGraph
    • getArgumentsLookup

      public Set<Object> getArgumentsLookup()
    • getProfileLog

      protected String getProfileLog()
    • getOutputs

      public Collection<?> getOutputs()
    • isGridRegistered

      public boolean isGridRegistered()