Skip to content

Updated coding style to use accessor instead of get_access calls #169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 39 commits into from
Sep 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
898e959
initial commit of openMP example.
terdner Aug 11, 2020
5324ae6
Initial commit of the dpc_reduce
terdner Aug 11, 2020
d61768f
added guid to sample.json
terdner Aug 12, 2020
0f155d3
fixed sample.json files.
terdner Aug 12, 2020
4c65ac4
fixed the include files. Somehow I copied a slightly old repo and it…
terdner Aug 12, 2020
d676c19
added license.txt file ran through formating tool one more time remov…
terdner Aug 12, 2020
f640fa8
renamed license.txt to License.txt
terdner Aug 12, 2020
41f93e6
added "ciTests" to the sample.json file. It passed the check.
terdner Aug 12, 2020
587f7dd
fixed make error
terdner Aug 13, 2020
2e8cd49
fixed sample.json
terdner Aug 13, 2020
dd29f84
removed "2020" from the License.txt file due to update guidelines.
terdner Aug 18, 2020
5c0c2c6
added comment regarding where you can find dpc_common in both files p…
terdner Aug 18, 2020
5d33696
Modified names of the functions to represent what they do (ie. calc_p…
terdner Aug 18, 2020
b64226e
initial check-in to the C++ repo
terdner Aug 19, 2020
337a695
put correct comment on dpc_common.hpp
terdner Aug 21, 2020
b8a1501
added commenting indicating where they can find corresponding include…
terdner Aug 21, 2020
fa136fe
added comment line
terdner Aug 21, 2020
51f6f53
removed openMP repo from DPC++ as it will be moved to C++ directory
terdner Aug 21, 2020
45873ea
Update README.md
terdner Aug 21, 2020
883b68e
Update README.md
terdner Aug 21, 2020
e5b08dc
Update README.md
terdner Aug 21, 2020
56a9907
Update README.md
terdner Aug 21, 2020
9fc1933
fixed category line in sample.json to match exact text expected.
terdner Aug 24, 2020
3a902f3
Merge branch 'master' of https://github.com/terdner/oneAPI-samples
terdner Aug 24, 2020
5645a6b
Merge branch 'master' into master
JoeOster Aug 24, 2020
ae020b6
removing openMP from the DPC directory. It has been moved to C++ dir…
terdner Aug 24, 2020
51a0543
fixed tf_init call
terdner Aug 25, 2020
3607ed5
Merge pull request #2 from oneapi-src/master
terdner Aug 25, 2020
2e6b7d6
removed all calls into PSTL internal logic. This is what was causing…
terdner Aug 27, 2020
64a894a
Merge branch 'master' of https://github.com/terdner/oneAPI-samples
terdner Aug 27, 2020
db810f4
Merge branch 'master' of https://github.com/oneapi-src/oneAPI-samples…
terdner Sep 4, 2020
6fd6b8b
fixed env variable to run on CPU
terdner Sep 4, 2020
bbb7c80
update Readme file to include information about setting
terdner Sep 4, 2020
947ea80
Merge pull request #4 from oneapi-src/master
terdner Sep 9, 2020
87f8a11
added option in Cmake file to support unnamed lambda option. You ne…
terdner Sep 11, 2020
59ef0ab
path to output file from compile has changed. it no longer seems to …
terdner Sep 11, 2020
0ea231b
started to remove get_access and change it to accessor name()
terdner Sep 18, 2020
0c577d3
fixed remaining get_access
terdner Sep 18, 2020
dd2c016
removed commented out old code
terdner Sep 18, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ if (NOT CMAKE_BUILD_TYPE)
FORCE)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fsycl -std=c++17")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -fsycl -std=c++17 -fsycl-unnamed-lambda")

set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -ltbb -lsycl")

add_executable (dpc_reduce src/main.cpp)

add_custom_target (run
COMMAND CL_CONFIG_CPU_FORCE_PRIVATE_MEM_SIZE=16MB dpc_reduce
COMMAND CL_CONFIG_CPU_FORCE_PRIVATE_MEM_SIZE=16MB ./dpc_reduce
WORKING_DIRECTORY ${CMAKE_PROJECT_DIR}
)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"cd build",
"cmake ..",
"make",
"CL_CONFIG_CPU_FORCE_PRIVATE_MEM_SIZE=16MB ./src/dpc_reduce"
"CL_CONFIG_CPU_FORCE_PRIVATE_MEM_SIZE=16MB ./dpc_reduce"
]
}
]
Expand Down
58 changes: 27 additions & 31 deletions DirectProgramming/DPC++/ParallelPatterns/dpc_reduce/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-License-Identifier: MIT
// =============================================================
#include <mpi.h>

#include <CL/sycl.hpp>
#include <iomanip> // setprecision library
#include <iostream>
Expand Down Expand Up @@ -72,7 +71,7 @@ float calc_pi_dpstd_native(size_t num_steps, Policy&& policy) {
buffer<float, 1> buf{data, range<1>{num_steps}};

policy.queue().submit([&](handler& h) {
auto writeresult = buf.get_access<access::mode::write>(h);
accessor writeresult(buf,h,write_only);
h.parallel_for(range<1>{num_steps}, [=](id<1> idx) {
float x = ((float)idx[0] - 0.5) / (float)num_steps;
writeresult[idx[0]] = 4.0f / (1.0 + x * x);
Expand All @@ -83,15 +82,18 @@ float calc_pi_dpstd_native(size_t num_steps, Policy&& policy) {
// Single task is needed here to make sure
// data is not written over.
policy.queue().submit([&](handler& h) {
auto a = buf.get_access<access::mode::read_write>(h);
accessor a(buf,h);
h.single_task([=]() {
for (int i = 1; i < num_steps; i++) a[0] += a[i];
});
});
policy.queue().wait();

float mynewresult =
buf.get_access<access::mode::read>()[0] / (float)num_steps;

// float mynewresult = buf.get_access<access::mode::read>()[0] / (float)num_steps;
host_accessor answer(buf,read_only) ;
float mynewresult = answer[0]/(float)num_steps;

return mynewresult;
}

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

// fill buffer with calculations
policy.queue().submit([&](handler& h) {
auto writeresult = buf.get_access<access::mode::write>(h);
accessor writeresult(buf, h, write_only);
h.parallel_for(range<1>{num_steps}, [=](id<1> idx) {
float x = ((float)idx[0] - 0.5) / (float)num_steps;
writeresult[idx[0]] = 4.0f / (1.0 + x * x);
Expand All @@ -126,8 +128,8 @@ float calc_pi_dpstd_native2(size_t num_steps, Policy&& policy, int group_size) {
buffer<float, 1> bufc{c, range<1>{num_groups}};
for (int j = 0; j < num_groups; j++) {
policy.queue().submit([&](handler& h) {
auto my_a = buf.get_access<access::mode::read>(h);
auto my_c = bufc.get_access<access::mode::write>(h);
accessor my_a(buf,h,read_only);
accessor my_c(bufc,h,write_only);
h.single_task([=]() {
for (int i = 0 + group_size * j; i < group_size + group_size * j; i++)
my_c[j] += my_a[i];
Expand All @@ -136,7 +138,7 @@ float calc_pi_dpstd_native2(size_t num_steps, Policy&& policy, int group_size) {
}
policy.queue().wait();

auto src = bufc.get_access<access::mode::read>();
host_accessor src(bufc,read_only);

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

// fill the buffer with the calculation using parallel for
policy.queue().submit([&](handler& h) {
auto writeresult = buf.get_access<access::mode::write>(h);
accessor writeresult(buf,h,write_only);

h.parallel_for(range<1>{num_steps}, [=](id<1> idx) {
float x = (float)idx[0] / (float)num_steps;
writeresult[idx[0]] = 4.0f / (1.0f + x * x);
Expand Down Expand Up @@ -343,9 +346,8 @@ float calc_pi_dpstd_native3(size_t num_steps, int groups, Policy&& policy) {
auto local_reduce_event =
policy.queue().submit([&buf, &temp_buf, &brick_reduce, &tf_init,
num_steps, n_groups, workgroup_size](handler& h) {
auto access_buf = buf.template get_access<access::mode::read_write>(h);
auto temp_acc =
temp_buf.template get_access<access::mode::discard_write>(h);
accessor access_buf(buf,h);
accessor temp_acc(temp_buf,h,write_only);
// Create temporary local buffer
accessor<float, 1, access::mode::read_write, access::target::local>
temp_buf_local(range<1>(workgroup_size), h);
Expand Down Expand Up @@ -373,8 +375,7 @@ float calc_pi_dpstd_native3(size_t num_steps, int groups, Policy&& policy) {
reduce_event = policy.queue().submit([&reduce_event, &temp_buf, &combine,
countby2, n_groups](handler& h) {
h.depends_on(reduce_event);
auto temp_acc =
temp_buf.template get_access<access::mode::read_write>(h);
accessor temp_acc(temp_buf,h);
h.parallel_for(range<1>(n_groups), [=](item<1> item_id) mutable {
auto global_idx = item_id.get_linear_id();

Expand All @@ -388,10 +389,9 @@ float calc_pi_dpstd_native3(size_t num_steps, int groups, Policy&& policy) {
countby2 *= 2;
} while (countby2 < n_groups);
}

float answer = temp_buf.template get_access<access::mode::read>()[0];
result = answer / (float)num_steps;
return result;

host_accessor answer(temp_buf,read_only) ;
return answer[0]/(float)num_steps;
}

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

// fill buffer with 1...num_steps
policy.queue().submit([&](handler& h) {
auto writeresult = buf2.get_access<access::mode::write>(h);
accessor writeresult(buf2,h);
h.parallel_for(range<1>{num_steps},
[=](id<1> idx) { writeresult[idx[0]] = (float)idx[0]; });
});
Expand Down Expand Up @@ -453,9 +453,8 @@ float calc_pi_dpstd_native4(size_t num_steps, int groups, Policy&& policy) {
policy.queue().submit([&buf2, &temp_buf, &brick_reduce, &tf_init,
num_steps, n_groups, workgroup_size](handler& h) {
// grab access to the previous input
auto access_buf = buf2.template get_access<access::mode::read_write>(h);
auto temp_acc =
temp_buf.template get_access<access::mode::discard_write>(h);
accessor access_buf(buf2,h);
accessor temp_acc(temp_buf,h,write_only);
// Create temporary local buffer
accessor<float, 1, access::mode::read_write, access::target::local>
temp_buf_local(range<1>(workgroup_size), h);
Expand Down Expand Up @@ -484,8 +483,7 @@ float calc_pi_dpstd_native4(size_t num_steps, int groups, Policy&& policy) {
reduce_event = policy.queue().submit([&reduce_event, &temp_buf, &combine,
countby2, n_groups](handler& h) {
h.depends_on(reduce_event);
auto temp_acc =
temp_buf.template get_access<access::mode::read_write>(h);
accessor temp_acc(temp_buf,h);
h.parallel_for(range<1>(n_groups), [=](item<1> item_id) mutable {
auto global_idx = item_id.get_linear_id();

Expand All @@ -499,10 +497,8 @@ float calc_pi_dpstd_native4(size_t num_steps, int groups, Policy&& policy) {
countby2 *= 2;
} while (countby2 < n_groups);
}
float answer = temp_buf.template get_access<access::mode::read_write>()[0];
result = answer / (float)num_steps;

return result;
host_accessor answer(temp_buf,read_only) ;
return answer[0]/(float)num_steps;
}

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

MPI_Finalize();
Expand Down