cornell-zhang / heterocl

HeteroCL: A Multi-Paradigm Programming Infrastructure for Software-Defined Heterogeneous Computing
https://cornell-zhang.github.io/heterocl/
Apache License 2.0
326 stars 92 forks source link

[API] Add user-defined project folder support #253

Closed chhzh123 closed 4 years ago

chhzh123 commented 4 years ago

This PR will fix #252 . Users can specify where they want to store and execute their projects by target.config(project="path/to/project").

Following is a full example generating two programs of different schedules and also retaining their results in different folders.

def gemm():
    dtype = hcl.Float()
    M = 64
    K = 64
    N = 64
    A = hcl.placeholder((M, K), "A", dtype=dtype)
    B = hcl.placeholder((K, N), "B", dtype=dtype)
    k = hcl.reduce_axis(0, K)
    def kernel(A, B):
        C = hcl.compute((M, N), lambda x, y: hcl.sum(A[x, k] * B[k, y], axis=k, dtype=dtype), "C", dtype=dtype)
        return C

    def make_schedule(opt=False,project="gemm"):
        s = hcl.create_schedule([A, B], kernel)
        target = hcl.platform.zc706
        target.config(compile="vivado_hls", mode="csyn", project=project) # note this line
        s.to([A, B],target.xcel)
        s.to(kernel.C,target.host)

        def optimization():
            s[kernel.C].pipeline(kernel.C.axis[1])
            s.partition(A,hcl.Partition.Block,dim=2,factor=16)
            s.partition(B,hcl.Partition.Block,dim=1,factor=16)

        if opt:
            optimization()
        f = hcl.build(s, target)

        np_A = np.random.randint(0, 10, (M, K))
        np_B = np.random.randint(0, 10, (K, N))
        np_C = np.zeros((M, N))
        hcl_A = hcl.asarray(np_A)
        hcl_B = hcl.asarray(np_B)
        hcl_C = hcl.asarray(np_C)
        f(hcl_A, hcl_B, hcl_C)

    make_schedule(opt=False, project="gemm")
    make_schedule(opt=True, project="gemm-opt")
chhzh123 commented 4 years ago

It seems Vivado HLS is not installed on the CI server. The previous tests in test_vivado_hls are all skipped without execution. Then how can we test the "csim" or "csyn" mode? @zhangzhiru @seanlatias @Hecmay

hecmay commented 4 years ago

We test it on the private servers right now. We may consider let github automatically deploy HeteroCL to AWS instance (that is running FPGA AMI) to test the full flow, but the cost is another concern...

chhzh123 commented 4 years ago
  1. Fix #256 .
  2. Generate the project folder based on the target name and the schedule name. Users can set the project name by target.config(project="project") and the schedule name by s = hcl.create_schedule(A, kernel, name="schedule"). The final folder name will be project-schedule. If no schedule name is specified, the folder name is just the project name.
zhangzhiru commented 4 years ago

@chhzh123 I suggest we name the folder as - instead since one schedule can be reused by multiple targets?

chhzh123 commented 4 years ago

@chhzh123 I suggest we name the folder as - instead since one schedule can be reused by multiple targets?

What did you mean by - ?

This PR has already enabled multiple schedules to match different targets. For multiple targets, for example, we can write

s = hcl.create_schedule([A], kernel)

target_aws = hcl.platform.aws_f1
target_aws.config(compile="vitis", mode="sw_sim", project="aws")
f1 = hcl.build(s, target_aws)

target_zynq = hcl.platform.zc706
target_zynq.config(compile="vivado_hls", mode="csim", project="zynq")
f2 = hcl.build(s, target_zynq)

and two folders aws and zynq will be created.

zhangzhiru commented 4 years ago

Hmm, somehow my message gets marbled. I typed "-"

chhzh123 commented 4 years ago

If multiple schedules are considered, as shown below

s1 = hcl.create_schedule([A], kernel, name="s1")
s2 = hcl.create_schedule([A], kernel, name="s2")

target_aws = hcl.platform.aws_f1
target_aws.config(compile="vitis", mode="sw_sim", project="aws")
f1 = hcl.build(s1, target_aws)
f2 = hcl.build(s2, target_aws)

target_zynq = hcl.platform.zc706
target_zynq.config(compile="vivado_hls", mode="csim", project="zynq")
f3 = hcl.build(s1, target_zynq)
f4 = hcl.build(s2, target_zynq)

Then aws-s1, aws-s2, zynq-s1, and zynq-s2 will be created.

zhangzhiru commented 4 years ago

Try one more time: "ScheduleName-TargetName"

zhangzhiru commented 4 years ago

Let's show the schedule name first since: (1) the programmer typically specifies it before the target (2) it's probably more often for one to explore multiple schedule but only target a fixed device

hecmay commented 4 years ago

Can you also merge with the master branch and resolve the conflicts?

chhzh123 commented 4 years ago

Can you also merge with the master branch and resolve the conflicts?

Yes, I think #247 should be merged into the master branch before this PR. After that, I will resolve the conflicts.

chhzh123 commented 4 years ago
  1. Change folder name to Schedule-Target.
    • If no schedule name is specified by users, the name will be automatically generated from "s1", "s2" ...
    • If no target name is specified, by default a project folder will be generated as before.
  2. Users can retrieve multiple reports via f.report() as shown below. Since the schedule and the target are attached to the built Module, it is no need to pass any arguments to the report function.
    report1 = f1.report()
    report2 = f2.report()
chhzh123 commented 4 years ago

@Hecmay Could you help check the functionality of other backend tools? I only test this feature on vivado_hls.