From bdb8aae107442f804f3cf19e83649aaec27bcc6a Mon Sep 17 00:00:00 2001 From: Mike J Innes Date: Tue, 27 Feb 2018 21:41:03 +0000 Subject: [PATCH] move cache logic --- src/jit/JIT.jl | 1 - src/jit/inplace.jl | 11 ----------- src/jit/shapes.jl | 14 ++++++++++++++ 3 files changed, 14 insertions(+), 12 deletions(-) delete mode 100644 src/jit/inplace.jl diff --git a/src/jit/JIT.jl b/src/jit/JIT.jl index 2f30bb0c..6085ce5e 100644 --- a/src/jit/JIT.jl +++ b/src/jit/JIT.jl @@ -1,7 +1,6 @@ module JIT include("shapes.jl") -include("inplace.jl") include("trace.jl") include("lib.jl") diff --git a/src/jit/inplace.jl b/src/jit/inplace.jl deleted file mode 100644 index cf87b102..00000000 --- a/src/jit/inplace.jl +++ /dev/null @@ -1,11 +0,0 @@ -mutable struct Cached{F,A} - f::F - buffer::A -end - -function (c::Cached)(args...) - sh = shape(c.f, shape(args)...) - bytes(sh) > length(c.buffer) && (c.buffer = similar(c.buffer, bytes(sh))) - y = restructure(sh, c.buffer) - inplace!(c.f, y, args...) -end diff --git a/src/jit/shapes.jl b/src/jit/shapes.jl index bd6f4993..6d516523 100644 --- a/src/jit/shapes.jl +++ b/src/jit/shapes.jl @@ -35,3 +35,17 @@ function restructure(sh::Shape{T}, buf::Vector{UInt8}) where T buf = unsafe_wrap(Array, pointer(buf), sizeof(sh)) reshape(reinterpret(T, buf), size(sh)) end + +# Execution with caches + +mutable struct Cached{F,A} + f::F + buffer::A +end + +function (c::Cached)(args...) + sh = shape(c.f, shape(args)...) + bytes(sh) > length(c.buffer) && (c.buffer = similar(c.buffer, bytes(sh))) + y = restructure(sh, c.buffer) + inplace!(c.f, y, args...) +end