Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/sleefdft.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ IMPORT void SleefDFT_float_execute(struct SleefDFT *ptr, const float *in, float
IMPORT void SleefDFT_dispose(struct SleefDFT *ptr);

IMPORT void SleefDFT_setPath(struct SleefDFT *ptr, char *pathStr);
IMPORT int SleefDFT_getPath(struct SleefDFT *ptr, char *pathStr, int pathStrSize);

//

Expand Down
46 changes: 28 additions & 18 deletions src/dft-tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -81,24 +81,34 @@ if((NOT MSVC) AND NOT SLEEF_CLANG_ON_WINDOWS)
target_compile_definitions(${TARGET_MEASUREDFT} PRIVATE ${COMMON_TARGET_DEFINITIONS})
target_link_libraries(${TARGET_MEASUREDFT} ${COMMON_LINK_LIBRARIES})
set_target_properties(${TARGET_MEASUREDFT} PROPERTIES ${COMMON_TARGET_PROPERTIES})

# Target executable bench1dst
set(TARGET_BENCH1DST "bench1dst")
add_executable(${TARGET_BENCH1DST} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
add_dependencies(${TARGET_BENCH1DST} ${TARGET_HEADERS} ${TARGET_LIBSLEEF} ${TARGET_LIBDFT})
target_compile_definitions(${TARGET_BENCH1DST} PRIVATE ${COMMON_TARGET_DEFINITIONS})
target_link_libraries(${TARGET_BENCH1DST} ${COMMON_LINK_LIBRARIES})
set_target_properties(${TARGET_BENCH1DST} PROPERTIES ${COMMON_TARGET_PROPERTIES})

# Target executable bench1dmt
set(TARGET_BENCH1DMT "bench1dmt")
add_executable(${TARGET_BENCH1DMT} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
add_dependencies(${TARGET_BENCH1DMT} ${TARGET_HEADERS} ${TARGET_LIBSLEEF} ${TARGET_LIBDFT})
target_compile_definitions(${TARGET_BENCH1DMT} PRIVATE ${COMMON_TARGET_DEFINITIONS} MULTITHREAD=1)
target_link_libraries(${TARGET_BENCH1DMT} ${COMMON_LINK_LIBRARIES})
set_target_properties(${TARGET_BENCH1DMT} PROPERTIES ${COMMON_TARGET_PROPERTIES})
endif()

# Target executable bench1dst
set(TARGET_BENCH1DST "bench1dst")
add_executable(${TARGET_BENCH1DST} bench1d.cpp ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
add_dependencies(${TARGET_BENCH1DST} ${TARGET_HEADERS} ${TARGET_LIBSLEEF} ${TARGET_LIBDFT})
target_compile_definitions(${TARGET_BENCH1DST} PRIVATE ${COMMON_TARGET_DEFINITIONS})
target_link_libraries(${TARGET_BENCH1DST} ${COMMON_LINK_LIBRARIES})
set_target_properties(${TARGET_BENCH1DST} PROPERTIES ${COMMON_TARGET_PROPERTIES})

# Target executable bench1dmt
set(TARGET_BENCH1DMT "bench1dmt")
add_executable(${TARGET_BENCH1DMT} bench1d.cpp ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
add_dependencies(${TARGET_BENCH1DMT} ${TARGET_HEADERS} ${TARGET_LIBSLEEF} ${TARGET_LIBDFT})
target_compile_definitions(${TARGET_BENCH1DMT} PRIVATE ${COMMON_TARGET_DEFINITIONS} MULTITHREAD=1)
target_link_libraries(${TARGET_BENCH1DMT} ${COMMON_LINK_LIBRARIES})
set_target_properties(${TARGET_BENCH1DMT} PROPERTIES ${COMMON_TARGET_PROPERTIES})

# Target executable test_dftplanner
set(TARGET_TEST_DFTPLANNER "test_dftplanner")
add_executable(${TARGET_TEST_DFTPLANNER} test_dftplanner.cpp ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
add_dependencies(${TARGET_TEST_DFTPLANNER} ${TARGET_HEADERS} ${TARGET_LIBSLEEF} ${TARGET_LIBDFT})
target_compile_definitions(${TARGET_TEST_DFTPLANNER} PRIVATE ${COMMON_TARGET_DEFINITIONS})
target_link_libraries(${TARGET_TEST_DFTPLANNER} ${COMMON_LINK_LIBRARIES})
set_target_properties(${TARGET_TEST_DFTPLANNER} PROPERTIES ${COMMON_TARGET_PROPERTIES})
add_test(NAME ${TARGET_TEST_DFTPLANNER} COMMAND $<TARGET_FILE:${TARGET_TEST_DFTPLANNER}> ${PROJECT_BINARY_DIR}/test.plan)
set_tests_properties(${TARGET_TEST_DFTPLANNER} PROPERTIES COST 2)

# Target executable roundtriptest1ddp
set(TARGET_ROUNDTRIPTEST1DDP "roundtriptest1ddp")
add_executable(${TARGET_ROUNDTRIPTEST1DDP} roundtriptest1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
Expand Down Expand Up @@ -188,15 +198,15 @@ if (LIBFFTW3 AND NOT SLEEF_DISABLE_FFTW)

# Target executable bench1dfftwst
set(TARGET_BENCH1DFFTWST "bench1dfftwst")
add_executable(${TARGET_BENCH1DFFTWST} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
add_executable(${TARGET_BENCH1DFFTWST} bench1d.cpp ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
target_compile_definitions(${TARGET_BENCH1DFFTWST} PRIVATE ${COMMON_TARGET_DEFINITIONS} USEFFTW=1)
target_link_libraries(${TARGET_BENCH1DFFTWST} ${COMMON_LINK_LIBRARIES} ${LIBFFTW3})
set_target_properties(${TARGET_BENCH1DFFTWST} PROPERTIES ${COMMON_TARGET_PROPERTIES})

if (FALSE)
# Target executable bench1dfftwmt
set(TARGET_BENCH1DFFTWMT "bench1dfftwmt")
add_executable(${TARGET_BENCH1DFFTWMT} bench1d.c ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
add_executable(${TARGET_BENCH1DFFTWMT} bench1d.cpp ${PROJECT_SOURCE_DIR}/include/sleefdft.h)
target_compile_definitions(${TARGET_BENCH1DFFTWMT} PRIVATE ${COMMON_TARGET_DEFINITIONS} USEFFTW=1 MULTITHREAD=1)
target_link_libraries(${TARGET_BENCH1DFFTWMT} ${COMMON_LINK_LIBRARIES} ${LIBFFTW3})
set_target_properties(${TARGET_BENCH1DFFTWMT} PROPERTIES ${COMMON_TARGET_PROPERTIES})
Expand Down
42 changes: 23 additions & 19 deletions src/dft-tester/bench1d.c → src/dft-tester/bench1d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
// (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 <math.h>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cassert>
#include <cmath>
#include <complex.h>
#include <time.h>
#include <unistd.h>
#include <sys/time.h>
#include <ctime>
#include <chrono>

#ifdef USEFFTW
#include <fftw3.h>
Expand All @@ -27,16 +24,19 @@
typedef double real;

static uint64_t gettime() {
struct timespec tp;
clock_gettime(CLOCK_MONOTONIC, &tp);
return (uint64_t)tp.tv_sec * 1000000000 + ((uint64_t)tp.tv_nsec);
return std::chrono::duration_cast<std::chrono::nanoseconds>
(std::chrono::system_clock::now() - std::chrono::system_clock::from_time_t(0)).count();
}

#define REPEAT 8

int main(int argc, char **argv) {
if (argc == 1) {
#ifdef USEFFTW
fprintf(stderr, "%s <log2n>\n", argv[0]);
#else
fprintf(stderr, "%s <log2n> <plan file name> <plan string>\n", argv[0]);
#endif
exit(-1);
}

Expand All @@ -49,7 +49,7 @@ int main(int argc, char **argv) {
}

const int n = 1 << log2n;
const int64_t niter = (int)(100000000000.0 / n / log2n);
const int64_t niter = (int64_t)(100000000000.0 / n / log2n);

printf("Number of iterations = %lld\n", (long long int)niter);

Expand All @@ -66,12 +66,16 @@ int main(int argc, char **argv) {
//fftw_plan w = fftw_plan_dft_1d(n, in, out, backward ? FFTW_BACKWARD : FFTW_FORWARD, FFTW_PATIENT);

for(int i=0;i<n;i++) {
in[i] = (2.0 * (rand() / (double)RAND_MAX) - 1) + (2.0 * (rand() / (double)RAND_MAX) - 1) * _Complex_I;
auto a = (2.0 * (rand() / (double)RAND_MAX) - 1) + (2.0 * (rand() / (double)RAND_MAX) - 1) * _Complex_I;
in[i][0] = creal(a);
in[i][1] = cimag(a);
}

for(int64_t i=0;i<niter/2;i++) fftw_execute(w);
#else
SleefDFT_setPlanFilePath(NULL, NULL, SLEEF_PLAN_RESET);
const char *planfn = (argc < 3 || strcmp(argv[2], "-") == 0) ? NULL : argv[2];

SleefDFT_setPlanFilePath(planfn, NULL, SLEEF_PLAN_AUTOMATIC);

real *in = (real *)Sleef_malloc(n*2 * sizeof(real));
real *out = (real *)Sleef_malloc(n*2 * sizeof(real));
Expand All @@ -81,12 +85,12 @@ int main(int argc, char **argv) {
#else
int mode = SLEEF_MODE_MEASURE | SLEEF_MODE_VERBOSE | SLEEF_MODE_NO_MT;
#endif
if (argc >= 3) mode = SLEEF_MODE_VERBOSE | SLEEF_MODE_ESTIMATE;
if (argc >= 4) mode = SLEEF_MODE_VERBOSE | SLEEF_MODE_ESTIMATE;

if (backward) mode |= SLEEF_MODE_BACKWARD;
struct SleefDFT *p = SleefDFT_double_init1d(n, in, out, mode);

if (argc >= 3) SleefDFT_setPath(p, argv[2]);
if (argc >= 4) SleefDFT_setPath(p, argv[3]);

for(int i=0;i<n*2;i++) {
in[i] = (2.0 * (rand() / (double)RAND_MAX) - 1);
Expand Down
160 changes: 160 additions & 0 deletions src/dft-tester/test_dftplanner.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
// Copyright Naoki Shibata and contributors 2010 - 2025.
// 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)

#include <iostream>
#include <vector>

#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cmath>

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

using namespace std;

int main(int argc, char **argv) {
if (argc == 1) {
fprintf(stderr, "%s <plan file name>\n", argv[0]);
exit(-1);
}

SleefDFT_setPlanFilePath(argv[1], NULL, SLEEF_PLAN_AUTOMATIC);

double *din = (double *)Sleef_malloc(1024*2 * sizeof(double));
double *dout = (double *)Sleef_malloc(1024*2 * sizeof(double));

float *fin = (float *)Sleef_malloc(1024*2 * sizeof(double));
float *fout = (float *)Sleef_malloc(1024*2 * sizeof(double));

#ifdef MULTITHREAD
int mode = SLEEF_MODE_MEASURE | SLEEF_MODE_VERBOSE;
#else
int mode = SLEEF_MODE_MEASURE | SLEEF_MODE_VERBOSE | SLEEF_MODE_NO_MT;
#endif

SleefDFT *p;

//

p = SleefDFT_double_init1d(1024, din, dout, mode);

vector<char> pathd1024(1024);
SleefDFT_getPath(p, pathd1024.data(), pathd1024.size());

cout << "Path (1024) : " << pathd1024.data() << endl;

SleefDFT_dispose(p);

//

p = SleefDFT_double_init1d(512, din, dout, mode);

vector<char> pathd512(512);
SleefDFT_getPath(p, pathd512.data(), pathd512.size());

cout << "Path (512) : " << pathd512.data() << endl;

SleefDFT_dispose(p);

//

p = SleefDFT_float_init1d(1024, fin, fout, mode);

vector<char> pathf1024(1024);
SleefDFT_getPath(p, pathf1024.data(), pathf1024.size());

cout << "Path (1024) : " << pathf1024.data() << endl;

SleefDFT_dispose(p);

//

p = SleefDFT_float_init1d(512, fin, fout, mode);

vector<char> pathf512(512);
SleefDFT_getPath(p, pathf512.data(), pathf512.size());

cout << "Path (512) : " << pathf512.data() << endl;

SleefDFT_dispose(p);

//

p = SleefDFT_double_init1d(1024, din, dout, mode);

vector<char> pathd1024_2(1024);
SleefDFT_getPath(p, pathd1024_2.data(), pathd1024_2.size());

cout << "Path2 (1024) : " << pathd1024_2.data() << endl;

SleefDFT_dispose(p);

if (pathd1024.size() != pathd1024_2.size() || memcmp(pathd1024.data(), pathd1024_2.data(), pathd1024.size()) != 0) {
cerr << "Paths do not match" << endl;
exit(-1);
}

//

p = SleefDFT_double_init1d(512, din, dout, mode);

vector<char> pathd512_2(512);
SleefDFT_getPath(p, pathd512_2.data(), pathd512_2.size());

cout << "Path2 (512) : " << pathd512_2.data() << endl;

SleefDFT_dispose(p);

if (pathd512.size() != pathd512_2.size() || memcmp(pathd512.data(), pathd512_2.data(), pathd512.size()) != 0) {
cerr << "Paths do not match" << endl;
exit(-1);
}

//

p = SleefDFT_float_init1d(1024, fin, fout, mode);

vector<char> pathf1024_2(1024);
SleefDFT_getPath(p, pathf1024_2.data(), pathf1024_2.size());

cout << "Path2 (1024) : " << pathf1024_2.data() << endl;

SleefDFT_dispose(p);

if (pathf1024.size() != pathf1024_2.size() || memcmp(pathf1024.data(), pathf1024_2.data(), pathf1024.size()) != 0) {
cerr << "Paths do not match" << endl;
exit(-1);
}

//

p = SleefDFT_float_init1d(512, fin, fout, mode);

vector<char> pathf512_2(512);
SleefDFT_getPath(p, pathf512_2.data(), pathf512_2.size());

cout << "Path2 (512) : " << pathf512_2.data() << endl;

SleefDFT_dispose(p);

if (pathf512.size() != pathf512_2.size() || memcmp(pathf512.data(), pathf512_2.data(), pathf512.size()) != 0) {
cerr << "Paths do not match" << endl;
exit(-1);
}

//

Sleef_free(din);
Sleef_free(dout);
Sleef_free(fin);
Sleef_free(fout);

cerr << "OK" << endl;

exit(0);
}
Loading
Loading