From 32e5b38760dc470b9e20c718b2adade92bfe2f80 Mon Sep 17 00:00:00 2001
From: hashimsharif <hashim.sharif91@gmail.com>
Date: Fri, 15 May 2020 00:30:24 -0500
Subject: [PATCH] Outer loop (numner of runs) for HPVM Loop sources

---
 .../benchmarks/alexnet/src/alexnet_loop.cpp   | 45 ++++++++-------
 .../benchmarks/alexnet2/src/alexnet2_loop.cpp | 50 +++++++++--------
 .../benchmarks/resnet18/src/resnet18_loop.cpp | 55 ++++++++++---------
 .../vgg16_cifar10/src/vgg16_cifar10_loop.cpp  |  2 +-
 .../src/vgg16_cifar100_loop.cpp               | 45 ++++++++-------
 5 files changed, 106 insertions(+), 91 deletions(-)

diff --git a/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet/src/alexnet_loop.cpp b/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet/src/alexnet_loop.cpp
index a62b2ea33a..82dfcb725b 100644
--- a/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet/src/alexnet_loop.cpp
+++ b/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet/src/alexnet_loop.cpp
@@ -445,32 +445,37 @@ int main(){
   startMemTracking();
   startProfiling();
 
-  for (int i = 0; i < batch_count; i++){
+  for (int j = 0; j < 14; j++){
+    for (int i = 0; i < batch_count; i++){
+    
+      int start = i * batch_size;
+      int end = (i + 1) * batch_size;
   
-    int start = i * batch_size;
-    int end = (i + 1) * batch_size;
-
-    // copyInputBatch(input_path.c_str(),start,end,3,32,32, input);
-
-	// Replaced create4DTensor and copyInputBatch with readInputBatch 
-    void* input = readInputBatch(input_path.c_str(), 0,
-                     start, end, 
-                     3, 32, 32);
- 
-    args->input = input;
-    args->input_bytes = 0; 
+      // copyInputBatch(input_path.c_str(),start,end,3,32,32, input);
   
-    void* dfg = __visc__launch(0, root, (void*) args);
-
-    __visc__wait(dfg); 
+  	// Replaced create4DTensor and copyInputBatch with readInputBatch 
+      void* input = readInputBatch(input_path.c_str(), 0,
+                       start, end, 
+                       3, 32, 32);
+   
+      args->input = input;
+      args->input_bytes = 0; 
+    
+      void* dfg = __visc__launch(0, root, (void*) args);
   
-    void *result = static_cast<RootIn*>(args)->input;
-    hpvm_request_tensor(result, 0);
+      __visc__wait(dfg); 
+    
+      void *result = static_cast<RootIn*>(args)->input;
+      hpvm_request_tensor(result, 0);
+    
+      llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
   
-    llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
+      freeBatchMemory();
+    }
 
-    freeBatchMemory();
   }
+
+
   stopProfiling();
   __visc__cleanup();  
   
diff --git a/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet2/src/alexnet2_loop.cpp b/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet2/src/alexnet2_loop.cpp
index e3c06325a6..956f8fbe8b 100644
--- a/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet2/src/alexnet2_loop.cpp
+++ b/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet2/src/alexnet2_loop.cpp
@@ -496,31 +496,35 @@ int main(){
   startMemTracking();
   startProfiling();
 
-  for (int i = 0; i < batch_count; i++){
-
-    int start = i * batch_size; 
-    int end = (i + 1) * batch_size; 
-
-    // copyInputBatch(input_path.c_str(),start,end,3,32,32, input);
-
-    void* input = readInputBatch(input_path.c_str(), 0,
-                     start, end,
-                     3, 32, 32);
-
-    args->input = input; 
-    args->input_bytes = 0; 
-
-    void* dfg = __visc__launch(0, root, (void*) args); 
-
-    __visc__wait(dfg); 
-
-    void *result = static_cast<RootIn*>(args)->input; 
-    hpvm_request_tensor(result, 0); 
+  for (int j = 0; j < 14; j++){
+    for (int i = 0; i < batch_count; i++){
+  
+      int start = i * batch_size; 
+      int end = (i + 1) * batch_size; 
+  
+      // copyInputBatch(input_path.c_str(),start,end,3,32,32, input);
+  
+      void* input = readInputBatch(input_path.c_str(), 0,
+                       start, end,
+                       3, 32, 32);
+  
+      args->input = input; 
+      args->input_bytes = 0; 
+  
+      void* dfg = __visc__launch(0, root, (void*) args); 
+  
+      __visc__wait(dfg); 
+  
+      void *result = static_cast<RootIn*>(args)->input; 
+      hpvm_request_tensor(result, 0); 
+  
+      llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
+        
+      freeBatchMemory();
+    }
 
-    llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
-      
-    freeBatchMemory();
   }
+
   stopProfiling();
   __visc__cleanup(); 
 
diff --git a/llvm/test/VISC/DNN_Benchmarks/benchmarks/resnet18/src/resnet18_loop.cpp b/llvm/test/VISC/DNN_Benchmarks/benchmarks/resnet18/src/resnet18_loop.cpp
index 4c91f0e661..c65c6b5a77 100644
--- a/llvm/test/VISC/DNN_Benchmarks/benchmarks/resnet18/src/resnet18_loop.cpp
+++ b/llvm/test/VISC/DNN_Benchmarks/benchmarks/resnet18/src/resnet18_loop.cpp
@@ -1436,33 +1436,36 @@ int main(){
   startMemTracking();
   startProfiling();
 
-  for (int i = 0; i < batch_count; i++){
-
-    int start = i * batch_size;
-    int end = (i + 1) * batch_size;
-
-    //copyInputBatch(input_path.c_str(),start,end,3,32,32, input);
-
-    // NOTE-HASHIM: Commented out above line and line that does create4DTensor
-    void* input = readInputBatch(input_path.c_str(), 0,
-    				 start, end,
-    				 3, 32, 32);
-
-    args->input = input;
-    args->input_bytes = 0;
-
-    void* dfg = __visc__launch(0, root, (void*) args);
-
-    __visc__wait(dfg);
-
-    void *result = static_cast<RootIn*>(args)->input;
-    hpvm_request_tensor(result, 0);
-
-    llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
+  for (int j = 0; j < 14; j++){
+    for (int i = 0; i < batch_count; i++){
+  
+      int start = i * batch_size;
+      int end = (i + 1) * batch_size;
+  
+      //copyInputBatch(input_path.c_str(),start,end,3,32,32, input);
+  
+      // NOTE-HASHIM: Commented out above line and line that does create4DTensor
+      void* input = readInputBatch(input_path.c_str(), 0,
+      				 start, end,
+      				 3, 32, 32);
+  
+      args->input = input;
+      args->input_bytes = 0;
+  
+      void* dfg = __visc__launch(0, root, (void*) args);
+  
+      __visc__wait(dfg);
+  
+      void *result = static_cast<RootIn*>(args)->input;
+      hpvm_request_tensor(result, 0);
+  
+      llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
+  
+      printf("RUNNING BATCH = %d \n", i);
+      
+      freeBatchMemory();
+    }
 
-    printf("RUNNING BATCH = %d \n", i);
-    
-    freeBatchMemory();
   }
   
   stopProfiling();
diff --git a/llvm/test/VISC/DNN_Benchmarks/benchmarks/vgg16_cifar10/src/vgg16_cifar10_loop.cpp b/llvm/test/VISC/DNN_Benchmarks/benchmarks/vgg16_cifar10/src/vgg16_cifar10_loop.cpp
index 770020438c..aa505131e1 100644
--- a/llvm/test/VISC/DNN_Benchmarks/benchmarks/vgg16_cifar10/src/vgg16_cifar10_loop.cpp
+++ b/llvm/test/VISC/DNN_Benchmarks/benchmarks/vgg16_cifar10/src/vgg16_cifar10_loop.cpp
@@ -979,7 +979,7 @@ int main(){
   startMemTracking();
   startProfiling();
 
-  for (int j = 0; j < 10; j++){
+  for (int j = 0; j < 14; j++){
     for (int i = 0; i < batch_count; i++){
 
       int start = i * batch_size;
diff --git a/llvm/test/VISC/DNN_Benchmarks/benchmarks/vgg16_cifar100/src/vgg16_cifar100_loop.cpp b/llvm/test/VISC/DNN_Benchmarks/benchmarks/vgg16_cifar100/src/vgg16_cifar100_loop.cpp
index 7bb78e07bb..ee5643a8d2 100644
--- a/llvm/test/VISC/DNN_Benchmarks/benchmarks/vgg16_cifar100/src/vgg16_cifar100_loop.cpp
+++ b/llvm/test/VISC/DNN_Benchmarks/benchmarks/vgg16_cifar100/src/vgg16_cifar100_loop.cpp
@@ -979,28 +979,31 @@ int main(){
   startMemTracking();
   startProfiling();
 
-  for (int i = 0; i < batch_count; i++) {
-
-    int start = i * batch_size;
-    int end = (i + 1) * batch_size;
-
-    void* input = readInputBatch(input_path.c_str(), 0,
-                                 start, end, 
-                                 3, 32, 32);
-
-    args->input = input;
-    args->input_bytes = 0;
-
-    void* dfg = __visc__launch(0, root, (void*) args); 
-
-    __visc__wait(dfg); 
-
-    void *result = static_cast<RootIn*>(args)->input; 
-    hpvm_request_tensor(result, 0); 
-
-    llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
+  for (int j = 0; j < 14; j++){
+    for (int i = 0; i < batch_count; i++) {
+  
+      int start = i * batch_size;
+      int end = (i + 1) * batch_size;
+  
+      void* input = readInputBatch(input_path.c_str(), 0,
+                                   start, end, 
+                                   3, 32, 32);
+  
+      args->input = input;
+      args->input_bytes = 0;
+  
+      void* dfg = __visc__launch(0, root, (void*) args); 
+  
+      __visc__wait(dfg); 
+  
+      void *result = static_cast<RootIn*>(args)->input; 
+      hpvm_request_tensor(result, 0); 
+  
+      llvm_hpvm_invokeRtControl(result, labels_path.c_str(), start, end);
+  
+      freeBatchMemory();
+    }
 
-    freeBatchMemory();
   }
 
   stopProfiling();
-- 
GitLab