提交 515f7319 authored 作者: Arnaud Bergeron's avatar Arnaud Bergeron 提交者: Pascal Lamblin

Add a opt to deal with AbstractConvs that are partially on the GPU.

上级 0ce3cc18
...@@ -855,6 +855,7 @@ def local_gpu_conv(node, context_name): ...@@ -855,6 +855,7 @@ def local_gpu_conv(node, context_name):
register_opt()(conv_groupopt) register_opt()(conv_groupopt)
# These two deal with any abstract convs that have a transfer somewhere
@register_opt() @register_opt()
@op_lifter([AbstractConv2d]) @op_lifter([AbstractConv2d])
def local_lift_abstractconv2d(node, context_name): def local_lift_abstractconv2d(node, context_name):
...@@ -874,6 +875,24 @@ def local_lift_abstractconv2dgrad(node, context_name): ...@@ -874,6 +875,24 @@ def local_lift_abstractconv2dgrad(node, context_name):
node.inputs[2])] node.inputs[2])]
# This will deal with ops that don't have an explicit transfer but
# have one of their inputs on the GPU already and the other not on the
# GPU (to avoid endlessly replacing things).
@register_opt()
@local_optimizer()([AbstractConv2d])
def local_gpu_abstractconv2d(node):
if isinstance(node.op, BaseAbstractConv2d):
if ((isinstance(node.inputs[0].type, GpuArrayType) or
isinstance(node.inputs[1].type, GpuArrayType)) and
not (isinstance(node.inputs[0].type, GpuArrayType) or
isinstance(node.inputs[1].type, GpuArrayType))):
inps = list(node.inputs)
ctx_name = infer_context_name(inps[0], inps[1])
inps[0] = as_gpuarray_variable(inps[0], context_name=ctx_name)
inps[1] = as_gpuarray_variable(inps[1], context_name=ctx_name)
return as_tensor_variable(node.op(*inps))
@register_opt("low_memory") @register_opt("low_memory")
@local_optimizer([GpuCAReduceCuda]) @local_optimizer([GpuCAReduceCuda])
def local_gpu_elemwise_careduce(node): def local_gpu_elemwise_careduce(node):
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论