Skip to content

Commit a07f18d

Browse files
authored
Various updates to DFT (#652)
1 parent e5a99ed commit a07f18d

File tree

16 files changed

+297
-139
lines changed

16 files changed

+297
-139
lines changed

Configure.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ endif()
9898
# Include TLFloat as a submodule
9999

100100
if (SLEEF_ENABLE_TLFLOAT)
101-
set(TLFLOAT_MINIMUM_VERSION 1.12.0)
102-
set(TLFLOAT_GIT_TAG "6ad1b86fc3fb89d8a4f7b1ff94e4f85e675ea69e")
101+
set(TLFLOAT_MINIMUM_VERSION 1.14.0)
102+
set(TLFLOAT_GIT_TAG "a1d500b51f17436e4658b1804f94ca01643675a1")
103103

104104
set(TLFLOAT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/submodules/tlfloat")
105105
set(TLFLOAT_INSTALL_DIR "${SLEEF_SUBMODULE_INSTALL_DIR}/tlfloat")

src/dft-tester/CMakeLists.txt

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,21 @@ if((NOT MSVC) AND NOT SLEEF_CLANG_ON_WINDOWS)
8282
target_link_libraries(${TARGET_MEASUREDFT} ${COMMON_LINK_LIBRARIES})
8383
set_target_properties(${TARGET_MEASUREDFT} PROPERTIES ${COMMON_TARGET_PROPERTIES})
8484

85-
# Target executable bench1d
86-
set(TARGET_BENCH1D "bench1d")
87-
add_executable(${TARGET_BENCH1D} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
88-
add_dependencies(${TARGET_BENCH1D} ${TARGET_HEADERS} ${TARGET_LIBSLEEF} ${TARGET_LIBDFT})
89-
target_compile_definitions(${TARGET_BENCH1D} PRIVATE ${COMMON_TARGET_DEFINITIONS})
90-
target_link_libraries(${TARGET_BENCH1D} ${COMMON_LINK_LIBRARIES})
91-
set_target_properties(${TARGET_BENCH1D} PROPERTIES ${COMMON_TARGET_PROPERTIES})
85+
# Target executable bench1dst
86+
set(TARGET_BENCH1DST "bench1dst")
87+
add_executable(${TARGET_BENCH1DST} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
88+
add_dependencies(${TARGET_BENCH1DST} ${TARGET_HEADERS} ${TARGET_LIBSLEEF} ${TARGET_LIBDFT})
89+
target_compile_definitions(${TARGET_BENCH1DST} PRIVATE ${COMMON_TARGET_DEFINITIONS})
90+
target_link_libraries(${TARGET_BENCH1DST} ${COMMON_LINK_LIBRARIES})
91+
set_target_properties(${TARGET_BENCH1DST} PROPERTIES ${COMMON_TARGET_PROPERTIES})
92+
93+
# Target executable bench1dmt
94+
set(TARGET_BENCH1DMT "bench1dmt")
95+
add_executable(${TARGET_BENCH1DMT} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
96+
add_dependencies(${TARGET_BENCH1DMT} ${TARGET_HEADERS} ${TARGET_LIBSLEEF} ${TARGET_LIBDFT})
97+
target_compile_definitions(${TARGET_BENCH1DMT} PRIVATE ${COMMON_TARGET_DEFINITIONS} MULTITHREAD=1)
98+
target_link_libraries(${TARGET_BENCH1DMT} ${COMMON_LINK_LIBRARIES})
99+
set_target_properties(${TARGET_BENCH1DMT} PROPERTIES ${COMMON_TARGET_PROPERTIES})
92100
endif()
93101

94102
# Target executable roundtriptest1ddp
@@ -177,6 +185,22 @@ if (LIBFFTW3 AND NOT SLEEF_DISABLE_FFTW)
177185
add_test_dft(${TARGET_FFTWTEST2DSP}_8_8 $<TARGET_FILE:${TARGET_FFTWTEST2DSP}> 8 8)
178186
add_test_dft(${TARGET_FFTWTEST2DSP}_10_10 $<TARGET_FILE:${TARGET_FFTWTEST2DSP}> 10 10)
179187
add_test_dft(${TARGET_FFTWTEST2DSP}_5_15 $<TARGET_FILE:${TARGET_FFTWTEST2DSP}> 5 15)
188+
189+
# Target executable bench1dfftwst
190+
set(TARGET_BENCH1DFFTWST "bench1dfftwst")
191+
add_executable(${TARGET_BENCH1DFFTWST} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
192+
target_compile_definitions(${TARGET_BENCH1DFFTWST} PRIVATE ${COMMON_TARGET_DEFINITIONS} USEFFTW=1)
193+
target_link_libraries(${TARGET_BENCH1DFFTWST} ${COMMON_LINK_LIBRARIES} ${LIBFFTW3})
194+
set_target_properties(${TARGET_BENCH1DFFTWST} PROPERTIES ${COMMON_TARGET_PROPERTIES})
195+
196+
if (FALSE)
197+
# Target executable bench1dfftwmt
198+
set(TARGET_BENCH1DFFTWMT "bench1dfftwmt")
199+
add_executable(${TARGET_BENCH1DFFTWMT} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
200+
target_compile_definitions(${TARGET_BENCH1DFFTWMT} PRIVATE ${COMMON_TARGET_DEFINITIONS} USEFFTW=1 MULTITHREAD=1)
201+
target_link_libraries(${TARGET_BENCH1DFFTWMT} ${COMMON_LINK_LIBRARIES} ${LIBFFTW3})
202+
set_target_properties(${TARGET_BENCH1DFFTWMT} PROPERTIES ${COMMON_TARGET_PROPERTIES})
203+
endif()
180204
else(LIBFFTW3 AND NOT SLEEF_DISABLE_FFTW)
181205
if(MSVC OR SLEEF_CLANG_ON_WINDOWS)
182206
# Test roundtriptestdp

src/dft-tester/bench1d.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ int main(int argc, char **argv) {
5757
fftw_complex *in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);
5858
fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);
5959

60-
#if 0
60+
#ifdef MULTITHREAD
6161
int fftw_init_threads(void);
6262
fftw_plan_with_nthreads(omp_get_max_threads());
6363
#endif
@@ -76,7 +76,11 @@ int main(int argc, char **argv) {
7676
real *in = (real *)Sleef_malloc(n*2 * sizeof(real));
7777
real *out = (real *)Sleef_malloc(n*2 * sizeof(real));
7878

79-
int mode = SLEEF_MODE_MEASURE | SLEEF_MODE_VERBOSE; // | SLEEF_MODE_NO_MT;
79+
#ifdef MULTITHREAD
80+
int mode = SLEEF_MODE_MEASURE | SLEEF_MODE_VERBOSE;
81+
#else
82+
int mode = SLEEF_MODE_MEASURE | SLEEF_MODE_VERBOSE | SLEEF_MODE_NO_MT;
83+
#endif
8084
if (argc >= 3) mode = SLEEF_MODE_VERBOSE | SLEEF_MODE_ESTIMATE;
8185

8286
if (backward) mode |= SLEEF_MODE_BACKWARD;

src/dft-tester/fftwtest1d.c

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,22 @@ static double squ(double x) { return x * x; }
4040
double check_cf(int n) {
4141
fftw_complex *in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);
4242
fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);
43+
44+
if (!in || !out) {
45+
fprintf(stderr, "Memory allocation failed");
46+
exit(-1);
47+
}
48+
4349
fftw_plan w = fftw_plan_dft_1d(n, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
4450

4551
real *sx = (real *)Sleef_malloc(n*2*sizeof(real));
4652
real *sy = (real *)Sleef_malloc(n*2*sizeof(real));
53+
54+
if (!sx || !sy) {
55+
fprintf(stderr, "Memory allocation failed");
56+
exit(-1);
57+
}
58+
4759
struct SleefDFT *p = SleefDFT_init1d(n, sx, sy, MODE);
4860

4961
for(int i=0;i<n;i++) {
@@ -79,10 +91,22 @@ double check_cf(int n) {
7991
double check_cb(int n) {
8092
fftw_complex *in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);
8193
fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n);
94+
95+
if (!in || !out) {
96+
fprintf(stderr, "Memory allocation failed");
97+
exit(-1);
98+
}
99+
82100
fftw_plan w = fftw_plan_dft_1d(n, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
83101

84102
real *sx = (real *)Sleef_malloc(n*2*sizeof(real));
85103
real *sy = (real *)Sleef_malloc(n*2*sizeof(real));
104+
105+
if (!sx || !sy) {
106+
fprintf(stderr, "Memory allocation failed");
107+
exit(-1);
108+
}
109+
86110
struct SleefDFT *p = SleefDFT_init1d(n, sx, sy, SLEEF_MODE_BACKWARD | MODE);
87111

88112
for(int i=0;i<n;i++) {
@@ -118,10 +142,22 @@ double check_cb(int n) {
118142
double check_rf(int n) {
119143
double *in = (double *) fftw_malloc(sizeof(double) * n);
120144
fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * (n/2+1));
145+
146+
if (!in || !out) {
147+
fprintf(stderr, "Memory allocation failed");
148+
exit(-1);
149+
}
150+
121151
fftw_plan w = fftw_plan_dft_r2c_1d(n, in, out, FFTW_ESTIMATE);
122152

123153
real *sx = (real *)Sleef_malloc(n*sizeof(real));
124154
real *sy = (real *)Sleef_malloc((n/2+1)*sizeof(real)*2);
155+
156+
if (!sx || !sy) {
157+
fprintf(stderr, "Memory allocation failed");
158+
exit(-1);
159+
}
160+
125161
struct SleefDFT *p = SleefDFT_init1d(n, sx, sy, SLEEF_MODE_REAL | MODE);
126162

127163
for(int i=0;i<n;i++) {
@@ -155,10 +191,22 @@ double check_rf(int n) {
155191
double check_rb(int n) {
156192
fftw_complex *in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * (n/2+1));
157193
double *out = (double *) fftw_malloc(sizeof(double) * n);
194+
195+
if (!in || !out) {
196+
fprintf(stderr, "Memory allocation failed");
197+
exit(-1);
198+
}
199+
158200
fftw_plan w = fftw_plan_dft_c2r_1d(n, in, out, FFTW_ESTIMATE);
159201

160202
real *sx = (real *)Sleef_malloc((n/2+1) * sizeof(real)*2);
161203
real *sy = (real *)Sleef_malloc(sizeof(real)*n);
204+
205+
if (!sx || !sy) {
206+
fprintf(stderr, "Memory allocation failed");
207+
exit(-1);
208+
}
209+
162210
struct SleefDFT *p = SleefDFT_init1d(n, sx, sy, SLEEF_MODE_REAL | SLEEF_MODE_BACKWARD | MODE);
163211

164212
for(int i=0;i<n/2;i++) {

src/dft-tester/fftwtest2d.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,22 @@ static double squ(double x) { return x * x; }
4040
double check_cf(int n, int m) {
4141
fftw_complex *in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n * m);
4242
fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n * m);
43+
44+
if (!in || !out) {
45+
fprintf(stderr, "Memory allocation failed");
46+
exit(-1);
47+
}
48+
4349
fftw_plan w = fftw_plan_dft_2d(n, m, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
4450

4551
real *sx = (real *)Sleef_malloc(n*m*2*sizeof(real));
4652
real *sy = (real *)Sleef_malloc(n*m*2*sizeof(real));
53+
54+
if (!sx || !sy) {
55+
fprintf(stderr, "Memory allocation failed");
56+
exit(-1);
57+
}
58+
4759
struct SleefDFT *p = SleefDFT_init2d(n, m, sx, sy, MODE);
4860

4961
for(int i=0;i<n*m;i++) {
@@ -79,10 +91,22 @@ double check_cf(int n, int m) {
7991
double check_cb(int n, int m) {
8092
fftw_complex *in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n * m);
8193
fftw_complex *out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * n * m);
94+
95+
if (!in || !out) {
96+
fprintf(stderr, "Memory allocation failed");
97+
exit(-1);
98+
}
99+
82100
fftw_plan w = fftw_plan_dft_2d(n, m, in, out, FFTW_BACKWARD, FFTW_ESTIMATE);
83101

84102
real *sx = (real *)Sleef_malloc(n*m*2*sizeof(real));
85103
real *sy = (real *)Sleef_malloc(n*m*2*sizeof(real));
104+
105+
if (!sx || !sy) {
106+
fprintf(stderr, "Memory allocation failed");
107+
exit(-1);
108+
}
109+
86110
struct SleefDFT *p = SleefDFT_init2d(n, m, sx, sy, SLEEF_MODE_BACKWARD | MODE);
87111

88112
for(int i=0;i<n*m;i++) {

src/dft-tester/naivetest.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ int check_cf(int n) {
102102
cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
103103
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
104104

105+
if (!sx || !sy || !ts || !fs) {
106+
fprintf(stderr, "Memory allocation failed");
107+
exit(-1);
108+
}
109+
105110
//
106111

107112
for(i=0;i<n;i++) {
@@ -158,6 +163,11 @@ int check_cb(int n) {
158163
cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
159164
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
160165

166+
if (!sx || !sy || !ts || !fs) {
167+
fprintf(stderr, "Memory allocation failed");
168+
exit(-1);
169+
}
170+
161171
//
162172

163173
for(i=0;i<n;i++) {
@@ -212,6 +222,11 @@ int check_rf(int n) {
212222
cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
213223
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
214224

225+
if (!sx || !sy || !ts || !fs) {
226+
fprintf(stderr, "Memory allocation failed");
227+
exit(-1);
228+
}
229+
215230
//
216231

217232
for(i=0;i<n;i++) {
@@ -262,6 +277,11 @@ int check_rb(int n) {
262277
cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
263278
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
264279

280+
if (!ts || !fs) {
281+
fprintf(stderr, "Memory allocation failed");
282+
exit(-1);
283+
}
284+
265285
//
266286

267287
for(i=0;i<n/2;i++) {
@@ -277,6 +297,11 @@ int check_rb(int n) {
277297
real *sx = (real *)Sleef_malloc((n/2+1) * sizeof(real)*2);
278298
real *sy = (real *)Sleef_malloc(sizeof(real)*n);
279299

300+
if (!sx || !sy) {
301+
fprintf(stderr, "Memory allocation failed");
302+
exit(-1);
303+
}
304+
280305
for(i=0;i<n/2+1;i++) {
281306
sx[2*i+0] = creal(fs[i]);
282307
sx[2*i+1] = cimag(fs[i]);
@@ -332,6 +357,11 @@ int check_arf(int n) {
332357
cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
333358
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
334359

360+
if (!sx || !sy || !ts || !fs) {
361+
fprintf(stderr, "Memory allocation failed");
362+
exit(-1);
363+
}
364+
335365
//
336366

337367
for(i=0;i<n;i++) {
@@ -389,6 +419,11 @@ int check_arb(int n) {
389419
cmpl *ts = (cmpl *)malloc(sizeof(cmpl)*n);
390420
cmpl *fs = (cmpl *)malloc(sizeof(cmpl)*n);
391421

422+
if (!sx || !sy || !ts || !fs) {
423+
fprintf(stderr, "Memory allocation failed");
424+
exit(-1);
425+
}
426+
392427
//
393428

394429
for(i=0;i<n/2;i++) {

src/dft-tester/roundtriptest1d.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ double check_c(int n) {
4343
real *sy = (real *)Sleef_malloc(n*2 * sizeof(real));
4444
real *sz = (real *)Sleef_malloc(n*2 * sizeof(real));
4545

46+
if (!sx || !sy || !sz) {
47+
fprintf(stderr, "Memory allocation failed");
48+
exit(-1);
49+
}
50+
4651
for(int i=0;i<n*2;i++) sx[i] = (real)(2.0 * (rand() / (double)RAND_MAX) - 1);
4752

4853
//

src/dft-tester/roundtriptest2d.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ double check_c(int n, int m) {
4343
real *sy = (real *)Sleef_malloc(n*m*2 * sizeof(real));
4444
real *sz = (real *)Sleef_malloc(n*m*2 * sizeof(real));
4545

46+
if (!sx || !sy || !sz) {
47+
fprintf(stderr, "Memory allocation failed");
48+
exit(-1);
49+
}
50+
4651
for(int i=0;i<n*m*2;i++) sx[i] = (real)(2.0 * (rand() / (double)RAND_MAX) - 1);
4752

4853
//

src/dft/CMakeLists.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ endif()
206206
# Compiler properties
207207

208208
set(CMAKE_C_FLAGS "${ORG_CMAKE_C_FLAGS} ${DFT_C_FLAGS} ${OpenMP_C_FLAGS}")
209+
set(CMAKE_CXX_FLAGS "${ORG_CMAKE_C_FLAGS} ${DFT_C_FLAGS} ${OpenMP_C_FLAGS}")
209210
set(COMMON_TARGET_PROPERTIES
210211
C_STANDARD 99 # -std=gnu99
211212
)
@@ -214,7 +215,7 @@ if (BUILD_SHARED_LIBS)
214215
list(APPEND COMMON_TARGET_PROPERTIES POSITION_INDEPENDENT_CODE ON) # -fPIC
215216
endif()
216217

217-
set(COMMON_TARGET_DEFINITIONS ${COMMON_TARGET_DEFINITIONS} MAXBUTWIDTH=${SLEEFDFT_MAXBUTWIDTH})
218+
set(COMMON_TARGET_DEFINITIONS ${COMMON_TARGET_DEFINITIONS} MAXBUTWIDTHDP=${SLEEFDFT_MAXBUTWIDTH} MAXBUTWIDTHSP=${SLEEFDFT_MAXBUTWIDTH})
218219

219220
if (SLEEFDFT_ENABLE_STREAM)
220221
set(COMMON_TARGET_DEFINITIONS ${COMMON_TARGET_DEFINITIONS} ENABLE_STREAM=1)
@@ -251,7 +252,7 @@ endif()
251252

252253
add_custom_command(OUTPUT dispatchparam.h
253254
COMMENT "Generating dispatchparam.h"
254-
COMMAND $<TARGET_FILE:${TARGET_MKDISPATCH}> paramonly ${SLEEFDFT_MAXBUTWIDTH} ${ISALIST_DP} > ${CMAKE_CURRENT_BINARY_DIR}/dispatchparam.h
255+
COMMAND $<TARGET_FILE:${TARGET_MKDISPATCH}> paramonly ALL ${SLEEFDFT_MAXBUTWIDTH} ${ISALIST_SP} > ${CMAKE_CURRENT_BINARY_DIR}/dispatchparam.h
255256
DEPENDS ${TARGET_MKDISPATCH}
256257
)
257258
add_custom_target(dispatchparam.h_generated SOURCES ${CMAKE_CURRENT_BINARY_DIR}/dispatchparam.h)
@@ -267,7 +268,7 @@ foreach(T ${LIST_SUPPORTED_FPTYPE})
267268
string(CONCAT S "dispatch" ${ST} ".hpp") # S is dispatchdp.hpp
268269
add_custom_command(OUTPUT ${S}
269270
COMMENT "Generating ${S}"
270-
COMMAND $<TARGET_FILE:${TARGET_MKDISPATCH}> ${LT} ${SLEEFDFT_MAXBUTWIDTH} ${ISALIST_${CST}} > ${S}
271+
COMMAND $<TARGET_FILE:${TARGET_MKDISPATCH}> ${LT} ${CST} ${SLEEFDFT_MAXBUTWIDTH} ${ISALIST_${CST}} > ${S}
271272
DEPENDS ${TARGET_MKDISPATCH}
272273
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
273274
)
@@ -316,7 +317,7 @@ foreach(T ${LIST_SUPPORTED_FPTYPE})
316317
if(UNROLL_TARGET_${CST})
317318
add_custom_command(OUTPUT ${UNROLL_TARGET_${CST}}
318319
COMMENT "Generating ${UNROLL_TARGET_${CST}}"
319-
COMMAND $<TARGET_FILE:${TARGET_MKUNROLL}> ${LT} ${ISALIST_${CST}}
320+
COMMAND $<TARGET_FILE:${TARGET_MKUNROLL}> ${LT} ${CST} ${ISALIST_${CST}}
320321
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
321322
DEPENDS ${TARGET_MKUNROLL} unroll0.org.copied
322323
)

0 commit comments

Comments
 (0)