Skip to content

Commit 9ca2e6c

Browse files
committed
add the data
1 parent e0258ad commit 9ca2e6c

File tree

4 files changed

+132
-1
lines changed

4 files changed

+132
-1
lines changed

source/module_basis/module_pw/test_gpu/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ if (USE_CUDA)
33
AddTest(
44
TARGET pw_test_gpu
55
LIBS parameter ${math_libs} base planewave device FFTW3::FFTW3_FLOAT
6-
SOURCES pw_test.cpp pw_basis_k_C2C.cpp
6+
SOURCES pw_test.cpp pw_basis_k_batch.cpp
77
)
88
endif()
99

source/module_basis/module_pw/test_gpu/pw_basis_k_C2C.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,3 +276,48 @@ TYPED_TEST(PW_BASIS_K_GPU_TEST, FloatDouble)
276276
EXPECT_NEAR(this->h_rhog[ig].imag(), this->h_rhogout[ig].imag(), 1e-4);
277277
}
278278
}
279+
280+
TYPED_TEST(PW_BASIS_K_GPU_TEST, convulution)
281+
{
282+
using T = typename TestFixture::T;
283+
using Device = typename TestFixture::Device;
284+
ModulePW::PW_Basis_K pwtest;
285+
pwtest.set_device("gpu");
286+
pwtest.set_precision("mixing");
287+
// if (typeid(T) == typeid(float))
288+
// {
289+
// pwtest.fft_bundle.setfft("gpu", "single");
290+
// }
291+
// if (typeid(T) == typeid(double))
292+
// {
293+
std::cout << "Using double precision" << std::endl;
294+
pwtest.fft_bundle.setfft("gpu", "double");
295+
// }
296+
// else
297+
// {
298+
// cout << "Error: Unsupported type" << endl;
299+
// return;
300+
// }
301+
this->init(pwtest);
302+
int startiz = pwtest.startz_current;
303+
const int nx = pwtest.nx;
304+
const int ny = pwtest.ny;
305+
const int nz = pwtest.nz;
306+
const int nplane = pwtest.nplane;
307+
const int npwk = pwtest.npwk[0];;
308+
for (int ixy = 0; ixy < nx * ny; ++ixy)
309+
{
310+
const int offset = ixy * nz + startiz;
311+
const int startz = ixy * nplane;
312+
for (int iz = 0; iz < nplane; ++iz)
313+
{
314+
EXPECT_NEAR(this->tmp[offset + iz].real(), this->h_rhor[startz + iz].real(), 1e-4);
315+
}
316+
}
317+
318+
for (int ig = 0; ig < npwk; ++ig)
319+
{
320+
EXPECT_NEAR(this->h_rhog[ig].real(), this->h_rhogout[ig].real(), 1e-4);
321+
EXPECT_NEAR(this->h_rhog[ig].imag(), this->h_rhogout[ig].imag(), 1e-4);
322+
}
323+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#include "cuda_runtime.h"
2+
#include "fftw3.h"
3+
#include "module_base/module_device/device.h"
4+
#include "module_base/vector3.h"
5+
#include "module_basis/module_pw/pw_basis_k.h"
6+
#include "pw_test.h"
7+
#include <complex>
8+
#include <vector>
9+
#include <gtest/gtest.h>
10+
#include <typeinfo>
11+
12+
using namespace std;
13+
14+
class PW_BASIS_K_BATCH_GPU_TEST : public ::testing::Test
15+
{
16+
public:
17+
const int batch = 10; // Number of batches
18+
const int npwk = 30; // Number of planewaves
19+
const int nxyz = 1000; // Size of the 3D grid
20+
std::vector<int> box_index; // Index mapping for 3D grid
21+
int* d_box_index=nullptr; // Device memory for box_index
22+
std::vector<std::complex<double>> rhog; // Input data for the test,
23+
std::complex<double>* d_rhog = nullptr; // Device memory for rhoG data
24+
std::vector<std::complex<double>> rhor = nullptr; // Device memory for output rhoG data
25+
std::complex<double>* d_rhor = nullptr; // Device memory for output data
26+
void SetUp() override
27+
{
28+
box_index.resize(npwk);
29+
rhog.resize(npwk);
30+
resize_memory_int_gpu_op()(d_box_index, npwk);
31+
resize_memory_complex_gpu_op()(d_rhog, npwk);
32+
// Initialize the box_index and input with some values
33+
int idx = 0;
34+
std::generate_n(box_index.begin(), npwk, [&idx] { return idx * idx++; });
35+
idx =0;
36+
std::generate_n(rhog.begin(), npwk, [&idx] { return std::complex<double>(sqrt(idx), 1/(idx+1)); });
37+
synchronize_memory_int_h2d_op()(d_box_index, box_index.data(), npwk);
38+
synchronize_memory_complex_h2d_op()(d_rhog, rhog.data(), npwk);
39+
// Initialize the box_index with some values
40+
41+
// resize_memory_int_gpu_op
42+
}
43+
void TearDown() override
44+
{
45+
box_index.clear();
46+
rhog.clear();
47+
delete_memory_int_gpu_op()(d_box_index);
48+
delete_memory_complex_gpu_op()(d_rhog);
49+
}
50+
};
51+
52+
TEST_F(PW_BASIS_K_BATCH_GPU_TEST,convulution)
53+
{
54+
for (int i = 0; i < npwk; ++i)
55+
{
56+
EXPECT_EQ(box_index[i], i * i);
57+
}
58+
}

source/module_basis/module_pw/test_gpu/pw_test.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#define __PWTEST
33
#include "gtest/gtest.h"
44
#include <iostream>
5+
#include "module_base/module_device/memory_op.h"
6+
#include "module_basis/module_pw/kernels/pw_op.h"
57
using namespace std;
68
extern int nproc_in_pool, rank_in_pool;
79
extern string precision_flag, device_flag;
@@ -33,5 +35,31 @@ class PWTEST: public testing::Test
3335
}
3436
void TearDown(){}
3537
};
38+
using set_3d_fft_box_cpu_op = ModulePW::set_3d_fft_box_op<double, base_device::DEVICE_CPU>;
39+
using set_3d_fft_box_gpu_op = ModulePW::set_3d_fft_box_op<double, base_device::DEVICE_GPU>;
40+
using set_recip_to_real_output_cpu_op = ModulePW::set_recip_to_real_output_op<double, base_device::DEVICE_CPU>;
41+
using set_recip_to_real_output_gpu_op = ModulePW::set_recip_to_real_output_op<double, base_device::DEVICE_GPU>;
42+
using set_real_to_recip_output_cpu_op = ModulePW::set_real_to_recip_output_op<double, base_device::DEVICE_CPU>;
43+
using set_real_to_recip_output_gpu_op = ModulePW::set_real_to_recip_output_op<double, base_device::DEVICE_GPU>;
3644

45+
using resize_memory_complex_gpu_op
46+
= base_device::memory::resize_memory_op<std::complex<double>, base_device::DEVICE_GPU>;
47+
using delete_memory_complex_gpu_op
48+
= base_device::memory::delete_memory_op<std::complex<double>, base_device::DEVICE_GPU>;
49+
using synchronize_memory_complex_h2d_op = base_device::memory::
50+
synchronize_memory_op<std::complex<double>, base_device::DEVICE_GPU, base_device::DEVICE_CPU>;
51+
using synchronize_memory_complex_d2h_op = base_device::memory::
52+
synchronize_memory_op<std::complex<double>, base_device::DEVICE_CPU, base_device::DEVICE_GPU>;
53+
54+
using resize_memory_double_gpu_op = base_device::memory::resize_memory_op<double, base_device::DEVICE_GPU>;
55+
using delete_memory_double_gpu_op = base_device::memory::delete_memory_op<double, base_device::DEVICE_GPU>;
56+
using synchronize_memory_double_h2d_op
57+
= base_device::memory::synchronize_memory_op<double, base_device::DEVICE_GPU, base_device::DEVICE_CPU>;
58+
using synchronize_memory_double_d2h_op
59+
= base_device::memory::synchronize_memory_op<double, base_device::DEVICE_CPU, base_device::DEVICE_GPU>;
60+
61+
using delete_memory_int_gpu_op = base_device::memory::delete_memory_op<int, base_device::DEVICE_GPU>;
62+
using resize_memory_int_gpu_op = base_device::memory::resize_memory_op<int, base_device::DEVICE_GPU>;
63+
using synchronize_memory_int_h2d_op
64+
= base_device::memory::synchronize_memory_op<int, base_device::DEVICE_GPU, base_device::DEVICE_CPU>;
3765
#endif

0 commit comments

Comments
 (0)