def test_function_from_group_dict(): data = {('a','b'): (1, 1) , ('b','a'): (0, 10)} fn = function_from_group_dict(data) assert fn(0, 'a', 'b') == 1 assert fn(0, 'b', 'a') == 0 assert fn(1000, 'a', 'b') == 1001 assert fn(1000, 'b', 'a') == 10000
def make_commtime_function(cdict, known_shapes): """ Create callable function from a dict of intercept/slopes, known shapes inputs: cdict - dict mapping {(sender, receiver) : {'intercept':i, 'slope':s}} input_shapes - dict from input variables to shapes {TensorVar : shape} outputs: commtime - function :: (ApplyNode, sender, receiver) -> time (float) """ bytes_fn = function_from_group_dict(cdict) known_shapes = {str(key): known_shapes[key] for key in known_shapes} def bytes(var): """ Compute the bytes that a theano variable holds """ shape = known_shapes[str(var)] return prod(shape) * bytes_of_dtype(var.dtype) def commtime(var, sender, receiver): """ Returns the communication time to transmit a variable """ if sender == receiver: return 0 if (sender, receiver) not in cdict: return 1e9 nbytes = bytes(var) intercept = cdict[sender, receiver]["intercept"] slope = cdict[sender, receiver]["slope"] return slope * nbytes + intercept return commtime
def make_commtime_function(cdict, known_shapes): """ Create callable function from a dict of intercept/slopes, known shapes inputs: cdict - dict mapping {(sender, receiver) : {'intercept':i, 'slope':s}} input_shapes - dict from input variables to shapes {TensorVar : shape} outputs: commtime - function :: (ApplyNode, sender, receiver) -> time (float) """ bytes_fn = function_from_group_dict(cdict) known_shapes = {str(key): known_shapes[key] for key in known_shapes} def bytes(var): """ Compute the bytes that a theano variable holds """ shape = known_shapes[str(var)] return prod(shape) * bytes_of_dtype(var.dtype) def commtime(var, sender, receiver): """ Returns the communication time to transmit a variable """ if sender == receiver: return 0 if (sender, receiver) not in cdict: return 1e9 nbytes = bytes(var) intercept = cdict[sender, receiver]['intercept'] slope = cdict[sender, receiver]['slope'] return slope * nbytes + intercept return commtime