Browse Source

julia: Simplify codelet declarations.

Pierre Huchant 5 years ago
parent
commit
8e4dfa48fa

+ 2 - 2
julia/examples/axpy/axpy.jl

@@ -47,8 +47,8 @@ function axpy(N, NBLOCKS, alpha, display = true)
     )
 
     cl = starpu_codelet(
-        cpu_func = CPU_CODELETS["axpy"],
-        cuda_func = CUDA_CODELETS["axpy"],
+        cpu_func = "axpy",
+        cuda_func = "axpy",
         #cuda_func = STARPU_SAXPY,
         modes = [STARPU_R, STARPU_RW],
         perfmodel = perfmodel

+ 1 - 3
julia/examples/callback/callback.jl

@@ -37,9 +37,7 @@ function variable_with_starpu(val ::Ref{Int32})
     )
 
     cl = starpu_codelet(
-        cpu_func = CPU_CODELETS["variable"],
-        # cuda_func = CUDA_CODELETS["matrix_mult"],
-        #opencl_func="ocl_matrix_mult",
+        cpu_func = "variable",
         modes = [STARPU_RW],
         perfmodel = perfmodel
     )

+ 6 - 6
julia/examples/cholesky/cholesky.jl

@@ -75,23 +75,23 @@ function cholesky(mat :: Matrix{Float32}, size, nblocks)
         symbol = "history_perf"
     )
     cl_11 = starpu_codelet(
-        cpu_func = CPU_CODELETS["u11"],
+        cpu_func = "u11",
         # This kernel cannot be translated to CUDA yet.
-        # cuda_func = CUDA_CODELETS["u11"],
+        # cuda_func = "u11",
         modes = [STARPU_RW],
         color = 0xffff00,
         perfmodel = perfmodel
     )
     cl_21 = starpu_codelet(
-        cpu_func = CPU_CODELETS["u21"],
-        # cuda_func = CUDA_CODELETS["u21"],
+        cpu_func = "u21",
+        # cuda_func = "u21",
         modes = [STARPU_R, STARPU_RW],
         color = 0x8080ff,
         perfmodel = perfmodel
     )
     cl_22 = starpu_codelet(
-        cpu_func = CPU_CODELETS["u22"],
-        # cuda_func = CUDA_CODELETS["u22"],
+        cpu_func = "u22",
+        # cuda_func = "u22",
         modes = [STARPU_R, STARPU_R, STARPU_RW],
         color = 0x00ff00,
         perfmodel = perfmodel

+ 3 - 3
julia/examples/dependency/end_dep.jl

@@ -53,16 +53,16 @@ function main()
         )
 
         clA = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletA"],
+            cpu_func = "codeletA",
             perfmodel = perfmodel
         )
         clB = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletB"],
+            cpu_func = "codeletB",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )
         clC = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletC"],
+            cpu_func = "codeletC",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )

+ 3 - 3
julia/examples/dependency/tag_dep.jl

@@ -75,17 +75,17 @@ function main()
     )
 
         clA = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletA"],
+            cpu_func = "codeletA",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )
         clB = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletB"],
+            cpu_func = "codeletB",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )
         clC = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletC"],
+            cpu_func = "codeletC",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )

+ 3 - 3
julia/examples/dependency/task_dep.jl

@@ -43,17 +43,17 @@ function main()
         )
 
         clA = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletA"],
+            cpu_func = "codeletA",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )
         clB = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletB"],
+            cpu_func = "codeletB",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )
         clC = starpu_codelet(
-            cpu_func = CPU_CODELETS["codeletC"],
+            cpu_func = "codeletC",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )

+ 2 - 2
julia/examples/gemm/gemm.jl

@@ -45,8 +45,8 @@ function multiply_with_starpu(A :: Matrix{Float32}, B :: Matrix{Float32}, C :: M
             symbol = "history_perf"
         )
         cl = starpu_codelet(
-            cpu_func = CPU_CODELETS["gemm"],
-            cuda_func = CUDA_CODELETS["gemm"],
+            cpu_func = "gemm",
+            cuda_func = "gemm",
             modes = [STARPU_R, STARPU_R, STARPU_RW],
             perfmodel = perfmodel
         )

+ 1 - 1
julia/examples/mandelbrot/cpu_mandelbrot.c

@@ -71,7 +71,7 @@ void cpu_mandelbrot(void *descr[], void *cl_arg)
 }
 
 char* CPU = "cpu_mandelbrot";
-char* GPU = "gpu_mandelbrot";
+char* GPU = "";
 extern char *starpu_find_function(char *name, char *device)
 {
 	if (!strcmp(device,"gpu")) return GPU;

+ 1 - 1
julia/examples/mult/cpu_mult.c

@@ -93,7 +93,7 @@ void cpu_mult(void *descr[], void *cl_arg)
 }
 
 char* CPU = "cpu_mult";
-char* GPU = "gpu_mult";
+char* GPU = "";
 extern char *starpu_find_function(char *name, char *device)
 {
 	if (!strcmp(device,"gpu")) return GPU;

+ 3 - 3
julia/examples/mult/mult.jl

@@ -87,9 +87,9 @@ function multiply_with_starpu(A :: Matrix{Float32}, B :: Matrix{Float32}, C :: M
             symbol = "history_perf"
         )
         cl = starpu_codelet(
-            cpu_func = CPU_CODELETS["matrix_mult"],
-            # cuda_func = CUDA_CODELETS["matrix_mult"],
-            #opencl_func="ocl_matrix_mult",
+            cpu_func = "matrix_mult",
+            cuda_func = "matrix_mult",
+            #opencl_func="matrix_mult",
             modes = [STARPU_R, STARPU_R, STARPU_W],
             perfmodel = perfmodel
         )

+ 2 - 2
julia/examples/task_insert_color/task_insert_color.jl

@@ -35,13 +35,13 @@ function task_insert_color_with_starpu(val ::Ref{Int32})
         )
 
         cl1 = starpu_codelet(
-            cpu_func = CPU_CODELETS["task_insert_color"],
+            cpu_func = "task_insert_color",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )
 
         cl2 = starpu_codelet(
-            cpu_func = CPU_CODELETS["task_insert_color"],
+            cpu_func = "task_insert_color",
             modes = [STARPU_RW],
             perfmodel = perfmodel,
             color = 0x0000FF

+ 3 - 3
julia/examples/vector_scal/vector_scal.jl

@@ -41,9 +41,9 @@ function vector_scal_with_starpu(v :: Vector{Float32}, m :: Int32, k :: Float32,
             symbol = "history_perf"
         )
         cl = starpu_codelet(
-            cpu_func = CPU_CODELETS["vector_scal"],
-            # cuda_func = CUDA_CODELETS["vector_scal"],
-            #opencl_func="ocl_matrix_mult",
+            cpu_func = "vector_scal",
+            # cuda_func = "vector_scal",
+            #opencl_func="",
             modes = [STARPU_RW],
             perfmodel = perfmodel
         )

+ 3 - 3
julia/src/compiler/c.jl

@@ -80,9 +80,9 @@ function transform_to_cpu_kernel(expr :: StarpuExprFunction)
     return output
 end
 
-function generate_c_struct_param_declaration(funcname)
-    scalar_parameters = CODELETS_SCALARS[funcname]
-    struct_params_name = CODELETS_PARAMS_STRUCT[funcname]
+function generate_c_struct_param_declaration(codelet_name)
+    scalar_parameters = CODELETS_SCALARS[codelet_name]
+    struct_params_name = CODELETS_PARAMS_STRUCT[codelet_name]
 
     output = "struct $struct_params_name {\n"
     for p in scalar_parameters

+ 4 - 6
julia/src/compiler/file_generation.jl

@@ -107,7 +107,7 @@ macro codelet(x)
     cpu_name = name
     cuda_name = "CUDA_"*name
     dump(name)
-    parse_scalar_parameters(parsed, cpu_name, cuda_name)
+    parse_scalar_parameters(parsed, name)
     c_struct_param_decl = generate_c_struct_param_declaration(name)
     cpu_expr = transform_to_cpu_kernel(parsed)
 
@@ -144,7 +144,7 @@ macro codelet(x)
     end
 end
 
-function parse_scalar_parameters(expr :: StarpuExprFunction, cpu_name::String, cuda_name::String)
+function parse_scalar_parameters(expr :: StarpuExprFunction, codelet_name)
     scalar_parameters = []
     for i in (1 : length(expr.args))
         type = expr.args[i].typ
@@ -153,8 +153,7 @@ function parse_scalar_parameters(expr :: StarpuExprFunction, cpu_name::String, c
         end
     end
 
-    CODELETS_SCALARS[cpu_name] = scalar_parameters
-    CODELETS_SCALARS[cuda_name] = scalar_parameters
+    CODELETS_SCALARS[codelet_name] = scalar_parameters
 
     # declare structure carrying scalar parameters
     struct_params_name = Symbol("params_", rand_string())
@@ -170,6 +169,5 @@ function parse_scalar_parameters(expr :: StarpuExprFunction, cpu_name::String, c
     eval(Meta.parse(add_to_dict_str))
 
     # save structure name
-    CODELETS_PARAMS_STRUCT[cpu_name] = struct_params_name
-    CODELETS_PARAMS_STRUCT[cuda_name] = struct_params_name
+    CODELETS_PARAMS_STRUCT[codelet_name] = struct_params_name
 end

+ 0 - 6
julia/src/globals.jl

@@ -23,16 +23,10 @@ global starpu_target=STARPU_CPU
 global generated_cuda_kernel_file_name = "PRINT TO STDOUT"
 global generated_cpu_kernel_file_name = "PRINT TO STDOUT"
 
-export CPU_CODELETS
 global CPU_CODELETS=Dict{String,String}()
-
-export CUDA_CODELETS
 global CUDA_CODELETS=Dict{String,String}()
 
-export CODELETS_SCALARS
 global CODELETS_SCALARS=Dict{String,Any}()
-
-export CODELETS_PARAMS_STRUCT
 global CODELETS_PARAMS_STRUCT=Dict{String,Any}()
 
 global starpu_type_traduction_dict = Dict(

+ 1 - 0
julia/src/init.jl

@@ -28,6 +28,7 @@ function starpu_init()
         dump(ff)
         for k in keys(CUDA_CODELETS)
             CPU_CODELETS[k]=unsafe_string(ccall(ff,Cstring, (Cstring,Cstring),Cstring_from_String(string(k)),Cstring_from_String("cpu")))
+            CUDA_CODELETS[k]=unsafe_string(ccall(ff,Cstring, (Cstring,Cstring),Cstring_from_String(string(k)),Cstring_from_String("gpu")))
             print(k,">>>>",CPU_CODELETS[k],"\n")
         end
     else

+ 15 - 19
julia/src/task.jl

@@ -27,8 +27,8 @@ end
 global codelet_list = Vector{jl_starpu_codelet}()
 
 function starpu_codelet(;
-                        cpu_func :: Union{String, STARPU_BLAS} = "",
-                        cuda_func :: Union{String, STARPU_BLAS} = "",
+                        cpu_func :: Union{String, STARPU_BLAS, Cvoid} = "",
+                        cuda_func :: Union{String, STARPU_BLAS, Cvoid} = "",
                         opencl_func :: String = "",
                         modes = [],
                         perfmodel :: starpu_perfmodel,
@@ -42,7 +42,7 @@ function starpu_codelet(;
 
 
     if (where_to_execute == nothing)
-        real_where = ((cpu_func != "") * STARPU_CPU) | ((cuda_func != "") * STARPU_CUDA)
+        real_where = ((cpu_func != nothing) * STARPU_CPU) | ((cuda_func != nothing) * STARPU_CUDA)
     else
         real_where = where_to_execute
     end
@@ -63,7 +63,7 @@ function starpu_codelet(;
         output.cpu_func = cpu_blas_codelets[cpu_func]
         output.c_codelet.cpu_func = load_wrapper_function_pointer(output.cpu_func)
     else
-        output.c_codelet.cpu_func = load_starpu_function_pointer(cpu_func)
+        output.c_codelet.cpu_func = load_starpu_function_pointer(get(CPU_CODELETS, cpu_func, ""))
     end
 
     if typeof(cuda_func) == STARPU_BLAS
@@ -71,10 +71,10 @@ function starpu_codelet(;
         output.c_codelet.cuda_func = load_wrapper_function_pointer(output.cuda_func)
         output.c_codelet.cuda_flags[1] = STARPU_CUDA_ASYNC
     else
-        output.c_codelet.cuda_func = load_starpu_function_pointer(cuda_func)
+        output.c_codelet.cuda_func = load_starpu_function_pointer(get(CUDA_CODELETS, cuda_func, ""))
     end
 
-    output.c_codelet.opencl_func = load_starpu_function_pointer(opencl_func)
+    output.c_codelet.opencl_func = load_starpu_function_pointer("")
 
     # Codelets must not be garbage collected before starpu shutdown is called.
     lock(mutex)
@@ -114,15 +114,11 @@ function starpu_task(; cl :: Union{Cvoid, jl_starpu_codelet} = nothing, handles
     output = jl_starpu_task(cl, handles, map((x -> x.object), handles), false, nothing, Vector{Cint}(undef, 1), callback, callback_arg, starpu_task(zero))
 
     # handle scalar_parameters
-    codelet_name = cl.cpu_func
-    if isempty(codelet_name)
-        codelet_name = cl.cuda_func
-    end
-    if isempty(codelet_name)
-        codelet_name = cl.opencl_func
-    end
-    if isempty(codelet_name)
-        error("No function provided with codelet.")
+    codelet_name = ""
+    if isa(cl.cpu_func, String) && cl.cpu_func != ""
+        codelet = cl.cpu_func
+    elseif isa(cl.gpu_func, String) && cl.gpu_func != ""
+        codelet = cl.gpu_func
     end
     scalar_parameters = get(CODELETS_SCALARS, codelet_name, nothing)
     if scalar_parameters != nothing
@@ -173,8 +169,8 @@ function starpu_task(; cl :: Union{Cvoid, jl_starpu_codelet} = nothing, handles
 end
 
 
-function create_param_struct_from_clarg(name, cl_arg)
-    struct_params_name = CODELETS_PARAMS_STRUCT[name]
+function create_param_struct_from_clarg(codelet_name, cl_arg)
+    struct_params_name = CODELETS_PARAMS_STRUCT[codelet_name]
 
     if struct_params_name == false
         error("structure name not found in CODELET_PARAMS_STRUCT")
@@ -254,8 +250,8 @@ macro starpu_async_cl(expr, modes, cl_arg=(), color ::UInt32=0x00000000)
     )
     println(CPU_CODELETS[string(expr.args[1])])
     cl = starpu_codelet(
-        cpu_func = CPU_CODELETS[string(expr.args[1])],
-        # cuda_func = CUDA_CODELETS[string(expr.args[1])],
+        cpu_func  = string(expr.args[1]),
+        cuda_func = string(expr.args[1]),
         #opencl_func="ocl_matrix_mult",
         ### TODO: CORRECT !
         modes = map((x -> starpu_modes(x)),modes.args),