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 ae9fdc1731f17a7f3dbc55df809c6a6f956e7ed4..1ccc5bd1b4e48a0019a78c6550b7ea9d1f679b91 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 @@ -369,10 +369,32 @@ void testTensorHalfGroupConv(){ } -void testTensorPool(){ +void testTensorPooling(){ + void* x = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 2, 1, 4, 4); - fillTensorWithOnes(x); - void* output = tensorPooling(x, 0, 2, 2, 0, 0, 1, 1); + fillTensorWithOnes(x); + + float* data_arr = (float*) ((Tensor*) x)->host_data; + for(int i = 0; i < ((Tensor*) x)->num_elems; i += 4){ + data_arr[i] = i; + } + + void* output = tensorPooling(x, 0, 2, 2, 0, 0, 2, 2); + printTensorValues(output); +} + + +void testTensorHalfPooling(){ + + void* x = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 2, 1, 4, 4); + fillTensorWithOnes(x); + + float* data_arr = (float*) ((Tensor*) x)->host_data; + for(int i = 0; i < ((Tensor*) x)->num_elems; i += 4){ + data_arr[i] = i; + } + + void* output = tensorPooling(x, 0, 2, 2, 0, 0, 2, 2); printTensorValues(output); } @@ -701,8 +723,142 @@ void testSampleFilter(){ + +void testPerforationCalls(void* input, void* filter, + int pad_h, int pad_w, + int stride_h, int stride_w, + int row, int col){ + + + float interpolation_rate = 1.0; + for (int offset = 0; offset < 2; offset++){ + + printf("\n\n\n\**Test -- pad_h = %d pad_w = %d stride_h = %d stride_w = %d row = %d col = %d offset= %d \n\n", + pad_h, pad_w, stride_h, stride_w, row, col, offset); + + + void* res_exact = tensorConvolution(input, filter, pad_h, pad_w, + stride_h, stride_w, + 1, 1); + + printf ("tensorConvolution Result :"); + printTensorValues(res_exact); + + + void* res_exact2 = tensorConvApprox(input, filter, pad_h, pad_w, + stride_h, stride_w, + 1, 1, 1, 1, 1, 1); + + printf ("\nBaseline Result :"); + printTensorValues(res_exact2); + + + void* res_exact3 = tensorConvApproxHalf2(input, filter, pad_h, pad_w, + stride_h, stride_w, + 1, 1, 1, 1, 1, 1); + convertToFP32((struct Tensor*) res_exact3); + + printf ("\nFP16_Baseline Result :"); + printTensorValues(res_exact3); + + + void* res_sim = tensorConvPerfCuda(input, filter, + pad_h, pad_w, + stride_h, stride_w, + 1, 1, + row, col, + offset); + + printf ("\nConvPerfCuda Result :"); + printTensorValues(res_sim); + + + void* res = tensorConvApprox(input, filter, + pad_h, pad_w, + stride_h, stride_w, + 1, 1, + row, col, + 1, offset); + + + printf ("\nConvApprox Result :"); + printTensorValues(res); + + + void* res_half = tensorConvApproxHalf2(input, filter, + pad_h, pad_w, + stride_h, stride_w, + 1, 1, + row, col, + 1, offset); + + convertToFP32((struct Tensor*) res_half); + + printf ("\nConvApproxHalf2 Result :"); + printTensorValues(res_half); + + } + + + printf ("\n\n\n\ --- End of Test \n\n\n"); +} + + + + + +/**** Tests Perforation for a set of different inputs */ void testPerforation(){ + + 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); + + Tensor* filter = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 3, 3, 3); + fillTensorWithVal(filter, 1); + + + /* + 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; + */ + + + testPerforationCalls(input, filter, 0, 0, 1, 1, 1, 2); + + testPerforationCalls(input, filter, 0, 0, 1, 1, 2, 1); + + + testPerforationCalls(input, filter, 1, 1, 1, 1, 1, 3); + + testPerforationCalls(input, filter, 1, 1, 1, 1, 3, 1); + + + testPerforationCalls(input, filter, 1, 1, 2, 2, 1, 4); + + testPerforationCalls(input, filter, 1, 1, 2, 2, 4, 1); + +} + + + + +/*void testPerforation(){ + printf("***** Testing Perforation ***** \n\n"); Tensor* input = (Tensor*) create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 1, 1, 6, 6); fillTensorWithVal(input, 3); @@ -718,8 +874,6 @@ void testPerforation(){ host_ptr[3] = 0; host_ptr[4] = 0; host_ptr[5] = 0; - //host_ptr[6] = 0; - //host_ptr[7] = 0; //printTensorValues(input); @@ -746,7 +900,7 @@ void testPerforation(){ //printTensorValues(res4); } - +*/ @@ -859,22 +1013,13 @@ void testSampling(){ void testSamplingCalls(void* input, void* filter, int pad_h, int pad_w, - int stride_h, int stride_w, int skip_every){ - - - //for (int i = 0; i < 2; i++){ - - // float interpolation_rate; - // if (i == 0) - // interpolation_rate = 1.0; - // else - // interpolation_rate = 0.5; + int stride_h, int stride_w, + int skip_every){ float interpolation_rate = 1.0; 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 interpolation_rate = %f \n\n", pad_h, pad_w, stride_h, stride_w, skip_every, offset, interpolation_rate); @@ -1252,9 +1397,13 @@ int main(){ testTensorBatchNorm(); testTensorHalfBatchNorm(); - ///testTensorPooling(); - ///testTensorHalfPooling(); + testTensorPooling(); + testTensorHalfPooling(); + + testSampling_3_3(); + testSampling_1_1(); + testPerforation(); //testTensorError(); //testQuantization(); @@ -1280,10 +1429,6 @@ int main(){ /********* SAMPLING TESTS **** - testSampling_3_3(); - - - testSampling_1_1(); *************/