-
CHAMONT David authoredCHAMONT David authored
sycl-gray-scott.cpp 1.96 KiB
#include <CL/sycl.hpp>
#include <array>
#include <iostream>
using namespace cl::sycl;
constexpr int SIZE 5;
constexpr int ITER 2;
int main() {
// Loop through available platforms and devices
for (auto const& this_platform : platform::get_platforms() ) {
std::cout << "Found platform: "
<< this_platform.get_info<info::platform::name>() << "\n";
for (auto const& this_device : this_platform.get_devices() ) {
std::cout << " Device: "
<< this_device.get_info<info::device::name>() << "\n";
}
}
// Create SYCL queue
queue q;
// Running platform and device
std::cout << "Running on platform: "
<< q.get_platform().get_info<info::platform::name>() << "\n";
std::cout << " Device: "
<< q.get_device().get_info<info::device::name>() << "\n";
std::cout << "\n";
// Initialize input array
std::array<float,SIZE*SIZE> input;
std::array<float,SIZE*SIZE> output;
for (int i = 0; i < SIZE; i++) {
for (int j = 0; j < SIZE; j++) {
input[i*SIZE+j] = i + j;
}
}
// Create buffers
buffer<float,2> input_buffer{input.data(),range<2>{SIZE,SIZE}};
buffer<float,2> output_buffer{output.data(),range<2>{SIZE,SIZE}};
// Submit command group for execution
q.submit([&](handler& cgh) {
// Create accessors for input and output buffers
accessor input_accessor(input_buffer, cgh, read_only);
accessor output_accessor(output_buffer, cgh, write_only);
// Define the kernel
cgh.parallel_for(SIZE, [=](id<1> idx) {
output_accessor[idx] = input_accessor[idx] * input_accessor[idx];
});
});
// Wait for the command group to finish
q.wait();
// Print the result
host_accessor output_host_accessor(output_buffer, read_only);
for (int i = 0; i < SIZE; i++) {
std::cout << output_host_accessor[i] << " ";
}
std::cout << std::endl;
return 0;
}