Skip to content
Snippets Groups Projects
Commit 58cff6a8 authored by Sandipan Mohanty's avatar Sandipan Mohanty
Browse files

Add Jan's material on SYCL

parent d91cdc07
No related branches found
No related tags found
No related merge requests found
#include <sycl.hpp>
#include <iostream>
#include <vector>
auto main() -> int {
auto N{1'000'000};
std::vector v(N, 0.0);
{
// Create a buffer buf from v
sycl::buffer<double, 2> buf2{sycl::range{1000, 1000}};
}
}
#include <sycl.hpp>
auto main() -> int {
auto N{1'000u};
// Create a buffer of size N by N
sycl::queue q;
sycl::buffer<double, 2> bufA{sycl::range{N, N}};
q.submit([&](sycl::handler& h){
sycl::accessor accA{bufA, h, sycl::write_only, sycl::no_init};
h.parallel_for(sycl::range{1000, 1000}, [=](sycl::item<2> it){
// Use 2D idx to access 2D buffer
accA[it.get_id()] = 0;
// extract index components for traditional 2D access
auto i = it[0];
auto j = it[1];
accA[i][j] = it.get_linear_id();
});
});
{
sycl::host_accessor accA{bufA};
std::cout << "The linear index of [17, 511] is " << accA[17][511] << ".\n";
}
}
#include <sycl.hpp>
#include <iostream>
#include <numbers>
#include <vector>
using namespace sycl;
using namespace std::numbers;
auto main() -> int {
std::vector v(10'000'000, 0.0);
queue q;
{
buffer v_buf{v};
q.submit([&](handler& h){
accessor v{v_buf, h};
h.parallel_for(v.size(), [=](auto i){
v[i] = 2 * pi * i / v.size();
});
});
}
std::cout << v[v.size() / 2] << '\n';
}
No preview for this file type
day4/sycl.pdf 0 → 100644
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment