From 70246ab7bd03753a3509626a235adf8502a0afa1 Mon Sep 17 00:00:00 2001
From: Hashim Sharif <hsharif3@miranda.cs.illinois.edu>
Date: Tue, 8 Jun 2021 21:54:50 -0500
Subject: [PATCH] Adding nvdla pass sequence in hpvm-clang

---
 hpvm/tools/hpvm-clang/main.py.in | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/hpvm/tools/hpvm-clang/main.py.in b/hpvm/tools/hpvm-clang/main.py.in
index 6c81e27f26..57c68ec5d7 100644
--- a/hpvm/tools/hpvm-clang/main.py.in
+++ b/hpvm/tools/hpvm-clang/main.py.in
@@ -52,6 +52,18 @@ def compile_hpvm_c(
             "inplace", "hpvm-fuse", "dfg2llvm-wrapperapi",
             f"configuration-inputs-filename={conf_file}"
         ]
+      
+    elif tensor_target == "nvdla":
+        if conf_file is None:
+            raise ValueError("conf_file must be defined when tensor_target=='tensor'.")
+
+        passes += ["LLVMHPVM2NVDLAPass"]
+        pass_flags += [
+            "hpvm-nvdla",
+            "cprecision=fp16",
+            "calib-table=calib.txt"
+        ]
+        
     elif tensor_target == "cudnn":
         passes += ["LLVMInPlaceDFGAnalysis", "LLVMDFG2LLVM_CUDNN"]
         pass_flags += ["inplace", "dfg2llvm-cudnn"]
@@ -198,7 +210,7 @@ See option -b for that."""
         "-t",
         "--tensor-target",
         type=str,
-        choices=["tensor", "cudnn"],
+        choices=["tensor", "cudnn", "nvdla"],
         help="Backend to use for tensor operators",
     )
     parser.add_argument(
@@ -254,6 +266,7 @@ See option -b for that."""
     if args.tensor_target == "tensor":
         if args.conf_file is None:
             parser.error('Tensor target "tensor" requires --conf-file argument')
+        
     if args.x == "c":
         args.is_cpp = False
     elif args.x == "c++":
@@ -262,7 +275,7 @@ See option -b for that."""
         parser.error(f"Language mode {args.x} not supported yet -- only c or c++")
     if not HPVM_USE_OPENCL and args.opencl:
         parser.error(f"OpenCL is disabled for this build of HPVM.")
-    if not HPVM_HAS_TRT and args.tensor_target:
+    if not HPVM_HAS_TRT and args.tensor_target != "nvdla":
         parser.error(
             "Tensor domain support is disabled for this build of HPVM; "
             "please check your CMake warnings during compilation."
-- 
GitLab