hls.tcl 4.87 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# 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.

# Command line arguments:
19 20 21 22 23 24
# Arg 1: path to vta root
# Arg 2: path of config param script

if { [llength $argv] eq 4 } {
    set root_dir        [lindex $argv 2]
    set vta_config      [lindex $argv 3]
25
} else {
26 27
    puts "Not enough arguments provided!"
    exit
28 29
}

30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
# Derive paths
set src_dir "$root_dir/hardware/xilinx/src"
set sim_dir "$root_dir/hardware/xilinx/sim"
set test_dir "$root_dir/tests/hardware/common"

# C define flags that we want to pass to the compiler
set cflags [exec python $vta_config --cflags]

# Get the VTA configuration paramters
set ::device        [exec python $vta_config --get-fpga-dev]
set ::period        [exec python $vta_config --get-fpga-per]

# Get the VTA SRAM reshape/partition factors to get all memories
# to be of the same axi width.
set ::inp_reshape_factor    [exec python $vta_config --get-inp-mem-axi-ratio]
set ::inp_partition_factor  [exec python $vta_config --get-inp-mem-banks]
set ::wgt_reshape_factor    [exec python $vta_config --get-wgt-mem-axi-ratio]
set ::wgt_partition_factor  [exec python $vta_config --get-wgt-mem-banks]
set ::out_reshape_factor    [exec python $vta_config --get-out-mem-axi-ratio]
set ::out_partition_factor  [exec python $vta_config --get-out-mem-banks]


52 53 54
# Initializes the HLS design and sets HLS pragmas for memory partitioning.
# This is necessary because of a Vivado restriction that doesn't allow for
# buses wider than 1024 bits.
55
proc init_design {} {
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
    # Set device id
    set_part $::device

    # Set the clock frequency
    create_clock -period $::period -name default

    # HLS pragmas to reshape/partition the input memory read/write port
    set_directive_array_reshape -type block -factor $::inp_reshape_factor -dim 2 "load" inp_mem
    set_directive_array_reshape -type block -factor $::inp_reshape_factor -dim 2 "compute" inp_mem
    if {$::inp_partition_factor > 1} {
        set_directive_array_partition -type block -factor $::inp_partition_factor -dim 2 "load" inp_mem
        set_directive_array_partition -type block -factor $::inp_partition_factor -dim 2 "compute" inp_mem
    }
    # HLS pragmas to reshape/partition the weight memory read/write port
    set_directive_array_reshape -type block -factor $::wgt_reshape_factor -dim 2 "load" wgt_mem
    set_directive_array_reshape -type block -factor $::wgt_reshape_factor -dim 2 "compute" wgt_mem
    if {$::wgt_partition_factor >1} {
        set_directive_array_partition -type block -factor $::wgt_partition_factor -dim 2 "load" wgt_mem
        set_directive_array_partition -type block -factor $::wgt_partition_factor -dim 2 "compute" wgt_mem
    }
    # HLS pragmas to reshape/partition the output memory read/write port
    set_directive_array_reshape -type block -factor $::out_reshape_factor -dim 2 "compute" out_mem
    set_directive_array_reshape -type block -factor $::out_reshape_factor -dim 2 "store" out_mem
    if {$::out_partition_factor > 1} {
        set_directive_array_partition -type block -factor $::out_partition_factor -dim 2 "compute" out_mem
        set_directive_array_partition -type block -factor $::out_partition_factor -dim 2 "store" out_mem
    }
84 85 86
}

# HLS behavioral sim
87 88 89 90 91 92 93 94 95
open_project vta_sim
set_top vta
add_files $src_dir/vta.cc -cflags $cflags
add_files -tb $sim_dir/vta_test.cc -cflags $cflags
add_files -tb $test_dir/test_lib.cc -cflags $cflags
open_solution "soln"
init_design
csim_design -clean
close_project
96 97

# Generate fetch stage
98 99 100 101 102 103 104 105
open_project vta_fetch
set_top fetch
add_files $src_dir/vta.cc -cflags $cflags
open_solution "soln"
init_design
csynth_design
export_design -format ip_catalog
close_project
106 107

# Generate load stage
108 109 110 111 112 113 114 115
open_project vta_load
set_top load
add_files $src_dir/vta.cc -cflags $cflags
open_solution "soln"
init_design
csynth_design
export_design -format ip_catalog
close_project
116 117

# Generate compute stage
118 119 120 121 122 123 124 125
open_project vta_compute
set_top compute
add_files $src_dir/vta.cc -cflags $cflags
open_solution "soln"
init_design
csynth_design
export_design -format ip_catalog
close_project
126 127

# Generate store stage
128 129 130 131 132 133 134 135
open_project vta_store
set_top store
add_files $src_dir/vta.cc -cflags $cflags
open_solution "soln"
init_design
csynth_design
export_design -format ip_catalog
close_project
136 137 138

exit