From c9f8748acb95754a3c1c07039dc6ca8cbc8d4f6a Mon Sep 17 00:00:00 2001 From: Hashim Sharif <hsharif3@tyler.cs.illinois.edu> Date: Tue, 7 Apr 2020 00:33:24 -0500 Subject: [PATCH] Adding detailed unit test for 3*3 filter sampling --- .../dnn_sources/src/test_ops.cc | 213 ++++++++++++++++-- 1 file changed, 198 insertions(+), 15 deletions(-) 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 a58f4b1d47..14a8f2924c 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 @@ -627,23 +627,199 @@ void testSampling(){ Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 3, 3); fillTensorWithVal(filter, 1); - 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; + float* host_ptr = (float*) ((struct Tensor*) filter)->host_data; + host_ptr[0] = 2; + host_ptr[2] = 2; + host_ptr[4] = 2; + host_ptr[6] = 2; + host_ptr[8] = 2; + host_ptr[10] = 2; + host_ptr[12] = 2; + host_ptr[14] = 2; + host_ptr[16] = 2; + host_ptr[18] = 2; + host_ptr[20] = 2; + host_ptr[22] = 2; + host_ptr[24] = 2; + host_ptr[26] = 2; + //printTensorValues(input); + + void* res = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1); + + printTensorValues(res); + + + void* res2 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1); + + printTensorValues(res2); + + + void* res2_sim = tensorConvSampSim(input, filter, 0, 0, 1, 1, 1, 1, 2, 0); + + printTensorValues(res2_sim); + + + void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0); + + printTensorValues(res3); + + + void* res4 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0); + + printTensorValues(res4); + + + void* res4_half = tensorConvApproxHalf2(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0); + + convertToFP32((struct Tensor*) res4_half); + + printTensorValues(res4_half); + +} + + + + +void testSamplingCalls(void* input, void* filter, + int pad_h, int pad_w, + int stride_h, int stride_w, int skip_every){ + + + for (int offset = 0; offset < 2; offset++){ + + printf("\n\n\n\**Test -- pad_h = %d pad_w = %d stride_h = %d stride_w = %d skip_every = %d offset= %d \n\n", + pad_h, pad_w, stride_h, stride_w, skip_every, offset); + + void* res_sim = tensorConvSampSim(input, filter, pad_h, pad_w, + stride_h, stride_w, + 1, 1, skip_every, offset); + + printf ("ConvSampSim Result :"); + printTensorValues(res_sim); + + + void* res = tensorConvApprox(input, filter, pad_h, pad_w, + stride_h, stride_w, + 1, 1, 1, 1, skip_every, offset); + + + printf ("ConvApprox Result :"); + printTensorValues(res); + + + void* res_half = tensorConvApproxHalf2(input, filter, pad_h, pad_w, + stride_h, stride_w, + 1, 1, 1, 1, skip_every, offset); + + convertToFP32((struct Tensor*) res_half); + + printf ("ConvApproxHalf2 Result :"); + printTensorValues(res_half); + + } + + + printf ("\n\n\n\ --- End of Test \n\n\n"); +} + + + +/**** Tests Sample for a sample 3 * 3 Filter */ +void testSampling_3_3(){ + + + printf("***** Tests Sample for a sample 3 * 3 Filter ***** \n\n"); + Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 4, 4); + fillTensorWithVal(input, 1); + //fillWithOnesAndTwos(input); + + Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 3, 3); + fillTensorWithVal(filter, 1); + + + 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, 1, 1, 1, 1, 2); + + testSamplingCalls(input, filter, 1, 1, 1, 1, 3); + + testSamplingCalls(input, filter, 1, 1, 1, 1, 4); + + + + testSamplingCalls(input, filter, 1, 1, 2, 2, 2); + + testSamplingCalls(input, filter, 1, 1, 2, 2, 3); + + testSamplingCalls(input, filter, 1, 1, 2, 2, 4); + + + /* + float* host_ptr = (float*) ((struct Tensor*) filter)->host_data; + host_ptr[0] = 2; + host_ptr[2] = 2; + host_ptr[4] = 2; + host_ptr[6] = 2; + host_ptr[8] = 2; + host_ptr[10] = 2; + host_ptr[12] = 2; + host_ptr[14] = 2; + host_ptr[16] = 2; + host_ptr[18] = 2; + host_ptr[20] = 2; + host_ptr[22] = 2; + host_ptr[24] = 2; + host_ptr[26] = 2; //printTensorValues(input); - void* res = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1); + void* res = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1); printTensorValues(res); + + void* res2 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 1); + + printTensorValues(res2); + + + void* res2_sim = tensorConvSampSim(input, filter, 0, 0, 1, 1, 1, 1, 2, 0); + + printTensorValues(res2_sim); + + + void* res3 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 2, 0); + + printTensorValues(res3); + + + void* res4 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0); + + printTensorValues(res4); + + + void* res4_half = tensorConvApproxHalf2(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 4, 0); + + convertToFP32((struct Tensor*) res4_half); + + printTensorValues(res4_half); + + */ + + } + + + + void testSampling2(){ printf("***** TestingSampling2 ***** \n\n"); @@ -708,7 +884,14 @@ void testSampling3(){ printTensorValues(res3); printf ("\n"); - void* res4 = tensorConvApprox(input, filter, 0, 0, 1, 1, 1, 1, 1, 1, 3, 1); + + 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"); @@ -764,22 +947,22 @@ int main(){ //testSampleFilter(); - testPerforation(); + //-- testPerforation(); // testPerforation2(); - //-- testSampling(); + //testSampling(); - testSampling2(); + //testSampling2(); - testSampling3(); - - + //testSampling3(); + testSampling_3_3(); + stopProfiling(); return 0; -- GitLab