MCPcopy Create free account
hub / github.com/AMReX-Codes/amrex / async_test

Function async_test

Tests/GPU/Vector/main.cpp:60–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60void async_test()
61{
62 {
63 int N = 32*10; // 10 warps. Arbitrarily chosen.
64
65 Gpu::AsyncVector<Real> vec(N, 0.0);
66 auto ptr = vec.dataPtr();
67
68 // Compute-bound test. Should take some time.
69 amrex::ParallelFor(N, [=] AMREX_GPU_DEVICE (int n) noexcept
70 {
71 Real y = ptr[n];
72 Real x = 1.0;
73 for (int n = 0; n < 20; ++n) {
74 Real dx = -(x*x-y) / (2.*x);
75 x += dx;
76 }
77 ptr[n] = x;
78
79 if (n == 0)
80#ifdef AMREX_USE_GPU
81 { AMREX_DEVICE_PRINTF(" Answer = %1.16f -- should print second.\n", ptr[n]); }
82#else
83 { std::cout << "Answer = " << ptr[n] << " -- should print first." << '\n'; }
84#endif
85
86 });
87 }
88
89 // Async Vector now out of scope. Still completes correctly.
90
91#ifdef AMREX_USE_GPU
92 amrex::Print() << "Async Syncing -- should print first." << '\n';
93#else
94 amrex::Print() << "Async Syncing -- should print second." << '\n';
95#endif
96
97 Gpu::Device::streamSynchronize();
98}
99
100int main (int argc, char* argv[])
101{

Callers 1

mainFunction · 0.85

Calls 4

PrintClass · 0.85
streamSynchronizeFunction · 0.85
ParallelForFunction · 0.50
dataPtrMethod · 0.45

Tested by

no test coverage detected