123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281 |
- #include <stdlib.h>
- #include <string.h>
- #include <stdio.h>
- #include <stdbool.h>
- #include <math.h>
- #include <unistd.h>
- #include <getopt.h>
- #if defined HAVE_AMD_FFT || defined HAVE_APPLE_FFT
- #define HAVE_OPENCL 1
- #endif
- #ifdef HAVE_OPENCL
- #include "opencl_fft.h"
- #endif
- #ifdef HAVE_FFTW
- #include "cpu_fft.h"
- #endif
- #ifdef HAVE_CUDA_FFT
- #include "cuda_fft.h"
- #endif
- #include "utilities.h"
- int
- main (int argc, char **argv)
- {
- static OutputType outputType = OUT_NONE;
- static int only_time = 1;
- static bool new_line = true;
- char *timestamp;
- int ofn_len;
- char *output_filename;
- char fn_buffer[150];
- get_timestamp (×tamp);
- ofn_len = sprintf(fn_buffer, "results_%s.txt", timestamp);
- output_filename = (char *)malloc(sizeof(char) * (ofn_len + 1));
- strcpy(output_filename, fn_buffer);
- free(timestamp);
- #ifdef HAVE_OPENCL
- cl_platform_id opencl_platform;
- cl_uint opencl_n_devices;
- cl_device_id *opencl_devices;
- cl_context opencl_context;
- cl_command_queue *opencl_queues;
- cl_int err;
- #endif
- #ifdef HAVE_CUDA_FFT
- int cuda_n_devices;
- #endif
- #ifdef HAVE_AMD_FFT
- static int with_amd_fft = 1;
- TimeEntry *amd_time_entries;
- #endif
- #ifdef HAVE_CUDA_FFT
- static int with_cuda_fft = 1;
- TimeEntry *cuda_time_entries;
- #endif
- #ifdef HAVE_APPLE_FFT
- static int with_apple_fft = 1;
- TimeEntry *apple_time_entries;
- #endif
- #ifdef HAVE_FFTW
- static int with_fftw = 1;
- TimeEntry *fftw_time_entries;
- #endif
- static char *options_descritions[] = {
- "Set the required output format [ms(default),sec,mflops,gflops,GBs,MBs] of benchmark results.",
- "Set the range of one side sizes [N M] (N < M) of 1D FFT in form of powers of two (e.g. form 2^N to 2^M).",
- "Set the range of one side sizes [N M] (N < M) of 2D FFT in form of powers of two (e.g. form 2^N to 2^M).",
- "Set the range of one side sizes [N M] (N < M) of 3D FFT in form of powers of two (e.g. form 2^N to 2^M).",
- "Set the number of runs for each size of each kind of FFT.",
- #ifdef HAVE_AMD_FFT
- "Disable AMD FFT library from benchmarking.",
- #endif
- #ifdef HAVE_CUDA_FFT
- "Disable CUDA FFT library from benchmarking.",
- #endif
- #ifdef HAVE_APPLE_FFT
- "Disable Apple FFT library from benchmarking.",
- #endif
- #ifdef HAVE_FFTW
- "Disable FFTW library from benchmarking",
- #endif
- "Add calculation errors to the results.",
- "Name of the output file (default name is result.txt).",
- "Display this usage information."
- };
- static struct option long_options[] =
- {
- {"measure-format", required_argument, NULL, 'm'},
- {"1d-pow2-range", required_argument, NULL, '1'},
- {"2d-pow2-range", required_argument, NULL, '2'},
- {"3d-pow2-range", required_argument, NULL, '3'},
- {"number-of-runs", required_argument, NULL, 'r'},
- #ifdef HAVE_AMD_FFT
- {"disable-amd", no_argument, &with_amd_fft, 0},
- #endif
- #ifdef HAVE_CUDA_FFT
- {"disable-cuda", no_argument, &with_cuda_fft, 0},
- #endif
- #ifdef HAVE_APPLE_FFT
- {"disable-apple", no_argument, &with_apple_fft, 0},
- #endif
- #ifdef HAVE_FFTW
- {"disable-fftw", no_argument, &with_fftw, 0},
- #endif
- {"print-errors", no_argument, NULL, 'p'},
- {"output-file", no_argument, NULL, 'o'},
- {"help", no_argument, NULL, 'h'},
- {NULL, 0, NULL, 0}
- };
- static char *short_options = "hm:1:2:3:r:o:p";
- /* Parse options */
- int next_option;
- int out_indx;
- do {
- next_option = getopt_long (argc, argv, short_options, long_options, &out_indx);
- switch (next_option) {
- case 'm':
- outputType = get_output_type_by_measure(optarg);
- break;
- case '1':
- if (!get_fft_range(argv[optind - 1], argv[optind], N_POWERS_INTERVALS[0])) {
- print_usage(argv[0], long_options, options_descritions, 1);
- }
- break;
- case '2':
- if (!get_fft_range(argv[optind - 1], argv[optind], N_POWERS_INTERVALS[1])) {
- print_usage(argv[0], long_options, options_descritions, 1);
- }
- break;
- case '3':
- if (!get_fft_range(argv[optind - 1], argv[optind], N_POWERS_INTERVALS[2])) {
- print_usage(argv[0], long_options, options_descritions, 1);
- }
- break;
- case 'r':
- if (!get_number_of_runs(optarg, &N_RUNS)) {
- print_usage(argv[0], long_options, options_descritions, 1);
- }
- break;
- case 'o':
- strcpy(output_filename, (const char*)optarg);
- break;
- case 'p':
- only_time = 0;
- break;
- case 'h':
- print_usage(argv[0], long_options, options_descritions, 0);
- break;
- case '?':
- print_usage(argv[0], long_options, options_descritions, 1);
- }
- }
- while (next_option != -1);
- if (outputType == OUT_NONE) {
- outputType = get_output_type_by_measure(NULL);
- }
- /* Open output file */
- FILE *fp;
- fp = fopen (output_filename, "w");
- #ifdef HAVE_OPENCL
- OCL_CHECK_ERROR (clGetPlatformIDs (1, &opencl_platform, NULL));
- OCL_CHECK_ERROR (clGetDeviceIDs (opencl_platform, CL_DEVICE_TYPE_ALL, 0, NULL, &opencl_n_devices));
- opencl_devices = malloc (opencl_n_devices * sizeof (cl_device_id));
- OCL_CHECK_ERROR (clGetDeviceIDs (opencl_platform, CL_DEVICE_TYPE_ALL, opencl_n_devices, opencl_devices, NULL));
- opencl_context = clCreateContext (NULL, opencl_n_devices, opencl_devices, NULL, NULL, &err);
- OCL_CHECK_ERROR (err);
- opencl_queues = malloc (opencl_n_devices * sizeof (cl_command_queue));
- for (int i = 0; i < opencl_n_devices; i++) {
- opencl_queues[i] = clCreateCommandQueue (opencl_context, opencl_devices[i], 0, &err);
- OCL_CHECK_ERROR (err);
- }
- #endif
- #ifdef HAVE_CUDA_FFT
- cudaGetDeviceCount(&cuda_n_devices);
- #endif
- #ifdef HAVE_AMD_FFT
- amd_time_entries = (TimeEntry *)malloc(sizeof(TimeEntry) * opencl_n_devices);
- if (with_amd_fft) {
- printf ("Testing AMD FFT ...\n");
- loop_data_opencl ("AMD", compute_amd_fft, opencl_context, opencl_queues, opencl_n_devices, outputType, amd_time_entries);
- }
- #endif
- #ifdef HAVE_APPLE_FFT
- apple_time_entries = (TimeEntry *)malloc(sizeof(TimeEntry) * opencl_n_devices);
- if (with_apple_fft) {
- printf ("Testing Apple FFT ...\n");
- loop_data_opencl ("APP", compute_apple_fft, opencl_context, opencl_queues, opencl_n_devices, outputType, apple_time_entries);
- }
- #endif
- #ifdef HAVE_CUDA_FFT
- cuda_time_entries = (TimeEntry *)malloc(sizeof(TimeEntry) * cuda_n_devices);
- if (with_cuda_fft) {
- printf ("Testing CUDA FFT ...\n");
- loop_data_cuda ("CUDA", compute_cuda_fft, cuda_n_devices, outputType, cuda_time_entries);
- }
- #endif
- #ifdef HAVE_FFTW
- fftw_time_entries = (TimeEntry *)malloc(sizeof(TimeEntry));
- if (with_fftw) {
- printf ("Testing FFTW3 ...\n");
- loop_data_fftw (outputType, &(fftw_time_entries[0]));
- }
- #endif
- /* Write headers */
- write_headers_in_file (N_DIMS, only_time, fp);
- #ifdef HAVE_AMD_FFT
- if (with_amd_fft) {
- write_time_entries_in_file (amd_time_entries, opencl_n_devices, N_DIMS, only_time, new_line, fp);
- }
- #endif
- #ifdef HAVE_APPLE_FFT
- if (with_apple_fft) {
- write_time_entries_in_file (apple_time_entries, opencl_n_devices, N_DIMS, only_time, new_line, fp);
- }
- #endif
- #ifdef HAVE_CUDA_FFT
- if (with_cuda_fft) {
- write_time_entries_in_file (cuda_time_entries, cuda_n_devices, N_DIMS, only_time, new_line, fp);
- }
- #endif
- #ifdef HAVE_FFTW
- if (with_fftw) {
- write_time_entries_in_file (fftw_time_entries, 1, N_DIMS, only_time, new_line, fp);
- }
- #endif
- #ifdef HAVE_OPENCL
- for (int i = 0; i < opencl_n_devices; i++) {
- clReleaseCommandQueue (opencl_queues[i]);
- }
- clReleaseContext (opencl_context);
- free (opencl_queues);
- free (opencl_devices);
- #endif
- fclose (fp);
- free(output_filename);
- return 0;
- }
|