Exemplo n.º 1
0
def create_extern_module(stage, dicts, ip_type="hls", path=None):
    input_ops = [i._op for i in stage.input_stages]
    input_bufs = [i._buf for i in stage.input_stages]
    output_bufs = [stage._buf]

    # input and output arguments
    assert "args" in dicts.keys()
    annotate_dict = dicts
    for name, dtype in dicts["args"]:
        annotate_dict["input::" + name] = dtype
    del annotate_dict["args"]

    # check dependencies
    if ("deps" in dicts.keys()):
        assert os.path.exists(dicts["deps"]), \
                "deps path {} not exists".format(dicts["deps"])

    op = stage._op.op
    assert ip_type in ["rtl", "hls", "host"]
    body = _make.ExternModule("top", _make.StringImm(ip_type), op.body,
                              list(annotate_dict.keys()),
                              list(annotate_dict.values()))

    new_op = _ExternOp(op.name, op.tag, op.axis, input_ops, input_bufs,
                       output_bufs, body)
    stage._op = new_op.output(0)
Exemplo n.º 2
0
def create_extern_module(stage, ip_type="hls", path=None):

    input_ops   = [i._op for i in stage.input_stages]
    input_bufs  = [i._buf for i in stage.input_stages]
    output_bufs = [stage._buf]

    # input and output arguments
    assert stage.ext_ip_name is not None
    attr_keys, attr_values = ["kname"], [stage.ext_ip_name]
    index = 1
    for tensor in stage.inputs:
        try: 
            attr_keys.append("arg:" + tensor.name)
            v = [ tensor.dtype ] 
            for dim in tensor.shape:
                v.append(str(dim))
            attr_values.append(":".join(v))

        except:
            # input is a scalar data type (constant)
            assert isinstance(tensor, (int, float))
            attr_keys.append("arg:{}".format(tensor))
            shape = "int32" if isinstance(tensor, int) else "float32"
            v = [ shape,  "1" ]
            attr_values.append(":".join(v))

        index += 1

    assert len(stage.source) > 0
    attr_keys.append("source")
    v = []
    for _ in stage.source:
      assert os.path.exists(_), "deps path {} not exists".format(_)
      v.append(_)
    attr_values.append(":".join(v))

    attr_keys.append("port_types")
    if len(stage.port_types) > 0:
        assert len(stage.port_types) == len(stage.inputs)
        v = [ str(int(_)) for _ in stage.port_types ]
        attr_values.append(":".join(v))
    else:
        v = [ str(0) for _ in range(len(stage.inputs)) ]
        attr_values.append(":".join(v))

    op = stage._op.op
    assert ip_type in ["RTL", "HLS", "HOST"]
    print(attr_keys, attr_values)
    body = _make.ExternModule(
        "vhls", _make.StringImm(ip_type), op.body, 
        attr_keys, attr_values)

    new_op = _ExternOp(
        op.name, op.tag, op.axis, 
        input_ops, input_bufs, output_bufs, body)
    stage._op = new_op.output(0)
Exemplo n.º 3
0
    def mutate_For(self, node):
        self.count += 1
        loop_var = self.mutate(node.loop_var)
        _min = self.mutate(node.min)
        extent = self.mutate(node.extent)
        self.range_[loop_var] = extent.value - _min.value
        body = self.mutate(node.body)

        if (self.count == self.axis):
            self.count = 0
            if isinstance(body, _stmt.AttrStmt):
                body = body.body
            # insert index map
            index_map = {k.name: v for k, v in self.index_map.items()}
            for i in range(len(self.args)):
                self.info["index" + str(i)] = str(index_map[self.args[i]])

            body = _make.ExternModule("rtl", _make.StringImm("test"), body,
                                      list(self.info.keys()),
                                      list(self.info.values()))

        return _make.For(loop_var, _min, extent, node.for_type,
                         node.device_api, body)