Skip to content

Commit 8dfe3bc

Browse files
authored
[Refactor] Remove some dependencies in module_base (#7311)
* Remove useless include in math_ylm_op * Remove incorrect include file in parallel_global.cpp * Remove some parameter.h dependency
1 parent 61734d8 commit 8dfe3bc

9 files changed

Lines changed: 26 additions & 15 deletions

File tree

source/source_base/kernels/math_ylm_op.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef MODULE_BASE_MATH_MULTI_DEVICE_H
22
#define MODULE_BASE_MATH_MULTI_DEVICE_H
33

4-
#include "source_psi/psi.h"
4+
#include "source_base/module_device/types.h"
55
#include <complex>
66

77
namespace ModuleBase {

source/source_base/module_device/device.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,10 @@ int get_device_num(std::string device_flag);
3131
/**
3232
* @brief Output the device information
3333
* for source_esolver
34+
* @param output output stream.
35+
* @param device device flag, "cpu" / "gpu" / "dsp".
3436
*/
35-
void output_device_info(std::ostream& output);
37+
void output_device_info(std::ostream& output, const std::string& device);
3638

3739
/**
3840
* @brief Safely probes for GPU availability without exiting on error.

source/source_base/module_device/output_device.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "gpu_runtime.h"
44

55
#include "source_base/tool_quit.h"
6-
#include "source_io/module_parameter/parameter.h"
76

87
#include <base/macros/macros.h>
98
#include <cstring>
@@ -92,7 +91,7 @@ int get_device_num(std::string device_flag)
9291
return 0;
9392
}
9493

95-
void output_device_info(std::ostream &output)
94+
void output_device_info(std::ostream &output, const std::string& device)
9695
{
9796
#ifdef __MPI
9897
int world_rank, world_size;
@@ -105,7 +104,7 @@ void output_device_info(std::ostream &output)
105104
// Get local hardware info
106105
int local_gpu_count = 0;
107106
#if defined(__CUDA) || defined(__ROCM)
108-
if(PARAM.inp.device == "gpu" && local_rank == 0)
107+
if(device == "gpu" && local_rank == 0)
109108
{
110109
local_gpu_count = get_device_num("gpu");
111110
}
@@ -129,7 +128,7 @@ void output_device_info(std::ostream &output)
129128
std::string cpu_name = get_device_name("cpu");
130129
std::string gpu_name;
131130
#if defined(__CUDA) || defined(__ROCM)
132-
if(PARAM.inp.device == "gpu" && total_gpus > 0)
131+
if(device == "gpu" && total_gpus > 0)
133132
{
134133
gpu_name = get_device_name("gpu");
135134
}
@@ -139,7 +138,7 @@ void output_device_info(std::ostream &output)
139138
output << " RUNNING WITH DEVICE : " << "CPU" << " / "
140139
<< cpu_name << " (x" << total_cpus << ")" << std::endl;
141140
#if defined(__CUDA) || defined(__ROCM)
142-
if(PARAM.inp.device == "gpu" && total_gpus > 0)
141+
if(device == "gpu" && total_gpus > 0)
143142
{
144143
output << " " << "GPU" << " / "
145144
<< gpu_name << " (x" << total_gpus << ")" << std::endl;
@@ -152,7 +151,7 @@ void output_device_info(std::ostream &output)
152151
output << " RUNNING WITH DEVICE : " << "CPU" << " / "
153152
<< cpu_name << " (x" << cpu_sockets << ")" << std::endl;
154153
#if defined(__CUDA) || defined(__ROCM)
155-
if(PARAM.inp.device == "gpu")
154+
if(device == "gpu")
156155
{
157156
int gpu_count = get_device_num("gpu");
158157
if(gpu_count > 0)

source/source_base/module_fft/fft_bundle.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ void FFT_Bundle::initfft(int nx_in,
7474
{
7575
ModuleBase::WARNING_QUIT("device", "now dsp fft is not supported for the float type");
7676
}
77-
fft_double = make_unique<FFT_DSP<double>>();
77+
auto dsp_fft = make_unique<FFT_DSP<double>>();
78+
dsp_fft->cluster_id = this->dsp_cluster_id_;
79+
fft_double = std::move(dsp_fft);
7880
fft_double->initfft(nx_in, ny_in, nz_in);
7981
}else
8082
#endif

source/source_base/module_fft/fft_bundle.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ class FFT_Bundle
3232
*/
3333
void setfft(std::string device_in, std::string precision_in);
3434

35+
/**
36+
* @brief Set the DSP cluster id for the FFT_DSP backend.
37+
* @param id cluster id, typically computed as (MPI rank % dsp_count).
38+
*
39+
* Caller-injected DSP routing info; only used when device == "dsp".
40+
*/
41+
void set_dsp_cluster_id(int id) { this->dsp_cluster_id_ = id; }
42+
3543
/**
3644
* @brief Initialize the fft parameters.
3745
* @param nx_in number of grid points in x direction.
@@ -202,6 +210,7 @@ class FFT_Bundle
202210

203211
std::string device = "cpu";
204212
std::string precision = "double";
213+
int dsp_cluster_id_ = 0;
205214
};
206215
// Use RAII (Resource Acquisition Is Initialization) to
207216
// control the resources used by hthread when setting the DSP

source/source_base/module_fft/fft_dsp.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "fft_dsp.h"
22

3-
#include "source_base/global_variable.h"
43
#include "source_base/global_function.h"
5-
#include "source_io/module_parameter/parameter.h"
64

75
#include <iostream>
86
#include <string.h>
@@ -15,7 +13,6 @@ void FFT_DSP<double>::initfft(int nx_in, int ny_in, int nz_in)
1513
this->nx = nx_in;
1614
this->ny = ny_in;
1715
this->nz = nz_in;
18-
cluster_id = GlobalV::MY_RANK % PARAM.inp.dsp_count;
1916
nxyz = this->nx * this->ny * this->nz;
2017
}
2118
template <>

source/source_base/parallel_global.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "source_base/global_function.h"
1515
#include "source_base/parallel_common.h"
1616
#include "source_base/parallel_reduce.h"
17-
#include "source_io/module_parameter/parameter.h"
17+
#include "source_base/global_variable.h"
1818
#include "source_base/tool_quit.h"
1919
#include "source_main/version.h"
2020

source/source_basis/module_pw/pw_basis_k.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "pw_basis_k.h"
22

33
#include "source_base/constants.h"
4+
#include "source_base/global_variable.h"
45
#include "source_base/memory.h"
56
#include "source_base/timer.h"
67
#include "source_io/module_parameter/parameter.h"
@@ -215,6 +216,7 @@ void PW_Basis_K::setuptransform()
215216
std::string fft_device = this->device;
216217
#if defined(__DSP)
217218
fft_device = "dsp";
219+
this->fft_bundle.set_dsp_cluster_id(GlobalV::MY_RANK % PARAM.inp.dsp_count);
218220
#endif
219221
this->fft_bundle.setfft(fft_device, this->precision);
220222
if (this->xprime)

source/source_esolver/esolver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ std::string determine_type()
115115
c = std::toupper(c);
116116
}
117117
}
118-
base_device::information::output_device_info(std::cout);
119-
base_device::information::output_device_info(GlobalV::ofs_running);
118+
base_device::information::output_device_info(std::cout, PARAM.inp.device);
119+
base_device::information::output_device_info(GlobalV::ofs_running, PARAM.inp.device);
120120
/***auto end_time = std::chrono::high_resolution_clock::now();
121121
auto duration = std::chrono::duration_cast<std::chrono::duration<double>>(end_time - start_time);
122122
std::cout << "hipGetDeviceInfo took " << duration.count() << " seconds" << std::endl;***/

0 commit comments

Comments
 (0)