From d8d55c3e346d36289c34825c0277b3bb9486aa62 Mon Sep 17 00:00:00 2001
From: Yifan Zhao <yifanz16@illinois.edu>
Date: Sun, 4 Apr 2021 02:16:10 -0500
Subject: [PATCH] Fixed some problems in HPVM benchmark 'pipeline'

---
 hpvm/test/benchmarks/CMakeLists.txt           | 17 +++++++++++++++++
 hpvm/test/benchmarks/hpvm-cava/CMakeLists.txt | 15 +--------------
 hpvm/test/benchmarks/pipeline/CMakeLists.txt  | 19 ++++++++++---------
 hpvm/test/benchmarks/pipeline/src/main.cc     |  4 ++++
 4 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/hpvm/test/benchmarks/CMakeLists.txt b/hpvm/test/benchmarks/CMakeLists.txt
index 4d4f0691fc..ab12243beb 100644
--- a/hpvm/test/benchmarks/CMakeLists.txt
+++ b/hpvm/test/benchmarks/CMakeLists.txt
@@ -34,5 +34,22 @@ function(add_hpvm_benchmark
   add_custom_target(${target_name} DEPENDS ${output_bin_path})
 endfunction(add_hpvm_benchmark)
 
+function(add_hpvm_cpu_gpu_benchmark
+  target_prefix common_flags language_mode main_src util_bitcodes
+)
+  set(all_flags_cpu ${common_flags} "-DDEVICE=CPU_TARGET")
+  add_hpvm_benchmark(
+    "${target_prefix}_cpu" "${target_prefix}-cpu" "${all_flags_cpu}" ${language_mode}
+    ${main_src} "${util_bitcodes}"
+  )
+  if(HPVM_USE_OPENCL)
+    set(all_flags_gpu ${common_flags} "--opencl" "-DDEVICE=GPU_TARGET")
+    add_hpvm_benchmark(
+      "${target_prefix}_gpu" "${target_prefix}-gpu" "${all_flags_gpu}" ${language_mode}
+      ${main_src} "${util_bitcodes}"
+    )
+  endif()
+endfunction()
+
 add_subdirectory(hpvm-cava)
 add_subdirectory(pipeline)
diff --git a/hpvm/test/benchmarks/hpvm-cava/CMakeLists.txt b/hpvm/test/benchmarks/hpvm-cava/CMakeLists.txt
index d89a01a056..33867168d1 100644
--- a/hpvm/test/benchmarks/hpvm-cava/CMakeLists.txt
+++ b/hpvm/test/benchmarks/hpvm-cava/CMakeLists.txt
@@ -8,17 +8,4 @@ set(
 
 # Sets ${util_bitcodes}
 hpvm_compile_util_sources("${compiler_flags}" "${other_srcs}" "c")
-
-set(all_flags_cpu ${compiler_flags} "-DDEVICE=CPU_TARGET" "-lpthread")
-add_hpvm_benchmark(
-  "hpvm_cava_cpu" "hpvm-cava-cpu" "${all_flags_cpu}" "c"
-  src/main.c "${util_bitcodes}"
-)
-
-if(HPVM_USE_OPENCL)
-  set(all_flags_gpu ${compiler_flags} "-DDEVICE=GPU_TARGET" "--opencl" "-lpthread")
-  add_hpvm_benchmark(
-    "hpvm_cava_gpu" "hpvm-cava-gpu" "${all_flags_gpu}" "c"
-    src/main.c "${util_bitcodes}"
-  )
-endif()
+add_hpvm_cpu_gpu_benchmark(hpvm_cava "${compiler_flags}" c src/main.c "${util_bitcodes}")
diff --git a/hpvm/test/benchmarks/pipeline/CMakeLists.txt b/hpvm/test/benchmarks/pipeline/CMakeLists.txt
index db2b8eeab1..cede337ca2 100644
--- a/hpvm/test/benchmarks/pipeline/CMakeLists.txt
+++ b/hpvm/test/benchmarks/pipeline/CMakeLists.txt
@@ -1,15 +1,16 @@
 find_package(OpenCV 2)
 if(${OpenCV_FOUND})
-  set(
-    all_flags
-    -O3 -I${OpenCV_INCLUDE_DIRS}
-    -ffast-math -fno-lax-vector-conversions -fno-vectorize -fno-slp-vectorize
-    -lpthread
+  foreach(incl_dir ${OpenCV_INCLUDE_DIRS})
+    list(APPEND all_flags "-I${incl_dir}")
+  endforeach()
+  foreach(link_lib ${OpenCV_LIBS})
+    list(APPEND all_flags "-l${link_lib}")
+  endforeach()
+  list(
+    APPEND all_flags -L "${OpenCV_INSTALL_PATH}/lib"
+    -O3 -ffast-math -fno-lax-vector-conversions -fno-vectorize -fno-slp-vectorize
   )
-  add_hpvm_benchmark("pipeline_cpu" "pipeline-cpu" "${all_flags}" "c++" src/main.cc "")
-  if(HPVM_USE_OPENCL)
-    add_hpvm_benchmark("pipeline_gpu" "pipeline-gpu" "${all_flags};--opencl" "c++" src/main.cc "")
-  endif()
+  add_hpvm_cpu_gpu_benchmark("pipeline" "${all_flags}" c++ src/main.cc "")
 else()
   message(WARNING "opencv-2 not found; not compiling HPVM benchmark 'pipeline'.")
 endif()
diff --git a/hpvm/test/benchmarks/pipeline/src/main.cc b/hpvm/test/benchmarks/pipeline/src/main.cc
index 057c13b627..5fcb205ca7 100644
--- a/hpvm/test/benchmarks/pipeline/src/main.cc
+++ b/hpvm/test/benchmarks/pipeline/src/main.cc
@@ -27,6 +27,10 @@
 #define HEIGHT 640
 #define WIDTH 480
 
+#ifndef DEVICE
+#error "The macro 'DEVICE' must be defined to CPU_TARGET or GPU_TARGET."
+#endif
+
 std::string input_window = "GPU Pipeline - Input Video";
 std::string output_window = "GPU Pipeline - Edge Mapping";
 
-- 
GitLab