From e2825030cc87a49592bab3762768a55bb135e4f7 Mon Sep 17 00:00:00 2001 From: simon2 Date: Sat, 22 May 2021 00:08:21 +0900 Subject: [PATCH] add get_batched_matrices function to generate batched matrices in one function --- benchmarker/kernels/batchmatmul/args.hpp | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 benchmarker/kernels/batchmatmul/args.hpp diff --git a/benchmarker/kernels/batchmatmul/args.hpp b/benchmarker/kernels/batchmatmul/args.hpp new file mode 100644 index 00000000..89742c7f --- /dev/null +++ b/benchmarker/kernels/batchmatmul/args.hpp @@ -0,0 +1,68 @@ +// traditional BLAS API: +// M - Number of rows in matrices A and C. +// N - Number of columns in matrices B and C. +// K - Number of columns in matrix A; number of rows in matrix B. +// we remap from intuitive order to BLAS-style + +struct Options { + std::string precision; + size_t cnt_rows_A_rows_C; + size_t cnt_cols_A_rows_B; + size_t cnt_cols_B_cols_C; + size_t batch_size; + size_t nb_epoch; +}; + +Options parse_args(const int argc, char *argv[]) { + if (argc != 7) + { + std::cerr << "provide precision, m, n, k, batch_size, nb_epoch as command line parameters\n"; + std::cerr << "got " << argc << " parameters\n"; + exit(-1); + } + Options options; + options.precision = std::string(argv[1]); + options.cnt_rows_A_rows_C = atoi(argv[2]); + options.cnt_cols_A_rows_B = atoi(argv[3]); + options.cnt_cols_B_cols_C = atoi(argv[4]); + options.batch_size = atoi(argv[5]); + options.nb_epoch = atoi(argv[6]); + return options; +} + +template +void get_matrices(size_t &cnt_rows_A_rows_C, + size_t &cnt_cols_A_rows_B, + size_t &cnt_cols_B_cols_C, + precision * & A, + precision * & B, + precision * & C) { + size_t i; + A = (precision*) malloc(sizeof(precision) * cnt_rows_A_rows_C * cnt_cols_A_rows_B); + B = (precision*) malloc(sizeof(precision) * cnt_cols_A_rows_B * cnt_cols_B_cols_C); + C = (precision*) malloc(sizeof(precision) * cnt_rows_A_rows_C * cnt_cols_B_cols_C); + //fprintf(stderr, "done malloc\n"); + for(i=0; i < cnt_rows_A_rows_C * cnt_cols_A_rows_B; i++) { A[i] = static_cast(rand())/RAND_MAX;} + for(i=0; i < cnt_cols_A_rows_B * cnt_cols_B_cols_C; i++) { B[i] = static_cast(rand())/RAND_MAX;} + for(i=0; i < cnt_rows_A_rows_C * cnt_cols_B_cols_C; i++) { C[i] = static_cast(rand())/RAND_MAX;} + //fprintf(stderr, "done random init\n"); +} + +template +void get_batched_matrices(size_t &cnt_rows_A_rows_C, + size_t &cnt_cols_A_rows_B, + size_t &cnt_cols_B_cols_C, + precision ** & A, + precision ** & B, + precision ** & C, + size_t batch_size) { + A = (precision**) malloc(sizeof(precision*) * batch_size); + B = (precision**) malloc(sizeof(precision*) * batch_size); + C = (precision**) malloc(sizeof(precision*) * batch_size); + fprintf(stderr, "done malloc\n"); + for(size_t i=0; i(cnt_rows_A_rows_C, cnt_cols_A_rows_B, cnt_cols_B_cols_C, + A[i], B[i], C[i]); + } + fprintf(stderr, "done random init\n"); +} \ No newline at end of file