Browse Source

julia: check example results.

Pierre Huchant 5 years ago
parent
commit
a814f0c3d1

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

@@ -61,7 +61,7 @@ function display()
     if v[] == 42
         println("result is correct")
     else
-        println("result is incorret")
+        error("result is incorret")
     end
 end
 

+ 3 - 2
julia/examples/cholesky/cholesky.jl

@@ -84,14 +84,14 @@ function cholesky(mat :: Matrix{Float32}, size, nblocks)
     )
     cl_21 = starpu_codelet(
         cpu_func = "u21",
-        # cuda_func = "u21",
+        cuda_func = "u21",
         modes = [STARPU_R, STARPU_RW],
         color = 0x8080ff,
         perfmodel = perfmodel
     )
     cl_22 = starpu_codelet(
         cpu_func = "u22",
-        # cuda_func = "u22",
+        cuda_func = "u22",
         modes = [STARPU_R, STARPU_R, STARPU_RW],
         color = 0x00ff00,
         perfmodel = perfmodel
@@ -166,6 +166,7 @@ end
 
 function main(size_p :: Int, nblocks :: Int, verbose = false)
     starpu_init()
+    starpu_cublas_init()
 
     mat :: Matrix{Float32} = zeros(Float32, size_p, size_p)
 

+ 28 - 5
julia/examples/gemm/gemm.jl

@@ -14,6 +14,7 @@
 # See the GNU Lesser General Public License in COPYING.LGPL for more details.
 #
 using StarPU
+using LinearAlgebra.BLAS
 
 @target STARPU_CPU+STARPU_CUDA
 @codelet function gemm(A :: Matrix{Float32}, B :: Matrix{Float32}, C :: Matrix{Float32}, alpha :: Float32, beta :: Float32) :: Nothing
@@ -21,9 +22,9 @@ using StarPU
     M :: Int32 = height(A)
     N :: Int32 = width(B)
     K :: Int32 = width(A)
-    lda :: Int32 = height(A)
-    ldb :: Int32 = height(B)
-    ldc :: Int32 = height(C)
+    lda :: Int32 = ld(A)
+    ldb :: Int32 = ld(B)
+    ldc :: Int32 = ld(C)
     STARPU_SGEMM("N", "N", M, N, K, alpha, A, lda, B, ldb, beta, C, ldc)
 
     return
@@ -63,6 +64,7 @@ function multiply_with_starpu(A :: Matrix{Float32}, B :: Matrix{Float32}, C :: M
                     end
                 end
             end
+            starpu_task_wait_for_all()
             t=time_ns()-t
             if (tmin==0 || tmin>t)
                 tmin=t
@@ -92,11 +94,31 @@ function approximately_equals(
     return true
 end
 
+function check(expected, A, B, C, alpha, beta)
+    for i in 1 : 10
+        gemm!('N', 'N', alpha, A, B, beta, expected)
+    end
+
+    height,width = size(C)
+    for i in 1:height
+        for j in 1:width
+            got = C[i, j]
+            exp = expected[i, j]
+
+            err = abs(exp - got) / exp
+            if err > 0.0001
+                error("[$i] -> $got != $exp (err $err)")
+            end
+        end
+    end
+end
+
 function compute_times(io,start_dim, step_dim, stop_dim, nslicesx, nslicesy)
     for dim in (start_dim : step_dim : stop_dim)
         A = Array(rand(Cfloat, dim, dim))
         B = Array(rand(Cfloat, dim, dim))
         C = zeros(Float32, dim, dim)
+        C_ref = copy(C)
         starpu_memory_pin(A)
         starpu_memory_pin(B)
         starpu_memory_pin(C)
@@ -111,6 +133,7 @@ function compute_times(io,start_dim, step_dim, stop_dim, nslicesx, nslicesy)
         starpu_memory_unpin(A)
         starpu_memory_unpin(B)
         starpu_memory_unpin(C)
+        check(C_ref, A, B, C, alpha, beta)
     end
 end
 
@@ -121,9 +144,9 @@ else
 end
 
 starpu_init()
-
+starpu_cublas_init()
 io=open(filename,"w")
-compute_times(io,64,512,4096,2,2)
+compute_times(io,64,512,4096,1,1)
 close(io)
 
 starpu_shutdown()

+ 12 - 14
julia/examples/mult/mult.jl

@@ -116,23 +116,20 @@ function multiply_with_starpu(A :: Matrix{Float32}, B :: Matrix{Float32}, C :: M
 end
 
 
-function approximately_equals(
-    A :: Matrix{Cfloat},
-    B :: Matrix{Cfloat},
-    eps = 1e-2
-)
-    (height, width) = size(A)
-
-    for j in (1 : width)
-        for i in (1 : height)
-            if (abs(A[i,j] - B[i,j]) > eps * max(abs(B[i,j]), abs(A[i,j])))
-                println("A[$i,$j] : $(A[i,j]), B[$i,$j] : $(B[i,j])")
-                return false
+function check(A, B, C)
+    expected = A * B
+    height,width = size(C)
+    for i in 1:height
+        for j in 1:width
+            got = C[i, j]
+            exp = expected[i, j]
+
+            err = abs(exp - got) / exp
+            if err > 0.0001
+                error("[$i] -> $got != $exp (err $err)")
             end
         end
     end
-
-    return true
 end
 
 function compute_times(io,start_dim, step_dim, stop_dim, nslicesx, nslicesy, stride)
@@ -145,6 +142,7 @@ function compute_times(io,start_dim, step_dim, stop_dim, nslicesx, nslicesy, str
         size=dim*dim*4*3/1024/1024
         println(io,"$size $flops")
         println("$size $flops")
+        check(A, B, C)
     end
 end
 

+ 1 - 1
julia/examples/variable/variable.jl

@@ -44,7 +44,7 @@ function display(niter)
     if foo[] == niter
         println("result is correct")
     else
-        println("result is incorret")
+        error("result is incorret")
     end
 end
 

+ 17 - 0
julia/examples/vector_scal/vector_scal.jl

@@ -67,9 +67,24 @@ function vector_scal_with_starpu(v :: Vector{Float32}, m :: Int32, k :: Float32,
     return tmin
 end
 
+function check(ref, res, m, k, l)
+    expected = ref .* m .+ (k+l)
+
+    for i in 1:length(expected)
+        got = res[i]
+        exp = expected[i]
+
+        err = abs(exp - got) / exp
+        if err > 0.0001
+            error("[$i] -> $got != $exp (err $err)")
+        end
+    end
+end
+
 function compute_times(io,start_dim, step_dim, stop_dim)
     for size in (start_dim : step_dim : stop_dim)
         V = Array(rand(Cfloat, size))
+        V_ref = copy(V)
         starpu_memory_pin(V)
 
         m :: Int32 = 10
@@ -85,6 +100,8 @@ function compute_times(io,start_dim, step_dim, stop_dim)
         println("OUTPUT ", V[1:10])
         println(io,"$size $mt")
         println("$size $mt")
+
+        check(V_ref, V, m, k, l)
     end
 end