Skip to content

Commit 7565f9a

Browse files
committed
Remove ctx parameter in delete_memory_op
1 parent 248a9e2 commit 7565f9a

Some content is hidden

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

61 files changed

+406
-413
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
@@ -332,9 +332,9 @@ TEST_F(TestModuleBaseMathMultiDevice, cal_ylm_real_op_gpu)
332332
EXPECT_LT(fabs(ylm[ii] - expected_ylm[ii]), 6e-5);
333333
}
334334

335-
delmem_var_op()(gpu_ctx, d_g);
336-
delmem_var_op()(gpu_ctx, d_p);
337-
delmem_var_op()(gpu_ctx, d_ylm);
335+
delmem_var_op()(d_g);
336+
delmem_var_op()(d_p);
337+
delmem_var_op()(d_ylm);
338338
}
339339

340340
#endif // __CUDA || __UT_USE_CUDA || __ROCM || __UT_USE_ROCM

source/module_base/math_chebyshev.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ Chebyshev<REAL, Device>::~Chebyshev()
8484
delete[] polytrace;
8585
if (base_device::get_device_type<Device>(this->ctx) == base_device::GpuDevice)
8686
{
87-
delmem_var_op()(this->ctx, this->coef_real);
88-
delmem_complex_op()(this->ctx, this->coef_complex);
87+
delmem_var_op()(this->coef_real);
88+
delmem_complex_op()(this->coef_complex);
8989
}
9090
else
9191
{
@@ -132,7 +132,7 @@ REAL Chebyshev<REAL, Device>::ddot_real(const std::complex<REAL>* psi_L,
132132
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()(&result, dot_device, 1);
135-
delmem_var_op()(this->ctx, dot_device);
135+
delmem_var_op()(dot_device);
136136
}
137137
else
138138
{
@@ -151,7 +151,7 @@ REAL Chebyshev<REAL, Device>::ddot_real(const std::complex<REAL>* psi_L,
151151
pL += 2 * LDA;
152152
pR += 2 * LDA;
153153
}
154-
delmem_var_op()(this->ctx, dot_device);
154+
delmem_var_op()(dot_device);
155155
}
156156
return result;
157157
}
@@ -462,9 +462,9 @@ void Chebyshev<REAL, Device>::calfinalvec_real(
462462
arrayn = arraynp1;
463463
arraynp1 = tem;
464464
}
465-
delmem_complex_op()(this->ctx, arraynp1);
466-
delmem_complex_op()(this->ctx, arrayn);
467-
delmem_complex_op()(this->ctx, arrayn_1);
465+
delmem_complex_op()(arraynp1);
466+
delmem_complex_op()(arrayn);
467+
delmem_complex_op()(arrayn_1);
468468
return;
469469
}
470470

@@ -527,9 +527,9 @@ void Chebyshev<REAL, Device>::calfinalvec_complex(
527527
arrayn = arraynp1;
528528
arraynp1 = tem;
529529
}
530-
delmem_complex_op()(this->ctx, arraynp1);
531-
delmem_complex_op()(this->ctx, arrayn);
532-
delmem_complex_op()(this->ctx, arrayn_1);
530+
delmem_complex_op()(arraynp1);
531+
delmem_complex_op()(arrayn);
532+
delmem_complex_op()(arrayn_1);
533533
return;
534534
}
535535

@@ -618,9 +618,9 @@ void Chebyshev<REAL, Device>::tracepolyA(
618618
arraynp1 = tem;
619619
}
620620

621-
delmem_complex_op()(this->ctx, arraynp1);
622-
delmem_complex_op()(this->ctx, arrayn);
623-
delmem_complex_op()(this->ctx, arrayn_1);
621+
delmem_complex_op()(arraynp1);
622+
delmem_complex_op()(arrayn);
623+
delmem_complex_op()(arrayn_1);
624624
return;
625625
}
626626

@@ -754,9 +754,9 @@ bool Chebyshev<REAL, Device>::checkconverge(
754754
arraynp1 = tem;
755755
}
756756

757-
delmem_complex_op()(this->ctx, arraynp1);
758-
delmem_complex_op()(this->ctx, arrayn);
759-
delmem_complex_op()(this->ctx, arrayn_1);
757+
delmem_complex_op()(arraynp1);
758+
delmem_complex_op()(arrayn);
759+
delmem_complex_op()(arrayn_1);
760760
return converge;
761761
}
762762

source/module_base/math_ylmreal.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ void YlmReal::Ylm_Real(Device * ctx, const int lmax2, const int ng, const FPTYPE
342342
p,
343343
ylm);
344344

345-
delmem_var_op()(ctx, p);
346-
delmem_var_op()(ctx, phi);
347-
delmem_var_op()(ctx, cost);
345+
delmem_var_op()(p);
346+
delmem_var_op()(phi);
347+
delmem_var_op()(cost);
348348
} // end subroutine ylmr2
349349

350350
//==========================================================

source/module_base/module_device/cuda/memory_op.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void resize_memory_op<FPTYPE, base_device::DEVICE_GPU>::operator()(FPTYPE*& arr,
5858
{
5959
if (arr != nullptr)
6060
{
61-
delete_memory_op<FPTYPE, base_device::DEVICE_GPU>()(gpu_ctx, arr);
61+
delete_memory_op<FPTYPE, base_device::DEVICE_GPU>()(arr);
6262
}
6363
cudaErrcheck(cudaMalloc((void**)&arr, sizeof(FPTYPE) * size));
6464
std::string record_string;
@@ -179,7 +179,7 @@ struct cast_memory_op<FPTYPE_out, FPTYPE_in, base_device::DEVICE_CPU, base_devic
179179
};
180180

181181
template <typename FPTYPE>
182-
void delete_memory_op<FPTYPE, base_device::DEVICE_GPU>::operator()(const base_device::DEVICE_GPU* dev, FPTYPE* arr)
182+
void delete_memory_op<FPTYPE, base_device::DEVICE_GPU>::operator()(FPTYPE* arr)
183183
{
184184
cudaErrcheck(cudaFree(arr));
185185
}

source/module_base/module_device/memory_op.cpp

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct cast_memory_op<FPTYPE_out, FPTYPE_in, base_device::DEVICE_CPU, base_devic
9090
template <typename FPTYPE>
9191
struct delete_memory_op<FPTYPE, base_device::DEVICE_CPU>
9292
{
93-
void operator()(const base_device::DEVICE_CPU* dev, FPTYPE* arr)
93+
void operator()(FPTYPE* arr)
9494
{
9595
free(arr);
9696
}
@@ -230,7 +230,7 @@ struct cast_memory_op<FPTYPE_out, FPTYPE_in, base_device::DEVICE_CPU, base_devic
230230
template <typename FPTYPE>
231231
struct delete_memory_op<FPTYPE, base_device::DEVICE_GPU>
232232
{
233-
void operator()(const base_device::DEVICE_GPU* dev, FPTYPE* arr)
233+
void operator()(FPTYPE* arr)
234234
{
235235
}
236236
};
@@ -336,7 +336,7 @@ template struct delete_memory_op<std::complex<double>, base_device::DEVICE_GPU>;
336336
template <typename FPTYPE>
337337
struct resize_memory_op_mt<FPTYPE, base_device::DEVICE_CPU>
338338
{
339-
void operator()(const base_device::DEVICE_CPU* dev, FPTYPE*& arr, const size_t size, const char* record_in)
339+
void operator()(FPTYPE*& arr, const size_t size, const char* record_in)
340340
{
341341
if (arr != nullptr)
342342
{
@@ -363,7 +363,7 @@ struct resize_memory_op_mt<FPTYPE, base_device::DEVICE_CPU>
363363
template <typename FPTYPE>
364364
struct delete_memory_op_mt<FPTYPE, base_device::DEVICE_CPU>
365365
{
366-
void operator()(const base_device::DEVICE_CPU* dev, FPTYPE* arr)
366+
void operator()(FPTYPE* arr)
367367
{
368368
free_ht(arr);
369369
}
@@ -397,54 +397,54 @@ void resize_memory(FPTYPE* arr, const size_t size, base_device::AbacusDevice_t d
397397
template <typename FPTYPE>
398398
void set_memory(FPTYPE* arr, const int var, const size_t size, base_device::AbacusDevice_t device_type){
399399
if (device_type == base_device::AbacusDevice_t::CpuDevice){
400-
set_memory_op<FPTYPE, base_device::DEVICE_CPU>()(cpu_ctx, arr, var, size);
400+
set_memory_op<FPTYPE, base_device::DEVICE_CPU>()(arr, var, size);
401401
}
402402
else if (device_type == base_device::AbacusDevice_t::GpuDevice){
403-
set_memory_op<FPTYPE, base_device::DEVICE_GPU>()(gpu_ctx, arr, var, size);
403+
set_memory_op<FPTYPE, base_device::DEVICE_GPU>()(arr, var, size);
404404
}
405405
}
406406

407407
template <typename FPTYPE>
408408
void synchronize_memory(FPTYPE* arr_out, const FPTYPE* arr_in, const size_t size, base_device::AbacusDevice_t device_type_out, base_device::AbacusDevice_t device_type_in){
409409
if (device_type_out == base_device::AbacusDevice_t::CpuDevice || device_type_in == base_device::AbacusDevice_t::CpuDevice){
410-
synchronize_memory_op<FPTYPE, DEVICE_CPU, DEVICE_CPU>()(cpu_ctx, cpu_ctx, arr_out, arr_in, size);
410+
synchronize_memory_op<FPTYPE, DEVICE_CPU, DEVICE_CPU>()(arr_out, arr_in, size);
411411
}
412412
else if (device_type_out == base_device::AbacusDevice_t::CpuDevice || device_type_in == base_device::AbacusDevice_t::GpuDevice){
413-
synchronize_memory_op<FPTYPE, DEVICE_CPU, DEVICE_GPU>()(cpu_ctx, gpu_ctx, arr_out, arr_in, size);
413+
synchronize_memory_op<FPTYPE, DEVICE_CPU, DEVICE_GPU>()(arr_out, arr_in, size);
414414
}
415415
else if (device_type_out == base_device::AbacusDevice_t::GpuDevice || device_type_in == base_device::AbacusDevice_t::CpuDevice){
416-
synchronize_memory_op<FPTYPE, DEVICE_GPU, DEVICE_CPU>()(gpu_ctx, cpu_ctx, arr_out, arr_in, size);
416+
synchronize_memory_op<FPTYPE, DEVICE_GPU, DEVICE_CPU>()(arr_out, arr_in, size);
417417
}
418418
else if (device_type_out == base_device::AbacusDevice_t::GpuDevice || device_type_in == base_device::AbacusDevice_t::GpuDevice){
419-
synchronize_memory_op<FPTYPE, DEVICE_GPU, DEVICE_GPU>()(gpu_ctx, gpu_ctx, arr_out, arr_in, size);
419+
synchronize_memory_op<FPTYPE, DEVICE_GPU, DEVICE_GPU>()(arr_out, arr_in, size);
420420
}
421421
}
422422

423423
template <typename FPTYPE_out, typename FPTYPE_in>
424424
void cast_memory(FPTYPE_out* arr_out, const FPTYPE_in* arr_in, const size_t size, base_device::AbacusDevice_t device_type_out, base_device::AbacusDevice_t device_type_in)
425425
{
426426
if (device_type_out == base_device::AbacusDevice_t::CpuDevice || device_type_in == base_device::AbacusDevice_t::CpuDevice){
427-
cast_memory_op<FPTYPE_out, FPTYPE_in, DEVICE_CPU, DEVICE_CPU>()(cpu_ctx, cpu_ctx, arr_out, arr_in, size);
427+
cast_memory_op<FPTYPE_out, FPTYPE_in, DEVICE_CPU, DEVICE_CPU>()(arr_out, arr_in, size);
428428
}
429429
else if (device_type_out == base_device::AbacusDevice_t::CpuDevice || device_type_in == base_device::AbacusDevice_t::GpuDevice){
430-
cast_memory_op<FPTYPE_out, FPTYPE_in, DEVICE_CPU, DEVICE_GPU>()(cpu_ctx, gpu_ctx, arr_out, arr_in, size);
430+
cast_memory_op<FPTYPE_out, FPTYPE_in, DEVICE_CPU, DEVICE_GPU>()(arr_out, arr_in, size);
431431
}
432432
else if (device_type_out == base_device::AbacusDevice_t::GpuDevice || device_type_in == base_device::AbacusDevice_t::CpuDevice){
433-
cast_memory_op<FPTYPE_out, FPTYPE_in, DEVICE_GPU, DEVICE_CPU>()(gpu_ctx, cpu_ctx, arr_out, arr_in, size);
433+
cast_memory_op<FPTYPE_out, FPTYPE_in, DEVICE_GPU, DEVICE_CPU>()(arr_out, arr_in, size);
434434
}
435435
else if (device_type_out == base_device::AbacusDevice_t::GpuDevice || device_type_in == base_device::AbacusDevice_t::GpuDevice){
436-
cast_memory_op<FPTYPE_out, FPTYPE_in, DEVICE_GPU, DEVICE_GPU>()(gpu_ctx, gpu_ctx, arr_out, arr_in, size);
436+
cast_memory_op<FPTYPE_out, FPTYPE_in, DEVICE_GPU, DEVICE_GPU>()(arr_out, arr_in, size);
437437
}
438438
}
439439

440440
template <typename FPTYPE>
441441
void delete_memory(FPTYPE* arr, base_device::AbacusDevice_t device_type)
442442
{
443443
if (device_type == base_device::AbacusDevice_t::CpuDevice){
444-
delete_memory_op<FPTYPE, DEVICE_CPU>()(cpu_ctx, arr);
444+
delete_memory_op<FPTYPE, DEVICE_CPU>()(arr);
445445
}
446446
else if (device_type == base_device::AbacusDevice_t::GpuDevice){
447-
delete_memory_op<FPTYPE, DEVICE_GPU>()(gpu_ctx, arr);
447+
delete_memory_op<FPTYPE, DEVICE_GPU>()(arr);
448448
}
449449
}
450450

source/module_base/module_device/memory_op.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ struct cast_memory_op
6262
/// @brief memcpy for multi-device
6363
///
6464
/// Input Parameters
65-
/// \param dev_out : the type of computing device of arr_out
66-
/// \param dev_in : the type of computing device of arr_in
6765
/// \param arr_in : input array
6866
/// \param size : array size
6967
///
@@ -80,9 +78,8 @@ struct delete_memory_op
8078
/// @brief free memory for multi-device
8179
///
8280
/// Input Parameters
83-
/// \param dev : the type of computing device
8481
/// \param arr : the input array
85-
void operator()(const Device* dev, FPTYPE* arr);
82+
void operator()(FPTYPE* arr);
8683
};
8784

8885
template <typename FPTYPE>
@@ -141,7 +138,7 @@ struct synchronize_memory_op<FPTYPE, base_device::DEVICE_GPU, base_device::DEVIC
141138
template <typename FPTYPE>
142139
struct delete_memory_op<FPTYPE, base_device::DEVICE_GPU>
143140
{
144-
void operator()(const base_device::DEVICE_GPU* dev, FPTYPE* arr);
141+
void operator()(FPTYPE* arr);
145142
};
146143
#endif // __CUDA || __UT_USE_CUDA || __ROCM || __UT_USE_ROCM
147144

@@ -153,13 +150,12 @@ struct resize_memory_op_mt
153150
/// @brief Allocate memory for a given pointer. Note this op will free the pointer first.
154151
///
155152
/// Input Parameters
156-
/// \param dev : the type of computing device
157153
/// \param size : array size
158154
/// \param record_string : label for memory record
159155
///
160156
/// Output Parameters
161157
/// \param arr : allocated array
162-
void operator()(const Device* dev, FPTYPE*& arr, const size_t size, const char* record_in = nullptr);
158+
void operator()(FPTYPE*& arr, const size_t size, const char* record_in = nullptr);
163159
};
164160

165161
template <typename FPTYPE, typename Device>
@@ -168,9 +164,8 @@ struct delete_memory_op_mt
168164
/// @brief free memory for multi-device
169165
///
170166
/// Input Parameters
171-
/// \param dev : the type of computing device
172167
/// \param arr : the input array
173-
void operator()(const Device* dev, FPTYPE* arr);
168+
void operator()(FPTYPE* arr);
174169
};
175170

176171
#endif // __DSP

source/module_base/module_device/rocm/memory_op.hip.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void resize_memory_op<FPTYPE, base_device::DEVICE_GPU>::operator()(FPTYPE*& arr,
4545
{
4646
if (arr != nullptr)
4747
{
48-
delete_memory_op<FPTYPE, base_device::DEVICE_GPU>()(dev, arr);
48+
delete_memory_op<FPTYPE, base_device::DEVICE_GPU>()(arr);
4949
}
5050
hipErrcheck(hipMalloc((void**)&arr, sizeof(FPTYPE) * size));
5151
}
@@ -152,7 +152,7 @@ struct cast_memory_op<FPTYPE_out, FPTYPE_in, base_device::DEVICE_CPU, base_devic
152152
};
153153

154154
template <typename FPTYPE>
155-
void delete_memory_op<FPTYPE, base_device::DEVICE_GPU>::operator()(const base_device::DEVICE_GPU* dev, FPTYPE* arr)
155+
void delete_memory_op<FPTYPE, base_device::DEVICE_GPU>::operator()(FPTYPE* arr)
156156
{
157157
hipErrcheck(hipFree(arr));
158158
}

source/module_base/module_device/test/memory_test.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -161,13 +161,13 @@ TEST_F(TestModulePsiMemory, synchronize_memory_op_complex_double_cpu_to_cpu)
161161
TEST_F(TestModulePsiMemory, delete_memory_op_double_cpu)
162162
{
163163
double* h_xx = (double*)malloc(sizeof(double) * xx.size());
164-
delete_memory_double_cpu_op()(cpu_ctx, h_xx);
164+
delete_memory_double_cpu_op()(h_xx);
165165
}
166166

167167
TEST_F(TestModulePsiMemory, delete_memory_op_complex_double_cpu)
168168
{
169169
std::complex<double>* hz_xx = (std::complex<double>*)malloc(sizeof(std::complex<double>) * z_xx.size());
170-
delete_memory_complex_double_cpu_op()(cpu_ctx, hz_xx);
170+
delete_memory_complex_double_cpu_op()(hz_xx);
171171
}
172172

173173
#if __UT_USE_CUDA || __UT_USE_ROCM
@@ -338,13 +338,13 @@ TEST_F(TestModulePsiMemory, synchronize_memory_op_complex_double_gpu_to_gpu)
338338
TEST_F(TestModulePsiMemory, delete_memory_op_double_gpu)
339339
{
340340
thrust::device_ptr<double> d_xx = thrust::device_malloc<double>(xx.size());
341-
delete_memory_double_gpu_op()(gpu_ctx, thrust::raw_pointer_cast(d_xx));
341+
delete_memory_double_gpu_op()(thrust::raw_pointer_cast(d_xx));
342342
}
343343

344344
TEST_F(TestModulePsiMemory, delete_memory_op_complex_double_gpu)
345345
{
346346
thrust::device_ptr<std::complex<double>> dz_xx = thrust::device_malloc<std::complex<double>>(z_xx.size());
347-
delete_memory_complex_double_gpu_op()(gpu_ctx, thrust::raw_pointer_cast(dz_xx));
347+
delete_memory_complex_double_gpu_op()(thrust::raw_pointer_cast(dz_xx));
348348
}
349349

350350
#endif // __UT_USE_CUDA || __UT_USE_ROCM

source/module_base/parallel_device.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void bcast_dev(const Device* ctx, T* object, const int& n, const MPI_Comm& comm,
5858
base_device::memory::synchronize_memory_op<T, Device, base_device::DEVICE_CPU>()(object, object_cpu, n);
5959
if(alloc)
6060
{
61-
base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU>()(cpu_ctx, object_cpu);
61+
base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU>()(object_cpu);
6262
}
6363
}
6464
return;
@@ -95,7 +95,7 @@ void reduce_dev(const Device* ctx, T* object, const int& n, const MPI_Comm& comm
9595
base_device::memory::synchronize_memory_op<T, Device, base_device::DEVICE_CPU>()(object, object_cpu, n);
9696
if(alloc)
9797
{
98-
base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU>()(cpu_ctx, object_cpu);
98+
base_device::memory::delete_memory_op<T, base_device::DEVICE_CPU>()(object_cpu);
9999
}
100100
}
101101
return;

source/module_base/test/blas_connector_test.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ TEST(blas_connector, ScalGpu) {
111111
syncmem_z2z_h2d_op()(result_gpu, result, sizeof(std::complex<double>) * 8);
112112
BlasConnector::scal(size,scale,result_gpu,incx,base_device::AbacusDevice_t::GpuDevice);
113113
syncmem_z2z_d2h_op()(result, result_gpu, sizeof(std::complex<double>) * 8);
114-
delmem_zd_op()(gpu_ctx, result_gpu);
114+
delmem_zd_op()(result_gpu);
115115
// incx is the spacing between elements if result
116116
for (int i = 0; i < size; i++) {
117117
EXPECT_DOUBLE_EQ(answer[i].real(), result[i].real());
@@ -214,8 +214,8 @@ TEST(blas_connector, AxpyGpu) {
214214
syncmem_z2z_h2d_op()(x_gpu, x_const.data(), sizeof(std::complex<double>) * size);
215215
BlasConnector::axpy(size, scale, x_gpu, incx, result_gpu, incy, base_device::AbacusDevice_t::GpuDevice);
216216
syncmem_z2z_d2h_op()(result.data(), result_gpu, sizeof(std::complex<double>) * size);
217-
delmem_zd_op()(gpu_ctx, result_gpu);
218-
delmem_zd_op()(gpu_ctx, x_gpu);
217+
delmem_zd_op()(result_gpu);
218+
delmem_zd_op()(x_gpu);
219219
for (int i = 0; i < size; i++) {
220220
EXPECT_DOUBLE_EQ(answer[i].real(), result[i].real());
221221
EXPECT_DOUBLE_EQ(answer[i].imag(), result[i].imag());
@@ -672,9 +672,9 @@ TEST(blas_connector, GemmGpu) {
672672
a_gpu, lda, b_gpu, ldb, beta_const,
673673
result_gpu, ldc, base_device::AbacusDevice_t::GpuDevice);
674674
syncmem_z2z_d2h_op()(result.data(), result_gpu, sizeof(std::complex<double>) * size_n * ldc);
675-
delmem_zd_op()(gpu_ctx, result_gpu);
676-
delmem_zd_op()(gpu_ctx, a_gpu);
677-
delmem_zd_op()(gpu_ctx, b_gpu);
675+
delmem_zd_op()(result_gpu);
676+
delmem_zd_op()(a_gpu);
677+
delmem_zd_op()(b_gpu);
678678
for (int i = 0; i < size_m; i++)
679679
for (int j = 0; j < size_n; j++) {
680680
EXPECT_DOUBLE_EQ(answer[i + j * ldc].real(),

0 commit comments

Comments
 (0)