def __init__(self, node_name, cname, pool_params, act_params, gen_ctrl=None, at_ver=3): if gen_ctrl is None: self.gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl if act_params is not None: self.at_act_params = gen_active_at_params(act_params, force_relu=True) else: self.at_act_params = NO_ACTIVATION self.at_globalpool_params = gen_globalpool_at_params(pool_params) self.in_dim = pool_params.in_dims[0] self.out_dim = pool_params.out_dims[0] self.cname = cname self.node_name = node_name self.at_ver = at_ver
def __init__(self, node_name, cname, pool_params, act_params, gen_ctrl=None, at_ver=3, force_relu=True): if gen_ctrl is None: self.gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl if act_params is not None: self.at_act_params = gen_active_at_params(act_params, force_relu=force_relu) else: self.at_act_params = NO_ACTIVATION self.at_globalpool_params = gen_globalpool_at_params(pool_params) in_dim = pool_params.in_dims[0] reduce_sz = reduce(lambda x, y: x * y, (sz for idx, sz in enumerate(in_dim.shape) if idx not in pool_params.axis), 1) #self.c = in_dim.size()/reduce_sz self.c = reduce_sz (self.h, self.w) = balanced_divisors(in_dim.size() / reduce_sz) self.cname = cname self.node_name = node_name self.at_ver = at_ver
def __init__(self, node_name, cname, matrixadd_params, act_params, act_q=None, at_ver=3, gen_ctrl=None, force_relu=True): if gen_ctrl is None: self.gen_ctrl = gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl self.cname = cname self.node_name = node_name self.at_ver = at_ver if act_params is not None: self.at_act_params = gen_active_at_params( act_params, force_relu=force_relu, asymmetric=act_q.in_qs[0].zero_point != 0) else: self.at_act_params = NO_ACTIVATION self.matrixadd_params = matrixadd_params dimensions = make_three_dims(matrixadd_params.in_dims[0]) self.feat_dim = dimensions[0] self.width = dimensions[1] self.height = dimensions[2]
def __init__(self, node_name, cname, tens_vect_mul_params, act_params, at_ver=3, gen_ctrl=None, force_relu=True): if gen_ctrl is None: self.gen_ctrl = gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl self.cname = cname self.node_name = node_name self.at_ver = at_ver if act_params is not None: self.at_act_params = gen_active_at_params(act_params, force_relu=force_relu) else: self.at_act_params = NO_ACTIVATION self.tens_vect_mul_params = tens_vect_mul_params dimensions = tens_vect_mul_params.in_dims[0] self.feat_dim = dimensions[0] self.width = dimensions[1] self.height = dimensions[2]
def __init__(self, node_name, cname, tens_vect_mul_params, act_params, at_ver=3, gen_ctrl=None, force_relu=True): if gen_ctrl is None: self.gen_ctrl = gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl self.cname = cname self.node_name = node_name self.at_ver = at_ver if act_params is not None: self.at_act_params = gen_active_at_params( act_params, force_relu=force_relu) else: self.at_act_params = NO_ACTIVATION self.tens_vect_mul_params = tens_vect_mul_params if tens_vect_mul_params.in_dims[0] == tens_vect_mul_params.in_dims[1]: # broadcast matrix * matrix self.feat_dim = tens_vect_mul_params.in_dims[0].size() self.height = 1 self.width = 1 else: # probably need more logic here to handle dimensions = tens_vect_mul_params.in_dims[0] self.feat_dim = dimensions[0] self.width = dimensions[1] self.height = dimensions[2]
def __init__(self, node_name, cname, linear_params, linear_q, act_params, act_q, at_ver=3, gen_ctrl=None, force_relu=True): if gen_ctrl is None: self.gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl assert linear_params is not None, "linear should always be included" at_linear_params = gen_linear_at_params(linear_params) in_dim = linear_params.in_dims[0] out_dim = linear_params.out_dims[0] filter_q = linear_q.in_qs[1] in_q = linear_q.in_qs[0] out_q = linear_q.out_qs[0] bias_q = linear_q.in_qs[2] if act_params is not None: at_act_params = gen_active_at_params(act_params, force_relu=force_relu) if in_dim is None: in_dim = act_params.in_dims[0] if out_dim is None: out_dim = act_params.out_dims[0] if in_q is None: in_q = act_q.in_qs[0] out_q = act_q.out_qs[0] else: at_act_params = NO_ACTIVATION self.at_linear_params = at_linear_params self.in_dim = in_dim.size() self.out_dim = out_dim.size() self.in_q = in_q self.bias_q = bias_q self.out_q = out_q self.filter_q = filter_q self.at_act_params = at_act_params self.cname = cname self.node_name = node_name self.at_ver = at_ver
def __init__(self, node_name, cname, pool_params, act_params, qrec, act_q=None, gen_ctrl=None, at_ver=3, force_relu=True): if gen_ctrl is None: self.gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl if pool_params.ker_in_order and pool_params.ker_in_order[0] == [ "h", "w", "c" ]: self.gen_ctrl.hwc = 1 if not qrec.out_qs[0].signed: self.gen_ctrl.output_datasize = -qrec.out_qs[0].dtype_bits // 8 if not qrec.in_qs[0].signed: self.gen_ctrl.input_datasize = -qrec.in_qs[0].dtype_bits // 8 if act_params is not None: self.at_act_params = gen_active_at_params( act_params, force_relu=force_relu, asymmetric=act_q.in_qs[0].zero_point != 0) else: self.at_act_params = NO_ACTIVATION pad_compatibilities = [] self.at_pool_params = gen_pool_at_params(pool_params, pad_compatibilities) self.in_dim = pool_params.in_dims[0] self.out_dim = pool_params.out_dims[0] self.cname = cname self.node_name = node_name self.at_ver = at_ver
def __init__(self, node_name, cname, matadd_params, act_params=None, add_q=None, act_q=None, force_relu=True, gen_ctrl=None): if gen_ctrl is None: gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname if not add_q.out_qs[0].signed: gen_ctrl.output_datasize = -add_q.out_qs[0].dtype_bits // 8 if not add_q.in_qs[0].signed: gen_ctrl.input_datasize = -add_q.in_qs[0].dtype_bits // 8 if act_params is not None: at_act_params = gen_active_at_params( act_params, force_relu=force_relu, asymmetric=act_q.in_qs[0].zero_point != 0) else: at_act_params = NO_ACTIVATION dimensions = make_three_dims(matadd_params.in_dims[0]) attrs = { 'feat': dimensions[0], 'width': dimensions[1], 'height': dimensions[2], 'act_oper': at_act_params.ReLUOper } extra_attrs = {'cname': cname, 'node_name': node_name} super().__init__(attrs, extra_attrs, gen_ctrl=gen_ctrl)
def __init__(self, node_name, cname, pool_params, act_params, act_q=None, gen_ctrl=None, at_ver=3, force_relu=True): if gen_ctrl is None: self.gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl if pool_params.ker_in_order and pool_params.ker_in_order[0] == [ "h", "w", "c" ]: self.gen_ctrl.hwc = 1 if act_params is not None: self.at_act_params = gen_active_at_params( act_params, force_relu=force_relu, asymmetric=act_q.in_qs[0].zero_point != 0) else: self.at_act_params = NO_ACTIVATION self.at_globalpool_params = gen_globalpool_at_params(pool_params) in_dim = pool_params.in_dims[0] reduce_sz = reduce(lambda x, y: x * y, (sz for idx, sz in enumerate(in_dim.shape) if idx not in pool_params.axis), 1) #self.c = in_dim.size()/reduce_sz self.c = reduce_sz (self.h, self.w) = balanced_divisors(in_dim.size() / reduce_sz) self.cname = cname self.node_name = node_name self.at_ver = at_ver
def __init__(self, node_name, cname, conv_params, conv_q, pool_params, pool_q, act_params, act_q, at_ver=3, gen_ctrl=None): self.ne16 = False if gen_ctrl is None: self.gen_ctrl = gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl in_q = filter_q = out_q = bias_q = mul_biases_q = None in_dim = out_dim = None pad_compatibilities = [] if conv_params is not None: if conv_params.ker_in_order and conv_params.ker_in_order[0] == [ "h", "w", "c" ]: self.hwc = True self.gen_ctrl.hwc = 1 at_conv_params = gen_conv_at_params(conv_params, pad_compatibilities) in_dim = conv_params.in_dims[0] out_dim = conv_params.out_dims[0] # Set ENABLEIM2COL on 1x1 filters by default if conv_params.filter.h == 1 and conv_params.filter.w == 1 and gen_ctrl.enableim2col is None: gen_ctrl.enableim2col = 1 filter_q = conv_q.in_qs[1] in_q = conv_q.in_qs[0] out_q = conv_q.out_qs[0] bias_q = conv_q.in_qs[2] if conv_params.has_mul_bias: mul_biases_q = conv_q.mul_biases_q self.ne16 = conv_q.cache.get('ne16') else: at_conv_params = NO_CONV if pool_params is not None: if pool_params.ker_in_order and pool_params.ker_in_order[0] == [ "h", "w", "c" ]: self.hwc = True self.gen_ctrl.hwc = 1 at_pool_params = gen_pool_at_params(pool_params, pad_compatibilities) if in_dim is None: in_dim = pool_params.in_dims[0] out_dim = pool_params.out_dims[0] if in_q is None: in_q = pool_q.in_qs[0] out_q = pool_q.out_qs[0] else: at_pool_params = NO_POOL if act_params is not None: if act_params.ker_in_order and act_params.ker_in_order[0] == [ "h", "w", "c" ]: self.hwc = True self.gen_ctrl.hwc = 1 if in_q is None: in_q = act_q.in_qs[0] at_act_params = gen_active_at_params( act_params, force_relu=False, asymmetric=act_q.in_qs[0].zero_point != 0) if isinstance(act_params, ReluActivationParameters) and act_params.upper_bound: self.gen_ctrl.relun = act_params.upper_bound if in_dim is None: in_dim = act_params.in_dims[0].expand_to_chw() if out_dim is None: out_dim = act_params.out_dims[0].expand_to_chw() out_q = act_q.out_qs[0] else: at_act_params = NO_ACTIVATION if pad_compatibilities: reduction = PadDim.pad_compatibility_reduce( *pad_compatibilities, "convolution padding is not compatible with pool padding") if not reduction[2]: # default is balanced pad left at_pad_ctrl = next(i for i, v in enumerate(reduction) if v) LOG.debug("%s: generating pad control block", node_name) self.gen_ctrl.PadType = at_pad_ctrl self.in_dim = in_dim self.out_dim = out_dim self.in_q = in_q self.bias_q = bias_q self.out_q = out_q self.filter_q = filter_q self.mul_biases_q = mul_biases_q self.at_act_params = at_act_params self.at_pool_params = at_pool_params self.at_conv_params = at_conv_params self.cname = cname self.node_name = node_name self.at_ver = at_ver
def __init__(self, node_name, cname, conv_params, conv_q, pool_params, pool_q, act_params, act_q, at_ver=3, gen_ctrl=None, force_relu=True): if gen_ctrl is None: self.gen_ctrl = gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl in_q = filter_q = out_q = bias_q = mul_biases_q = None in_dim = out_dim = None pad_compatibilities = [] if conv_params is not None: at_conv_params = gen_conv_at_params(conv_params, pad_compatibilities) in_dim = conv_params.in_dims[0] out_dim = conv_params.out_dims[0] # Set ENABLEIM2COL on 1x1 filters by default if conv_params.filter.h == 1 and conv_params.filter.w == 1 and gen_ctrl.enableim2col is None: gen_ctrl.enableim2col = 1 filter_q = conv_q.in_qs[1] in_q = conv_q.in_qs[0] out_q = conv_q.out_qs[0] bias_q = conv_q.in_qs[2] if conv_params.has_mul_bias: mul_biases_q = conv_q.mul_biases_q else: at_conv_params = NO_CONV if pool_params is not None: at_pool_params = gen_pool_at_params(pool_params, pad_compatibilities) if in_dim is None: in_dim = pool_params.in_dims[0] out_dim = pool_params.out_dims[0] if in_q is None: in_q = pool_q.in_qs[0] out_q = pool_q.out_qs[0] else: at_pool_params = NO_POOL if act_params is not None: at_act_params = gen_active_at_params(act_params, force_relu=force_relu) if in_dim is None: in_dim = act_params.in_dims[0].expand_to_chw() if out_dim is None: out_dim = act_params.out_dims[0].expand_to_chw() if in_q is None: in_q = act_q.in_qs[0] out_q = act_q.out_qs[0] else: at_act_params = NO_ACTIVATION if pad_compatibilities: reduction = PadDim.pad_compatibility_reduce( *pad_compatibilities, "convolution padding is not compatible with pool padding") if not reduction[2]: # default is balanced pad left at_pad_ctrl = next(i for i, v in enumerate(reduction) if v) LOG.debug("%s: generating pad control block", node_name) self.gen_ctrl.PadType = at_pad_ctrl self.in_dim = in_dim self.out_dim = out_dim self.in_q = in_q self.bias_q = bias_q self.out_q = out_q self.filter_q = filter_q self.mul_biases_q = mul_biases_q self.at_act_params = at_act_params self.at_pool_params = at_pool_params self.at_conv_params = at_conv_params self.cname = cname self.node_name = node_name self.at_ver = at_ver