Skip to content

Commit

Permalink
updates to work with 2021.3
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesreinders committed Aug 19, 2021
1 parent 1c04c06 commit f7b2a51
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

// SPDX-License-Identifier: MIT

// -------------------------------------------------------
// Changed from Book:
// dropped 'using namespace sycl::ONEAPI'
// this allows reduction to use the sycl::reduction,
// added sycl::ONEAPI:: to minimum.
// -------------------------------------------------------

#include <CL/sycl.hpp>
#include <iostream>
#include <random>

using namespace sycl;
using namespace sycl::ONEAPI;

template <typename T, typename I>
struct pair {
Expand All @@ -19,7 +25,7 @@ struct pair {
};

template <typename T, typename I>
using minloc = minimum<pair<T, I>>;
using minloc = sycl::ONEAPI::minimum<pair<T, I>>;

int main() {
constexpr size_t N = 16;
Expand All @@ -34,7 +40,7 @@ int main() {
std::numeric_limits<float>::max(), std::numeric_limits<int>::min()};
*res = identity;

auto red = reduction(res, identity, minloc<float, int>());
auto red = sycl::reduction(res, identity, minloc<float, int>());

Q.submit([&](handler& h) {
h.parallel_for(nd_range<1>{N, L}, red, [=](nd_item<1> item, auto& res) {
Expand Down
10 changes: 8 additions & 2 deletions samples/Ch14_common_parallel_patterns/fig_14_8_one_reduction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@

// SPDX-License-Identifier: MIT

// -------------------------------------------------------
// Changed from Book:
// dropped 'using namespace sycl::ONEAPI'
// this allows reduction to use the sycl::reduction,
// added sycl::ONEAPI:: to plus
// -------------------------------------------------------

#include <CL/sycl.hpp>
#include <iostream>
#include <numeric>

using namespace sycl;
using namespace sycl::ONEAPI;

int main() {

Expand All @@ -24,7 +30,7 @@ int main() {
// BEGIN CODE SNIP
h.parallel_for(
nd_range<1>{N, B},
reduction(sum, plus<>()),
reduction(sum, sycl::ONEAPI::plus<>()),
[=](nd_item<1> it, auto& sum) {
int i = it.get_global_id(0);
sum += data[i];
Expand Down
14 changes: 10 additions & 4 deletions samples/Ch18_using_libs/fig_18_11_std_fill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@

// SPDX-License-Identifier: MIT

#include <CL/sycl.hpp>
// -------------------------------------------------------
// Changed from Book:
// old naming dpstd:: is now oneapi::dpl::
// -------------------------------------------------------

#include <oneapi/dpl/execution>
#include <oneapi/dpl/algorithm>
#include <oneapi/dpl/iterator>
#include <CL/sycl.hpp>

int main(){
sycl::queue Q;
sycl::buffer<int> buf { 1000 };

auto buf_begin = dpstd::begin(buf);
auto buf_end = dpstd::end(buf);
auto buf_begin = oneapi::dpl::begin(buf);
auto buf_end = oneapi::dpl::end(buf);

auto policy = dpstd::execution::make_device_policy<class fill>( Q );
auto policy = oneapi::dpl::execution::make_device_policy<class fill>( Q );
std::fill(policy, buf_begin, buf_end, 42);

return 0;
Expand Down
26 changes: 17 additions & 9 deletions samples/Ch18_using_libs/fig_18_13_binary_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

// SPDX-License-Identifier: MIT

#include <iostream>
#include <CL/sycl.hpp>
// -------------------------------------------------------
// Changed from Book:
// dpstd:: is now
// oneapi::dpl::
// dpstd::execution::default_policy is now
// oneapi::dpl::execution::dpcpp_default
// -------------------------------------------------------

#include <oneapi/dpl/execution>
#include <oneapi/dpl/algorithm>
#include <oneapi/dpl/iterator>
#include <iostream>
#include <CL/sycl.hpp>

using namespace sycl;

Expand All @@ -27,17 +35,17 @@ int main()
}

// create dpc++ iterators
auto k_beg = dpstd::begin(kB);
auto k_end = dpstd::end(kB);
auto v_beg = dpstd::begin(vB);
auto v_end = dpstd::end(vB);
auto r_beg = dpstd::begin(rB);
auto k_beg = oneapi::dpl::begin(kB);
auto k_end = oneapi::dpl::end(kB);
auto v_beg = oneapi::dpl::begin(vB);
auto v_end = oneapi::dpl::end(vB);
auto r_beg = oneapi::dpl::begin(rB);

// create named policy from existing one
auto policy = dpstd::execution::make_device_policy<class bSearch>(dpstd::execution::default_policy);
auto policy = oneapi::dpl::execution::make_device_policy<class bSearch>(oneapi::dpl::execution::dpcpp_default);

// call algorithm
dpstd::binary_search(policy, k_beg, k_end, v_beg, v_end, r_beg);
oneapi::dpl::binary_search(policy, k_beg, k_end, v_beg, v_end, r_beg);

// check data
accessor r{rB};
Expand Down
9 changes: 7 additions & 2 deletions samples/Ch18_using_libs/fig_18_15_pstl_usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@

// SPDX-License-Identifier: MIT

#include <CL/sycl.hpp>
// -------------------------------------------------------
// Changed from Book:
// old naming dpstd:: is now oneapi::dpl::
// -------------------------------------------------------

#include <oneapi/dpl/execution>
#include <oneapi/dpl/algorithm>
#include <CL/sycl.hpp>

int main(){
sycl::queue Q;
Expand All @@ -13,7 +18,7 @@ int main(){
alloc(Q.get_context(), Q.get_device());
std::vector<int, decltype(alloc)> vec(n, alloc);

std::fill(dpstd::execution::make_device_policy(Q),
std::fill(oneapi::dpl::execution::make_device_policy(Q),
vec.begin(), vec.end(), 78);
Q.wait();

Expand Down

0 comments on commit f7b2a51

Please sign in to comment.