diff --git a/llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h b/llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h index d2f37a35ed9d1e9b3d25fb7776faf84fc08385ba..30bf817d0d301f3ceb002c89246c2944d8af3bb2 100644 --- a/llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h +++ b/llvm/projects/hpvm-tensor-rt/dnn_sources/include/utils.h @@ -226,8 +226,6 @@ void* readInputTensor(const char* file_name, int data_type, int dim1_size, int d tensor_data[i] = (float) file_data[i] / 255.0f; } - //printf("tensor_data[%d] = %f \n", 10, tensor_data[10]); - // NOTE: Using NCHW format struct Tensor* input = (struct Tensor*) create4DTensor(data_type, nchw, dim1_size, dim2_size, dim3_size, dim4_size); @@ -337,7 +335,6 @@ struct Tensor* readInputBatch(const char* file_name, int data_type, fseek(file, file_header_size, SEEK_SET); // Skipping the file header size_t bytes_read = fread(tensor_data, 1, size_in_bytes, file); - // printf("size in bytes = %lu, bytes read = %lu \n", size_in_bytes, bytes_read); fclose(file); @@ -353,6 +350,39 @@ struct Tensor* readInputBatch(const char* file_name, int data_type, +void copyInputBatch(const char* file_name, + int start, int end, + int dim2_size, int dim3_size, int dim4_size, + void* inputTensor_ptr){ + + struct Tensor* inputTensor = (struct Tensor*) inputTensor_ptr; + + int dim1_size = end - start; + // FIXIT: Don't assume floating point types + int type_size = 4; // NOTE: Assuming floating point tensors + long int num_elems = dim1_size * dim2_size * dim3_size * dim4_size; + long int size_in_bytes = type_size * dim1_size * dim2_size * dim3_size * dim4_size; + float* tensor_data = (float*) malloc(sizeof(float) * num_elems); + int file_header_size = type_size * start * dim2_size * dim3_size * dim4_size; + + FILE* file = fopen(file_name, "rb"); + if(file == NULL){ + printf("Data file %s is not found. Aborting... \n", file_name); + abort(); + } + + fseek(file, file_header_size, SEEK_SET); // Skipping the file header + size_t bytes_read = fread(tensor_data, 1, size_in_bytes, file); + + fclose(file); + + + initTensorData(inputTensor, tensor_data, size_in_bytes); + free(tensor_data); +} + + + uint8_t* readLabels(const char* labels_file, int num_labels){ uint8_t* labels = (uint8_t*) malloc(sizeof(uint8_t) * num_labels); diff --git a/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet/src/alexnet.cpp b/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet/src/alexnet.cpp index 58c5bf380aa632342a3e7978699df07d92ca1294..7b44c7699cecb8d7bada8c68ebf66cfc16322a7e 100644 --- a/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet/src/alexnet.cpp +++ b/llvm/test/VISC/DNN_Benchmarks/benchmarks/alexnet/src/alexnet.cpp @@ -372,7 +372,10 @@ int main(){ std::string dir_prefix = std::string("../../../../../../projects/hpvm-tensor-rt/model_params/alexnet_cifar10_test/"); std::string input_path = dir_prefix + std::string("input.bin"); - void* input = readTrainedWeights(input_path.c_str(), 0,10000,3,32,32); + //void* input = readTrainedWeights(input_path.c_str(), 0,10000,3,32,32); + void* input = create4DTensor(0,nchw,10000,3,32,32); + copyInputBatch(input_path.c_str(),0,10000,3,32,32, input); + std::string labels_path = dir_prefix + std::string("labels.bin"); uint8_t* labels = readLabels(labels_path.c_str(),10000); std::string conv2d_1_w_path = dir_prefix + std::string("conv2d_1_w.bin"); diff --git a/llvm/test/VISC/DNN_Benchmarks/common/include/tensorUtils.h b/llvm/test/VISC/DNN_Benchmarks/common/include/tensorUtils.h index d2f37a35ed9d1e9b3d25fb7776faf84fc08385ba..30bf817d0d301f3ceb002c89246c2944d8af3bb2 100644 --- a/llvm/test/VISC/DNN_Benchmarks/common/include/tensorUtils.h +++ b/llvm/test/VISC/DNN_Benchmarks/common/include/tensorUtils.h @@ -226,8 +226,6 @@ void* readInputTensor(const char* file_name, int data_type, int dim1_size, int d tensor_data[i] = (float) file_data[i] / 255.0f; } - //printf("tensor_data[%d] = %f \n", 10, tensor_data[10]); - // NOTE: Using NCHW format struct Tensor* input = (struct Tensor*) create4DTensor(data_type, nchw, dim1_size, dim2_size, dim3_size, dim4_size); @@ -337,7 +335,6 @@ struct Tensor* readInputBatch(const char* file_name, int data_type, fseek(file, file_header_size, SEEK_SET); // Skipping the file header size_t bytes_read = fread(tensor_data, 1, size_in_bytes, file); - // printf("size in bytes = %lu, bytes read = %lu \n", size_in_bytes, bytes_read); fclose(file); @@ -353,6 +350,39 @@ struct Tensor* readInputBatch(const char* file_name, int data_type, +void copyInputBatch(const char* file_name, + int start, int end, + int dim2_size, int dim3_size, int dim4_size, + void* inputTensor_ptr){ + + struct Tensor* inputTensor = (struct Tensor*) inputTensor_ptr; + + int dim1_size = end - start; + // FIXIT: Don't assume floating point types + int type_size = 4; // NOTE: Assuming floating point tensors + long int num_elems = dim1_size * dim2_size * dim3_size * dim4_size; + long int size_in_bytes = type_size * dim1_size * dim2_size * dim3_size * dim4_size; + float* tensor_data = (float*) malloc(sizeof(float) * num_elems); + int file_header_size = type_size * start * dim2_size * dim3_size * dim4_size; + + FILE* file = fopen(file_name, "rb"); + if(file == NULL){ + printf("Data file %s is not found. Aborting... \n", file_name); + abort(); + } + + fseek(file, file_header_size, SEEK_SET); // Skipping the file header + size_t bytes_read = fread(tensor_data, 1, size_in_bytes, file); + + fclose(file); + + + initTensorData(inputTensor, tensor_data, size_in_bytes); + free(tensor_data); +} + + + uint8_t* readLabels(const char* labels_file, int num_labels){ uint8_t* labels = (uint8_t*) malloc(sizeof(uint8_t) * num_labels);