Exemplo n.º 1
0
        private void GenerateBinBn(BinaryWriter bw, K210ConvLayerConfig layer, K210Conv2dParamAddress paramAddress, K210BinGenerationContext context)
        {
            paramAddress.Bn = context.AlignStreamPosition(128);

            for (int j = 0; j < layer.BNConfigs.Length; j++)
            {
                var bn  = layer.BNConfigs[j];
                var reg = new kpu_batchnorm_argument_t();
                reg.norm_add   = (uint)bn.Add;
                reg.norm_mul   = (uint)bn.Mul;
                reg.norm_shift = (byte)bn.Shift;

                bw.Write(reg.Value);
            }
        }
Exemplo n.º 2
0
        private void GenerateBinWeights(BinaryWriter bw, K210ConvLayerConfig layer, K210Conv2dParamAddress paramAddress, K210BinGenerationContext context)
        {
            paramAddress.Weights = context.AlignStreamPosition(128);

            if (context.WeightsBits == 8)
            {
                foreach (var v in layer.Weights)
                {
                    bw.Write((byte)v);
                }
            }
            else
            {
                foreach (var v in layer.Weights)
                {
                    bw.Write(v);
                }
            }
        }
Exemplo n.º 3
0
        private void GenerateBinActivation(BinaryWriter bw, K210ConvLayerConfig layer, K210Conv2dParamAddress paramAddress, K210BinGenerationContext context)
        {
            paramAddress.Activation = context.AlignStreamPosition(256);

            var reg     = new kpu_activate_table_t();
            var configs = layer.ActConfigs;

            for (int i = 0; i < configs.Length; i++)
            {
                var     config = configs[i];
                ref var param  = ref reg.activate_para[i];
                param.x_start      = config.StartX;
                param.y_mul        = (ushort)config.Mul;
                param.shift_number = (byte)config.Shift;
            }