Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

FFT Serial app #33

Merged
merged 21 commits into from
Oct 7, 2023
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
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ BreakBeforeBinaryOperators: None
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakInheritanceList: BeforeColon
ColumnLimit: 80
ColumnLimit: 120
CompactNamespaces: false
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
Expand All @@ -52,7 +52,7 @@ FixNamespaceComments: true
IncludeBlocks: Preserve
IndentCaseLabels: true
IndentPPDirectives: None
IndentWidth: 2
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: true
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[submodule "externals/mdspan"]
path = externals/mdspan
url = https://github.com/kokkos/mdspan
[submodule "externals/magic_enum"]
path = externals/magic_enum
url = https://github.com/mhaseeb123/magic_enum
[submodule "externals/argparse"]
path = externals/argparse
url = https://github.com/mhaseeb123/argparse
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ set(GCC_EXPECTED_VERSION 11.2)
if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS GCC_EXPECTED_VERSION)
message(
FATAL_ERROR
"GCC: GCB requires GCC v${GCC_EXPECTED_VERSION} or higher to build but found v${CMAKE_CXX_COMPILER_VERSION}"
"GCC: nvstdpar requires GCC v${GCC_EXPECTED_VERSION} or higher to build but found v${CMAKE_CXX_COMPILER_VERSION}"
)
endif()

Expand All @@ -84,10 +84,11 @@ endif()
set(CXX_STANDARD_REQUIRED ON)

# required minimum CXX standard
set(CMAKE_CXX_STANDARD_REQUIRED 20)
set(CMAKE_CXX_STANDARD_REQUIRED 23)

if(NOT CXX_STANDARD OR (CXX_STANDARD LESS ${CMAKE_CXX_STANDARD_REQUIRED}))
set(CXX_STANDARD ${CMAKE_CXX_STANDARD_REQUIRED})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++${CXX_STANDARD}")
message(STATUS "Setting CXX_STANDARD to ${CMAKE_CXX_STANDARD_REQUIRED}")
endif()

Expand Down
6 changes: 6 additions & 0 deletions apps/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ add_subdirectory(1d_stencil)
# ----------------------------------------------------------------------------------------#
message(STATUS "Adding choleskey example...")
add_subdirectory(choleskey)

# ----------------------------------------------------------------------------------------#
# Add fft demo
# ----------------------------------------------------------------------------------------#
message(STATUS "Adding fft...")
add_subdirectory(fft)
4 changes: 2 additions & 2 deletions apps/choleskey/choleskey_stdpar_snd.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/*
* MIT License
*
* Copyright (c) 2023 Chuanqiu He
* Copyright (c) 2023 Weile Wei
* Copyright (c) 2023 Chuanqiu He
* Copyright (c) 2023 Weile Wei
* Copyright (c) 2023 The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt of any
* required approvals from the U.S. Dept. of Energy).All rights reserved.
Expand Down
2 changes: 1 addition & 1 deletion apps/comm-study/comm-study-no-senders.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ auto work(P& A, P& B, P& Y, int N) {

// get sum(Y) - one last memcpy (not USM) D2H
sum +=
std::reduce(std::execution::par_unseq, &Y[0], &Y[N], 0.0, std::plus<T>());
std::transform_reduce(std::execution::par_unseq, &Y[0], &Y[N], 0.0, std::plus<T>(), [](T &val){return val * val;});

return sum / N;
}
Expand Down
40 changes: 40 additions & 0 deletions apps/fft/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
project(fft LANGUAGES CXX)

file(GLOB CPP_SOURCES "*.cpp")

foreach(source_file ${CPP_SOURCES})
if(NOT STDPAR STREQUAL "gpu")
if("${source_file}" MATCHES ".*gpu.*scheduler.*" OR "${source_file}"
MATCHES ".*cuda.*")
message(STATUS "Skipping ${source_file} as stdpar=${STDPAR}")
continue()
endif()
endif()

# get the file name without an extension
get_filename_component(exec_name ${source_file} NAME_WE)

# add an executable with the same name as the source file
add_executable(${exec_name} ${_EXCLUDE} ${source_file})

# add dependency on argparse
add_dependencies(${exec_name} argparse magic_enum)

set_source_files_properties(${source_file} PROPERTIES LANGUAGE CXX
LINKER_LANGUAGE CXX)
target_include_directories(
${exec_name}
PRIVATE ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR}/../../include
${ARGPARSE_INCLUDE_DIR} ${MAGICENUM_INCLUDE_DIR} ${MDSPAN_INCLUDE_DIR})

target_link_libraries(${exec_name} PUBLIC ${MPI_LIBS} stdexec)

set_target_properties(
${exec_name}
PROPERTIES CXX_STANDARD ${CXX_STANDARD}
CXX_EXTENSIONS NO
INSTALL_RPATH_USE_LINK_PATH ON)

# installation
install(TARGETS ${exec_name} DESTINATION ${CMAKE_INSTALL_BINDIR})
endforeach()
138 changes: 138 additions & 0 deletions apps/fft/fft-serial.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/*
* MIT License
*
* Copyright (c) 2023 The Regents of the University of California,
* through Lawrence Berkeley National Laboratory (subject to receipt of any
* required approvals from the U.S. Dept. of Energy).All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/*
* commons for the fft codes
*/

#include "fft.hpp"

//
// simulation
//
int main(int argc, char* argv[])
{
// parse params
fft_params_t args = argparse::parse<fft_params_t>(argc, argv);

// see if help wanted
if (args.help)
{
args.print(); // prints all variables
return 0;
}

// simulation variables
int N = args.N;
sig_type_t sig_type = args.sig;
int freq = args.freq;
bool print_sig = args.print_sig;
bool print_time = args.print_time;

// x[n] signal
//std::vector<data_t> test_sig{2,1,-1,5,0,3,0,-4};
//N = test_sig.size();

Timer timer;

sig_t x_n(N, sig_type);

if (!isPowOf2(N))
{
N = ceilPowOf2(N);
std::cout << "log_2(N) != integer. Padding zeros for N = " << N << std::endl;

x_n.resize(N);
}

sig_t y_n(x_n);

if (print_sig)
{
std::cout << std::endl << "x[n] = ";
x_n.printSignal();
std::cout << std::endl;
}

// niterations
int niters = ilog2(N);

std::function<void(data_t *, int, const int)> fft = [&](data_t *x, int lN, const int N)
{
int stride = N/lN;

if (lN == 2)
{
auto x_0 = x[0] + x[1]* WNk(N, 0);
x[1] = x[0] - x[1]* WNk(N, 0);
x[0] = x_0;
return;
}

// vectors for left and right
std::vector<data_t> e(lN/2);
std::vector<data_t> o(lN/2);

// copy data into vectors
for (auto k = 0; k < lN/2; k++)
{
e[k] = x[2*k];
o[k] = x[2*k+1];
}

// compute N/2 pt FFT on even
fft(e.data(), lN/2, N);

// compute N/2 pt FFT on odd
fft(o.data(), lN/2, N);

// combine even and odd FFTs
for (int k = 0; k < lN/2; k++)
{
x[k] = e[k] + o[k] * WNk(N, k * stride);
x[k+lN/2] = e[k] - o[k] * WNk(N, k * stride);
}

return;
};

// fft radix-2 algorithm with senders
fft(y_n.data(), N, N);

if (print_sig)
{
std::cout << "X[k] = ";
y_n.printSignal();
std::cout << std::endl;
}

auto elapsed = timer.stop();

if (print_time)
std::cout << "Elapsed Time: " << elapsed << " ms" << std::endl;

return 0;
}
Loading
Loading