move cache logic
This commit is contained in:
parent
2c74976602
commit
bdb8aae107
@ -1,7 +1,6 @@
|
|||||||
module JIT
|
module JIT
|
||||||
|
|
||||||
include("shapes.jl")
|
include("shapes.jl")
|
||||||
include("inplace.jl")
|
|
||||||
include("trace.jl")
|
include("trace.jl")
|
||||||
include("lib.jl")
|
include("lib.jl")
|
||||||
|
|
||||||
|
@ -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
|
|
@ -35,3 +35,17 @@ function restructure(sh::Shape{T}, buf::Vector{UInt8}) where T
|
|||||||
buf = unsafe_wrap(Array, pointer(buf), sizeof(sh))
|
buf = unsafe_wrap(Array, pointer(buf), sizeof(sh))
|
||||||
reshape(reinterpret(T, buf), size(sh))
|
reshape(reinterpret(T, buf), size(sh))
|
||||||
end
|
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
|
||||||
|
Loading…
Reference in New Issue
Block a user