Skip to content

Commit 10f7fb3

Browse files
authored
updated oneDPL jupyter notebooks (#1216)
* updated with the latest 2023 changes * Updated the notebooks with oneDPL changes * updated onedpl notebooks for latest changes * updated onedpl notebooks for latest changes
1 parent beafc8a commit 10f7fb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+136
-159
lines changed

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/02_DPCPP_Program_Structure/DPCPP_Program_Structure.ipynb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,10 +611,10 @@
611611
"#include <sycl/sycl.hpp>\n",
612612
"#include <iostream>\n",
613613
"using namespace sycl;\n",
614-
"class my_device_selector : public device_selector {\n",
614+
"class my_device_selector {\n",
615615
"public:\n",
616616
" my_device_selector(std::string vendorName) : vendorName_(vendorName){};\n",
617-
" int operator()(const device& dev) const override {\n",
617+
" int operator()(const device& dev) const {\n",
618618
" int rating = 0;\n",
619619
" //We are querying for the custom device specific to a Vendor and if it is a GPU device we\n",
620620
" //are giving the highest rating as 3 . The second preference is given to any GPU device and the third preference is given to\n",
@@ -705,7 +705,7 @@
705705
"// Number of complex numbers passing to the SYCL code\n",
706706
"static const int num_elements = 10000;\n",
707707
"\n",
708-
"class CustomDeviceSelector : public device_selector {\n",
708+
"class CustomDeviceSelector {\n",
709709
" public:\n",
710710
" CustomDeviceSelector(std::string vendorName) : vendorName_(vendorName){};\n",
711711
" int operator()(const device &dev) const override {\n",
@@ -1007,9 +1007,9 @@
10071007
]
10081008
}
10091009
],
1010-
"metadata": {
1010+
"metadata": {
10111011
"kernelspec": {
1012-
"display_name": "Python 3.7 (Intel® oneAPI)",
1012+
"display_name": "Python 3 (Intel® oneAPI 2022.3)",
10131013
"language": "python",
10141014
"name": "c009-intel_distribution_of_python_3_oneapi-beta05-python"
10151015
},
@@ -1023,7 +1023,7 @@
10231023
"name": "python",
10241024
"nbconvert_exporter": "python",
10251025
"pygments_lexer": "ipython3",
1026-
"version": "3.9.7"
1026+
"version": "3.9.13"
10271027
},
10281028
"toc": {
10291029
"base_numbering": 1,

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/02_DPCPP_Program_Structure/lab/complex_mult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ using namespace std;
1717
// Number of complex numbers passing to the SYCL code
1818
static const int num_elements = 10000;
1919

20-
class CustomDeviceSelector : public device_selector {
20+
class CustomDeviceSelector {
2121
public:
2222
CustomDeviceSelector(std::string vendorName) : vendorName_(vendorName){};
2323
int operator()(const device &dev) const override {

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/02_DPCPP_Program_Structure/src/complex_mult.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,21 @@ using namespace std;
1717
// Number of complex numbers passing to the SYCL code
1818
static const int num_elements = 10000;
1919

20-
class CustomDeviceSelector : public device_selector {
20+
class CustomDeviceSelector {
2121
public:
2222
CustomDeviceSelector(std::string vendorName) : vendorName_(vendorName){};
2323
int operator()(const device &dev) const override {
2424
int device_rating = 0;
2525
//We are querying for the custom device specific to a Vendor and if it is a GPU device we
2626
//are giving the highest rating as 3 . The second preference is given to any GPU device and the third preference is given to
2727
//CPU device.
28-
//**************Step1: Uncomment the following lines where you are setting the rating for the devices********
29-
/*if (dev.is_gpu() & (dev.get_info<info::device::name>().find(vendorName_) !=
28+
if (dev.is_gpu() & (dev.get_info<info::device::name>().find(vendorName_) !=
3029
std::string::npos))
3130
device_rating = 3;
3231
else if (dev.is_gpu())
3332
device_rating = 2;
3433
else if (dev.is_cpu())
35-
device_rating = 1;*/
34+
device_rating = 1;
3635
return device_rating;
3736
};
3837

@@ -65,12 +64,9 @@ void SYCLParallel(queue &q, std::vector<Complex2> &in_vect1,
6564
accessor V1(bufin_vect1,h,read_only);
6665
accessor V2(bufin_vect2,h,read_only);
6766
// Accessor set to Write mode
68-
//**************STEP 2: Uncomment the below line to set the Write Accessor********************
69-
//accessor V3 (bufout_vect,h,write_only);
67+
accessor V3 (bufout_vect,h,write_only);
7068
h.parallel_for(R, [=](auto i) {
71-
//**************STEP 3: Uncomment the below line to call the complex_mul function that computes the multiplication
72-
//of the complex numbers********************
73-
//V3[i] = V1[i].complex_mul(V2[i]);
69+
V3[i] = V1[i].complex_mul(V2[i]);
7470
});
7571
});
7672
q.wait_and_throw();

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/02_DPCPP_Program_Structure/src/custom_device_sample.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
#include <sycl/sycl.hpp>
77
#include <iostream>
88
using namespace sycl;
9-
class my_device_selector : public device_selector {
9+
class my_device_selector {
1010
public:
1111
my_device_selector(std::string vendorName) : vendorName_(vendorName){};
12-
int operator()(const device& dev) const override {
12+
int operator()(const device& dev) const {
1313
int rating = 0;
1414
//We are querying for the custom device specific to a Vendor and if it is a GPU device we
1515
//are giving the highest rating as 3 . The second preference is given to any GPU device and the third preference is given to

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/07_DPCPP_Library/lab/binary_search.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <oneapi/dpl/execution>
99
#include <oneapi/dpl/iterator>
1010
#include <iostream>
11-
#include <sycl/sycl.hpp>
11+
1212

1313
using namespace sycl;
1414
using namespace oneapi::dpl::execution;
@@ -50,7 +50,7 @@ int main() {
5050

5151
//function object to be passed to sort function
5252

53-
//Calling the dpstd binary search algorithm. We pass in the policy, the buffer iterators for the input vectors and the output.
53+
//Calling the onedpl binary search algorithm. We pass in the policy, the buffer iterators for the input vectors and the output.
5454
// Default comparator is the operator < used here.
5555
const auto i = oneapi::dpl::binary_search(policy,keys_begin,keys_end,vals_begin,vals_end,result_begin);
5656

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/07_DPCPP_Library/lab/counting_iterator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main() {
1717
oneapi::dpl::counting_iterator<int> count_b = count_a + 100;
1818
int init = count_a[0]; // OK: init == 0
1919
//*count_b = 7; // ERROR: counting_iterator doesn't provide write operations
20-
auto sum = std::reduce(dpl::execution::dpcpp_default,
20+
auto sum = oneapi::dpl::reduce(dpl::execution::dpcpp_default,
2121
count_a, count_b, init); // sum is (0 + 0 + 1 + ... + 99) = 4950
2222
std::cout << "The Sum is: " <<sum<<"\n";
2323

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/07_DPCPP_Library/lab/discard_iterator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <iostream>
1212

1313
#include <tuple>
14-
#include <sycl/sycl.hpp>
14+
1515

1616
using namespace sycl;
1717
using namespace oneapi::dpl::execution;
@@ -46,7 +46,7 @@ int main() {
4646

4747
auto zipped_first = oneapi::dpl::make_zip_iterator(keys_begin, vals_begin);
4848

49-
auto iter_res = std::copy_if(dpl::execution::dpcpp_default,zipped_first, zipped_first + num_elements,
49+
auto iter_res = oneapi::dpl::copy_if(dpl::execution::dpcpp_default,zipped_first, zipped_first + num_elements,
5050
dpl::make_zip_iterator(result_begin, dpl::discard_iterator()),
5151
[](auto t){return get<1>(t) == 1;});
5252

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/07_DPCPP_Library/lab/dpl_buffer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <oneapi/dpl/algorithm>
88
#include <oneapi/dpl/execution>
99
#include <oneapi/dpl/iterator>
10-
#include <sycl/sycl.hpp>
10+
1111
using namespace sycl;
1212
using namespace oneapi::dpl::execution;
1313

@@ -23,8 +23,8 @@ int main(){
2323
auto buf_begin = oneapi::dpl::begin(buf);
2424
auto buf_end = oneapi::dpl::end(buf);
2525

26-
std::for_each(make_device_policy(q), buf_begin, buf_end, [](int &a){ a *= 3; });
27-
std::sort(make_device_policy(q), buf_begin, buf_end);
26+
oneapi::dpl::for_each(make_device_policy(q), buf_begin, buf_end, [](int &a){ a *= 3; });
27+
oneapi::dpl::sort(make_device_policy(q), buf_begin, buf_end);
2828
}
2929

3030
for(int i = 0; i < v.size(); i++) std::cout << v[i] << "\n";

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/07_DPCPP_Library/lab/dpl_simple.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <oneapi/dpl/algorithm>
88
#include <oneapi/dpl/execution>
9-
#include<sycl/sycl.hpp>
9+
1010
using namespace sycl;
1111
constexpr int N = 4;
1212

@@ -16,7 +16,7 @@ int main() {
1616
std::vector<int> v(N);
1717

1818
//# Parallel STL fill function with device policy
19-
std::fill(oneapi::dpl::execution::make_device_policy(q), v.begin(), v.end(), 20);
19+
oneapi::dpl::fill(oneapi::dpl::execution::make_device_policy(q), v.begin(), v.end(), 20);
2020

2121
for(int i = 0; i < v.size(); i++) std::cout << v[i] << "\n";
2222
return 0;

DirectProgramming/DPC++/Jupyter/oneapi-essentials-training/07_DPCPP_Library/lab/dpl_sortdouble.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <oneapi/dpl/algorithm>
88
#include <oneapi/dpl/execution>
9-
#include<sycl/sycl.hpp>
9+
1010
using namespace sycl;
1111
using namespace oneapi::dpl::execution;
1212

@@ -15,8 +15,8 @@ int main() {
1515
std::cout << "Device : " << q.get_device().get_info<info::device::name>() << "\n";
1616
std::vector<int> v{2,3,1,4};
1717

18-
std::for_each(make_device_policy(q), v.begin(), v.end(), [](int &a){ a *= 2; });
19-
std::sort(make_device_policy(q), v.begin(), v.end());
18+
oneapi::dpl::for_each(make_device_policy(q), v.begin(), v.end(), [](int &a){ a *= 2; });
19+
oneapi::dpl::sort(make_device_policy(q), v.begin(), v.end());
2020

2121
for(int i = 0; i < v.size(); i++) std::cout << v[i] << "\n";
2222
return 0;

0 commit comments

Comments
 (0)