提交 8fb5d66c authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron

Add the gpuarray.preallocate configuration variable. This will help fix out of…

Add the gpuarray.preallocate configuration variable. This will help fix out of memory errors in certain sequences of tests.
上级 4ad36ddc
...@@ -4,7 +4,8 @@ import logging ...@@ -4,7 +4,8 @@ import logging
import theano import theano
from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr, from theano.configparser import (AddConfigVar, BoolParam, ConfigParam, EnumStr,
IntParam, StrParam, TheanoConfigParser) FloatParam, IntParam, StrParam,
TheanoConfigParser)
from theano.misc.cpucount import cpuCount from theano.misc.cpucount import cpuCount
from theano.misc.windows import call_subprocess_Popen from theano.misc.windows import call_subprocess_Popen
...@@ -219,6 +220,14 @@ AddConfigVar('gpuarray.sync', ...@@ -219,6 +220,14 @@ AddConfigVar('gpuarray.sync',
BoolParam(False), BoolParam(False),
in_c_key=True) in_c_key=True)
AddConfigVar('gpuarray.preallocate',
"""If 0 it doesn't do anything. If between 0 and 1 it
will preallocate that fraction of the total GPU memory.
If 1 or greater it will preallocate that amount of memory
(in megabytes).""",
FloatParam(0, lambda i: i >= 0),
in_c_key=False)
def safe_no_dnn_workmem(workmem): def safe_no_dnn_workmem(workmem):
""" """
......
...@@ -46,7 +46,16 @@ def init_dev(dev, name=None): ...@@ -46,7 +46,16 @@ def init_dev(dev, name=None):
"are in sync.") "are in sync.")
global pygpu_activated global pygpu_activated
if dev not in init_dev.devmap: if dev not in init_dev.devmap:
init_dev.devmap[dev] = pygpu.init(dev) ctx = pygpu.init(dev)
init_dev.devmap[dev] = ctx
if config.gpuarray.preallocate != 0:
if config.gpuarray.preallocate < 1:
gmem = config.gpuarray.preallocate * ctx.total_gmem
else:
gmem = config.gpuarray.preallocate * (1024*1024)
# This will allocate and immediatly free an object of size gmem
# which will reserve that amount of memory on the GPU.
pygpu.empty((gmem,), dtype='int8', context=ctx)
context = init_dev.devmap[dev] context = init_dev.devmap[dev]
# This will map the context name to the real context object. # This will map the context name to the real context object.
reg_context(name, context) reg_context(name, context)
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论