Exemple #1
0
def set_dim_func_(inputs, data_format="DefaultFormat", axis=1):
    """set dim info"""
    shape = get_shape(input[1])
    params = check_inputs(inputs, data_format, axis)
    axis = params.get("axis", (0, ))
    is_special5d = params.get("is_special5d", False)
    hash_key1 = str((tuple(shape), input[1].dtype))
    if hash_key1 in set_dim_map_:
        return ct_util.set_dims_by_key(hash_key1, set_dim_map_), hash_key1
    hash_key = str((len(shape), input[1].dtype, axis, is_special5d))
    return ct_util.set_dims_by_key(hash_key, set_dim_map_)
Exemple #2
0
def segment_max_set_dim_func(data, segment_ids, num_segments):
    key = []
    key.append(tuple(data.shape))
    key.append(data.dtype)
    hash_key = str((tuple(key)))

    return ct_util.set_dims_by_key(hash_key, segment_max_set_dim_map), hash_key
Exemple #3
0
def load3d_set_dim(tensor_fmap, kernel, stride, pad):
    fmap_n, fmap_c1, fmap_h, fmap_w, fmap_c0 = tensor_fmap.shape
    filter_h, filter_w = kernel
    # calculate the tiling factor.
    ho = (fmap_h + pad[0] + pad[1] - filter_h) // (stride[0]) + 1
    wo = (fmap_w + pad[2] + pad[3] - filter_w) // (stride[1]) + 1
    mode = True
    if (ho.value * wo.value) % 16 == 0:
        h_cut = (ho * wo) // 16
        if has_pad(pad):
            mode = False
    else:
        h_cut = (fmap_n * ho * wo) // 16
        mode = False
    co_cut = filter_h * filter_w

    key = ((fmap_n, fmap_c1, fmap_h, fmap_w, fmap_c0), kernel, stride, pad)

    set_dims = ct_util.set_dims_by_key(str(key), load3d_set_dim_map)
    if set_dims == '':
        dims = ()
        if mode and fmap_n.value > 1:
            dims += ((1, 0), )
        dims += ((h_cut, 0), (co_cut, 0))
        return ct_util.set_dims(dims), str(key)
    return set_dims, str(key)
Exemple #4
0
def smooth_l1_loss_set_dim_func(prediction, _target, anchor_samples,
                                _anchor_sample_correct, _delta):
    """dim function"""
    key = get_shape(prediction)

    hash_key = str((tuple(key), prediction.dtype, anchor_samples.dtype))
    return ct_util.set_dims_by_key(hash_key, smooth_l1_loss_set_dim_map), hash_key
Exemple #5
0
def fused_layernorm_set_dim_func(data, _gamma, _beta, begin_norm_axis,
                                 begin_params_axis):
    """dim function"""
    shape = [x.value for x in data.shape]
    hash_key = str(
        (tuple(shape), begin_norm_axis, begin_params_axis, data.dtype))
    return ct_util.set_dims_by_key(hash_key,
                                   fused_layernorm_set_dim_map), hash_key
Exemple #6
0
def transpose_set_dim_func(data, axes):
    key = []
    shape = [x.value for x in data.shape]
    key.append(tuple(shape))
    key.append(tuple(axes))

    hash_key = str((tuple(key), data.dtype))
    return ct_util.set_dims_by_key(hash_key, transpose_set_dim_map), hash_key
Exemple #7
0
def set_dim_func_(dy,
                  data,
                  mean,
                  var,
                  gamma,
                  eps=1e-3,
                  data_format="DefaultFormat",
                  axis=1):
    """set dim info"""
    shape = get_shape(data)
    params = check_inputs(dy, data, mean, var, gamma, data_format, axis)
    axis = params["axis"]
    is_special5d = params["is_special5d"]
    hash_key1 = str((tuple(shape), data.dtype))
    if hash_key1 in set_dim_map_:
        return ct_util.set_dims_by_key(hash_key1, set_dim_map_), hash_key1
    hash_key = str((len(shape), data.dtype, axis, is_special5d))
    return ct_util.set_dims_by_key(hash_key, set_dim_map_), hash_key
Exemple #8
0
def softmax_grad_set_dim_func(x, dy, axis):
    key = []
    shape = [int(x.shape[i].value) for i in range(len(x.shape))]
    key.append(tuple(shape))
    key.append(axis)
    dtype = x.dtype

    hash_key = str((tuple(key), dtype))
    return ct_util.set_dims_by_key(hash_key,
                                   softmax_grad_set_dim_map), hash_key
Exemple #9
0
def maxpool_grad_set_dim_func(x, y, dy, kernel, stride, pad):
    """dim func for maxpool grad"""
    key = str((tuple(x.shape), tuple(kernel), tuple(stride), pad))
    attrs = {}
    if key in set_attr_map_.keys():
        for attr in set_attr_map_[key]:
            attrs[attr[0]] = attr[1]
    if key in maxpool_grad_dim_map.keys():
        return ct_util.set_dims_by_key(key, maxpool_grad_dim_map), key, attrs
    return "", key, attrs
Exemple #10
0
def unsortedsegmentsum_set_dim_func(input_data, ids_tensor, num_segments):
    key = []
    for x in input_data.shape:
        key.append(x)
    for x in ids_tensor.shape:
        key.append(x)
    key.append(num_segments)
    hash_key = str((tuple(key), input_data.dtype))

    return ct_util.set_dims_by_key(hash_key,
                                   unsortedsegmentsum_set_dim_map), hash_key
Exemple #11
0
def smooth_l1_loss_ad_set_dim_func(head,
                                   prediction,
                                   target,
                                   anchor_samples,
                                   anchor_sample_correct=0,
                                   delta=1.0):
    key = []
    for x in prediction.shape:
        key.append(x)

    hash_key = str((tuple(key), prediction.dtype, anchor_samples.dtype))
    return ct_util.set_dims_by_key(hash_key,
                                   smooth_l1_loss_ad_set_dim_map), hash_key
Exemple #12
0
def encode_one_hot_set_dim_func(groundtruth_class, anchor_sample, class_num):
    """setdim function"""
    shape1 = []
    shape2 = []
    for x in groundtruth_class.shape:
        shape1.append(x)
    for x in anchor_sample.shape:
        shape2.append(x)
    hash_key = str(
        (tuple(shape1), tuple(shape2), class_num, groundtruth_class.dtype))

    return ct_util.set_dims_by_key(hash_key,
                                   encode_one_hot_set_dim_map), hash_key
Exemple #13
0
def set_dim_func_(input1):
    """
    Tiling func.

    Args:
        input1:tvm.Tensor of type float32, 3d shape.

    Returns:
        Tiling parameter.
    """
    shape1 = input1.shape
    hash_key = str((shape1))
    if hash_key in set_dim_map_.keys():
        print(set_dim_map_.keys())
    return ct_util.set_dims_by_key(hash_key, set_dim_map_), hash_key
def fused_layer_norm_grad_set_dim_func(x, _dy, _variance, _mean, _gamma,
                                       begin_norm_axis, begin_params_axis):
    """dim function"""
    shape = get_shape(x)
    if begin_norm_axis < 0:
        begin_norm_axis = begin_norm_axis + len(shape)
    if begin_params_axis < 0:
        begin_params_axis = begin_params_axis + len(shape)
    hash_key = str((shape, begin_norm_axis, begin_params_axis, x.dtype))
    attr_map = dict()
    attr_map["pragma_checkcoincident"] = 0
    if hash_key in fused_layer_norm_grad_set_attr_map.keys():
        for attr in fused_layer_norm_grad_set_attr_map[hash_key]:
            attr_map[attr] = 1

    return ct_util.set_dims_by_key(hash_key, fused_layer_norm_grad_set_dim_map), hash_key, attr_map
Exemple #15
0
def four2five_set_dim_func(data, format_, dst_type):
    """set dim info for attr."""
    shape = get_shape(data)
    if format_ == 'NCHW':
        n, _, h, w = shape
    else:
        n, h, w, _ = shape

    shape[0] = 1
    if h != 1 and w != 1:
        if format_ == 'NCHW' and shape[1] > 16:
            shape[1] = 1
        if format_ == 'NHWC' and shape[-1] > 16:
            shape[-1] = 1

    if n == 1:
        shape.remove(shape[0])

    hash_key = str((tuple(shape), format_, data.dtype, dst_type))
    return ct_util.set_dims_by_key(hash_key, four2five_set_dim_map), hash_key
Exemple #16
0
def relu6_grad_set_dim_func(dy, features):
    shape = [x.value for x in dy.shape]
    hash_key = str((tuple(shape), dy.dtype))
    return ct_util.set_dims_by_key(hash_key, relu6_grad_set_dim_map), hash_key
Exemple #17
0
def add_set_dim_func(dy, A, w):
    shape1 = [x.value for x in dy.shape]
    shape2 = [x.value for x in w.shape]
    hash_key = gen_set_dim_key(dy, shape1, shape2)
    return [ct_util.set_dims_by_key(hash_key, add_set_dim_map), hash_key]
Exemple #18
0
def fractal2two_set_dim_func(data, out_dtype, shape_original, format_):
    shape = [x for x in data.shape]

    hash_key = str((tuple(shape), format_, data.dtype))
    return ct_util.set_dims_by_key(hash_key, fractal2two_set_dim_map), hash_key
Exemple #19
0
def two2fractal_set_dim_func(data, format_):
    shape = [x for x in data.shape]

    hash_key = str((tuple(shape), format_, data.dtype))
    return ct_util.set_dims_by_key(hash_key, two2fractal_set_dim_map), hash_key
Exemple #20
0
def lamb_apply_optimizer_assign_set_dim_func(data):
    """set dim info for attr."""
    shape = get_shape(data)
    hash_key = str((tuple(shape), data.dtype))
    return ct_util.set_dims_by_key(
        hash_key, lamb_apply_optimizer_assign_set_dim_map), hash_key