def test_c_nan(self): for dtype in ["floatX", "complex64", "complex128"]: self.with_linker(gof.CLinker(), add, dtype=dtype, test_nan=True) self.with_linker(gof.CLinker(), mul, dtype=dtype, test_nan=True) for dtype in ["floatX"]: self.with_linker(gof.CLinker(), minimum, dtype=dtype, test_nan=True) self.with_linker(gof.CLinker(), maximum, dtype=dtype, test_nan=True)
def test_c_nan(self): if not theano.config.cxx: raise SkipTest("G++ not available, so we need to skip this test.") for dtype in ["floatX", "complex64", "complex128"]: self.with_linker(gof.CLinker(), scalar.add, dtype=dtype, test_nan=True) self.with_linker(gof.CLinker(), scalar.mul, dtype=dtype, test_nan=True) for dtype in ["floatX"]: self.with_linker(gof.CLinker(), scalar.minimum, dtype=dtype, test_nan=True) self.with_linker(gof.CLinker(), scalar.maximum, dtype=dtype, test_nan=True)
def test_c(self): for dtype in self.dtypes + self.bin_dtypes: for op in self.reds: self.with_linker(gof.CLinker(), op, dtype=dtype, pre_scalar_op=self.pre_scalar_op)
def local_scan_to_gpua(node): info = copy.deepcopy(node.op.info) if info.get('gpua', False): return info['gpua'] = True nw_ins = [node.inputs[0]] e = (1 + node.op.n_seqs + node.op.n_mit_mot + node.op.n_mit_sot + node.op.n_sit_sot + node.op.n_shared_outs) nw_ins += [safe_to_gpu(x) for x in node.inputs[1:e]] b = e e = e + node.op.n_nit_sot nw_ins += node.inputs[b:e] nw_ins += [safe_to_gpu(x) for x in node.inputs[e:]] scan_ins = [tensor_to_gpu(x) for x in node.op.inputs] scan_outs = [safe_to_gpu(x) for x in node.op.outputs] scan_outs = scan_utils.clone( scan_outs, replace=zip(node.op.inputs, [safe_to_cpu(x) for x in scan_ins])) # We need to construct the hash here, because scan # __init__ does not know about the gpu and can not # handle graphs with inputs being on the gpu tmp_in, tmp_out = gpu_reconstruct_graph(scan_ins, scan_outs) local_fgraph = gof.FunctionGraph(tmp_in, tmp_out, clone=False) _cmodule_key = gof.CLinker().cmodule_key_(local_fgraph, []) info['gpu_hash'] = hash(_cmodule_key) nw_op = scan_op.Scan(scan_ins, scan_outs, info, typeConstructor=GpuArrayType).make_node(*nw_ins) return nw_op.outputs
def test_same_inputs(self): x = TensorType('float64', [0, 0])('x') e = Elemwise(add)(x, x) f = gof.CLinker().accept(Env([x], [e])).make_function() xv = numpy.random.rand(2, 2) zv = xv + xv assert (f(xv) == zv).all()
def test_c_nan(self): for dtype in self.dtypes: if not dtype.startswith('float'): continue for op in self.reds: self.with_linker(gof.CLinker(), op, dtype=dtype, test_nan=True, pre_scalar_op=self.pre_scalar_op)
def test_weird_strides(self): x = TensorType('float64', [0, 0, 0, 0, 0])('x') y = TensorType('float64', [0, 0, 0, 0, 0])('y') e = Elemwise(add)(x, y) f = gof.CLinker().accept(Env([x, y], [e])).make_function() xv = numpy.random.rand(2, 2, 2, 2, 2) yv = numpy.random.rand(2, 2, 2, 2, 2).transpose(4, 0, 3, 1, 2) zv = xv + yv assert (f(xv, yv) == zv).all()
def test_fill(self): x = TensorType('float64', [0, 0])('x') y = TensorType('float64', [1, 1])('y') e = Elemwise(Second(transfer_type(0)), {0: 0})(x, y) f = gof.CLinker().accept(Env([x, y], [e])).make_function() xv = numpy.ones((5, 5)) yv = numpy.random.rand(1, 1) f(xv, yv) assert (xv == yv).all()
def test_same_inputs(self): if not theano.config.cxx: raise SkipTest("G++ not available, so we need to skip this test.") x = self.ctype('float64', [0, 0])('x') e = self.cop(scalar.add)(x, x) f = gof.CLinker().accept(FunctionGraph([x], [e])).make_function() xv = self.rand_cval((2, 2)) zv = xv + xv assert (f(xv) == zv).all()
def test_weird_strides(self): if not theano.config.cxx: raise SkipTest("G++ not available, so we need to skip this test.") x = self.ctype('float64', [0, 0, 0, 0, 0])('x') y = self.ctype('float64', [0, 0, 0, 0, 0])('y') e = self.cop(scalar.add)(x, y) f = gof.CLinker().accept(FunctionGraph([x, y], [e])).make_function() xv = self.rand_cval((2, 2, 2, 2, 2)) yv = self.rand_cval((2, 2, 2, 2, 2)).transpose(4, 0, 3, 1, 2) zv = xv + yv assert (f(xv, yv) == zv).all()
def test_fill(self): if not theano.config.cxx: raise SkipTest("G++ not available, so we need to skip this test.") x = self.ctype('float64', [0, 0])('x') y = self.ctype('float64', [1, 1])('y') e = self.cop(scalar.Second(scalar.transfer_type(0)), {0: 0})(x, y) f = gof.CLinker().accept(FunctionGraph([x, y], [e])).make_function() xv = self.rand_cval((5, 5)) yv = self.rand_cval((1, 1)) f(xv, yv) assert (xv == yv).all()
def test_c(self): if not theano.config.cxx: raise SkipTest("G++ not available, so we need to skip this test.") for dtype in ["floatX", "complex64", "complex128", "int8", "uint8"]: self.with_linker(gof.CLinker(), scalar.add, dtype=dtype) self.with_linker(gof.CLinker(), scalar.mul, dtype=dtype) for dtype in ["floatX", "int8", "uint8"]: self.with_linker(gof.CLinker(), scalar.minimum, dtype=dtype) self.with_linker(gof.CLinker(), scalar.maximum, dtype=dtype) self.with_linker(gof.CLinker(), scalar.and_, dtype=dtype, tensor_op=tensor.all) self.with_linker(gof.CLinker(), scalar.or_, dtype=dtype, tensor_op=tensor.any) for dtype in ["int8", "uint8"]: self.with_linker(gof.CLinker(), scalar.or_, dtype=dtype) self.with_linker(gof.CLinker(), scalar.and_, dtype=dtype) self.with_linker(gof.CLinker(), scalar.xor, dtype=dtype)
def test_c(self): for dtype in ["floatX", "complex64", "complex128", "int8", "uint8"]: self.with_linker(gof.CLinker(), add, dtype=dtype) self.with_linker(gof.CLinker(), mul, dtype=dtype) for dtype in ["floatX", "int8", "uint8"]: self.with_linker(gof.CLinker(), minimum, dtype=dtype) self.with_linker(gof.CLinker(), maximum, dtype=dtype) for dtype in ["int8", "uint8"]: self.with_linker(gof.CLinker(), or_, dtype=dtype) self.with_linker(gof.CLinker(), and_, dtype=dtype) self.with_linker(gof.CLinker(), xor, dtype=dtype)
def local_scan_to_gpua(node, context_name): info = copy.deepcopy(node.op.info) if info.get('gpua', False): return info['gpua'] = True nw_ins = [node.inputs[0]] e = (1 + node.op.n_seqs + node.op.n_mit_mot + node.op.n_mit_sot + node.op.n_sit_sot + node.op.n_shared_outs) nw_ins += [safe_to_gpu(x, context_name) for x in node.inputs[1:e]] b = e e = e + node.op.n_nit_sot nw_ins += node.inputs[b:e] nw_ins += [safe_to_gpu(x, context_name) for x in node.inputs[e:]] scan_ins = [tensor_to_gpu(x, context_name) for x in node.op.inputs] # The inner output corresponding to the looping condition should not be # moved to the gpu if node.op.info['as_while']: scan_outs = [safe_to_gpu(x, context_name) for x in node.op.outputs[:-1]] scan_outs += [node.op.outputs[-1]] else: scan_outs = [safe_to_gpu(x, context_name) for x in node.op.outputs] scan_outs = scan_utils.clone( scan_outs, replace=list(zip(node.op.inputs, (safe_to_cpu(x) for x in scan_ins)))) # We need to construct the hash here, because scan # __init__ does not know about the gpu and can not # handle graphs with inputs being on the gpu tmp_in, tmp_out = gpu_reconstruct_graph(scan_ins, scan_outs) local_fgraph = gof.FunctionGraph(tmp_in, tmp_out, clone=True) _cmodule_key = gof.CLinker().cmodule_key_(local_fgraph, []) info['gpu_hash'] = hash(_cmodule_key) def typebuild(dtype, broadcastable, context_name=context_name): return GpuArrayType(dtype=dtype, broadcastable=broadcastable, context_name=context_name) nw_op = scan_op.Scan(scan_ins, scan_outs, info, typeConstructor=typebuild).make_node(*nw_ins) return nw_op.outputs
'clinker': y }) else: if x != y: raise Exception("Output mismatch.", { 'performlinker': x, 'clinker': y }) # If a string is passed as the linker argument in the constructor for # Mode, it will be used as the key to retrieve the real linker in this # dictionary predefined_linkers = { 'py': gof.PerformLinker(), 'c': gof.CLinker(), 'c|py': gof.OpWiseCLinker(), 'c|py_nogc': gof.OpWiseCLinker(allow_gc=False), 'c&py': gof.DualLinker(checker=check_equal), 'vm': gof.vm.VM_Linker(use_cloop=False), 'cvm': gof.vm.VM_Linker(use_cloop=True), 'vm_nogc': gof.vm.VM_Linker(allow_gc=False, use_cloop=False), 'cvm_nogc': gof.vm.VM_Linker(allow_gc=False, use_cloop=True), } def register_linker(name, linker): """Add a `Linker` which can be referred to by `name` in `Mode`.""" if name in predefined_linkers: raise ValueError('Linker name already taken: %s' % name) predefined_linkers[name] = linker
def test_c_inplace(self): if not theano.config.cxx: raise SkipTest("G++ not available, so we need to skip this test.") self.with_linker_inplace(gof.CLinker(), self.cop, self.ctype, self.rand_cval)
def test_c_nan(self): for dtype in self.dtypes: for op in self.reds: self.with_linker(gof.CLinker(), op, dtype=dtype, test_nan=True)
def test_c(self): for dtype in self.dtypes + self.bin_dtypes: for op in self.reds: self.with_linker(gof.CLinker(), op, dtype=dtype)
def test_c(self): self.with_linker(gof.CLinker())
def test_c_inplace(self): self.with_linker_inplace(gof.CLinker())
import theano from theano import gof import theano.gof.vm from theano.configparser import config from theano.compile.ops import _output_guard from six import string_types _logger = logging.getLogger('theano.compile.mode') # If a string is passed as the linker argument in the constructor for # Mode, it will be used as the key to retrieve the real linker in this # dictionary predefined_linkers = { 'py': gof.PerformLinker(), # Use allow_gc Theano flag 'c': gof.CLinker(), # Don't support gc. so don't check allow_gc 'c|py': gof.OpWiseCLinker(), # Use allow_gc Theano flag 'c|py_nogc': gof.OpWiseCLinker(allow_gc=False), 'vm': gof.vm.VM_Linker(use_cloop=False), # Use allow_gc Theano flag 'cvm': gof.vm.VM_Linker(use_cloop=True), # Use allow_gc Theano flag 'vm_nogc': gof.vm.VM_Linker(allow_gc=False, use_cloop=False), 'cvm_nogc': gof.vm.VM_Linker(allow_gc=False, use_cloop=True) } def register_linker(name, linker): """Add a `Linker` which can be referred to by `name` in `Mode`.""" if name in predefined_linkers: raise ValueError('Linker name already taken: %s' % name) predefined_linkers[name] = linker
def test_c(self): if not theano.config.cxx: raise SkipTest("G++ not available, so we need to skip this test.") self.with_linker(gof.CLinker())