Skip to content

Commit

Permalink
Update the cuda example to use GPU buffers on the Read side
Browse files Browse the repository at this point in the history
  • Loading branch information
anagainaru committed Jan 28, 2022
1 parent 4e24af7 commit 1f258e0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion examples/cuda/cudaWriteRead.cu
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ int BPRead(const std::string fname, const size_t N, int nSteps)
adios2::Engine bpReader = io.Open(fname, adios2::Mode::Read);

unsigned int step = 0;
float *gpuSimData;
cudaMalloc(&gpuSimData, N * sizeof(float));
cudaMemset(gpuSimData, 0, N);
for (; bpReader.BeginStep() == adios2::StepStatus::OK; ++step)
{
auto data = io.InquireVariable<float>("data");
Expand All @@ -77,8 +80,10 @@ int BPRead(const std::string fname, const size_t N, int nSteps)
const adios2::Box<adios2::Dims> sel(start, count);
data.SetSelection(sel);

bpReader.Get(data, simData.data());
data.SetMemorySpace(adios2::MemorySpace::CUDA);
bpReader.Get(data, gpuSimData, adios2::Mode::Deferred);
bpReader.EndStep();
cudaMemcpy(simData.data(), gpuSimData, N, cudaMemcpyDeviceToHost);
std::cout << "Simualation step " << step << " : ";
std::cout << simData.size() << " elements: " << simData[1] << std::endl;
}
Expand Down

0 comments on commit 1f258e0

Please sign in to comment.