[go: up one dir, main page]

File: measuredft.c

package info (click to toggle)
sleef 3.6.1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 8,276 kB
  • sloc: ansic: 51,994; java: 151; makefile: 142; sh: 14
file content (175 lines) | stat: -rw-r--r-- 3,924 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
//   Copyright Naoki Shibata and contributors 2010 - 2021.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE.txt or copy at
//          http://www.boost.org/LICENSE_1_0.txt)

#define _DEFAULT_SOURCE
#define _XOPEN_SOURCE 700

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <assert.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>

#include <math.h>
#include <complex.h>

#include "sleef.h"
#include "sleefdft.h"

static uint64_t gettime() {
  struct timespec tp;
  clock_gettime(CLOCK_MONOTONIC, &tp);
  return (uint64_t)tp.tv_sec * 1000000000 + ((uint64_t)tp.tv_nsec);
}

int mode[] = { SLEEF_MODE_MEASURE | SLEEF_MODE_NO_MT, SLEEF_MODE_MEASURE};

#define ENABLE_SP
//#define ROUNDTRIP
#define REPEAT 2
//#define ENABLE_SLEEP
//#define WARMUP

int main(int argc, char **argv) {
  int start = 1, end = 18;
  if (argc > 1) start = atoi(argv[1]);
  if (argc > 2) end = atoi(argv[2]);

  double *din  = (double *)Sleef_malloc((1 << 18)*2 * sizeof(double));
  double *dout = (double *)Sleef_malloc((1 << 18)*2 * sizeof(double));
  float *sin  = (float *)Sleef_malloc((1 << 18)*2 * sizeof(float));
  float *sout = (float *)Sleef_malloc((1 << 18)*2 * sizeof(float));

  SleefDFT_setPlanFilePath(NULL, NULL, SLEEF_PLAN_RESET | SLEEF_PLAN_READONLY);

  for(int log2n=start;log2n<=end;log2n++) {
    const int n = 1 << log2n;
    int64_t niter = (int64_t)(1000000000.0 / REPEAT / n / log2n);

    printf("%d ", n);

    for(int m=0;m<2;m++) {
#ifdef ENABLE_SLEEP
      sleep(1);
#endif

      struct SleefDFT *pf = SleefDFT_double_init1d(n, NULL, NULL, mode[m]);
#ifdef ROUNDTRIP
      struct SleefDFT *pb = SleefDFT_double_init1d(n, NULL, NULL, mode[m] | SLEEF_MODE_BACKWARD);
#endif

      for(int i=0;i<n*2;i++) {
	din[i] = 0;
      }

#ifdef ENABLE_SLEEP
      sleep(1);
#endif

#ifdef WARMUP
      for(int64_t i=0;i<niter/2;i++) {
	SleefDFT_double_execute(pf, din, dout);
#ifdef ROUNDTRIP
	SleefDFT_double_execute(pb, dout, din);
#endif
      }
#endif

      uint64_t best = 1LL << 62;

      //printf("\n");
      for(int rep=0;rep<REPEAT;rep++) {
	uint64_t tm0 = gettime();
	for(int64_t i=0;i<niter;i++) {
	  SleefDFT_double_execute(pf, din, dout);
#ifdef ROUNDTRIP
	  SleefDFT_double_execute(pb, dout, din);
#endif
	}
	uint64_t tm1 = gettime();
	if (tm1 - tm0 < best) best = tm1 - tm0;
	//printf("%g\n", (double)(tm1 - tm0));
      }

      SleefDFT_dispose(pf);
#ifdef ROUNDTRIP
      SleefDFT_dispose(pb);
#endif

      double timeus = best / ((double)niter * 1000);

#ifdef ROUNDTRIP
      double mflops = 10 * n * log2n / timeus;
#else
      double mflops = 5 * n * log2n / timeus;
#endif

      printf("%g ", mflops);
    }

#ifdef ENABLE_SP
    for(int m=0;m<2;m++) {
#ifdef ENABLE_SLEEP
      sleep(1);
#endif

      struct SleefDFT *pf = SleefDFT_float_init1d(n, NULL, NULL, mode[m]);
#ifdef ROUNDTRIP
      struct SleefDFT *pb = SleefDFT_float_init1d(n, NULL, NULL, mode[m] | SLEEF_MODE_BACKWARD);
#endif

      for(int i=0;i<n*2;i++) {
	sin[i] = 0;
      }

#ifdef ENABLE_SLEEP
      sleep(1);
#endif

#ifdef WARMUP
      for(int64_t i=0;i<niter/2;i++) {
	SleefDFT_float_execute(pf, sin, sout);
#ifdef OUNDTRIP
	SleefDFT_float_execute(pb, sout, sin);
#endif
      }
#endif

      uint64_t best = 1LL << 62;

      for(int rep=0;rep<REPEAT;rep++) {
	uint64_t tm0 = gettime();
	for(int64_t i=0;i<niter;i++) {
	  SleefDFT_float_execute(pf, sin, sout);
#ifdef ROUNDTRIP
	  SleefDFT_float_execute(pb, sout, sin);
#endif
	}
	uint64_t tm1 = gettime();
	if (tm1 - tm0 < best) best = tm1 - tm0;
      }
      
      SleefDFT_dispose(pf);
#ifdef ROUNDTRIP
      SleefDFT_dispose(pb);
#endif

      double timeus = best / ((double)niter * 1000);

#ifdef ROUNDTRIP
      double mflops = 10 * n * log2n / timeus;
#else
      double mflops = 5 * n * log2n / timeus;
#endif

      printf("%g ", mflops);
    }
#endif
    
    printf("\n");
  }
}