提交 57f5c7c7 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Make negative values for gpuarray.preallocate disable the allocation

cache completely.
上级 69338f33
...@@ -235,11 +235,12 @@ AddConfigVar('gpuarray.sync', ...@@ -235,11 +235,12 @@ AddConfigVar('gpuarray.sync',
in_c_key=True) in_c_key=True)
AddConfigVar('gpuarray.preallocate', AddConfigVar('gpuarray.preallocate',
"""If 0 it doesn't do anything. If between 0 and 1 it """If negative it disables the allocation cache. If
will preallocate that fraction of the total GPU memory. between 0 and 1 it enables the allocation cache and
If 1 or greater it will preallocate that amount of memory preallocates that fraction of the total GPU memory. If 1
(in megabytes).""", or greater it will preallocate that amount of memory (in
FloatParam(0, lambda i: i >= 0), megabytes).""",
FloatParam(0),
in_c_key=False) in_c_key=False)
......
...@@ -51,13 +51,14 @@ def init_dev(dev, name=None): ...@@ -51,13 +51,14 @@ def init_dev(dev, name=None):
"Please update libgpuarray/pygpu.") "Please update libgpuarray/pygpu.")
global pygpu_activated global pygpu_activated
if dev not in init_dev.devmap: if dev not in init_dev.devmap:
ctx = pygpu.init(dev) ctx = pygpu.init(dev,
disable_alloc_cache=config.gpuarray.preallocate < 0)
init_dev.devmap[dev] = ctx init_dev.devmap[dev] = ctx
if config.gpuarray.preallocate != 0: if config.gpuarray.preallocate > 0:
if config.gpuarray.preallocate < 1: if config.gpuarray.preallocate < 1:
gmem = min(config.gpuarray.preallocate, 0.98) * ctx.total_gmem gmem = min(config.gpuarray.preallocate, 0.95) * ctx.total_gmem
else: else:
gmem = config.gpuarray.preallocate * (1024*1024) gmem = config.gpuarray.preallocate * (1024 * 1024)
# This will allocate and immediatly free an object of size gmem # This will allocate and immediatly free an object of size gmem
# which will reserve that amount of memory on the GPU. # which will reserve that amount of memory on the GPU.
pygpu.empty((gmem,), dtype='int8', context=ctx) pygpu.empty((gmem,), dtype='int8', context=ctx)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论