forked from abacusmodeling/abacus-develop
-
Notifications
You must be signed in to change notification settings - Fork 145
First stage of add DSP FFT #5878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
c1dac21
set fft_dsp
A-006 4a2894b
add information in map
A-006 51756fd
update Global_rank
A-006 9549092
update control flow
A-006 5d8dfe0
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] fb1e23a
Merge branch 'develop' into fft10
A-006 862d1cf
Merge branch 'develop' into fft10
A-006 e5d9214
add the fft_dsp in the fft_bundle
A-006 88c25d7
change teh cmake file
A-006 29e5068
Merge branch 'develop' into fft10
A-006 18a64b6
modify back scalapck
A-006 6e151a2
set the dsp ig2ixyz_k_cpu
A-006 813bf05
modify the pw_basis
A-006 50a8366
add the namespace
A-006 f6ca1f1
Merge branch 'develop' into fft10
A-006 7cc5469
remove mutable
A-006 f2ea839
Merge branch 'develop' into fft10
A-006 8d86c06
Merge branch 'develop' into fft10
A-006 8c18170
fix fft_dsp
A-006 b896780
add the convolution and allocate or destroy the b_id
A-006 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| #include "fft_dsp.h" | ||
| #include "module_base/global_variable.h" | ||
| #include <string.h> | ||
| #include <iostream> | ||
| #include <vector> | ||
| namespace ModulePW | ||
| { | ||
| template<> | ||
| void FFT_DSP<double>::initfft(int nx_in,int ny_in,int nz_in) | ||
| { | ||
| this->nx=nx_in; | ||
| this->ny=ny_in; | ||
| this->nz=nz_in; | ||
| cluster_id = GlobalV::MY_RANK; | ||
| } | ||
| template<> | ||
| void FFT_DSP<double>::setupFFT() | ||
| { | ||
| PROBLEM pbm_forward; | ||
| PROBLEM pbm_backward; | ||
| PLAN* ptr_plan_forward; | ||
| PLAN* ptr_plan_backward; | ||
| INT num_thread=8; | ||
| INT size; | ||
mohanchen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| //open cluster id | ||
| hthread_dev_open(cluster_id); | ||
| //load mt.dat | ||
| hthread_dat_load(cluster_id, "mt_fft_device.dat"); | ||
|
|
||
| thread_id_for = hthread_group_create(cluster_id, num_thread, NULL, 0, 0, NULL); | ||
| //create b_id for the barrier | ||
| b_id = hthread_barrier_create(cluster_id); | ||
| args_for[0] = b_id; | ||
|
|
||
| //compute the size of and malloc thread | ||
| size = nx*ny*nz*2*sizeof(E); | ||
| forward_in = (E*)hthread_malloc((int)cluster_id, size, HT_MEM_RW); | ||
|
|
||
| // //init 3d fft problem | ||
| pbm_forward.num_dim = 3; | ||
| pbm_forward.n[0] = nx; | ||
| pbm_forward.n[1] = ny; | ||
| pbm_forward.n[2] = nz; | ||
| pbm_forward.iFFT = 0; | ||
| pbm_forward.in = forward_in; | ||
| pbm_forward.out = forward_in; | ||
|
|
||
| // //make ptr plan | ||
| make_plan(&pbm_forward, &ptr_plan_forward, cluster_id, num_thread); | ||
| ptr_plan_forward->in = forward_in; | ||
| ptr_plan_forward->out = forward_in; | ||
| args_for[1] = (unsigned long)ptr_plan_forward; | ||
|
|
||
| //init 3d fft problem | ||
| pbm_backward.num_dim = 3; // dimensions of FFT | ||
| pbm_backward.n[0] = nx; // first dimension | ||
| pbm_backward.n[1] = ny; // second dimension | ||
| pbm_backward.n[2] = nz; // third dimension | ||
| pbm_backward.iFFT = 1; // 0 stand for forward,1 stand for backward | ||
| pbm_backward.in = forward_in; // the input data | ||
| pbm_backward.out = forward_in; // the output data | ||
|
|
||
| make_plan(&pbm_backward, &ptr_plan_backward, cluster_id, num_thread); | ||
| ptr_plan_backward->in = forward_in; | ||
| ptr_plan_backward->out = forward_in; | ||
| args_back[0]=b_id; | ||
| args_back[1]=(unsigned long)ptr_plan_backward; | ||
| } | ||
|
|
||
| template<> | ||
| void FFT_DSP<double>::fft3D_forward(std::complex<double>* in, | ||
| std::complex<double>* out) const | ||
| { | ||
| hthread_group_exec(thread_id_for, "execute_device", 1, 1, args_for); | ||
| hthread_group_wait(thread_id_for); | ||
| } | ||
|
|
||
| template<> | ||
| void FFT_DSP<double>::fft3D_backward(std::complex<double> * in, | ||
| std::complex<double>* out) const | ||
| { | ||
| hthread_group_exec(thread_id_for, "execute_device", 1, 1, args_back); | ||
| hthread_group_wait(thread_id_for); | ||
|
|
||
| } | ||
| template<> | ||
| void FFT_DSP<double>::cleanFFT() | ||
| { | ||
| if (ptr_plan_forward!=nullptr) | ||
| { | ||
| destroy_plan(ptr_plan_forward); | ||
| ptr_plan_forward=nullptr; | ||
| } | ||
| if (ptr_plan_backward!=nullptr) | ||
| { | ||
| destroy_plan(ptr_plan_backward); | ||
| ptr_plan_backward=nullptr; | ||
| } | ||
| } | ||
|
|
||
| template<> | ||
| void FFT_DSP<double>::clear() | ||
| { | ||
| this->cleanFFT(); | ||
| hthread_free(forward_in); | ||
| hthread_barrier_destroy(b_id); | ||
| hthread_group_destroy(thread_id_for); | ||
| } | ||
|
|
||
| template<> std::complex<double>* | ||
| FFT_DSP<double>::get_auxr_3d_data() const | ||
| { | ||
| return reinterpret_cast<std::complex<double>*>(this->forward_in); | ||
| } | ||
| template FFT_DSP<float>::FFT_DSP(); | ||
| template FFT_DSP<float>::~FFT_DSP(); | ||
| template FFT_DSP<double>::FFT_DSP(); | ||
| template FFT_DSP<double>::~FFT_DSP(); | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| #ifndef FFT_CUDA_H | ||
| #define FFT_CUDA_H | ||
|
|
||
| #include "fft_base.h" | ||
| #include <ctime> | ||
| #include <cstdlib> | ||
| #include <cmath> | ||
|
|
||
| #include "hthread_host.h" | ||
| #include "mtfft.h" | ||
| #include "fftw3.h" | ||
|
|
||
| namespace ModulePW | ||
| { | ||
| template <typename FPTYPE> | ||
| class FFT_DSP : public FFT_BASE<FPTYPE> | ||
| { | ||
| public: | ||
| FFT_DSP(){}; | ||
| ~FFT_DSP(){}; | ||
|
|
||
| void setupFFT() override; | ||
|
|
||
| void clear() override; | ||
|
|
||
| void cleanFFT() override; | ||
|
|
||
| /** | ||
| * @brief Initialize the fft parameters | ||
| * @param nx_in number of grid points in x direction | ||
| * @param ny_in number of grid points in y direction | ||
| * @param nz_in number of grid points in z direction | ||
| * | ||
| */ | ||
| virtual __attribute__((weak)) | ||
| void initfft(int nx_in, | ||
| int ny_in, | ||
| int nz_in) override; | ||
|
|
||
| /** | ||
| * @brief Get the real space data | ||
| * @return real space data | ||
| */ | ||
| virtual __attribute__((weak)) | ||
| std::complex<FPTYPE>* get_auxr_3d_data() const override; | ||
|
|
||
| /** | ||
| * @brief Forward FFT in 3D | ||
| * @param in input data, complex FPTYPE | ||
| * @param out output data, complex FPTYPE | ||
| * | ||
| * This function performs the forward FFT in 3D. | ||
| */ | ||
| virtual __attribute__((weak)) | ||
| void fft3D_forward(std::complex<FPTYPE>* in, | ||
| std::complex<FPTYPE>* out) const override; | ||
| /** | ||
| * @brief Backward FFT in 3D | ||
| * @param in input data, complex FPTYPE | ||
| * @param out output data, complex FPTYPE | ||
| * | ||
| * This function performs the backward FFT in 3D. | ||
| */ | ||
| virtual __attribute__((weak)) | ||
| void fft3D_backward(std::complex<FPTYPE>* in, | ||
| std::complex<FPTYPE>* out) const override; | ||
| public: | ||
| INT cluster_id=0; | ||
| INT b_id; | ||
| INT thread_id_for=0; | ||
| PLAN* ptr_plan_forward=nullptr; | ||
| PLAN* ptr_plan_backward=nullptr; | ||
| mutable unsigned long args_for[2]; | ||
| mutable unsigned long args_back[2]; | ||
| mutable E * forward_in; | ||
mohanchen marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| std::complex<float>* c_auxr_3d = nullptr; // fft space | ||
| std::complex<double>* z_auxr_3d = nullptr; // fft space | ||
|
|
||
| }; | ||
| void test_fft_dsp(); | ||
| } // namespace ModulePW | ||
| #endif | ||
20 changes: 20 additions & 0 deletions
20
source/module_basis/module_pw/module_fft/fft_dsp_float.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #include "fft_dsp.h" | ||
| namespace ModulePW | ||
| { | ||
|
|
||
| template<> | ||
| void FFT_DSP<float>::setupFFT() | ||
| { | ||
|
|
||
| } | ||
| template<> | ||
| void FFT_DSP<float>::clear() | ||
| { | ||
|
|
||
| } | ||
| template<> | ||
| void FFT_DSP<float>::cleanFFT() | ||
| { | ||
|
|
||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.