123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- #include "utilities.h"
- int N_RUNS = 4;
- const int DIMS[N_DIMS] = {1, 2, 3};
- int N_POWERS_INTERVALS[N_DIMS][2] = {{5, 11}, {8, 11}, {7, 7}};
- void write_headers_in_file (int n_dims, int only_time, FILE *fp)
- {
- fprintf (fp, "# ");
- for (int i = 0; i < n_dims; i++) {
- int min_power = N_POWERS_INTERVALS[i][0];
- int max_power = N_POWERS_INTERVALS[i][1];
- for (int j = min_power; j <= max_power; j++) {
- int side_size = pow(2,j);
- switch (DIMS[i]) {
- case 1:
- fprintf (fp, ";");
- fprintf (fp, "%d ", side_size);
- if (!only_time) {
- fprintf (fp, ";");
- fprintf (fp, "%d(Error) ", side_size);
- }
- break;
- case 2:
- fprintf (fp, ";");
- fprintf (fp, "%dx%d ", side_size, side_size);
- if (!only_time) {
- fprintf (fp, ";");
- fprintf (fp, "%dx%d(Error) ", side_size, side_size);
- }
- break;
- case 3:
- fprintf (fp, ";");
- fprintf (fp, "%dx%dx%d ", side_size, side_size, side_size);
- if (!only_time) {
- fprintf (fp, ";");
- fprintf (fp, "%dx%dx%d(Error) ", side_size, side_size, side_size);
- }
- break;
- }
- }
- }
- }
- void write_time_entries_in_file (TimeEntry* time_entries, int num_entries, int n_dims, int only_time, bool new_line, FILE *fp)
- {
- if (new_line) {
- fprintf (fp, "\n");
- }
- for (int i = 0; i < num_entries; i++) {
- fprintf (fp, "%s ", time_entries[i].lib_name);
- DimEntry *dim_entries = time_entries[i].dim_entries;
- for (int dim = 0; dim < n_dims; dim++) {
- DimEntry dim_entry = dim_entries[dim];
- for (int j = 0; j < (N_POWERS_INTERVALS[dim][1] - N_POWERS_INTERVALS[dim][0] + 1); j++) {
- if (only_time) {
- fprintf (fp, ";");
- fprintf (fp, "%f", dim_entry.times[j]);
- }
- else {
- fprintf (fp, ";%f;%f ", dim_entry.times[j], dim_entry.errors[j]);
- }
- }
- }
- if (i != num_entries -1) {
- fprintf (fp, "\n");
- }
- }
- }
- OutputType get_output_type_by_measure(char *measure) {
- OutputType outputType = OUT_MILLISECONDS;
- bool invalid_format = false;
- if (measure != NULL) {
- if (!strcmp(optarg, "ms"))
- outputType = OUT_MILLISECONDS;
- else if (!strcmp(optarg, "sec"))
- outputType = OUT_SECONDS;
- else if (!strcmp(optarg, "gflops"))
- outputType = OUT_GFLOPS;
- else if (!strcmp(optarg, "mflops"))
- outputType = OUT_MFLOPS;
- else if (!strcmp(optarg, "MBs") || !strcmp(optarg, "mbs"))
- outputType = OUT_THROUGHTPUT_MBS;
- else if (!strcmp(optarg, "GBs") || !strcmp(optarg, "gbs"))
- outputType = OUT_THROUGHTPUT_GBS;
- else {
- invalid_format = true;
- fprintf (stderr, "Incorrect measure format [%s], [ms] will be used.\nUse the following formats: ms,sec,mflops,gflops,GBs,MBs.\n\n", measure);
- }
- }
-
- if (!invalid_format || (measure == NULL)) {
- fprintf (stdout, "Output will be use measure [%s].\n\n", measure == NULL ? "ms" : measure);
- }
-
- return outputType;
- }
- bool get_fft_range(char *val1, char *val2, int *out_range) {
- int out_val1;
- int out_val2;
- bool range_is_valid = true;
- out_val1 = (int) strtol (val1, NULL, 10);
- out_val2 = (int) strtol (val2, NULL, 10);
- if (out_val1 != 0L &&
- out_val2 != 0L &&
- (out_val1 >= MIN_POW2 && out_val1 <= MAX_POW2) &&
- (out_val2 >= MIN_POW2 && out_val2 <= MAX_POW2) &&
- (out_val1 < out_val2)) {
- out_range[0] = out_val1;
- out_range[1] = out_val2;
- }
- else {
- fprintf (stderr, "Incorrect the range of powers, it should be in range [%d %d].\n\n", MIN_POW2, MAX_POW2);
- range_is_valid = false;
- }
- return range_is_valid;
- }
- bool get_number_of_runs(char *val, int *out) {
- bool value_valid = true;
- int out_val;
- out_val = (int) strtol (val, NULL, 10);
- if (out_val != 0L && (out_val >= MIN_RUNS && out_val <= MAX_RUNS)) {
- *out = out_val;
- }
- else {
- fprintf (stderr, "Incorrect the number of runs, the value should be from %d to %d.\n\n", MIN_RUNS, MAX_RUNS);
- value_valid = false;
- }
- return value_valid;
- }
- void print_usage(char *app_name, struct option long_options[], char **options_descritions, int exit_code)
- {
- printf ("Usage: %s [OPTIONS]\n", app_name);
- printf ("Options:\n");
- for (int i = 0; long_options[i].name != 0; i++) {
- printf(" --%-20s %s\n", long_options[i].name, options_descritions[i]);
- }
- exit (exit_code);
- }
- double get_measurements_with_format (OutputType outputType, size_t size_bytes, double time_sec)
- {
- double out_result = -1;
- if (outputType == OUT_MFLOPS) {
- size_t size = size_bytes / 2 / sizeof (float);
- out_result = 5 * size * log (size) / log (2) / (time_sec / 1000.0);
- }
- else if (outputType == OUT_GFLOPS) {
- out_result = -1;
- }
- else if (outputType == OUT_THROUGHTPUT_MBS) {
- out_result = ((double)size_bytes) / time_sec / 1000.0 / 1000.0;
- }
- else if (outputType == OUT_THROUGHTPUT_GBS) {
- out_result = ((double)size_bytes) / time_sec / 1000.0 / 1000.0 / 1000.0;
- }
- else if (outputType == OUT_MILLISECONDS) {
- out_result = time_sec * 1000.0;
- }
- else if (outputType == OUT_SECONDS) {
- out_result = time_sec * 1000.0;
- }
- else {
- fprintf (stderr, "Unknown output type of OpenCL routines!\n");
- }
- return out_result;
- }
- void get_timestamp (char **ts) {
- time_t rawtime;
- struct tm *timeinfo;
- time (&rawtime);
- timeinfo = localtime (&rawtime);
- *ts = (char *) malloc(sizeof(char) * 30);
- strftime (*ts, 30, "%d%m%Y%H%M%S", timeinfo);
- }
|