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 8b1cfbf5371c71d5f6d01897ed3d93d74a434c0f..e57adeadb414006f912cb26c16d6c4c577b8e542 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 @@ -447,6 +447,87 @@ void testSoftmaxOutput(void* output_ptr){ } + +void testPromiseError(){ + + printf("***** TensorQuantize ***** \n\n"); + void* input = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 2, 6, 1, 1); + float* host_ptr = (float*) ((struct Tensor*) input)->host_data; + + void* gold_tensor = create4DTensor(CUDNN_DATA_FLOAT, CUDNN_TENSOR_NCHW, 2, 6, 1, 1); + float* gold_ptr = (float*) ((struct Tensor*) gold_tensor)->host_data; + + gold_ptr[0] = -1; + gold_ptr[1] = -2; + gold_ptr[2] = -3; + gold_ptr[3] = -4; + gold_ptr[4] = -5; + gold_ptr[5] = 0; + gold_ptr[6] = 5; + gold_ptr[7] = 4; + gold_ptr[8] = 3; + gold_ptr[9] = 2; + gold_ptr[10] = 1; + gold_ptr[11] = 1; + + + int num_elems = 12; + int num_runs = 1000; + + float* result_ptr = (float*) malloc(sizeof(float) * num_elems); + + for (int swing = 1; swing <= 7; swing++){ + + for (int j = 0; j < num_elems; j++){ + result_ptr[j] = 0; + } + + float error_sum = 0.0; + + for (int i = 0; i < 1000; i++){ + host_ptr[0] = -1; + host_ptr[1] = -2; + host_ptr[2] = -3; + host_ptr[3] = -4; + host_ptr[4] = -5; + host_ptr[5] = 0; + host_ptr[6] = 5; + host_ptr[7] = 4; + host_ptr[8] = 3; + host_ptr[9] = 2; + host_ptr[10] = 1; + host_ptr[11] = 1; + + void* error_out = addPromiseError(input, swing); + //printTensorValues(error_out); + + // Move result data back to the host + hpvm_request_tensor(input, 0); + float* error_out_ptr = (float*) ((struct Tensor*) input)->host_data; + + for (int j = 0; j < num_elems; j++){ + result_ptr[j] += error_out_ptr[j]; + error_sum += (error_out_ptr[j] - gold_ptr[j]) * (error_out_ptr[j] - gold_ptr[j]); + } + } + + printf ("\n\n - Swing %d results : \n", swing); + for (int j = 0; j < num_elems; j++){ + result_ptr[j] = result_ptr[j] / num_runs; + printf(" %f ", result_ptr[j]); + } + + printf("mean_error = %f \n", error_sum / num_runs); + + printf(" \n"); + } + + +} + + + + void testQuantization(){ printf("***** TensorQuantize ***** \n\n"); @@ -465,7 +546,7 @@ void testQuantization(){ host_ptr[9] = 7.2; host_ptr[10] = 2.5; host_ptr[11] = 3; - + void* quantize_result1 = quantizeTensorPromise(input, -4, 6); @@ -525,16 +606,12 @@ void testQuantization(){ host_ptr[11] = 3; - void* quantize_result4 = quantizeTensorPromise(input, -10, 10); - + void* quantize_result4 = quantizeTensorPromise(input, -10, 10); printTensorValues(quantize_result4); - void* quantize_result5 = quantizeTensorPromise(input, -10, 10); - printTensorValues(quantize_result5); - //void* error_out = addPromiseError(quantize_result, 1); //printTensorValues(error_out); @@ -1076,6 +1153,12 @@ int main(){ //- testSampling_1_1(); + + + //testQuantization(); + + testPromiseError(); + stopProfiling();