Browse Source

julia: Add support for tags and an example.

Pierre Huchant 5 years ago
parent
commit
7a12408f7b

+ 2 - 0
julia/examples/Makefile.am

@@ -96,3 +96,5 @@ SHELL_TESTS			+=	mandelbrot/mandelbrot.sh
 STARPU_JULIA_EXAMPLES		+= callback/callback
 callback_callback_SOURCES	=	callback/callback.c
 SHELL_TESTS			+=	callback/callback.sh
+
+SHELL_TESTS			+=	dependency/sequential_consistency.sh

+ 118 - 0
julia/examples/dependency/sequential_consistency.jl

@@ -0,0 +1,118 @@
+# StarPU --- Runtime system for heterogeneous multicore architectures.
+#
+# Copyright (C) 2020       Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
+#
+# StarPU is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or (at
+# your option) any later version.
+#
+# StarPU is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# See the GNU Lesser General Public License in COPYING.LGPL for more details.
+#
+using StarPU
+
+@target STARPU_CPU
+@codelet function codeletA(val ::Ref{Int32}) :: Nothing
+    # print("[Task A] Value = ", val[]);
+    val[] = val[] * 2
+end
+
+function callbackA(arg)
+    clB = arg[1]
+    handle = arg[2]
+    tagHoldC = arg[3]
+
+    taskB = starpu_task(cl = clB, handles = [handle],
+                        callback = starpu_tag_notify_from_apps,
+                        callback_arg = tagHoldC,
+                        sequential_consistency=false)
+
+    starpu_task_submit(taskB)
+end
+
+@target STARPU_CPU
+@codelet function codeletB(val ::Ref{Int32}) :: Nothing
+    # println("[Task B] Value = ", val[]);
+    val[] = val[] +1
+end
+
+@target STARPU_CPU
+@codelet function codeletC(val ::Ref{Int32}) :: Nothing
+    # println("[Task C] Value = ", val[]);
+    val[] = val[] *2
+end
+
+
+# Submit taskA and hold it
+# Submit taskC and hold it
+# Release taskA
+# Execute taskA       --> callback: submit taskB
+# Execute taskB       --> callback: release taskC
+#
+# All three tasks use the same data in RW, taskB is submitted after
+# taskC, so taskB should normally only execute after taskC but as the
+# sequential consistency for (taskB, data) is unset, taskB can
+# execute straightaway
+function main()
+    value = Ref(Int32(12))
+
+    @starpu_block let
+    tagHoldA :: starpu_tag_t = 32
+    tagHoldC :: starpu_tag_t = 84
+    tagA :: starpu_tag_t = 421
+    tagC :: starpu_tag_t = 842
+
+    starpu_tag_declare_deps(tagA, tagHoldA)
+    starpu_tag_declare_deps(tagC, tagHoldC)
+
+    perfmodel = starpu_perfmodel(
+        perf_type = starpu_perfmodel_type(STARPU_HISTORY_BASED),
+        symbol = "history_perf"
+    )
+
+        clA = starpu_codelet(
+            cpu_func = CPU_CODELETS["codeletA"],
+            modes = [STARPU_RW],
+            perfmodel = perfmodel
+        )
+        clB = starpu_codelet(
+            cpu_func = CPU_CODELETS["codeletB"],
+            modes = [STARPU_RW],
+            perfmodel = perfmodel
+        )
+        clC = starpu_codelet(
+            cpu_func = CPU_CODELETS["codeletC"],
+            modes = [STARPU_RW],
+            perfmodel = perfmodel
+        )
+
+        handle = starpu_data_register(value)
+
+        taskA = starpu_task(cl = clA, handles = [handle], tag = tagA,
+                            callback = callbackA,
+                            callback_arg=(clB, handle, tagHoldC))
+        starpu_task_submit(taskA)
+
+        taskC = starpu_task(cl = clC, handles = [handle], tag = tagC)
+        starpu_task_submit(taskC)
+
+        # Release taskA (we want to make sure it will execute after taskC has been submitted)
+        starpu_tag_notify_from_apps(tagHoldA)
+
+        starpu_task_wait_for_all()
+    end
+
+    if value[] != 50
+        error("Incorrect value $(value[]) (expected 50)")
+    end
+
+    println("Value = ", value[])
+end
+
+starpu_init()
+main()
+starpu_shutdown()

+ 18 - 0
julia/examples/dependency/sequential_consistency.sh

@@ -0,0 +1,18 @@
+#!/bin/bash
+# StarPU --- Runtime system for heterogeneous multicore architectures.
+#
+# Copyright (C) 2020       Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
+#
+# StarPU is free software; you can redistribute it and/or modify
+# it under the terms of the GNU Lesser General Public License as published by
+# the Free Software Foundation; either version 2.1 of the License, or (at
+# your option) any later version.
+#
+# StarPU is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+#
+# See the GNU Lesser General Public License in COPYING.LGPL for more details.
+#
+
+$(dirname $0)/../execute.sh dependency/sequential_consistency.jl

+ 2 - 1
julia/src/StarPU.jl

@@ -20,7 +20,6 @@ module StarPU
 import Libdl
 using CBinding
 
-
 include("utils.jl")
 
 const starpu_wrapper_library_name=fstarpu_task_library_name()
@@ -67,10 +66,12 @@ export @starpu_filter
 export STARPU_PERFMODEL_INVALID, STARPU_PER_ARCH, STARPU_COMMON
 export STARPU_HISTORY_BASED, STARPU_REGRESSION_BASED
 export STARPU_NL_REGRESSION_BASED, STARPU_MULTIPLE_REGRESSION_BASED
+export starpu_tag_t
 export starpu_task_declare_deps
 export starpu_task_wait_for_n_submitted
 export starpu_task_destroy
 export starpu_tag_wait
+export starpu_tag_notify_from_apps
 export starpu_iteration_pop
 export starpu_iteration_push
 export starpu_tag_declare_deps

+ 8 - 1
julia/src/task.jl

@@ -91,7 +91,8 @@ task_list = Vector{jl_starpu_task}()
             Creates a new task which will run the specified codelet on handle buffers and cl_args data
         """
 function starpu_task(; cl :: Union{Cvoid, jl_starpu_codelet} = nothing, handles :: Vector{StarpuDataHandle} = StarpuDataHandle[], cl_arg = (),
-                     callback :: Union{Cvoid, Function} = nothing, callback_arg = nothing)
+                     callback :: Union{Cvoid, Function} = nothing, callback_arg = nothing, tag :: Union{Cvoid, starpu_tag_t} = nothing,
+                     sequential_consistency = true)
     if (cl == nothing)
         error("\"cl\" field can't be empty when creating a StarpuTask")
     end
@@ -124,6 +125,7 @@ function starpu_task(; cl :: Union{Cvoid, jl_starpu_codelet} = nothing, handles
     starpu_task_init(Ref(output.c_task))
     output.c_task.cl = pointer_from_objref(cl.c_codelet)
     output.c_task.synchronous = false
+    output.c_task.sequential_consistency = sequential_consistency
 
     ## TODO: check num handles equals num codelet buffers
     for i in 1:length(handles)
@@ -141,6 +143,11 @@ function starpu_task(; cl :: Union{Cvoid, jl_starpu_codelet} = nothing, handles
         output.c_task.callback_func = load_wrapper_function_pointer("julia_callback_func")
     end
 
+    if tag != nothing
+        output.c_task.tag_id = tag
+        output.c_task.use_tag = 1
+    end
+
     # Tasks must not be garbage collected before starpu_task_wait_for_all is called.
     # This is necessary in particular for tasks created inside callback functions.
     lock(mutex)

+ 1 - 0
julia/src/translate_headers.jl

@@ -63,6 +63,7 @@ function translate_starpu_headers()
                                "starpu_task_wait_for_n_submitted",
                                "starpu_tag_wait",
                                "starpu_tag_declare_deps_array",
+                               "starpu_tag_notify_from_apps",
                                "starpu_task_declare_deps_array",
                                "starpu_iteration_push",
                                "starpu_iteration_pop",