Skip to content

Commit 0fccf66

Browse files
committed
Remove all ctx parameters in resize_memory_op
1 parent 76d023b commit 0fccf66

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+426
-451
lines changed

source/module_base/kernels/test/math_op_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ TEST_F(TestModuleBaseMathMultiDevice, cal_ylm_real_op_gpu)
306306
std::vector<double> ylm(expected_ylm.size(), 0.0);
307307
double * d_ylm = nullptr, * d_g = nullptr, * d_p = nullptr;
308308

309-
resmem_var_op()(gpu_ctx, d_g, g.size());
310-
resmem_var_op()(gpu_ctx, d_p, p.size());
311-
resmem_var_op()(gpu_ctx, d_ylm, ylm.size());
309+
resmem_var_op()(d_g, g.size());
310+
resmem_var_op()(d_p, p.size());
311+
resmem_var_op()(d_ylm, ylm.size());
312312

313313
syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_g, g.data(), g.size());
314314
syncmem_var_h2d_op()(gpu_ctx, cpu_ctx, d_p, p.data(), p.size());

source/module_base/math_chebyshev.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ Chebyshev<REAL, Device>::Chebyshev(const int norder_in) : fftw(2 * EXTEND * nord
6363
coefc_cpu = new std::complex<REAL>[norder];
6464
if (base_device::get_device_type<Device>(this->ctx) == base_device::GpuDevice)
6565
{
66-
resmem_var_op()(this->ctx, this->coef_real, norder);
67-
resmem_complex_op()(this->ctx, this->coef_complex, norder);
66+
resmem_var_op()(this->coef_real, norder);
67+
resmem_complex_op()(this->coef_complex, norder);
6868
}
6969
else
7070
{
@@ -129,7 +129,7 @@ REAL Chebyshev<REAL, Device>::ddot_real(const std::complex<REAL>* psi_L,
129129
pL = (REAL*)psi_L;
130130
pR = (REAL*)psi_R;
131131
REAL* dot_device = nullptr;
132-
resmem_var_op()(this->ctx, dot_device, 1);
132+
resmem_var_op()(dot_device, 1);
133133
container::kernels::blas_dot<REAL, ct_Device>()(dim2, pL, 1, pR, 1, dot_device);
134134
syncmem_var_d2h_op()(cpu_ctx, this->ctx, &result, dot_device, 1);
135135
delmem_var_op()(this->ctx, dot_device);
@@ -140,7 +140,7 @@ REAL Chebyshev<REAL, Device>::ddot_real(const std::complex<REAL>* psi_L,
140140
pL = (REAL*)psi_L;
141141
pR = (REAL*)psi_R;
142142
REAL* dot_device = nullptr;
143-
resmem_var_op()(this->ctx, dot_device, 1);
143+
resmem_var_op()(dot_device, 1);
144144
for (int i = 0; i < m; ++i)
145145
{
146146
int dim2 = 2 * N;
@@ -427,9 +427,9 @@ void Chebyshev<REAL, Device>::calfinalvec_real(
427427
ndmxt = LDA * m;
428428
}
429429

430-
resmem_complex_op()(this->ctx, arraynp1, ndmxt);
431-
resmem_complex_op()(this->ctx, arrayn, ndmxt);
432-
resmem_complex_op()(this->ctx, arrayn_1, ndmxt);
430+
resmem_complex_op()(arraynp1, ndmxt);
431+
resmem_complex_op()(arrayn, ndmxt);
432+
resmem_complex_op()(arrayn_1, ndmxt);
433433

434434
memcpy_complex_op()(this->ctx, this->ctx, arrayn_1, wavein, ndmxt);
435435
// ModuleBase::GlobalFunc::DCOPY(wavein, arrayn_1, ndmxt);
@@ -496,9 +496,9 @@ void Chebyshev<REAL, Device>::calfinalvec_complex(
496496
ndmxt = LDA * m;
497497
}
498498

499-
resmem_complex_op()(this->ctx, arraynp1, ndmxt);
500-
resmem_complex_op()(this->ctx, arrayn, ndmxt);
501-
resmem_complex_op()(this->ctx, arrayn_1, ndmxt);
499+
resmem_complex_op()(arraynp1, ndmxt);
500+
resmem_complex_op()(arrayn, ndmxt);
501+
resmem_complex_op()(arrayn_1, ndmxt);
502502

503503
memcpy_complex_op()(this->ctx, this->ctx, arrayn_1, wavein, ndmxt);
504504

@@ -595,9 +595,9 @@ void Chebyshev<REAL, Device>::tracepolyA(
595595
ndmxt = LDA * m;
596596
}
597597

598-
resmem_complex_op()(this->ctx, arraynp1, ndmxt);
599-
resmem_complex_op()(this->ctx, arrayn, ndmxt);
600-
resmem_complex_op()(this->ctx, arrayn_1, ndmxt);
598+
resmem_complex_op()(arraynp1, ndmxt);
599+
resmem_complex_op()(arrayn, ndmxt);
600+
resmem_complex_op()(arrayn_1, ndmxt);
601601

602602
memcpy_complex_op()(this->ctx, this->ctx, arrayn_1, wavein, ndmxt);
603603
// ModuleBase::GlobalFunc::DCOPY(wavein, arrayn_1, ndmxt);
@@ -669,9 +669,9 @@ bool Chebyshev<REAL, Device>::checkconverge(
669669
std::complex<REAL>* arrayn = nullptr;
670670
std::complex<REAL>* arrayn_1 = nullptr;
671671

672-
resmem_complex_op()(this->ctx, arraynp1, LDA);
673-
resmem_complex_op()(this->ctx, arrayn, LDA);
674-
resmem_complex_op()(this->ctx, arrayn_1, LDA);
672+
resmem_complex_op()(arraynp1, LDA);
673+
resmem_complex_op()(arrayn, LDA);
674+
resmem_complex_op()(arrayn_1, LDA);
675675

676676
memcpy_complex_op()(this->ctx, this->ctx, arrayn_1, wavein, N);
677677
// ModuleBase::GlobalFunc::DCOPY(wavein, arrayn_1, N);

source/module_base/math_ylmreal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ void YlmReal::Ylm_Real(Device * ctx, const int lmax2, const int ng, const FPTYPE
327327
ModuleBase::WARNING_QUIT("YLM_REAL","l>30 or l<0");
328328
}
329329
FPTYPE * p = nullptr, * phi = nullptr, * cost = nullptr;
330-
resmem_var_op()(ctx, p, (lmax + 1) * (lmax + 1) * ng, "YlmReal::Ylm_Real");
330+
resmem_var_op()(p, (lmax + 1) * (lmax + 1) * ng, "YlmReal::Ylm_Real");
331331

332332
cal_ylm_real_op()(
333333
ctx,

source/module_base/module_device/cuda/memory_op.cu

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ __global__ void cast_memory(std::complex<FPTYPE_out>* out, const FPTYPE_in* in,
5252
}
5353

5454
template <typename FPTYPE>
55-
void resize_memory_op<FPTYPE, base_device::DEVICE_GPU>::operator()(const base_device::DEVICE_GPU* dev,
56-
FPTYPE*& arr,
57-
const size_t size,
55+
void resize_memory_op<FPTYPE, base_device::DEVICE_GPU>::operator()(FPTYPE*& arr,
56+
const size_t size,
5857
const char* record_in)
5958
{
6059
if (arr != nullptr)
6160
{
62-
delete_memory_op<FPTYPE, base_device::DEVICE_GPU>()(dev, arr);
61+
delete_memory_op<FPTYPE, base_device::DEVICE_GPU>()(gpu_ctx, arr);
6362
}
6463
cudaErrcheck(cudaMalloc((void**)&arr, sizeof(FPTYPE) * size));
6564
std::string record_string;

source/module_base/module_device/memory_op.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace memory
1818
template <typename FPTYPE>
1919
struct resize_memory_op<FPTYPE, base_device::DEVICE_CPU>
2020
{
21-
void operator()(const base_device::DEVICE_CPU* dev, FPTYPE*& arr, const size_t size, const char* record_in)
21+
void operator()(FPTYPE*& arr, const size_t size, const char* record_in)
2222
{
2323
if (arr != nullptr)
2424
{
@@ -156,8 +156,7 @@ template struct delete_memory_op<std::complex<double>*, base_device::DEVICE_CPU>
156156
template <typename FPTYPE>
157157
struct resize_memory_op<FPTYPE, base_device::DEVICE_GPU>
158158
{
159-
void operator()(const base_device::DEVICE_GPU* dev,
160-
FPTYPE*& arr,
159+
void operator()(FPTYPE*& arr,
161160
const size_t size,
162161
const char* record_in = nullptr)
163162
{
@@ -404,10 +403,10 @@ template <typename FPTYPE>
404403
void resize_memory(FPTYPE* arr, base_device::AbacusDevice_t device_type)
405404
{
406405
if (device_type == base_device::AbacusDevice_t::CpuDevice){
407-
resize_memory_op<FPTYPE, base_device::DEVICE_CPU>()(cpu_ctx, arr);
406+
resize_memory_op<FPTYPE, base_device::DEVICE_CPU>()(arr);
408407
}
409408
else if (device_type == base_device::AbacusDevice_t::GpuDevice){
410-
resize_memory_op<FPTYPE, base_device::DEVICE_GPU>()(gpu_ctx, arr);
409+
resize_memory_op<FPTYPE, base_device::DEVICE_GPU>()(arr);
411410
}
412411
}
413412

source/module_base/module_device/memory_op.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ struct resize_memory_op
1818
/// @brief Allocate memory for a given pointer. Note this op will free the pointer first.
1919
///
2020
/// Input Parameters
21-
/// \param dev : the type of computing device
2221
/// \param size : array size
2322
/// \param record_string : label for memory record
2423
///
2524
/// Output Parameters
2625
/// \param arr : allocated array
27-
void operator()(const Device* dev, FPTYPE*& arr, const size_t size, const char* record_in = nullptr);
26+
void operator()(FPTYPE*& arr, const size_t size, const char* record_in = nullptr);
2827
};
2928

3029
template <typename FPTYPE, typename Device>
@@ -113,8 +112,7 @@ void delete_memory(FPTYPE* arr, base_device::AbacusDevice_t device_type = base_d
113112
template <typename FPTYPE>
114113
struct resize_memory_op<FPTYPE, base_device::DEVICE_GPU>
115114
{
116-
void operator()(const base_device::DEVICE_GPU* dev,
117-
FPTYPE*& arr,
115+
void operator()(FPTYPE*& arr,
118116
const size_t size,
119117
const char* record_in = nullptr);
120118
};

source/module_base/module_device/test/memory_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ TEST_F(TestModulePsiMemory, set_memory_op_complex_double_cpu)
111111
TEST_F(TestModulePsiMemory, resize_memory_op_double_cpu)
112112
{
113113
double* xx_tmp = NULL;
114-
resize_memory_double_cpu_op()(cpu_ctx, xx_tmp, xx.size());
114+
resize_memory_double_cpu_op()(xx_tmp, xx.size());
115115
for (int ii = 0; ii < xx.size(); ii++)
116116
{
117117
xx_tmp[ii] = xx[ii];
@@ -126,7 +126,7 @@ TEST_F(TestModulePsiMemory, resize_memory_op_double_cpu)
126126
TEST_F(TestModulePsiMemory, resize_memory_op_comlex_double_cpu)
127127
{
128128
std::complex<double>* z_xx_tmp = NULL;
129-
resize_memory_comlex_double_cpu_op()(cpu_ctx, z_xx_tmp, z_xx.size());
129+
resize_memory_comlex_double_cpu_op()(z_xx_tmp, z_xx.size());
130130
for (int ii = 0; ii < z_xx.size(); ii++)
131131
{
132132
z_xx_tmp[ii] = z_xx[ii];
@@ -200,7 +200,7 @@ TEST_F(TestModulePsiMemory, set_memory_op_complex_double_gpu)
200200
TEST_F(TestModulePsiMemory, resize_memory_op_double_gpu)
201201
{
202202
double* xx_tmp = NULL;
203-
resize_memory_double_gpu_op()(gpu_ctx, xx_tmp, xx.size());
203+
resize_memory_double_gpu_op()(xx_tmp, xx.size());
204204

205205
thrust::device_ptr<double> d_xx(xx_tmp);
206206
thrust::copy(xx.begin(), xx.end(), d_xx);
@@ -217,7 +217,7 @@ TEST_F(TestModulePsiMemory, resize_memory_op_double_gpu)
217217
TEST_F(TestModulePsiMemory, resize_memory_op_complex_double_gpu)
218218
{
219219
std::complex<double>* z_xx_tmp = NULL;
220-
resize_memory_comlex_double_gpu_op()(gpu_ctx, z_xx_tmp, z_xx.size());
220+
resize_memory_comlex_double_gpu_op()(z_xx_tmp, z_xx.size());
221221

222222
thrust::device_ptr<std::complex<double>> dz_xx(z_xx_tmp);
223223
thrust::copy(z_xx.begin(), z_xx.end(), dz_xx);

source/module_base/parallel_device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void bcast_dev(const Device* ctx, T* object, const int& n, const MPI_Comm& comm,
3737
{
3838
if(tmp_space == nullptr)
3939
{
40-
base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU>()(cpu_ctx, object_cpu, n);
40+
base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU>()(object_cpu, n);
4141
alloc = true;
4242
}
4343
else
@@ -74,7 +74,7 @@ void reduce_dev(const Device* ctx, T* object, const int& n, const MPI_Comm& comm
7474
{
7575
if(tmp_space == nullptr)
7676
{
77-
base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU>()(cpu_ctx, object_cpu, n);
77+
base_device::memory::resize_memory_op<T, base_device::DEVICE_CPU>()(object_cpu, n);
7878
alloc = true;
7979
}
8080
else

source/module_base/test/blas_connector_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ TEST(blas_connector, ScalGpu) {
101101
const int incx = 1;
102102
std::complex<double> result[8], answer[8];
103103
std::complex<double>* result_gpu = nullptr;
104-
resmem_zd_op()(gpu_ctx, result_gpu, 8 * sizeof(std::complex<double>));
104+
resmem_zd_op()(result_gpu, 8 * sizeof(std::complex<double>));
105105
for (int i=0; i< size; i++) {
106106
result[i] = std::complex<double>{static_cast<double>(std::rand() / double(RAND_MAX)),
107107
static_cast<double>(std::rand() / double(RAND_MAX))};
@@ -198,8 +198,8 @@ TEST(blas_connector, AxpyGpu) {
198198
std::array<T, size> x_const, result, answer;
199199
T* x_gpu = nullptr;
200200
T* result_gpu = nullptr;
201-
resmem_zd_op()(gpu_ctx, x_gpu, size * sizeof(std::complex<double>));
202-
resmem_zd_op()(gpu_ctx, result_gpu, size * sizeof(std::complex<double>));
201+
resmem_zd_op()(x_gpu, size * sizeof(std::complex<double>));
202+
resmem_zd_op()(result_gpu, size * sizeof(std::complex<double>));
203203
std::generate(x_const.begin(), x_const.end(), []() {
204204
return T{static_cast<double>(std::rand() / double(RAND_MAX)),
205205
static_cast<double>(std::rand() / double(RAND_MAX))};
@@ -640,9 +640,9 @@ TEST(blas_connector, GemmGpu) {
640640
std::complex<double>* a_gpu = nullptr;
641641
std::complex<double>* b_gpu = nullptr;
642642
std::complex<double>* result_gpu = nullptr;
643-
resmem_zd_op()(gpu_ctx, a_gpu, size_k * lda * sizeof(std::complex<double>));
644-
resmem_zd_op()(gpu_ctx, b_gpu, size_n * ldb * sizeof(std::complex<double>));
645-
resmem_zd_op()(gpu_ctx, result_gpu, size_n * ldc * sizeof(std::complex<double>));
643+
resmem_zd_op()(a_gpu, size_k * lda * sizeof(std::complex<double>));
644+
resmem_zd_op()(b_gpu, size_n * ldb * sizeof(std::complex<double>));
645+
resmem_zd_op()(result_gpu, size_n * ldc * sizeof(std::complex<double>));
646646
std::generate(a_const.begin(), a_const.end(), []() {
647647
return T{static_cast<double>(std::rand() / double(RAND_MAX)),
648648
static_cast<double>(std::rand() / double(RAND_MAX))};

source/module_basis/module_pw/kernels/test/pw_op_test.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ TEST_F(TestModulePWPWMultiDevice, set_3d_fft_box_op_gpu)
102102
std::vector<std::complex<double>> res(out_1.size(), std::complex<double>{0, 0});
103103
int * d_box_index = NULL;
104104
std::complex<double>* d_res = NULL, * d_in_1 = NULL;
105-
resize_memory_int_gpu_op()(gpu_ctx, d_box_index, box_index.size());
106-
resize_memory_complex_gpu_op()(gpu_ctx, d_res, res.size());
107-
resize_memory_complex_gpu_op()(gpu_ctx, d_in_1, in_1.size());
105+
resize_memory_int_gpu_op()(d_box_index, box_index.size());
106+
resize_memory_complex_gpu_op()(d_res, res.size());
107+
resize_memory_complex_gpu_op()(d_in_1, in_1.size());
108108
synchronize_memory_int_h2d_op()(gpu_ctx, cpu_ctx, d_box_index, box_index.data(), box_index.size());
109109
synchronize_memory_complex_h2d_op()(gpu_ctx, cpu_ctx, d_res, res.data(), res.size());
110110
synchronize_memory_complex_h2d_op()(gpu_ctx, cpu_ctx, d_in_1, in_1.data(), in_1.size());
@@ -125,8 +125,8 @@ TEST_F(TestModulePWPWMultiDevice, set_recip_to_real_output_op_gpu)
125125
{
126126
std::vector<std::complex<double>> res(out_2.size(), std::complex<double>{0, 0});
127127
std::complex<double>* d_res = NULL, * d_in_2 = NULL;
128-
resize_memory_complex_gpu_op()(gpu_ctx, d_res, res.size());
129-
resize_memory_complex_gpu_op()(gpu_ctx, d_in_2, in_2.size());
128+
resize_memory_complex_gpu_op()(d_res, res.size());
129+
resize_memory_complex_gpu_op()(d_in_2, in_2.size());
130130
synchronize_memory_complex_h2d_op()(gpu_ctx, cpu_ctx, d_res, res.data(), res.size());
131131
synchronize_memory_complex_h2d_op()(gpu_ctx, cpu_ctx, d_in_2, in_2.data(), in_2.size());
132132

@@ -146,9 +146,9 @@ TEST_F(TestModulePWPWMultiDevice, set_real_to_recip_output_op_gpu)
146146
std::vector<std::complex<double>> res = out_3_init;
147147
int * d_box_index = NULL;
148148
std::complex<double>* d_res = NULL, * d_in_3 = NULL;
149-
resize_memory_int_gpu_op()(gpu_ctx, d_box_index, box_index.size());
150-
resize_memory_complex_gpu_op()(gpu_ctx, d_res, res.size());
151-
resize_memory_complex_gpu_op()(gpu_ctx, d_in_3, in_3.size());
149+
resize_memory_int_gpu_op()(d_box_index, box_index.size());
150+
resize_memory_complex_gpu_op()(d_res, res.size());
151+
resize_memory_complex_gpu_op()(d_in_3, in_3.size());
152152
synchronize_memory_int_h2d_op()(gpu_ctx, cpu_ctx, d_box_index, box_index.data(), box_index.size());
153153
synchronize_memory_complex_h2d_op()(gpu_ctx, cpu_ctx, d_res, res.data(), res.size());
154154
synchronize_memory_complex_h2d_op()(gpu_ctx, cpu_ctx, d_in_3, in_3.data(), in_3.size());

0 commit comments

Comments
 (0)