Skip to content

Commit e88ba9f

Browse files
fknorrpsalz
authored andcommitted
Modernize accessor creation in documentation
1 parent 0d87461 commit e88ba9f

File tree

6 files changed

+28
-30
lines changed

6 files changed

+28
-30
lines changed

README.md

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ Celerity without much hassle. If you know SYCL already, this will probably
2828
look very familiar to you:
2929

3030
```cpp
31-
celerity::buffer<float, 1> buf(celerity::range<1>(1024));
31+
celerity::buffer<float> buf{celerity::range<1>{1024}};
3232
queue.submit([=](celerity::handler& cgh) {
33-
auto acc = buf.get_access<sycl::access::mode::discard_write>(
34-
cgh,
35-
celerity::access::one_to_one() // 1
36-
);
37-
cgh.parallel_for<class MyKernel>(
38-
celerity::range<1>(1024), // 2
39-
[=](celerity::item<1> item) { // 3
40-
acc[item] = sycl::sin(item[0] / 1024.f); // 4
41-
});
33+
celerity::accessor acc{buf, cgh,
34+
celerity::access::one_to_one{}, // 1
35+
celerity::write_only, celerity::no_init};
36+
cgh.parallel_for<class MyKernel>(
37+
celerity::range<1>{1024}, // 2
38+
[=](celerity::item<1> item) { // 3
39+
acc[item] = sycl::sin(item[0] / 1024.f); // 4
40+
});
4241
});
4342
```
4443

docs/host-tasks.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@ cgh.host_task(celerity::on_master_node, []{ ... });
2424
2525
Buffers can be accessed in the usual fashion, although there is no `item` structure passed into the kernel. Instead,
2626
when constructing an accessor, a `fixed` or `all` range mapper is used to specify the range of interest. Also,
27-
the access target must be set to `host_buffer` explicitly in the call to `get_access`:
27+
the `*_host_task` selector must be used for selecting the access mode.
2828
2929
```cpp
3030
celerity::distr_queue q;
3131
celerity::buffer<float, 1> result;
3232
q.submit([=](celerity::handler &cgh) {
33-
auto acc = result.get_access<celerity::access_mode::read,
34-
celerity::target::host_task>(cgh,
35-
celerity::access::all());
33+
celerity::accessor acc{buffer, cgh, celerity::access::all{},
34+
celerity::read_only_host_task};
3635
cgh.host_task(celerity::on_master_node, [=]{
3736
printf("The result is %g\n", acc[0]);
3837
});
@@ -148,9 +147,9 @@ splitting them along the first (slowest) dimension into contiguous memory portio
148147
celerity::distr_queue q;
149148
celerity::buffer<float, 2> buf;
150149
q.submit([=](celerity::handler& cgh) {
151-
auto acc = buffer.get_access<celerity::access_mode::read,
152-
celerity::target::host_task>(cgh,
153-
celerity::experimental::access::even_split<2>());
150+
celerity::accessor acc{buffer, cgh,
151+
celerity::experimental::access::even_split<2>{},
152+
celerity::read_only_host_task};
154153
cgh.host_task(celerity::experimental::collective,
155154
[=](celerity::experimental::collective_partition part) {
156155
auto aw = acc.get_allocation_window(part);

docs/pitfalls.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ celerity::distr_queue q;
5050
celerity::buffer<int, 1> buf;
5151
bool flag = false;
5252
q.submit(celerity::allow_by_ref, [=, &flag](celerity::handler &cgh) {
53-
auto acc = buf.get_access<celerity::access_mode::read,
54-
celerity::target::host_task>(cgh, celerity::access::all<1>());
53+
celerity::accessor acc{buffer, cgh, celerity::access::all{},
54+
celerity::read_only_host_task};
5555
cgh.host_task(celerity::on_master_node, [=, &flag] {
5656
flag = acc[0] == 42;
5757
});

docs/range-mappers.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,24 @@ vice-versa.
3131
3232
### Usage
3333
34-
Range mappers are passed as the second argument into a call to
35-
`celerity::buffer::get_access`. This means that the spatial accessing
34+
Range mappers are passed as the third argument when constructing a
35+
`celerity::accessor`. This means that the spatial accessing
3636
behavior of a kernel can vary from buffer to buffer. For example, the
3737
following command group specifies two different range mappers (whose
3838
definition is omitted) for buffers `buf_a` and `buf_b`:
3939
4040
```cpp
4141
queue.submit([=](celerity::handler& cgh) {
42-
auto r_a = buf_a.get_access<celerity::access_mode::read>(cgh, my_mapper);
43-
auto dw_b = buf_b.get_access<celerity::access_mode::discard_write>(cgh, other_mapper);
42+
celerity::accessor r_a{cgh, buf_a, my_mapper, celerity::read_only};
43+
celerity::accessor dw_b{cgh, buf_b, other_mapper, celerity::write_only, celerity::no_init};
4444
4545
cgh.parallel_for<>(...);
4646
});
4747
```
4848

4949
> **NOTE**: In Celerity 0.1, range mappers were only used for compute kernels.
5050
> For master-node tasks (then called master-access tasks), explicit buffer ranges
51-
> were passed to `get_access`. These APIs have been unified and range mappers
51+
> were passed to `buffer::get_access`. These APIs have been unified and range mappers
5252
> are now required in all cases. In master node tasks, the `all` and `fixed`
5353
> mappers provide equivalent functionality to explicit ranges.
5454

docs/reductions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The following distributed program computes the sum from 0 to 999 in `sum_buf` us
1313
celerity::distr_queue q;
1414
celerity::buffer<size_t, 1> sum_buf{{1}};
1515
q.submit([=](celerity::handler& cgh) {
16-
auto rd = celerity::reduction(sum_buf, cgh, cl::sycl::plus<size_t>{},
16+
auto rd = celerity::reduction(sum_buf, cgh, sycl::plus<size_t>{},
1717
celerity::property::reduction::initialize_to_identity{});
1818
cgh.parallel_for(celerity::range<1>{1000}, rd,
1919
[=](celerity::item<1> item, auto& sum) { sum += item.get_id(0); });

docs/tutorial.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ aforementioned buffer accessors. Let's create these now - replace the TODO
170170
before the kernel function with the following:
171171
172172
```cpp
173-
auto r_input = input_buf.get_access<celerity::access_mode::read>(cgh, celerity::access::neighborhood(1, 1));
174-
auto dw_edge = edge_buf.get_access<celerity::access_mode::discard_write>(cgh, celerity::access::one_to_one());
173+
celerity::accessor r_input{input_buf, cgh, celerity::access::neighborhood{1, 1}, celerity::read_only};
174+
celerity::accessor dw_edge{edge_buf, cgh, celerity::access::one_to_one{}, celerity::write_only, celerity::no_init};
175175
```
176176

177177
If you have worked with SYCL before, these buffer accessors will look
@@ -183,8 +183,8 @@ the previous contents of `edge_buf`, which is why we choose to discard them
183183
and use the `discard_write` access mode.
184184

185185
So far everything works exactly as it would in a SYCL application. However,
186-
there is a second parameter passed into the `celerity::buffer::get_access`
187-
function that is not present in its SYCL counterpart. In fact, this parameter
186+
there is an additional parameter passed into the `accessor`
187+
constructor that is not present in its SYCL counterpart. In fact, this parameter
188188
represents one of Celerity's most important API additions: While access modes
189189
tell the runtime system how a kernel intends to access a buffer, it does not
190190
include any information about _where_ a kernel will access said buffer. In
@@ -252,7 +252,7 @@ your `main()` function:
252252

253253
```cpp
254254
queue.submit([=](celerity::handler& cgh) {
255-
auto out = edge_buf.get_access<celerity::access_mode::read, celerity::target::host_task>(cgh, celerity::access::all());
255+
celerity::accessor out{edge_buf, cgh, celerity::access::all{}, celerity::read_only_host_task};
256256
cgh.host_task(celerity::on_master_node, [=]() {
257257
stbi_write_png("result.png", img_width, img_height, 1, out.get_pointer(), 0);
258258
});

0 commit comments

Comments
 (0)