From 43664de01fc91dd4c9a42a922efd18d672c76047 Mon Sep 17 00:00:00 2001 From: Hashim Sharif <hsharif3@tyler.cs.illinois.edu> Date: Tue, 25 Feb 2020 02:03:17 -0600 Subject: [PATCH] Adding confidence dumps to all layer-level Autotuner sources --- .../src/promise/alexnet2_promise.cc | 2 +- .../src/promise/mobilenet_promise.cc | 48 ++++++++--- .../src/promise/mobilenet_shallow_promise.cc | 41 ++++++++-- .../src/promise/resnet18_promise.cc | 43 ++++++++-- .../src/promise/vgg16_cifar100_promise.cc | 47 +++++++++-- .../src/promise/vgg16_cifar10_promise.cc | 82 +++++++++++++------ 6 files changed, 205 insertions(+), 58 deletions(-) diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/alexnet2_promise.cc b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/alexnet2_promise.cc index 71df5b9d38..2cd364bf6b 100644 --- a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/alexnet2_promise.cc +++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/alexnet2_promise.cc @@ -129,7 +129,7 @@ int main(int argc, char* argv[]){ if(shouldDumpClassConf){ int relative_start = start - offset; int relative_end = end - offset; - copyClassConfsAndLabels(var_6, classConfs, predictedLabels, relative_start, relative_end); + copyClassConfsAndLabels(var_7, classConfs, predictedLabels, relative_start, relative_end); } freeBatchMemory(); diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/mobilenet_promise.cc b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/mobilenet_promise.cc index cbfc534681..691c97a3ef 100644 --- a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/mobilenet_promise.cc +++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/mobilenet_promise.cc @@ -6,8 +6,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <string.h> -#include "../../../tensor_runtime/include/tensor_runtime.h" -#include "../../include/utils.h" +#include "tensor_runtime.h" +#include "utils.h" int total_runs = 1; @@ -41,7 +41,17 @@ int main(int argc, char* argv[]){ offset = atoi(argv[5]); } - + bool shouldDumpClassConf = false; + float* classConfs; + int* predictedLabels; + if(argc > 6){ + shouldDumpClassConf = true; + classConfs = (float*) malloc(sizeof(float) * test_input_size); + predictedLabels = (int*) malloc(sizeof(int) * test_input_size); + } + + + llvm_hpvm_initTensorRt(1); @@ -58,12 +68,14 @@ int main(int argc, char* argv[]){ int batch_count = test_input_size / batch_size; float final_accuracy = 0.0; - for(int i = 0; i < batch_count; i++){ + std::string dir_prefix = std::string("../model_params/mobilenet/"); + std::string input_path = dir_prefix + std::string("input.bin"); + std::string labels_path = dir_prefix + std::string("labels.bin"); + std::string labels32_path = dir_prefix + std::string("labels32.bin"); + + for(int i = 0; i < batch_count; i++){ - std::string dir_prefix = std::string("../model_params/mobilenet/"); - std::string input_path = dir_prefix + std::string("input.bin"); - std::string labels_path = dir_prefix + std::string("labels.bin"); std::string conv2d_1_w_path = dir_prefix + std::string("conv2d_1_w.bin"); void* conv2d_1_w = readTrainedWeights(conv2d_1_w_path.c_str(), 0,32,3,3,3); std::string batch_normalization_1_gamma_path = dir_prefix + std::string("batch_normalization_1_gamma.bin"); @@ -433,9 +445,16 @@ int main(int argc, char* argv[]){ uint8_t* labels = readLabelsBatch(labels_path.c_str(),start,end); float accuracy = computeAccuracy2(labels, batch_size, var_83); - final_accuracy += accuracy; - freeBatchMemory(); - + final_accuracy += accuracy; + + if(shouldDumpClassConf){ + int relative_start = start - offset; + int relative_end = end - offset; + copyClassConfsAndLabels(var_83, classConfs, predictedLabels, relative_start, relative_end); + } + + + freeBatchMemory(); } final_accuracy = final_accuracy / batch_count; @@ -443,6 +462,15 @@ int main(int argc, char* argv[]){ if (final_accuracy < bench_acc) missed += 1; + + + if(shouldDumpClassConf){ + int labels_start = offset; + int labels_end = offset + test_input_size; + uint32_t* goldLabels = readLabelsBatch3(labels32_path.c_str(), labels_start, labels_end); + dumpClassConfsAndLabels(classConfs, predictedLabels, goldLabels, test_input_size); + } + } dumpExecutionAccuracies(); diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/mobilenet_shallow_promise.cc b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/mobilenet_shallow_promise.cc index 7a8136d7d3..89b3697298 100644 --- a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/mobilenet_shallow_promise.cc +++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/mobilenet_shallow_promise.cc @@ -6,8 +6,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <string.h> -#include "../../../tensor_runtime/include/tensor_runtime.h" -#include "../../include/utils.h" +#include "tensor_runtime.h" +#include "utils.h" int total_runs = 1; @@ -41,6 +41,16 @@ int main(int argc, char* argv[]){ offset = atoi(argv[5]); } + bool shouldDumpClassConf = false; + float* classConfs; + int* predictedLabels; + if(argc > 6){ + shouldDumpClassConf = true; + classConfs = (float*) malloc(sizeof(float) * test_input_size); + predictedLabels = (int*) malloc(sizeof(int) * test_input_size); + } + + llvm_hpvm_initTensorRt(1); @@ -56,11 +66,13 @@ int main(int argc, char* argv[]){ int batch_count = test_input_size / batch_size; float final_accuracy = 0.0; + std::string dir_prefix = std::string("../model_params/mobilenet_shallow/"); + std::string input_path = dir_prefix + std::string("input.bin"); + std::string labels_path = dir_prefix + std::string("labels.bin"); + std::string labels32_path = dir_prefix + std::string("labels32.bin"); + for(int i = 0; i < batch_count; i++){ - std::string dir_prefix = std::string("../model_params/mobilenet_shallow/"); - std::string input_path = dir_prefix + std::string("input.bin"); - std::string labels_path = dir_prefix + std::string("labels.bin"); std::string conv2d_1_w_path = dir_prefix + std::string("conv2d_1_w.bin"); void* conv2d_1_w = readTrainedWeights(conv2d_1_w_path.c_str(), 0,32,3,3,3); std::string batch_normalization_1_gamma_path = dir_prefix + std::string("batch_normalization_1_gamma.bin"); @@ -248,7 +260,15 @@ int main(int argc, char* argv[]){ uint8_t* labels = readLabelsBatch(labels_path.c_str(),start,end); float accuracy = computeAccuracy2(labels, batch_size, var_41); - final_accuracy += accuracy; + final_accuracy += accuracy; + + if(shouldDumpClassConf){ + int relative_start = start - offset; + int relative_end = end - offset; + copyClassConfsAndLabels(var_41, classConfs, predictedLabels, relative_start, relative_end); + } + + freeBatchMemory(); } @@ -259,6 +279,15 @@ int main(int argc, char* argv[]){ if (final_accuracy < bench_acc) missed += 1; + + + if(shouldDumpClassConf){ + int labels_start = offset; + int labels_end = offset + test_input_size; + uint32_t* goldLabels = readLabelsBatch3(labels32_path.c_str(), labels_start, labels_end); + dumpClassConfsAndLabels(classConfs, predictedLabels, goldLabels, test_input_size); + } + } dumpExecutionAccuracies(); diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/resnet18_promise.cc b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/resnet18_promise.cc index b229fc9c2b..21c7b051c2 100644 --- a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/resnet18_promise.cc +++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/resnet18_promise.cc @@ -6,8 +6,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <string.h> -#include "../../../tensor_runtime/include/tensor_runtime.h" -#include "../../include/utils.h" +#include "tensor_runtime.h" +#include "utils.h" int total_runs = 1; @@ -42,6 +42,16 @@ int main(int argc, char* argv[]){ } + bool shouldDumpClassConf = false; + float* classConfs; + int* predictedLabels; + if(argc > 6){ + shouldDumpClassConf = true; + classConfs = (float*) malloc(sizeof(float) * test_input_size); + predictedLabels = (int*) malloc(sizeof(int) * test_input_size); + } + + llvm_hpvm_initTensorRt(1); @@ -57,11 +67,14 @@ int main(int argc, char* argv[]){ int batch_count = test_input_size / batch_size; float final_accuracy = 0.0; + + std::string dir_prefix = std::string("../model_params/resnet18_cifar10_promise/"); + std::string input_path = dir_prefix + std::string("input.bin"); + std::string labels_path = dir_prefix + std::string("labels.bin"); + std::string labels32_path = dir_prefix + std::string("labels32.bin"); + for(int i = 0; i < batch_count; i++){ - std::string dir_prefix = std::string("../model_params/resnet18_cifar10_promise/"); - std::string input_path = dir_prefix + std::string("input.bin"); - std::string labels_path = dir_prefix + std::string("labels.bin"); std::string conv2d_1_w_path = dir_prefix + std::string("conv2d_1_w.bin"); void* conv2d_1_w = readTrainedWeights(conv2d_1_w_path.c_str(), 0,16,3,3,3); std::string conv2d_1_b_path = dir_prefix + std::string("conv2d_1_b.bin"); @@ -202,7 +215,16 @@ int main(int argc, char* argv[]){ uint8_t* labels = readLabelsBatch(labels_path.c_str(),start,end); float accuracy = computeAccuracy2(labels, batch_size, var_41); - final_accuracy += accuracy; + final_accuracy += accuracy; + + + if(shouldDumpClassConf){ + int relative_start = start - offset; + int relative_end = end - offset; + copyClassConfsAndLabels(var_41, classConfs, predictedLabels, relative_start, relative_end); + } + + freeBatchMemory(); } @@ -213,6 +235,15 @@ int main(int argc, char* argv[]){ if (final_accuracy < bench_acc) missed += 1; + + + if(shouldDumpClassConf){ + int labels_start = offset; + int labels_end = offset + test_input_size; + uint32_t* goldLabels = readLabelsBatch3(labels32_path.c_str(), labels_start, labels_end); + dumpClassConfsAndLabels(classConfs, predictedLabels, goldLabels, test_input_size); + } + } dumpExecutionAccuracies(); diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/vgg16_cifar100_promise.cc b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/vgg16_cifar100_promise.cc index ed11c5158d..27bc38e0e3 100644 --- a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/vgg16_cifar100_promise.cc +++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/vgg16_cifar100_promise.cc @@ -6,8 +6,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <string.h> -#include "../../../tensor_runtime/include/tensor_runtime.h" -#include "../../include/utils.h" +#include "tensor_runtime.h" +#include "utils.h" @@ -44,6 +44,17 @@ int main(int argc, char* argv[]){ } + bool shouldDumpClassConf = false; + float* classConfs; + int* predictedLabels; + if(argc > 6){ + shouldDumpClassConf = true; + classConfs = (float*) malloc(sizeof(float) * test_input_size); + predictedLabels = (int*) malloc(sizeof(int) * test_input_size); + } + + + llvm_hpvm_initTensorRt(1); @@ -59,12 +70,14 @@ int main(int argc, char* argv[]){ int batch_count = test_input_size / batch_size; float final_accuracy = 0.0; - + + std::string dir_prefix = std::string("../model_params/vgg16_cifar100_front/"); + std::string input_path = dir_prefix + std::string("input.bin"); + std::string labels_path = dir_prefix + std::string("labels.bin"); + std::string labels32_path = dir_prefix + std::string("labels32.bin"); + for(int i = 0; i < batch_count; i++){ - std::string dir_prefix = std::string("../model_params/vgg16_cifar100_front/"); - std::string input_path = dir_prefix + std::string("input.bin"); - std::string labels_path = dir_prefix + std::string("labels.bin"); std::string conv2d_1_w_path = dir_prefix + std::string("conv2d_1_w.bin"); void* conv2d_1_w = readTrainedWeights(conv2d_1_w_path.c_str(), 0,64,3,3,3); std::string conv2d_1_b_path = dir_prefix + std::string("conv2d_1_b.bin"); @@ -153,9 +166,16 @@ int main(int argc, char* argv[]){ uint8_t* labels = readLabelsBatch(labels_path.c_str(),start,end); float accuracy = computeAccuracy2(labels, batch_size, var_15, 100); - final_accuracy += accuracy; - freeBatchMemory(); - + final_accuracy += accuracy; + + + if(shouldDumpClassConf){ + int relative_start = start - offset; + int relative_end = end - offset; + copyClassConfsAndLabels(var_15, classConfs, predictedLabels, relative_start, relative_end); + } + + freeBatchMemory(); } final_accuracy = final_accuracy / batch_count; @@ -164,6 +184,15 @@ int main(int argc, char* argv[]){ if (final_accuracy < bench_acc) missed += 1; + + + if(shouldDumpClassConf){ + int labels_start = offset; + int labels_end = offset + test_input_size; + uint32_t* goldLabels = readLabelsBatch3(labels32_path.c_str(), labels_start, labels_end); + dumpClassConfsAndLabels(classConfs, predictedLabels, goldLabels, test_input_size); + } + } dumpExecutionAccuracies(); diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/vgg16_cifar10_promise.cc b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/vgg16_cifar10_promise.cc index 4398e721f9..c66de402d8 100644 --- a/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/vgg16_cifar10_promise.cc +++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/src/promise/vgg16_cifar10_promise.cc @@ -6,8 +6,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <string.h> -#include "../../../tensor_runtime/include/tensor_runtime.h" -#include "../../include/utils.h" +#include "tensor_runtime.h" +#include "utils.h" int total_runs = 1; @@ -17,31 +17,42 @@ int to_skip = 5; int main(int argc, char* argv[]){ - int test_input_size = 3000; - int batch_size = 1000; - int offset = 5000; + int test_input_size = 3000; + int batch_size = 1000; + int offset = 5000; - if (argc > 1){ - total_runs = atoi(argv[1]); - } + if (argc > 1){ + total_runs = atoi(argv[1]); + } - if (argc > 2){ - bench_acc = atof(argv[2]); - } + if (argc > 2){ + bench_acc = atof(argv[2]); + } - if(argc > 3){ - to_skip = atoi(argv[3]); - } + if(argc > 3){ + to_skip = atoi(argv[3]); + } - if(argc > 4){ - test_input_size = atoi(argv[4]); - } + if(argc > 4){ + test_input_size = atoi(argv[4]); + } - if(argc > 5){ - offset = atoi(argv[5]); - } + if(argc > 5){ + offset = atoi(argv[5]); + } + + bool shouldDumpClassConf = false; + float* classConfs; + int* predictedLabels; + if(argc > 6){ + shouldDumpClassConf = true; + classConfs = (float*) malloc(sizeof(float) * test_input_size); + predictedLabels = (int*) malloc(sizeof(int) * test_input_size); + } + + llvm_hpvm_initTensorRt(1); @@ -57,13 +68,14 @@ int main(int argc, char* argv[]){ int batch_count = test_input_size / batch_size; float final_accuracy = 0.0; - + + std::string dir_prefix = std::string("../model_params/vgg16_cifar10_2/"); + std::string input_path = dir_prefix + std::string("input.bin"); + std::string labels_path = dir_prefix + std::string("labels.bin"); + std::string labels32_path = dir_prefix + std::string("labels32.bin"); + for(int i = 0; i < batch_count; i++){ - std::string dir_prefix = std::string("../model_params/vgg16_cifar10_2/"); - - std::string input_path = dir_prefix + std::string("input.bin"); - std::string labels_path = dir_prefix + std::string("labels.bin"); std::string conv2d_1_w_path = dir_prefix + std::string("conv2d_1_w.bin"); void* conv2d_1_w = readTrainedWeights(conv2d_1_w_path.c_str(), 0,64,3,3,3); std::string conv2d_1_b_path = dir_prefix + std::string("conv2d_1_b.bin"); @@ -151,7 +163,16 @@ int main(int argc, char* argv[]){ uint8_t* labels = readLabelsBatch(labels_path.c_str(),start,end); float accuracy = computeAccuracy2(labels, batch_size, var_15); - final_accuracy += accuracy; + final_accuracy += accuracy; + + + if(shouldDumpClassConf){ + int relative_start = start - offset; + int relative_end = end - offset; + copyClassConfsAndLabels(var_15, classConfs, predictedLabels, relative_start, relative_end); + } + + freeBatchMemory(); } @@ -162,6 +183,15 @@ int main(int argc, char* argv[]){ if (final_accuracy < bench_acc) missed += 1; + + + if(shouldDumpClassConf){ + int labels_start = offset; + int labels_end = offset + test_input_size; + uint32_t* goldLabels = readLabelsBatch3(labels32_path.c_str(), labels_start, labels_end); + dumpClassConfsAndLabels(classConfs, predictedLabels, goldLabels, test_input_size); + } + } -- GitLab