コード例 #1
0
    def code(self, code_block=None):
        if code_block is None:
            code_block = CodeBlock()

        code_block.comment("generator for {}", self.node_name)

        if not self.gen_ctrl.is_unmodified:
            self.gen_ctrl.gen_ctrl_decl(code_block)

        gen_at_pool_relu(code_block, self.cname, self.in_q, self.out_q,
                         self.in_dim, self.out_dim, self.at_pool_params,
                         self.at_act_params, gen_ctrl=self.gen_ctrl,
                         at_ver=self.at_ver)

        return code_block
コード例 #2
0
    def code(self, code_block=None):
        if code_block is None:
            code_block = CodeBlock()

        code_block.comment("generator for {}", self.node_name)

        if not self.gen_ctrl.is_unmodified:
            self.gen_ctrl.gen_ctrl_decl(code_block)

        if self.at_conv_params == NO_CONV:
            if self.in_q.bits != self.out_q.bits:
                raise NotImplementedError(
                    "only homogenious operations are supported at present")
            LOG.debug("%s: pool relu inq %s outq %s control block",
                      self.node_name, self.in_q, self.out_q)
            gen_at_pool_relu(code_block,
                             self.cname,
                             self.in_q,
                             self.out_q,
                             self.in_dim,
                             self.out_dim,
                             self.at_pool_params,
                             self.at_act_params,
                             gen_ctrl=self.gen_ctrl,
                             at_ver=self.at_ver)
        else:
            if isinstance(self.at_conv_params, ConvATParam):
                if self.mul_biases_q is not None:
                    LOG.debug(
                        "%s: mulconv pool relu inq %s outq %s control block",
                        self.node_name, self.in_q, self.out_q)
                    gen_at_mulconv_pool_relu(code_block,
                                             self.cname,
                                             self.in_q,
                                             self.out_q,
                                             self.filter_q,
                                             self.bias_q,
                                             self.mul_biases_q,
                                             self.in_dim,
                                             self.out_dim,
                                             self.at_conv_params,
                                             self.at_pool_params,
                                             self.at_act_params,
                                             gen_ctrl=self.gen_ctrl,
                                             at_ver=self.at_ver)
                else:
                    LOG.debug(
                        "%s: conv pool relu inq %s outq %s control block",
                        self.node_name, self.in_q, self.out_q)
                    gen_at_conv_pool_relu(code_block,
                                          self.cname,
                                          self.in_q,
                                          self.out_q,
                                          self.filter_q,
                                          self.bias_q,
                                          self.in_dim,
                                          self.out_dim,
                                          self.at_conv_params,
                                          self.at_pool_params,
                                          self.at_act_params,
                                          gen_ctrl=self.gen_ctrl,
                                          at_ver=self.at_ver)
            elif isinstance(self.at_conv_params, GroupedConvATParam):
                if self.mul_biases_q is not None:
                    LOG.debug(
                        "%s: grouped conv pool relu inq %s outq %s control block",
                        self.node_name, self.in_q, self.out_q)
                    gen_at_grouped_mulconv_pool_relu(code_block,
                                                     self.cname,
                                                     self.in_q,
                                                     self.out_q,
                                                     self.filter_q,
                                                     self.bias_q,
                                                     self.mul_biases_q,
                                                     self.in_dim,
                                                     self.out_dim,
                                                     self.at_conv_params,
                                                     self.at_pool_params,
                                                     self.at_act_params,
                                                     gen_ctrl=self.gen_ctrl,
                                                     at_ver=self.at_ver)
                else:
                    LOG.debug(
                        "%s: grouped mulconv pool relu inq %s outq %s control block",
                        self.node_name, self.in_q, self.out_q)
                    gen_at_grouped_conv_pool_relu(code_block,
                                                  self.cname,
                                                  self.in_q,
                                                  self.out_q,
                                                  self.filter_q,
                                                  self.bias_q,
                                                  self.in_dim,
                                                  self.out_dim,
                                                  self.at_conv_params,
                                                  self.at_pool_params,
                                                  self.at_act_params,
                                                  gen_ctrl=self.gen_ctrl,
                                                  at_ver=self.at_ver)
            else:
                raise ValueError('Internal error')

        return code_block