Skip to content

Commit 49c309c

Browse files
authored
Remove parameter.h include of files in source_base (#7318)
* Remove parameter.h in timer.cpp * Remove parameter.h in tool_quit.cpp * Remove parameter.h in memory_op * Remove dependecies in blas_connector * Remove some dependencies in unit tests
1 parent 468cff5 commit 49c309c

11 files changed

Lines changed: 107 additions & 39 deletions

File tree

source/source_base/module_device/memory_op.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
#include "source_base/tool_threading.h"
55
#ifdef __DSP
66
#include "source_base/kernels/dsp/dsp_connector.h"
7-
#include "source_base/global_variable.h"
8-
#include "source_io/module_parameter/parameter.h"
97
#endif
108

119
#include <complex>
@@ -444,6 +442,16 @@ template struct delete_memory_op<std::complex<double>, base_device::DEVICE_GPU>;
444442

445443
#ifdef __DSP
446444

445+
namespace
446+
{
447+
int g_dsp_cluster_id = 0;
448+
}
449+
450+
void set_dsp_cluster_id(int id)
451+
{
452+
g_dsp_cluster_id = id;
453+
}
454+
447455
template <typename FPTYPE>
448456
struct resize_memory_op_mt<FPTYPE, base_device::DEVICE_CPU>
449457
{
@@ -453,7 +461,7 @@ struct resize_memory_op_mt<FPTYPE, base_device::DEVICE_CPU>
453461
{
454462
mtfunc::free_ht(arr);
455463
}
456-
arr = (FPTYPE*)mtfunc::malloc_ht(sizeof(FPTYPE) * size, GlobalV::MY_RANK % PARAM.inp.dsp_count);
464+
arr = (FPTYPE*)mtfunc::malloc_ht(sizeof(FPTYPE) * size, g_dsp_cluster_id);
457465
std::string record_string;
458466
if (record_in != nullptr)
459467
{

source/source_base/module_device/memory_op.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ struct delete_memory_op<FPTYPE, base_device::DEVICE_GPU>
220220

221221
#ifdef __DSP
222222

223+
/// @brief Inject the DSP cluster id used by mt-allocator (mtfunc::malloc_ht).
224+
/// Caller-injected (typically once after input parameters are read).
225+
/// Defaults to 0 if never set.
226+
void set_dsp_cluster_id(int id);
227+
223228
template <typename FPTYPE, typename Device>
224229
struct resize_memory_op_mt
225230
{

source/source_base/module_external/blas_connector.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,16 @@ class BlasConnector
426426

427427
static
428428
void vector_add_vector(const int& dim, std::complex<double> *result, const std::complex<double> *vector1, const double constant1, const std::complex<double> *vector2, const double constant2, base_device::AbacusDevice_t device_type = base_device::AbacusDevice_t::CpuDevice);
429+
430+
#ifdef __DSP
431+
/// @brief Inject the DSP cluster id used by mt-allocator BLAS kernels.
432+
/// Caller-injected (typically once after input parameters are read).
433+
/// Defaults to 0 if never set.
434+
static void set_dsp_cluster_id(int id);
435+
436+
private:
437+
static int dsp_cluster_id_;
438+
#endif
429439
};
430440

431441
#ifdef __CUDA

source/source_base/module_external/blas_connector_matrix.cpp

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33

44
#ifdef __DSP
55
#include "source_base/kernels/dsp/dsp_connector.h"
6-
#include "source_base/global_variable.h"
7-
#include "source_io/module_parameter/parameter.h"
6+
7+
int BlasConnector::dsp_cluster_id_ = 0;
8+
9+
void BlasConnector::set_dsp_cluster_id(int id)
10+
{
11+
dsp_cluster_id_ = id;
12+
}
813
#endif
914

1015
#ifdef __CUDA
@@ -31,7 +36,7 @@ void BlasConnector::gemm(const char transa, const char transb, const int m, cons
3136
else if (device_type == base_device::AbacusDevice_t::DspDevice){
3237
mtfunc::sgemm_mth_(&transb, &transa, &n, &m, &k,
3338
&alpha, b, &ldb, a, &lda,
34-
&beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
39+
&beta, c, &ldc, BlasConnector::dsp_cluster_id_);
3540
}
3641
#endif
3742
#ifdef __CUDA
@@ -68,7 +73,7 @@ void BlasConnector::gemm(const char transa,
6873
#ifdef __DSP
6974
else if (device_type == base_device::AbacusDevice_t::DspDevice)
7075
{
71-
mtfunc::dgemm_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
76+
mtfunc::dgemm_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, BlasConnector::dsp_cluster_id_);
7277
}
7378
#endif
7479
else if (device_type == base_device::AbacusDevice_t::GpuDevice)
@@ -107,7 +112,7 @@ void BlasConnector::gemm(const char transa,
107112
#ifdef __DSP
108113
else if (device_type == base_device::AbacusDevice_t::DspDevice)
109114
{
110-
mtfunc::cgemm_pack_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
115+
mtfunc::cgemm_pack_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, BlasConnector::dsp_cluster_id_);
111116
// cgemm_mth_ for raw dsp mth;
112117
// cgemm_pack_mth_ for dsp mth with memcpy to DSP buffer
113118
}
@@ -160,7 +165,7 @@ void BlasConnector::gemm(const char transa,
160165
#ifdef __DSP
161166
else if (device_type == base_device::AbacusDevice_t::DspDevice)
162167
{
163-
mtfunc::zgemm_pack_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
168+
mtfunc::zgemm_pack_mth_(&transb, &transa, &n, &m, &k, &alpha, b, &ldb, a, &lda, &beta, c, &ldc, BlasConnector::dsp_cluster_id_);
164169
// zgemm_mth_ for raw dsp mth;
165170
// zgemm_pack_mth_ for dsp mth with memcpy to DSP buffer
166171
}
@@ -205,7 +210,7 @@ void BlasConnector::gemm_cm(const char transa, const char transb, const int m, c
205210
else if (device_type == base_device::AbacusDevice_t::DspDevice){
206211
mtfunc::sgemm_mth_(&transb, &transa, &m, &n, &k,
207212
&alpha, a, &lda, b, &ldb,
208-
&beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
213+
&beta, c, &ldc, BlasConnector::dsp_cluster_id_);
209214
}
210215
#endif
211216
#ifdef __CUDA
@@ -242,7 +247,7 @@ void BlasConnector::gemm_cm(const char transa,
242247
#ifdef __DSP
243248
else if (device_type == base_device::AbacusDevice_t::DspDevice)
244249
{
245-
mtfunc::dgemm_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
250+
mtfunc::dgemm_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, BlasConnector::dsp_cluster_id_);
246251
}
247252
#endif
248253
#ifdef __CUDA
@@ -281,7 +286,7 @@ void BlasConnector::gemm_cm(const char transa,
281286
#ifdef __DSP
282287
else if (device_type == base_device::AbacusDevice_t::DspDevice)
283288
{
284-
mtfunc::cgemm_pack_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
289+
mtfunc::cgemm_pack_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, BlasConnector::dsp_cluster_id_);
285290
// cgemm_mth_ for raw dsp mth;
286291
// cgemm_pack_mth_ for dsp mth with memcpy to DSP buffer
287292
}
@@ -334,7 +339,7 @@ void BlasConnector::gemm_cm(const char transa,
334339
#ifdef __DSP
335340
else if (device_type == base_device::AbacusDevice_t::DspDevice)
336341
{
337-
mtfunc::zgemm_pack_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, GlobalV::MY_RANK % PARAM.inp.dsp_count);
342+
mtfunc::zgemm_pack_mth_(&transa, &transb, &m, &n, &k, &alpha, a, &lda, b, &ldb, &beta, c, &ldc, BlasConnector::dsp_cluster_id_);
338343
// zgemm_mth_ for raw dsp mth;
339344
// zgemm_pack_mth_ for dsp mth with memcpy to DSP buffer
340345
}
@@ -527,7 +532,7 @@ void BlasConnector::gemv(const char trans, const int m, const int n,
527532
&beta,
528533
Y,
529534
&incy,
530-
GlobalV::MY_RANK % PARAM.inp.dsp_count);
535+
BlasConnector::dsp_cluster_id_);
531536
}
532537
#endif
533538
#ifdef __CUDA
@@ -561,7 +566,7 @@ void BlasConnector::gemv(const char trans, const int m, const int n,
561566
&beta,
562567
Y,
563568
&incy,
564-
GlobalV::MY_RANK % PARAM.inp.dsp_count);
569+
BlasConnector::dsp_cluster_id_);
565570
}
566571
#endif
567572
#ifdef __CUDA
@@ -595,7 +600,7 @@ void BlasConnector::gemv(const char trans, const int m, const int n,
595600
&beta,
596601
Y,
597602
&incy,
598-
GlobalV::MY_RANK % PARAM.inp.dsp_count);
603+
BlasConnector::dsp_cluster_id_);
599604
}
600605
#endif
601606
#ifdef __CUDA
@@ -631,7 +636,7 @@ void BlasConnector::gemv(const char trans, const int m, const int n,
631636
&beta,
632637
Y,
633638
&incy,
634-
GlobalV::MY_RANK % PARAM.inp.dsp_count);
639+
BlasConnector::dsp_cluster_id_);
635640
}
636641
#endif
637642
#ifdef __CUDA

source/source_base/test/global_function_test.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "../global_function.h"
22
#include "../global_variable.h"
3-
#define private public
4-
#include "source_io/module_parameter/parameter.h"
5-
#undef private
63
#include "../vector3.h"
74
#include "../tool_quit.h"
85
#include <string>
@@ -60,7 +57,7 @@
6057
* - print out warning info in running.log file
6158
* - COPYARRAY
6259
* - copy complex or double arrays
63-
* - IS_COLUMN_MAJOR_KS_SOLVER(PARAM.input.ks_solver)
60+
* - IS_COLUMN_MAJOR_KS_SOLVER(ks_solver)
6461
* - judge whether the KS_SOLVER is column major
6562
* - VECTOR_TO_PTR
6663
* - get a copy of the ptr of a vector
@@ -662,8 +659,7 @@ TEST_F(GlobalFunctionTest, COPYARRAY)
662659

663660
TEST_F(GlobalFunctionTest,IsColumnMajor)
664661
{
665-
PARAM.input.ks_solver = "genelpa";
666-
EXPECT_TRUE(ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER(PARAM.input.ks_solver));
662+
EXPECT_TRUE(ModuleBase::GlobalFunc::IS_COLUMN_MAJOR_KS_SOLVER("genelpa"));
667663
}
668664

669665
TEST_F(GlobalFunctionTest,Vector2Ptr)

source/source_base/test/tool_quit_test.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
#include "../tool_quit.h"
22
#include "../global_variable.h"
3-
#define private public
4-
#include "source_io/module_parameter/parameter.h"
5-
#undef private
63
#include "gtest/gtest.h"
74
#include "gmock/gmock.h"
85
#ifdef __MPI
@@ -35,7 +32,7 @@ class ToolQuitTest : public testing::Test
3532
{
3633
GlobalV::ofs_warning.open("warning.log");
3734
GlobalV::ofs_running.open("running.log");
38-
PARAM.sys.global_out_dir = "OUT/";
35+
ModuleBase::set_quit_out_dir("OUT/");
3936
}
4037
void TearDown()
4138
{

source/source_base/timer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
#if defined(__CUDA) && defined(__USE_NVTX)
1919
#include "source_base/module_device/cuda_compat.h"
20-
#include "source_io/module_parameter/parameter.h"
2120
#endif
2221

2322
namespace ModuleBase
@@ -27,6 +26,7 @@ namespace ModuleBase
2726
// EXPLAIN :
2827
//----------------------------------------------------------
2928
bool timer::disabled = false;
29+
bool timer::enable_nvtx_ = false;
3030
size_t timer::n_now = 0;
3131
std::map<std::string,std::map<std::string,timer::Timer_One>> timer::timer_pool;
3232

@@ -99,7 +99,7 @@ void timer::start(const std::string &class_name,const std::string &name)
9999
++timer_one.calls;
100100
timer_one.start_flag = false;
101101
#if defined(__CUDA) && defined(__USE_NVTX)
102-
if (PARAM.inp.timer_enable_nvtx){
102+
if (enable_nvtx_){
103103
std::string label = class_name + ":" + name;
104104
nvtxRangePushA(label.data());
105105
}
@@ -143,7 +143,7 @@ void timer::end(const std::string &class_name,const std::string &name)
143143
#endif
144144
timer_one.start_flag = true;
145145
#if defined(__CUDA) && defined(__USE_NVTX)
146-
if (PARAM.inp.timer_enable_nvtx)
146+
if (enable_nvtx_)
147147
{ nvtxRangePop(); }
148148
#endif
149149
}

source/source_base/timer.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,15 @@ class timer
6363
disabled = false;
6464
}
6565

66+
/**
67+
* @brief Toggle NVTX range emission for CUDA profiling.
68+
* Caller-injected; only consulted when built with __CUDA && __USE_NVTX.
69+
*/
70+
static void set_nvtx_enabled(bool b)
71+
{
72+
enable_nvtx_ = b;
73+
}
74+
6675
/**
6776
* @brief Disable time computation
6877
*
@@ -101,6 +110,11 @@ class timer
101110
*/
102111
static bool disabled;
103112

113+
/**
114+
* @brief Member variable: NVTX range emission toggle (CUDA profiling only).
115+
*/
116+
static bool enable_nvtx_;
117+
104118
/**
105119
* @brief Member variable: the index of clocks
106120
*

source/source_base/tool_quit.cpp

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,23 @@
77

88
#else
99
#include "global_variable.h"
10-
#include "source_io/module_parameter/parameter.h"
1110
#include "global_file.h"
1211
#include "timer.h"
1312
#include "memory.h"
1413
#endif
1514

1615
namespace ModuleBase
1716
{
17+
namespace
18+
{
19+
std::string g_quit_out_dir;
20+
}
21+
22+
void set_quit_out_dir(const std::string& dir)
23+
{
24+
g_quit_out_dir = dir;
25+
}
26+
1827
//==========================================================
1928
// GLOBAL FUNCTION :
2029
// NAME : WARNING( write information into GlobalV::ofs_warning)
@@ -49,7 +58,7 @@ void QUIT(int ret)
4958
#else
5059
ModuleBase::timer::finish(GlobalV::ofs_running , !GlobalV::MY_RANK, false);
5160
ModuleBase::Global_File::close_all_log(GlobalV::MY_RANK);
52-
std::cout<<" See output information in : "<<PARAM.globalv.global_out_dir<<std::endl;
61+
std::cout<<" See output information in : "<<g_quit_out_dir<<std::endl;
5362
#endif
5463

5564
exit(ret);
@@ -94,7 +103,7 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
94103
std::cout << " ---------------------------------------------------------" << std::endl;
95104
std::cout << " " << std::endl;
96105
std::cout << " " << description << std::endl;
97-
std::cout << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
106+
std::cout << " CHECK IN FILE : " << g_quit_out_dir << "warning.log" << std::endl;
98107
std::cout << " " << std::endl;
99108
std::cout << " For detailed manual of ABACUS, please see the website" << std::endl;
100109
std::cout << " https://abacus.deepmodeling.com" << std::endl;
@@ -110,7 +119,7 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
110119
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
111120
GlobalV::ofs_running << std::endl;
112121
GlobalV::ofs_running << " " << description << std::endl;
113-
GlobalV::ofs_running << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
122+
GlobalV::ofs_running << " CHECK IN FILE : " << g_quit_out_dir << "warning.log" << std::endl;
114123
GlobalV::ofs_running << std::endl;
115124
GlobalV::ofs_running << " For detailed manual of ABACUS, please see the website" << std::endl;
116125
GlobalV::ofs_running << " https://abacus.deepmodeling.com" << std::endl;
@@ -121,7 +130,7 @@ void WARNING_QUIT(const std::string &file,const std::string &description,int ret
121130
GlobalV::ofs_running << " ---------------------------------------------------------" << std::endl;
122131

123132
WARNING(file,description);
124-
GlobalV::ofs_running<<" Check in file : "<<PARAM.globalv.global_out_dir<<"warning.log"<<std::endl;
133+
GlobalV::ofs_running<<" Check in file : "<<g_quit_out_dir<<"warning.log"<<std::endl;
125134

126135
#endif
127136

@@ -141,21 +150,21 @@ void CHECK_WARNING_QUIT(const bool error_in, const std::string &file,const std::
141150
std::cout.clear();
142151
if(!GlobalV::ofs_running.is_open())
143152
{
144-
std::string logfile = PARAM.globalv.global_out_dir + "running_" + calculation + ".log";
153+
std::string logfile = g_quit_out_dir + "running_" + calculation + ".log";
145154
GlobalV::ofs_running.open( logfile.c_str(), std::ios::app );
146155
}
147156
if(!GlobalV::ofs_warning.is_open())
148157
{
149-
std::string warningfile = PARAM.globalv.global_out_dir + "warning.log";
158+
std::string warningfile = g_quit_out_dir + "warning.log";
150159
GlobalV::ofs_warning.open( warningfile.c_str(), std::ios::app );
151160
}
152161

153162
//print error information
154163
std::cout << " ---------------------------------------------------------" << std::endl;
155164
std::cout << " ERROR! " << description << std::endl;
156-
std::cout << " CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
165+
std::cout << " CHECK IN FILE : " << g_quit_out_dir << "warning.log" << std::endl;
157166
std::cout << " ---------------------------------------------------------" << std::endl;
158-
GlobalV::ofs_running << " ERROR! CHECK IN FILE : " << PARAM.globalv.global_out_dir << "warning.log" << std::endl;
167+
GlobalV::ofs_running << " ERROR! CHECK IN FILE : " << g_quit_out_dir << "warning.log" << std::endl;
159168
GlobalV::ofs_warning << std::endl;
160169
GlobalV::ofs_warning << " ERROR! " << file << ", core " << GlobalV::MY_RANK+1 << ": " << description << std::endl;
161170
GlobalV::ofs_warning << std::endl;

source/source_base/tool_quit.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ namespace ModuleBase
2828
*/
2929
void WARNING(const std::string &file, const std::string &description);
3030

31+
/**
32+
* @brief Inject the global output directory used by QUIT/WARNING_QUIT/CHECK_WARNING_QUIT
33+
* for log path resolution and user-facing messages.
34+
*
35+
* Caller-injected (typically once after input parameters are read).
36+
* If never set, paths fall back to CWD.
37+
*/
38+
void set_quit_out_dir(const std::string& dir);
39+
3140
/**
3241
* @brief Close .log files and exit
3342
*

0 commit comments

Comments
 (0)