From 8da90445681a622a8e0a79d2e7d2aad09c7b4fc3 Mon Sep 17 00:00:00 2001 From: Hashim Sharif <hsharif3@tyler.cs.illinois.edu> Date: Sun, 19 Jul 2020 22:07:00 -0500 Subject: [PATCH] Adding unit test calls for sampling tests --- .../dnn_sources/src/unit_tests.cc | 170 +++++------------- 1 file changed, 43 insertions(+), 127 deletions(-) diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/unit_tests.cc b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/unit_tests.cc index 3c2edfc951..6926849d8b 100644 --- a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/unit_tests.cc +++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/unit_tests.cc @@ -806,7 +806,7 @@ void testPerforationCalls(void* input, void* filter, /**** Tests Perforation for a set of different inputs */ -void testPerforation(){ +void testPerforation(UnitTestResults& unitTestResults){ printf("***** Tests Sample for a sample 3 * 3 Filter ***** \n\n"); @@ -926,7 +926,7 @@ void testSampling(){ void testSamplingCalls(void* input, void* filter, int pad_h, int pad_w, int stride_h, int stride_w, - int skip_every){ + int skip_every, UnitTestResults& unitTestResults){ float interpolation_rate = 1.0; @@ -988,6 +988,19 @@ void testSamplingCalls(void* input, void* filter, printf ("\nConvApproxHalf2 Result :"); printTensorValues(res_half); + std::string suffix = std::string(" pad_h = ") + std::to_string(pad_h) + + std::string(" pad_w = ") + std::to_string(pad_w) + + std::string(" stride_h = ") + std::to_string(stride_h) + + std::string(" stride_w = ") + std::to_string(stride_w) + + std::string(" skip_every = ") + std::to_string(skip_every) + + std::string(" offset = ") + std::to_string(offset); + + std::string test_name = std::string("SAMP_FP32 ") + suffix; + + unitTestResults.compareTensors((Tensor*) res, (Tensor*) res_sim, 0.01, test_name); + + std::string fp16_test_name = std::string("SAMP_FP16 ") + suffix; + unitTestResults.compareTensors((Tensor*) res_half, (Tensor*) res_sim, 0.0001, fp16_test_name); } @@ -997,7 +1010,7 @@ void testSamplingCalls(void* input, void* filter, /**** Tests Sample for a sample 3 * 3 Filter */ -void testSampling_3_3(){ +void testSampling_3_3(UnitTestResults& unitTestResults){ printf("***** Tests Sample for a sample 3 * 3 Filter ***** \n\n"); @@ -1026,28 +1039,26 @@ void testSampling_3_3(){ host_ptr[26] = 2; + // Tests with padding = 0 stride = 1 + testSamplingCalls(input, filter, 0, 0, 1, 1, 2, unitTestResults); - testSamplingCalls(input, filter, 0, 0, 1, 1, 2); - - testSamplingCalls(input, filter, 0, 0, 1, 1, 3); - - testSamplingCalls(input, filter, 0, 0, 1, 1, 4); - + testSamplingCalls(input, filter, 0, 0, 1, 1, 3, unitTestResults); + testSamplingCalls(input, filter, 0, 0, 1, 1, 4, unitTestResults); - testSamplingCalls(input, filter, 1, 1, 1, 1, 2); + // Tests with padding = 1 stride = 1 + testSamplingCalls(input, filter, 1, 1, 1, 1, 2, unitTestResults); - testSamplingCalls(input, filter, 1, 1, 1, 1, 3); + testSamplingCalls(input, filter, 1, 1, 1, 1, 3, unitTestResults); - testSamplingCalls(input, filter, 1, 1, 1, 1, 4); + testSamplingCalls(input, filter, 1, 1, 1, 1, 4, unitTestResults); + // Tests with padding = 1 stride = 2 + testSamplingCalls(input, filter, 1, 1, 2, 2, 2, unitTestResults); + testSamplingCalls(input, filter, 1, 1, 2, 2, 3, unitTestResults); - testSamplingCalls(input, filter, 1, 1, 2, 2, 2); - - testSamplingCalls(input, filter, 1, 1, 2, 2, 3); - - testSamplingCalls(input, filter, 1, 1, 2, 2, 4); + testSamplingCalls(input, filter, 1, 1, 2, 2, 4, unitTestResults); } @@ -1058,105 +1069,8 @@ void testSampling_3_3(){ - - - -void testSampling2(){ - - printf("***** TestingSampling2 ***** \n\n"); - Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 4, 2, 2); - fillTensorWithVal(input, 2); - //fillWithOnesAndTwos(input); - - Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 4, 4, 1, 1); - fillTensorWithVal(filter, 2); - - // Interpolation not being applied most likely - void* res = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0); - - printTensorValues(res); - - - fillTensorWithVal(filter, 2); - - // Start from offset 1 completely failing - void* res2 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0); - - printTensorValues(res2); - - - fillTensorWithVal(filter, 2); - // NOTE -- even after reinitializing --- error remains - this is indicative of input corruption - - // Results are strange. Are filters being overwritten? - void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1); - - printTensorValues(res3); - -} - - - -void testSampling3(){ - - printf("***** TestingSampling3 ***** \n\n"); - Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 9, 2, 2); - fillTensorWithVal(input, 2); - //fillWithOnesAndTwos(input); - - Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 4, 9, 1, 1); - fillTensorWithVal(filter, 2); - - - // BASELINE : expected result -- 36, 36, 36, ... - void* res1 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1); - - printTensorValues(res1); - printf ("\n"); - - // BASELINE: expected result - 32, 32, 32, - void* res2 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0); - - printTensorValues(res2); - printf ("\n"); - - void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 3, 0); - - printTensorValues(res3); - printf ("\n"); - - - void* res2_sim = tensorConvSampSim(input, filter, 0, 0, 1, 1, 1, 1, 3, 0); - - printTensorValues(res2_sim); - printf ("\n"); - - - void* res4 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 3, 0); - - printTensorValues(res4); - printf ("\n"); - - void* res5 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0); - - printTensorValues(res5); - printf ("\n"); - - - void* res6 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 1); - - printTensorValues(res6); - printf ("\n"); - - -} - - - - - /**** Tests Sample for a sample 1 * 1 Filter */ -void testSampling_1_1(){ +void testSampling_1_1(UnitTestResults& unitTestResults){ Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 9, 2, 2); @@ -1167,19 +1081,20 @@ void testSampling_1_1(){ fillTensorWithVal(filter, 2); - testSamplingCalls(input, filter, 0, 0, 1, 1, 2); + // Tests with padding = 0 stride = 1 + testSamplingCalls(input, filter, 0, 0, 1, 1, 2, unitTestResults); - testSamplingCalls(input, filter, 0, 0, 1, 1, 3); + testSamplingCalls(input, filter, 0, 0, 1, 1, 3, unitTestResults); - testSamplingCalls(input, filter, 0, 0, 1, 1, 4); + testSamplingCalls(input, filter, 0, 0, 1, 1, 4, unitTestResults); + // Tests with padding = 1 stride = 1 + testSamplingCalls(input, filter, 1, 1, 1, 1, 2, unitTestResults); - testSamplingCalls(input, filter, 1, 1, 1, 1, 2); + testSamplingCalls(input, filter, 1, 1, 1, 1, 3, unitTestResults); - testSamplingCalls(input, filter, 1, 1, 1, 1, 3); - - testSamplingCalls(input, filter, 1, 1, 1, 1, 4); + testSamplingCalls(input, filter, 1, 1, 1, 1, 4, unitTestResults); } @@ -1314,13 +1229,14 @@ int main(){ testTensorPooling(); testTensorHalfPooling(); - testSampling_3_3(); - testSampling_1_1(); - - testPerforation(); - */ + + testSampling_3_3(unitTestResults); + testSampling_1_1(unitTestResults); + testPerforation(unitTestResults); + + unitTestResults.printSummary(); -- GitLab