-
-
Save al42and/aa33532ad491ab3a23ab1143310297ea to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From https://www.codingame.com/playgrounds/48226/introduction-to-sycl/hello-world | |
// By Codeplay software | |
#include <CL/sycl.hpp> | |
#include <iostream> | |
class vector_addition; | |
int main(int, char **) { | |
cl::sycl::float4 a = {1.0, 2.0, 3.0, 4.0}; | |
cl::sycl::float4 b = {4.0, 3.0, 2.0, 1.0}; | |
cl::sycl::float4 c = {0.0, 0.0, 0.0, 0.0}; | |
cl::sycl::default_selector device_selector; | |
cl::sycl::queue queue(device_selector); | |
std::cout << "Running on " | |
<< queue.get_device().get_info<cl::sycl::info::device::name>() | |
<< "\n"; | |
{ | |
cl::sycl::buffer<cl::sycl::float4, 1> a_sycl(&a, cl::sycl::range<1>(1)); | |
cl::sycl::buffer<cl::sycl::float4, 1> b_sycl(&b, cl::sycl::range<1>(1)); | |
cl::sycl::buffer<cl::sycl::float4, 1> c_sycl(&c, cl::sycl::range<1>(1)); | |
queue.submit([&](cl::sycl::handler &cgh) { | |
auto a_acc = a_sycl.get_access<cl::sycl::access::mode::read>(cgh); | |
auto b_acc = b_sycl.get_access<cl::sycl::access::mode::read>(cgh); | |
auto c_acc = c_sycl.get_access<cl::sycl::access::mode::discard_write>(cgh); | |
cgh.single_task<class vector_addition>( | |
[=]() { c_acc[0] = a_acc[0] + b_acc[0]; }); | |
}); | |
} | |
std::cout << " A { " << a.x() << ", " << a.y() << ", " << a.z() << ", " << a.w() << " }\n" | |
<< "+ B { " << b.x() << ", " << b.y() << ", " << b.z() << ", " << b.w() << " }\n" | |
<< "------------------\n" | |
<< "= C { " << c.x() << ", " << c.y() << ", " << c.z() << ", " << c.w() << " }" | |
<< std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment