Skip to content

Commit

Permalink
added ability to crash julia ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
kk49 committed May 9, 2012
1 parent a33e1a6 commit d10d6a8
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 14 deletions.
30 changes: 20 additions & 10 deletions demat_be_julia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,35 @@ end
# the quoted kernal code
#de_eval(a,idxSym) = de_eval(a,idxSym,x->x)

function de_eval(a::DeConst,idxSym::Symbol)
function de_eval(a::DeConst,idxSym)
@gensym r
( r
, quote ($r) = ($(a.p1)) end
, quote end
)
end

function de_eval(a::DeReadOp,idxSym::Symbol)
function de_eval(a::DeReadOp,idxSym)
@gensym r src
( r
, quote ($src) = ($a).p1.data end
, quote ($src) = ($(a.p1.data)) end
, quote ($r) = ($src)[($idxSym)] end
)
end

for op = deBinOpList
opType = de_op_to_type(op);
opSingle = de_op_to_scaler(op);
@eval function de_eval(v::DeBinOp{$opType},idxSym::Symbol)
opSingle = de_op_to_scaler(:($op));
@eval function de_eval(v::DeBinOp{$opType},idxSym)
@gensym r
p1 = de_eval(v.p1,idxSym)
p2 = de_eval(v.p2,idxSym)
#preamble = quote $(p1[2]);$(p2[2]) end
preamble = quote $(p1[2]);$(p2[2]) end
#preamble = quote end
#kernel = quote $(p1[3]);$(p2[3]);($r) = ($opSingle)(($(p1[1])),($(p2[1]))) end
kernel = quote $(p1[3]);$(p2[3]);($r) = ($($opSingle))(($(p1[1])),($(p2[1]))) end
#kernel = quote end
( r
, preamble
, kernel
Expand All @@ -83,7 +87,6 @@ end

function assign(lhs::DeArrJulia,rhs::DeExpr)
#println("Delayed Expression Setup Time:")
@gensym i
rhsSz = de_check_dims(rhs)
lhsSz = size(lhs)

Expand All @@ -95,25 +98,32 @@ function assign(lhs::DeArrJulia,rhs::DeExpr)
(rhsResult,rhsPreamble,rhsKernel) = de_eval(rhs,i)
rhsType = typeof(rhs);

ex = quote function ($hiddenFunc)(plhs::DeArrJulia,prhs::($rhsType))
ex = quote function ($hiddenFunc)(plhs::DeArrJulia,prhs::($rhsType))
N = size(plhs,1)
lhsData = plhs.data
$rhsPreamble
for ($i) = 1:N
@time ($rhsPreamble)
($i) = 1
@time ($rhsKernel)
@time (lhsData[($i)] =($rhsResult))
for ($i) = 2:N
$rhsKernel
lhsData[($i)] = ($rhsResult)
end
end
end

println("---- rhsResult ----")
println(rhsResult)
println("---- rhsPreamble----")
println(rhsPreamble)
println("---- rhsKernel ----")
println(rhsKernel)
println()
println(ex)

eval(ex)
@time ((eval(hiddenFunc))(lhs,rhs))
hf = eval(hiddenFunc)
@time hf(lhs,rhs)
end

assign(lhs::DeArrJulia,rhs::DeEle) = assign(lhs,de_promote(rhs)...)
Expand Down
7 changes: 7 additions & 0 deletions demat_crash_julia.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
load("demat.jl")

a = randn(1000000);
ad = DeVecJ{Float64}(a);
bd =DeVecJ{Float64}(copy(a));
finfer(assign,(ad,ad+1))

113 changes: 109 additions & 4 deletions demat_demo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ function demat_test()
for i = 1:1
println("-------------------")
println("#1 Delayed Expression:")
@time ad[] = bd+cd.*dd + 1.0
#@time ad[] = bd+cd.*dd + 1.0
@time ad[] = bd + 1.0

println("#2 Standard Julia Vector:")
@time a = b+c.*d + 1.0
#@time a = b+c.*d + 1.0
@time a = b + 1.0

println("#3 Standard Julia For Loop:")
@time for j = 1:N
a[j] = b[j] + c[j] * d[j] + 1.0
#a[j] = b[j] + c[j] * d[j] + 1.0
a[j] = b[j] + 1.0
end

println()
Expand All @@ -37,5 +40,107 @@ function demat_test()
r1
end

demat_test()
#demat_test()

a = randn(1000000);
ad = DeVecJ{Float64}(a);
bd =DeVecJ{Float64}(copy(a));
finfer(assign,(ad,ad+1))

function simple_test()

#--------------------------------------

function test1(x::Array{Float64})
local s = 0
local i
for i = 1:1000000
s += x[i] * i
end
s
end

#--------------------------------------

@gensym ns ti
@eval function test2(x::Array{Float64})
($ns) = x;
local s = 0
local ($ti)
for ($ti) = 1:1000000
s += ($ns)[($ti)] * ($ti)
end
s
end

#--------------------------------------

function extract_x3(x)
@gensym r

(r,quote ($r) = ($x) end)
end

function test3(x::Array{Float64})
@gensym ti

(rv,ex) = extract_x3(x)

@eval function hf()
local s = 0
local ($ti)
$ex
for ($ti) = 1:1000000
s += ($rv)[($ti)] * ($ti)
end
s
end

eval(hf)() #if eval is not here it returns the results for the last call to test3
end

#--------------------------------------
function extract_x4(xi,idx)
@gensym r src

(r,quote ($src) = ($x) end,quote ($r) = ($src)[($idx)] end)
end


function test4(x::Array{Float64})
@gensym ti

(rv,ex,bd) = extract_x4(x,ti)

@eval function hf()
local s = 0
local ($ti)
$ex
for ($ti) = 1:1000000
$bd
s += ($rv) * ($ti)
end
s
end

eval(hf)() #if eval is not here it returns the results for the last call to test3
end

#--------------------------------------

x = randn(1000000)
n = 20

local s1,s2,s3,s4

t1time = @elapsed for i = 1:n s1 = test1(x) end
t2time = @elapsed for i = 1:n s2 = test2(x) end
t3time = @elapsed for i = 1:n s3 = test3(x) end
t4time = @elapsed for i = 1:n s4 = test4(x) end

println(" t1time: ",t1time," s: ",s1)
println(" t2time: ",t2time," s: ",s2)
println(" t3time: ",t3time," s: ",s3)
println(" t4time: ",t4time," s: ",s4)
println()
end

0 comments on commit d10d6a8

Please sign in to comment.