瀏覽代碼

julia: Handle variable datatype and add variable example.

Pierre Huchant 5 年之前
父節點
當前提交
053fb466b5
共有 4 個文件被更改,包括 130 次插入1 次删除
  1. 8 1
      julia/StarPU.jl/src/compiler/c.jl
  2. 58 0
      julia/variable/Makefile
  3. 38 0
      julia/variable/variable.jl
  4. 26 0
      julia/variable/variable_native.jl

+ 8 - 1
julia/StarPU.jl/src/compiler/c.jl

@@ -172,6 +172,13 @@ function substitute_args(expr :: StarpuExprFunction)
             push!(function_start_affectations, post_affect)
             new_body = substitute_argument_usage(new_body, buffer_id, buffer_arg_name, expr.args[i].name, var_name)
             buffer_id += 1
+        elseif (expr.args[i].typ <: Ref)
+            func_interface = :STARPU_VARIABLE_GET_PTR
+            type_in_arg = eltype(expr.args[i].typ)
+            new_affect = starpu_parse( :($ptr :: Ptr{$type_in_arg} = $func_interface($buffer_arg_name[$buffer_id])) )
+            push!(function_start_affectations, new_affect)
+            new_body = substitute_argument_usage(new_body, buffer_id, buffer_arg_name, expr.args[i].name, Symbol("(*$var_name)"))
+            buffer_id += 1
         elseif (expr.args[i].typ <: Number || expr.args[i].typ <: AbstractChar)
             type_in_arg = eltype(expr.args[i].typ)
             field_name = scalar_parameters[scalar_id][1]
@@ -182,7 +189,7 @@ function substitute_args(expr :: StarpuExprFunction)
             push!(function_start_affectations, post_affect)
             scalar_id += 1
         else
-            error("Task arguments must be either vector or matrix or scalr (got $(expr.args[i].typ))")
+            error("Task arguments must be either matrix, vector, ref or scalar (got $(expr.args[i].typ))")
         end
 
 

+ 58 - 0
julia/variable/Makefile

@@ -0,0 +1,58 @@
+CC=gcc
+NVCC=nvcc
+ENABLE_CUDA=no
+LD=$(CC)
+
+ifeq ($(ENABLE_CUDA),yes)
+        LD := ${NVCC}
+endif
+
+CFLAGS = -O3 -g $(shell pkg-config --cflags starpu-1.3)
+CPU_CFLAGS = ${CFLAGS} -Wall -mavx -fomit-frame-pointer -march=native -ffast-math
+CUDA_CFLAGS = ${CFLAGS}
+LDFLAGS +=$(shell pkg-config --libs starpu-1.3)
+
+EXTERNLIB=extern_tasks.so
+GENERATEDLIB=generated_tasks.so
+
+C_OBJECTS=$(patsubst %.c,%.o,$(wildcard gen*.c))
+CUDA_OBJECTS=$(patsubst %.cu,%.o,$(wildcard gen*.cu))
+ifneq ($(ENABLE_CUDA),yes)
+	CUDA_OBJECTS:=
+endif
+
+LIBPATH=${PWD}/../StarPU.jl/lib
+
+all: ${EXTERNLIB}
+
+variable: variable.c cpu_variable.o #gpu_variable.o
+	$(CC) $(CPU_CFLAGS) $^ -o $@ $(LDFLAGS)
+
+%.o: %.c
+	$(CC) -c -fPIC $(CPU_CFLAGS) $^ -o $@
+
+%.o: %.cu
+	$(NVCC) -dc $(CUDA_CFLAGS) $^ --shared --compiler-options '-fPIC' -o $@ $(LDFLAGS)
+
+${EXTERNLIB}: cpu_variable.c
+	$(CC) $(CFLAGS) -shared -fPIC $(LDFLAGS) $^ -o $@
+
+${GENERATEDLIB}: $(C_OBJECTS) $(CUDA_OBJECTS)
+	$(LD) -shared $(LDFLAGS) $^ -o $@
+
+.PHONY: clean
+
+clean:
+	rm -f variable *.so *.o genc_*.c gencuda_*.cu *.dat
+
+# Performance Tests
+cstarpu.dat: variable
+	STARPU_NOPENCL=0 STARPU_SCHED=dmda STARPU_CALIBRATE=1 ./variable -0.800671 -0.158392 32 32 4096 4 > $@
+julia_generatedc.dat:
+	LD_LIBRARY_PATH+=${LIBPATH} STARPU_NOPENCL=0 STARPU_SCHED=dmda STARPU_CALIBRATE=1 julia variable.jl $@
+julia_native.dat:
+	LD_LIBRARY_PATH+=${LIBPATH} STARPU_NOPENCL=0 STARPU_SCHED=dmda STARPU_CALIBRATE=1 julia variable_native.jl $@
+julia_calllib.dat: ${EXTERNLIB}
+	LD_LIBRARY_PATH+=${LIBPATH} JULIA_TASK_LIB="${EXTERNLIB}" STARPU_NOPENCL=0 STARPU_SCHED=dmda STARPU_CALIBRATE=1 julia variable.jl julia_calllib.dat
+
+test: cstarpu.dat julia_generatedc.dat julia_native.dat julia_calllib.dat

+ 38 - 0
julia/variable/variable.jl

@@ -0,0 +1,38 @@
+import Libdl
+using StarPU
+
+@target STARPU_CPU
+@codelet function variable(val ::Ref{Float32}) :: Nothing
+    val[] = val[] + 1
+
+    return
+end
+
+starpu_init()
+
+function variable_with_starpu(val ::Ref{Float32}, niter)
+    @starpu_block let
+	hVal = starpu_data_register(val)
+
+	@starpu_sync_tasks for task in (1 : niter)
+                @starpu_async_cl variable(hVal) [STARPU_RW]
+	end
+    end
+end
+
+function display(niter)
+    foo = Ref(0.0f0)
+
+    variable_with_starpu(foo, niter)
+
+    println("variable -> ", foo[])
+    if foo[] == niter
+        println("result is correct")
+    else
+        println("result is incorret")
+    end
+end
+
+display(10)
+
+starpu_shutdown()

+ 26 - 0
julia/variable/variable_native.jl

@@ -0,0 +1,26 @@
+function variable(val ::Ref{Float32}) :: Nothing
+    val[] = val[] + 1
+
+    return
+end
+
+function variable_without_starpu(val ::Ref{Float32}, niter)
+    for i = 1:niter
+        variable(val)
+    end
+end
+
+function display(niter)
+    foo = Ref(0.0f0)
+
+    variable_without_starpu(foo, niter)
+
+    println("variable -> ", foo[])
+    if foo[] == niter
+        println("result is correct")
+    else
+        println("result is incorret")
+    end
+end
+
+display(10)