Skip to content

Commit 6e33836

Browse files
terdnerJoeOster
andauthored
Updated coding style to use accessor instead of get_access calls (#169)
* initial commit of openMP example. Signed-off-by: todd.erdner <[email protected]> * Initial commit of the dpc_reduce Signed-off-by: todd.erdner <[email protected]> * added guid to sample.json Signed-off-by: todd.erdner <[email protected]> * fixed sample.json files. Signed-off-by: todd.erdner <[email protected]> * fixed the include files. Somehow I copied a slightly old repo and it still had <chrono> and the omp_common.hpp file. They have been removed. Signed-off-by: todd.erdner <[email protected]> * added license.txt file ran through formating tool one more time removed all calls to "std::endl" and replaced with " \n" Signed-off-by: todd.erdner <[email protected]> * renamed license.txt to License.txt Signed-off-by: todd.erdner <[email protected]> * added "ciTests" to the sample.json file. It passed the check. Signed-off-by: todd.erdner <[email protected]> * fixed make error Signed-off-by: todd.erdner <[email protected]> * fixed sample.json Signed-off-by: todd.erdner <[email protected]> * removed "2020" from the License.txt file due to update guidelines. Signed-off-by: todd.erdner <[email protected]> * added comment regarding where you can find dpc_common in both files per Paul's comments. Signed-off-by: todd.erdner <[email protected]> * Modified names of the functions to represent what they do (ie. calc_pi_*) per suggestion from Paul. Signed-off-by: todd.erdner <[email protected]> * initial check-in to the C++ repo Signed-off-by: todd.erdner <[email protected]> * put correct comment on dpc_common.hpp Signed-off-by: todd.erdner <[email protected]> * added commenting indicating where they can find corresponding include files. Signed-off-by: todd.erdner <[email protected]> * added comment line Signed-off-by: todd.erdner <[email protected]> * removed openMP repo from DPC++ as it will be moved to C++ directory * Update README.md * Update README.md * Update README.md * Update README.md * fixed category line in sample.json to match exact text expected. * removing openMP from the DPC directory. It has been moved to C++ directory. * fixed tf_init call Signed-off-by: todd.erdner <[email protected]> * removed all calls into PSTL internal logic. This is what was causing fails between beta08 and beta09. Signed-off-by: todd.erdner <[email protected]> * fixed env variable to run on CPU Signed-off-by: todd.erdner <[email protected]> * update Readme file to include information about setting env variable to allocate more memory for any runs on the cpu Signed-off-by: todd.erdner <[email protected]> * added option in Cmake file to support unnamed lambda option. You need this to compile if the environment doesn't have this set by default. Signed-off-by: todd.erdner <[email protected]> * path to output file from compile has changed. it no longer seems to create the src directory. * started to remove get_access and change it to accessor name() Signed-off-by: todd.erdner <[email protected]> * fixed remaining get_access Signed-off-by: todd.erdner <[email protected]> * removed commented out old code Signed-off-by: todd.erdner <[email protected]> Co-authored-by: JoeOster <[email protected]>
1 parent 8a0473d commit 6e33836

File tree

1 file changed

+27
-31
lines changed
  • DirectProgramming/DPC++/ParallelPatterns/dpc_reduce/src

1 file changed

+27
-31
lines changed

DirectProgramming/DPC++/ParallelPatterns/dpc_reduce/src/main.cpp

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// SPDX-License-Identifier: MIT
55
// =============================================================
66
#include <mpi.h>
7-
87
#include <CL/sycl.hpp>
98
#include <iomanip> // setprecision library
109
#include <iostream>
@@ -72,7 +71,7 @@ float calc_pi_dpstd_native(size_t num_steps, Policy&& policy) {
7271
buffer<float, 1> buf{data, range<1>{num_steps}};
7372

7473
policy.queue().submit([&](handler& h) {
75-
auto writeresult = buf.get_access<access::mode::write>(h);
74+
accessor writeresult(buf,h,write_only);
7675
h.parallel_for(range<1>{num_steps}, [=](id<1> idx) {
7776
float x = ((float)idx[0] - 0.5) / (float)num_steps;
7877
writeresult[idx[0]] = 4.0f / (1.0 + x * x);
@@ -83,15 +82,18 @@ float calc_pi_dpstd_native(size_t num_steps, Policy&& policy) {
8382
// Single task is needed here to make sure
8483
// data is not written over.
8584
policy.queue().submit([&](handler& h) {
86-
auto a = buf.get_access<access::mode::read_write>(h);
85+
accessor a(buf,h);
8786
h.single_task([=]() {
8887
for (int i = 1; i < num_steps; i++) a[0] += a[i];
8988
});
9089
});
9190
policy.queue().wait();
9291

93-
float mynewresult =
94-
buf.get_access<access::mode::read>()[0] / (float)num_steps;
92+
93+
// float mynewresult = buf.get_access<access::mode::read>()[0] / (float)num_steps;
94+
host_accessor answer(buf,read_only) ;
95+
float mynewresult = answer[0]/(float)num_steps;
96+
9597
return mynewresult;
9698
}
9799

@@ -109,7 +111,7 @@ float calc_pi_dpstd_native2(size_t num_steps, Policy&& policy, int group_size) {
109111

110112
// fill buffer with calculations
111113
policy.queue().submit([&](handler& h) {
112-
auto writeresult = buf.get_access<access::mode::write>(h);
114+
accessor writeresult(buf, h, write_only);
113115
h.parallel_for(range<1>{num_steps}, [=](id<1> idx) {
114116
float x = ((float)idx[0] - 0.5) / (float)num_steps;
115117
writeresult[idx[0]] = 4.0f / (1.0 + x * x);
@@ -126,8 +128,8 @@ float calc_pi_dpstd_native2(size_t num_steps, Policy&& policy, int group_size) {
126128
buffer<float, 1> bufc{c, range<1>{num_groups}};
127129
for (int j = 0; j < num_groups; j++) {
128130
policy.queue().submit([&](handler& h) {
129-
auto my_a = buf.get_access<access::mode::read>(h);
130-
auto my_c = bufc.get_access<access::mode::write>(h);
131+
accessor my_a(buf,h,read_only);
132+
accessor my_c(bufc,h,write_only);
131133
h.single_task([=]() {
132134
for (int i = 0 + group_size * j; i < group_size + group_size * j; i++)
133135
my_c[j] += my_a[i];
@@ -136,7 +138,7 @@ float calc_pi_dpstd_native2(size_t num_steps, Policy&& policy, int group_size) {
136138
}
137139
policy.queue().wait();
138140

139-
auto src = bufc.get_access<access::mode::read>();
141+
host_accessor src(bufc,read_only);
140142

141143
// Sum up results on CPU
142144
float mynewresult = 0.0;
@@ -299,7 +301,8 @@ float calc_pi_dpstd_native3(size_t num_steps, int groups, Policy&& policy) {
299301

300302
// fill the buffer with the calculation using parallel for
301303
policy.queue().submit([&](handler& h) {
302-
auto writeresult = buf.get_access<access::mode::write>(h);
304+
accessor writeresult(buf,h,write_only);
305+
303306
h.parallel_for(range<1>{num_steps}, [=](id<1> idx) {
304307
float x = (float)idx[0] / (float)num_steps;
305308
writeresult[idx[0]] = 4.0f / (1.0f + x * x);
@@ -343,9 +346,8 @@ float calc_pi_dpstd_native3(size_t num_steps, int groups, Policy&& policy) {
343346
auto local_reduce_event =
344347
policy.queue().submit([&buf, &temp_buf, &brick_reduce, &tf_init,
345348
num_steps, n_groups, workgroup_size](handler& h) {
346-
auto access_buf = buf.template get_access<access::mode::read_write>(h);
347-
auto temp_acc =
348-
temp_buf.template get_access<access::mode::discard_write>(h);
349+
accessor access_buf(buf,h);
350+
accessor temp_acc(temp_buf,h,write_only);
349351
// Create temporary local buffer
350352
accessor<float, 1, access::mode::read_write, access::target::local>
351353
temp_buf_local(range<1>(workgroup_size), h);
@@ -373,8 +375,7 @@ float calc_pi_dpstd_native3(size_t num_steps, int groups, Policy&& policy) {
373375
reduce_event = policy.queue().submit([&reduce_event, &temp_buf, &combine,
374376
countby2, n_groups](handler& h) {
375377
h.depends_on(reduce_event);
376-
auto temp_acc =
377-
temp_buf.template get_access<access::mode::read_write>(h);
378+
accessor temp_acc(temp_buf,h);
378379
h.parallel_for(range<1>(n_groups), [=](item<1> item_id) mutable {
379380
auto global_idx = item_id.get_linear_id();
380381

@@ -388,10 +389,9 @@ float calc_pi_dpstd_native3(size_t num_steps, int groups, Policy&& policy) {
388389
countby2 *= 2;
389390
} while (countby2 < n_groups);
390391
}
391-
392-
float answer = temp_buf.template get_access<access::mode::read>()[0];
393-
result = answer / (float)num_steps;
394-
return result;
392+
393+
host_accessor answer(temp_buf,read_only) ;
394+
return answer[0]/(float)num_steps;
395395
}
396396

397397
// dpstd_native4 fills a buffer with number 1...num_steps and then
@@ -406,7 +406,7 @@ float calc_pi_dpstd_native4(size_t num_steps, int groups, Policy&& policy) {
406406

407407
// fill buffer with 1...num_steps
408408
policy.queue().submit([&](handler& h) {
409-
auto writeresult = buf2.get_access<access::mode::write>(h);
409+
accessor writeresult(buf2,h);
410410
h.parallel_for(range<1>{num_steps},
411411
[=](id<1> idx) { writeresult[idx[0]] = (float)idx[0]; });
412412
});
@@ -453,9 +453,8 @@ float calc_pi_dpstd_native4(size_t num_steps, int groups, Policy&& policy) {
453453
policy.queue().submit([&buf2, &temp_buf, &brick_reduce, &tf_init,
454454
num_steps, n_groups, workgroup_size](handler& h) {
455455
// grab access to the previous input
456-
auto access_buf = buf2.template get_access<access::mode::read_write>(h);
457-
auto temp_acc =
458-
temp_buf.template get_access<access::mode::discard_write>(h);
456+
accessor access_buf(buf2,h);
457+
accessor temp_acc(temp_buf,h,write_only);
459458
// Create temporary local buffer
460459
accessor<float, 1, access::mode::read_write, access::target::local>
461460
temp_buf_local(range<1>(workgroup_size), h);
@@ -484,8 +483,7 @@ float calc_pi_dpstd_native4(size_t num_steps, int groups, Policy&& policy) {
484483
reduce_event = policy.queue().submit([&reduce_event, &temp_buf, &combine,
485484
countby2, n_groups](handler& h) {
486485
h.depends_on(reduce_event);
487-
auto temp_acc =
488-
temp_buf.template get_access<access::mode::read_write>(h);
486+
accessor temp_acc(temp_buf,h);
489487
h.parallel_for(range<1>(n_groups), [=](item<1> item_id) mutable {
490488
auto global_idx = item_id.get_linear_id();
491489

@@ -499,10 +497,8 @@ float calc_pi_dpstd_native4(size_t num_steps, int groups, Policy&& policy) {
499497
countby2 *= 2;
500498
} while (countby2 < n_groups);
501499
}
502-
float answer = temp_buf.template get_access<access::mode::read_write>()[0];
503-
result = answer / (float)num_steps;
504-
505-
return result;
500+
host_accessor answer(temp_buf,read_only) ;
501+
return answer[0]/(float)num_steps;
506502
}
507503

508504
// This function shows the use of two different DPC++ library calls.
@@ -604,7 +600,7 @@ void mpi_native(float* results, int rank_num, int num_procs,
604600
// constructed at runtime.
605601
q.submit([&](handler& h) {
606602
// Accessors are used to get access to the memory owned by the buffers.
607-
auto results_accessor = results_buf.get_access<access::mode::write>(h);
603+
accessor results_accessor(results_buf,h,write_only);
608604
// Each kernel calculates a partial of the number Pi in parallel.
609605
h.parallel_for(num_items, [=](id<1> k) {
610606
float x = ((float)rank_num / (float)num_procs) + (float)k * dx + dx2;
@@ -786,7 +782,7 @@ int main(int argc, char** argv) {
786782
std::cout << "mpi transform_reduce:\t";
787783
std::cout << std::setprecision(3) << "PI =" << pi;
788784
std::cout << " in " << stop7 << " seconds\n";
789-
std::cout << "succes\n";
785+
std::cout << "success\n";
790786
}
791787

792788
MPI_Finalize();

0 commit comments

Comments
 (0)