vta_config.py 8.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.
17 18 19 20 21 22 23 24 25
"""VTA config tool"""
import os
import sys
import json
import argparse

def get_pkg_config(cfg):
    """Get the pkg config object."""
    curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
26
    proj_root = os.path.abspath(os.path.join(curr_path, "../../../"))
27
    pkg_config_py = os.path.join(proj_root, "vta/python/vta/pkg_config.py")
28 29 30 31 32 33 34 35
    libpkg = {"__file__": pkg_config_py}
    exec(compile(open(pkg_config_py, "rb").read(), pkg_config_py, "exec"), libpkg, libpkg)
    PkgConfig = libpkg["PkgConfig"]
    return PkgConfig(cfg, proj_root)

def main():
    """Main funciton"""
    parser = argparse.ArgumentParser()
36 37
    parser.add_argument("--use-cfg", type=str, default="",
                        help="path to the config json")
38 39
    parser.add_argument("--cflags", action="store_true",
                        help="print the cflags")
40 41 42 43
    parser.add_argument("--defs", action="store_true",
                        help="print the macro defs")
    parser.add_argument("--sources", action="store_true",
                        help="print the source file paths")
44 45 46
    parser.add_argument("--update", action="store_true",
                        help="Print out the json option.")
    parser.add_argument("--ldflags", action="store_true",
47
                        help="print the ldflags")
48 49
    parser.add_argument("--cfg-json", action="store_true",
                        help="print all the config json")
50 51
    parser.add_argument("--save-cfg-json", type=str, default="",
                        help="save config json to file")
52 53
    parser.add_argument("--target", action="store_true",
                        help="print the target")
54 55
    parser.add_argument("--cfg-str", action="store_true",
                        help="print the configuration string")
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
    parser.add_argument("--get-inp-mem-banks", action="store_true",
                        help="returns number of input memory banks")
    parser.add_argument("--get-inp-mem-width", action="store_true",
                        help="returns input memory read/write port width")
    parser.add_argument("--get-inp-mem-depth", action="store_true",
                        help="returns input memory depth")
    parser.add_argument("--get-inp-mem-axi-ratio", action="store_true",
                        help="returns ratio between input element width and axi width")
    parser.add_argument("--get-wgt-mem-banks", action="store_true",
                        help="returns number of weight memory banks")
    parser.add_argument("--get-wgt-mem-width", action="store_true",
                        help="returns weight memory read/write port width")
    parser.add_argument("--get-wgt-mem-depth", action="store_true",
                        help="returns weight memory depth")
    parser.add_argument("--get-wgt-mem-axi-ratio", action="store_true",
                        help="returns ratio between weight element width and axi width")
    parser.add_argument("--get-out-mem-banks", action="store_true",
                        help="returns number of output memory banks")
    parser.add_argument("--get-out-mem-width", action="store_true",
                        help="returns output memory read/write port width")
    parser.add_argument("--get-out-mem-depth", action="store_true",
                        help="returns output memory depth")
    parser.add_argument("--get-out-mem-axi-ratio", action="store_true",
                        help="returns ratio between output element width and axi width")
    parser.add_argument("--get-axi-cache-bits", action="store_true",
                        help="returns AXI system ARCACHE/AWCACHE hardcoded bit value")
    parser.add_argument("--get-axi-prot-bits", action="store_true",
                        help="returns AXI system ARPROT/AWPROT hardcoded bit value")
    parser.add_argument("--get-ip-reg-map-range", action="store_true",
                        help="returns ip register map address range")
    parser.add_argument("--get-fetch-base-addr", action="store_true",
                        help="returns fetch module base address")
    parser.add_argument("--get-load-base-addr", action="store_true",
                        help="returns load module base address")
    parser.add_argument("--get-compute-base-addr", action="store_true",
                        help="returns compute module base address")
    parser.add_argument("--get-store-base-addr", action="store_true",
                        help="returns store module base address")
    parser.add_argument("--get-fpga-dev", action="store_true",
                        help="returns FPGA device target")
    parser.add_argument("--get-fpga-family", action="store_true",
                        help="returns FPGA device family")
    parser.add_argument("--get-fpga-freq", action="store_true",
99
                        help="returns FPGA frequency")
100
    parser.add_argument("--get-fpga-per", action="store_true",
101
                        help="returns HLS target clock period")
102 103 104 105 106 107 108 109
    args = parser.parse_args()

    if len(sys.argv) == 1:
        parser.print_help()
        return

    curr_path = os.path.dirname(
        os.path.abspath(os.path.expanduser(__file__)))
110
    proj_root = os.path.abspath(os.path.join(curr_path, "../../../"))
111
    path_list = [
112
        os.path.join(proj_root, "vta/vta-hw/config/vta_config.json")
113
    ]
114 115
    if args.use_cfg:
        path_list = [args.use_cfg]
116 117 118 119
    ok_path_list = [p for p in path_list if os.path.exists(p)]
    if not ok_path_list:
        raise RuntimeError("Cannot find config in %s" % str(path_list))
    cfg = json.load(open(ok_path_list[0]))
120

121 122 123
    pkg = get_pkg_config(cfg)

    if args.target:
124
        print(pkg.TARGET)
125

126 127 128 129 130 131
    if args.defs:
        print(" ".join(pkg.macro_defs))

    if args.sources:
        print(" ".join(pkg.lib_source))

132
    if args.cflags:
133
        cflags_str = " ".join(pkg.cflags)
134
        if pkg.TARGET == "pynq":
135
            cflags_str += " -DVTA_TARGET_PYNQ"
136
        elif pkg.TARGET == "de10nano":
137 138
            cflags_str += " -DVTA_TARGET_DE10_NANO"
        elif pkg.TARGET == "ultra96":
139
            cflags_str += " -DVTA_TARGET_ULTRA96"
140
        print(cflags_str)
141 142 143 144 145 146 147

    if args.ldflags:
        print(" ".join(pkg.ldflags))

    if args.cfg_json:
        print(pkg.cfg_json)

148 149 150 151
    if args.save_cfg_json:
        with open(args.save_cfg_json, "w") as fo:
            fo.write(pkg.cfg_json)

152
    if args.cfg_str:
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
        print(pkg.TARGET + "_" + pkg.bitstream)

    if args.get_inp_mem_banks:
        print(pkg.inp_mem_banks)

    if args.get_inp_mem_width:
        print(pkg.inp_mem_width)

    if args.get_inp_mem_depth:
        print(pkg.inp_mem_depth)

    if args.get_inp_mem_axi_ratio:
        print(pkg.inp_mem_axi_ratio)

    if args.get_wgt_mem_banks:
        print(pkg.wgt_mem_banks)

    if args.get_wgt_mem_width:
        print(pkg.wgt_mem_width)

    if args.get_wgt_mem_depth:
        print(pkg.wgt_mem_depth)

    if args.get_wgt_mem_axi_ratio:
        print(pkg.wgt_mem_axi_ratio)

    if args.get_out_mem_banks:
        print(pkg.out_mem_banks)
181

182 183
    if args.get_out_mem_width:
        print(pkg.out_mem_width)
184

185 186
    if args.get_out_mem_depth:
        print(pkg.out_mem_depth)
187

188 189
    if args.get_out_mem_axi_ratio:
        print(pkg.out_mem_axi_ratio)
190

191 192
    if args.get_axi_cache_bits:
        print(pkg.axi_cache_bits)
193

194 195
    if args.get_axi_prot_bits:
        print(pkg.axi_prot_bits)
196

197 198
    if args.get_ip_reg_map_range:
        print(pkg.ip_reg_map_range)
199

200 201
    if args.get_fetch_base_addr:
        print(pkg.fetch_base_addr)
202

203 204
    if args.get_load_base_addr:
        print(pkg.load_base_addr)
205

206 207
    if args.get_compute_base_addr:
        print(pkg.compute_base_addr)
208

209 210
    if args.get_store_base_addr:
        print(pkg.store_base_addr)
211

212 213
    if args.get_fpga_dev:
        print(pkg.fpga_device)
214

215 216
    if args.get_fpga_family:
        print(pkg.fpga_family)
217

218 219
    if args.get_fpga_freq:
        print(pkg.fpga_freq)
220

221 222
    if args.get_fpga_per:
        print(pkg.fpga_per)
223

224 225
if __name__ == "__main__":
    main()