AdaptiveCpp / AdaptiveCpp/AdaptiveCpp

make_async_writeback_view() vs make_async_view()

Open
#846 1 comment 0 reactions 0 assignees View on GitHub
discussion
Dominant language
C++
Stars
1.9k
Forks
228
Avg merge
4d 1h
Merged PRs (30d)
25

Description

Hi,

I've stumbled across this blogpost [about buffers in hipsycl](https://hipsycl.github.io/hipsycl/extension/hipsycl-091-buffer-policies/).

For me it is not yet clear what the difference between the usage of make_async_writeback_view() and make_async_view() is.

Both operate on the actual data and **do not** copy it to internal storage (only relevant for CPUs?).
What does that mean in the context of running it on a GPU?

From my testing/understanding when running on a GPU, it does copy the data to the GPU RAM as I would've assumed to have the best performance.

What about the "optional" writeback? Is this only relevant for GPUs also?

My use case is a big vector of data which needs to be operated on and also written back to.

Based on my current knowledge I assumed make_async_writeback_view() would make the most sense.

When running my program I noticed I get a SEGFAULT when using make_async_writeback_view(), but not make_async_view() or make_async_buffer() (tested out of curiosity).

Here is my sample program. Is there anything completely wrong/that could be improved?

```
#include
#include
#include
using namespace sycl;

int main()
{
queue myQueue;
size_t size = 3000;
auto dims = sycl::range<3>{64, 64, 64};
std::vector> vectorOfBuffers;
std::vector vecWithData;
vecWithData.reserve(size * 64 * 64 * 64);

for (int index = 0; index < size * 64 * 64 * 64; index++)
{
sycl::float2 temp{1.0f, 0.0f};
vecWithData.push_back(temp);
}

std::cout << "vector size " << vecWithData.size() << std::endl;

for (int index = 0; index < size; index++)
{
std::cout << "Accessing index " << index * 64 * 64 * 64 << " out of " << vecWithData.size() << std::endl;
// Produces SEGFAULT
sycl::buffer complexIn = sycl::make_async_writeback_view(&vecWithData[index * 64 * 64 * 64], dims, myQueue);
// Both don't produce a SEGFAULT
// sycl::buffer complexIn = sycl::make_async_view(&vecWithData[index * 64 * 64 * 64], dims);
// sycl::buffer complexIn = sycl::make_async_buffer(&vecWithData[index * 64 * 64 * 64], dims);
myQueue.submit([&](sycl::handler &cgh)
{
sycl::accessor vec_acc{complexIn, cgh, sycl::read_write};
cgh.parallel_for(dims, [=](sycl::id<3> index) {
vec_acc[index] = vec_acc[index] * 3.0f;
}); });

vectorOfBuffers.push_back(complexIn);
}
myQueue.wait();
std::cout
<< "Finished" << std::endl;
getchar();
}
```

Any help appreciated!

Cheers

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.