From b96afee58d01287236f6828fb6cc9ee78c3550e9 Mon Sep 17 00:00:00 2001
From: Hashim Sharif <hsharif3@tyler.cs.illinois.edu>
Date: Fri, 27 Mar 2020 03:30:45 -0500
Subject: [PATCH] Adding test case for Perforation - checking start_offset

---
 .../dnn_sources/include/utils.h               | 12 ++--
 .../dnn_sources/src/test_ops.cc               | 64 +++++++++++++++++--
 2 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h b/llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h
index d082eac069..08f5cc7e72 100644
--- a/llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h
+++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h
@@ -152,12 +152,16 @@ void printTensorValues(void* tensor_ptr){
   hpvm_request_tensor(tensor, 0);
   
   // printing is specific to the floating point type
-  if(tensor->data_type == CUDNN_DATA_FLOAT){
-    float* data_arr = (float*) tensor->host_data;
-    for(unsigned int i = 0; i < tensor->num_elems; i++){
+  if(tensor->data_type != CUDNN_DATA_FLOAT){
+    printf("\n WARNING: The tensor is non-float type tensor \n\n");
+  }  
+
+  float* data_arr = (float*) tensor->host_data;
+
+  for(unsigned int i = 0; i < tensor->num_elems; i++){
       printf("%f,", data_arr[i]);    
-    }
   }
+   
 
   printf("\n");
 }
diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/test_ops.cc b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/test_ops.cc
index 43151dd965..12390b6a31 100644
--- a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/test_ops.cc
+++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/test_ops.cc
@@ -3,8 +3,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 
-#include "../../tensor_runtime/include/tensor_runtime.h"
-#include "../include/utils.h"
+#include "tensor_runtime.h"
+#include "utils.h"
+
 
 
 void testTensorGemm(){
@@ -465,7 +466,7 @@ void testQuantization(){
   
   printTensorValues(quantize_result);
 
-  void* error_out = addPromiseError(quantize_result, 7);
+  void* error_out = addPromiseError(quantize_result, 1);
 
   printTensorValues(error_out);
 
@@ -522,6 +523,56 @@ void testSampleFilter(){
 
 
 
+
+void testPerforation(){
+
+  printf("***** Testing Perforation ***** \n\n");
+  Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 1, 6, 6);
+  fillTensorWithVal(input, 3);
+  //fillWithOnesAndTwos(input);
+  
+  Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 1, 3, 3);
+  fillTensorWithVal(filter, 2);
+
+  float* host_ptr = (float*) ((struct Tensor*) input)->host_data;
+  host_ptr[0] = 0;
+  host_ptr[1] = 0;
+  host_ptr[2] = 0;
+  host_ptr[3] = 0;
+  host_ptr[4] = 0;
+  host_ptr[5] = 0;
+  //host_ptr[6] = 0;
+  //host_ptr[7] = 0;
+
+  //printTensorValues(input);
+
+  void* res = tensorConvPerfCuda(input, filter, 0, 0, 1, 1, 1, 1, 2, 1, 0);
+
+  printTensorValues(res);  
+
+  void* res2 = tensorConvApproxHalf2(input, filter, 0, 0, 1, 1, 1, 1, 2, 1, 1, 0);
+
+  //void* res2 = tensorConvPerfCuda(input, filter, 0, 0, 1, 1, 1, 1, 2, 1, 0);
+
+  convertToFP32((struct Tensor*) res2);
+  
+  printTensorValues(res2);
+
+
+  void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 3, 1, 1, 0);
+  
+  printTensorValues(res3);
+
+  
+  //void* res4 = tensorConvPerfSim(input, filter, 0, 0, 1, 1, 1, 1, 2, 1);
+  
+  //printTensorValues(res4);  
+}
+
+
+
+
+
 int main(){
 
   llvm_hpvm_initTensorRt(0);
@@ -548,9 +599,12 @@ int main(){
   //testLRN();
 
 
-  testSampleFilter();
+  //testSampleFilter();
+  
+
+  testPerforation();
+  
   
-    
   stopProfiling();
 
   return 0;
-- 
GitLab