Esempio n. 1
0
        public void GenerateBin(BinaryWriter bw, K210Conv2dLayerArgument argument, K210BinGenerationContext context)
        {
            bw.Write((uint)argument.Flags);
            bw.Write(argument.MainMemoryOutputAddress);
            // Param addresses
            var fixPosition = bw.BaseStream.Position;

            bw.BaseStream.Position += 4 * 4;

            GenerateBinLayer(bw, argument.Config, argument.ParamAddress, context);
            GenerateBinWeights(bw, argument.Config, argument.ParamAddress, context);
            GenerateBinBn(bw, argument.Config, argument.ParamAddress, context);
            GenerateBinActivation(bw, argument.Config, argument.ParamAddress, context);

            var newPosition = bw.BaseStream.Position;

            bw.BaseStream.Position = fixPosition;
            bw.Write(argument.ParamAddress.Layer);
            bw.Write(argument.ParamAddress.Weights);
            bw.Write(argument.ParamAddress.Bn);
            bw.Write(argument.ParamAddress.Activation);
            bw.BaseStream.Position = newPosition;
        }
Esempio n. 2
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;
            }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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);
                }
            }
        }