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 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, 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, 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
def __init__(self, node_name, cname, pool_params, pool_q, act_params, act_q, force_relu, gen_ctrl=None): if gen_ctrl is None: self.gen_ctrl = 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" ]: hwc = True gen_ctrl.hwc = 1 pad_compatibilities = [] at_pool_params = gen_pool_at_params(pool_params, pad_compatibilities) in_dim = pool_params.in_dims[0] out_dim = pool_params.out_dims[0] in_q = pool_q.in_qs[0] out_q = pool_q.out_qs[0] if act_params is not None: act_op = gen_activation_op( act_params.activation, force_relu=force_relu, asymmetric=act_q.in_qs[0].zero_point != 0) if out_dim is None: out_dim = act_params.out_dims[0].expand_to_chw() out_q = act_q.out_qs[0] else: act_op = "KOP_NONE" 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 attrs = { 'in_size': in_q.dtype_bits // 8 if in_q.signed else -in_q.dtype_bits // 8, 'out_size': out_q.dtype_bits // 8 if out_q.signed else -out_q.dtype_bits // 8, 'feat': in_dim.c, 'width': in_dim.w, 'height': in_dim.h, 'kop_pool': at_pool_params.PoolOper, 'fpx': at_pool_params.Fpx, 'fpy': at_pool_params.Fpy, 'dpx': at_pool_params.Dpx, 'dpy': at_pool_params.Dpy, 'spx': at_pool_params.Spx, 'spy': at_pool_params.Spy, 'pool_pad': at_pool_params.PoolPad, 'kop_act': act_op } extra_attrs = {'cname': cname, 'node_name': node_name} super().__init__(attrs, extra_attrs, gen_ctrl=gen_ctrl)
def __init__(self, node_name, cname, conv_params, conv_q, pool_params, pool_q, act_params, act_q, force_relu, gen_ctrl=None): if gen_ctrl is None: self.gen_ctrl = gen_ctrl = GenCtrl(None, cname=cname) else: gen_ctrl.cname = cname self.gen_ctrl = gen_ctrl is_ne16 = conv_q.cache.get('ne16') hwc = False if not is_ne16 and conv_params.ker_in_order and conv_params.ker_in_order[0] == ["h", "w", "c"]: hwc = True gen_ctrl.hwc = 1 if not is_ne16 and not hwc and conv_params.filter.h == 1 and conv_params.filter.w == 1 and gen_ctrl.enableim2col is None: gen_ctrl.enableim2col = 1 in_q = filter_q = out_q = bias_q = None in_dim = out_dim = None pad_compatibilities = [] 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] 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] pad_val = in_q.zero_point[0] if pool_params is not None: at_pool_params = gen_pool_at_params( pool_params, pad_compatibilities) out_dim = pool_params.out_dims[0] out_q = pool_q.out_qs[0] else: at_pool_params = NO_POOL if act_params is not None: act_op = gen_activation_op( act_params.activation, force_relu=force_relu, asymmetric=act_q.in_qs[0].zero_point != 0) if out_dim is None: out_dim = act_params.out_dims[0].expand_to_chw() out_q = act_q.out_qs[0] else: act_op = "KOP_NONE" 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 attrs = { 'in_size': in_q.dtype_bits//8 if in_q.signed else -in_q.dtype_bits//8, 'out_size': out_q.dtype_bits//8 if out_q.signed else -out_q.dtype_bits//8, 'bias_size': bias_q.dtype_bits//8, 'filter_bits': filter_q.bits, 'in_feat': in_dim.c, 'out_feat': out_dim.c, 'in_width': in_dim.w, 'in_height': in_dim.h, 'kop_conv': at_conv_params.ConvOper, 'fcx': at_conv_params.Fcx, 'fcy': at_conv_params.Fcy, 'dcx': at_conv_params.Dcx, 'dcy': at_conv_params.Dcy, 'scx': at_conv_params.Scx, 'scy': at_conv_params.Scy, 'conv_pad': at_conv_params.ConvPad, 'pad_value': pad_val, 'kop_pool': at_pool_params.PoolOper, 'fpx': at_pool_params.Fpx, 'fpy': at_pool_params.Fpy, 'dpx': at_pool_params.Dpx, 'dpy': at_pool_params.Dpy, 'spx': at_pool_params.Spx, 'spy': at_pool_params.Spy, 'pool_pad': at_pool_params.PoolPad, 'kop_act': act_op } extra_attrs = { 'cname': cname, 'node_name': node_name } super().__init__(attrs, extra_attrs, gen_ctrl=gen_ctrl)