Skip to content
Snippets Groups Projects
Commit 278f2f0c authored by CHAMONT David's avatar CHAMONT David
Browse files

Make the sycl namespace apparent.

parent dbf35208
No related branches found
No related tags found
No related merge requests found
......@@ -3,32 +3,32 @@
#include <iostream>
#include <iomanip>
using namespace cl::sycl;
using namespace cl;
constexpr std::size_t NB_ROWS { 4 } ;
constexpr std::size_t NB_COLS { 5 } ;
void compute( queue & q, buffer<float,2> & ibuffer, buffer<float,2> & obuffer ) {
void compute( sycl::queue & q, sycl::buffer<float,2> & ibuffer, sycl::buffer<float,2> & obuffer ) {
q.submit([&](handler& cgh) {
q.submit([&](sycl::handler& cgh) {
// Create accessors for input and output buffers
accessor iacc{ibuffer, cgh, read_only};
accessor oacc{obuffer, cgh, write_only};
sycl::accessor iacc{ibuffer, cgh, sycl::read_only};
sycl::accessor oacc{obuffer, cgh, sycl::write_only};
// Define the kernel
cgh.parallel_for(range<2>{NB_ROWS-2,NB_COLS-2}, [=](item<2> it) {
cgh.parallel_for(sycl::range<2>{NB_ROWS-2,NB_COLS-2}, [=](sycl::item<2> it) {
constexpr std::array<float,9> pattern{ 1., 1., 1., 1., -8., 1., 1., 1., 1.};
id<2> xy = it.get_id();
sycl::id<2> xy = it.get_id();
std::size_t r = xy[0] ;
std::size_t c = xy[1] ;
oacc[id<2>{r,c}] = 0.f;
oacc[sycl::id<2>{r,c}] = 0.f;
for(std::size_t dr = 0ul; dr < 3ul; ++dr){
for(std::size_t dc = 0ul; dc < 3ul; ++dc){
oacc[id<2>{r,c}] += iacc[id<2>{r+dr,c+dc}]*pattern[dr*3+dc];
oacc[sycl::id<2>{r,c}] += iacc[sycl::id<2>{r+dr,c+dc}]*pattern[dr*3+dc];
}
}
......@@ -43,9 +43,9 @@ int main() {
try {
// Create SYCL queue
queue q ;
sycl::queue q ;
std::cout << "\nDevice: "
<< q.get_device().get_info<info::device::name>()
<< q.get_device().get_info<sycl::info::device::name>()
<< std::endl;
// Initialize and display input array
......@@ -64,19 +64,19 @@ int main() {
// Ouput array and input/output buffers
std::array<float,(NB_ROWS-2)*(NB_COLS-2)> output;
buffer<float,2> input_buffer{input.data(),range<2>{NB_ROWS,NB_COLS}} ;
buffer<float,2> output_buffer{output.data(),range<2>{NB_ROWS-2,NB_COLS-2}} ;
sycl::buffer<float,2> input_buffer{input.data(),sycl::range<2>{NB_ROWS,NB_COLS}} ;
sycl::buffer<float,2> output_buffer{output.data(),sycl::range<2>{NB_ROWS-2,NB_COLS-2}} ;
// apply the stencil
compute(q,input_buffer,output_buffer) ;
// Print the result
std::cout << "\nOUTPUT: " << std::endl;
host_accessor output_host_accessor{output_buffer, read_only};
sycl::host_accessor output_host_accessor{output_buffer, sycl::read_only};
for (std::size_t r = 0; r < (NB_ROWS-2); r++) {
std::cout << " ";
for (std::size_t c = 0; c < (NB_COLS-2); c++) {
std::cout << std::setw(9) << output_host_accessor[id<2>{r,c}] << " ";
std::cout << std::setw(9) << output_host_accessor[sycl::id<2>{r,c}] << " ";
}
std::cout << std::endl;
}
......@@ -86,7 +86,7 @@ int main() {
return 0;
}
catch (exception & e) {
catch (sycl::exception & e) {
std::cout << e.what() << std::endl;
std::cout << e.code().message() << std::endl;
}
......
......@@ -5,7 +5,7 @@
#include <iostream>
#include <vector>
namespace sycl = cl::sycl;
namespace sycl = cl;
// Définition des constantes de l'équation de Gray-Scott
constexpr double Du = 0.02;
......
......@@ -4,21 +4,21 @@
#define SIZE 10
using namespace cl::sycl;
using namespace cl;
void display ( device const & d ) {
void display ( sycl::device const & d ) {
auto const & p = d.get_platform() ;
std::cout
<< " platform name: " << p.get_info<info::platform::name>() << "\n"
<< " name: " << d.get_info<info::device::name>() << "\n"
<< " vendor: " << d.get_info<info::device::vendor>() << "\n"
<< " platform name: " << p.get_info<sycl::info::platform::name>() << "\n"
<< " name: " << d.get_info<sycl::info::device::name>() << "\n"
<< " vendor: " << d.get_info<sycl::info::device::vendor>() << "\n"
<< " is_cpu: " << d.is_cpu() << "\n"
<< " is_gpu: " << d.is_gpu() << "\n"
<< " is_accelerator: " << d.is_accelerator() << "\n"
<< " default selector rating: " << default_selector_v(d) << "\n"
<< " cpu selector rating: " << cpu_selector_v(d) << "\n"
<< " gpu selector rating: " << gpu_selector_v(d) << "\n"
<< " acc selector rating: " << accelerator_selector_v(d) << "\n"
<< " default selector rating: " << sycl::default_selector_v(d) << "\n"
<< " cpu selector rating: " << sycl::cpu_selector_v(d) << "\n"
<< " gpu selector rating: " << sycl::gpu_selector_v(d) << "\n"
<< " acc selector rating: " << sycl::accelerator_selector_v(d) << "\n"
<< std::flush ;
}
......@@ -26,7 +26,7 @@ int main() {
// Loop through available platforms and devices
int rank1 = 0;
for (auto const & this_platform : platform::get_platforms() ) {
for (auto const & this_platform : sycl::platform::get_platforms() ) {
for (auto const & this_device : this_platform.get_devices() ) {
std::cout << "\nRank " << rank1++ << "\n";
display(this_device) ;
......
......@@ -3,16 +3,16 @@
#include <iostream>
#include <iomanip>
using namespace cl::sycl;
using namespace cl;
void list_ranks() {
int rank = 0;
queue q { [&]( device const & d ) {
sycl::queue q { [&]( sycl::device const & d ) {
std::string title { "rank " } ;
title += std::to_string(rank++) ;
auto const & p = d.get_platform() ;
std::string device = d.get_info<info::device::name>();
std::string device = d.get_info<sycl::info::device::name>();
std::cout << std::setw(12) << title << ' ' << device << std::endl;
return 0 ;
}};
......@@ -22,9 +22,9 @@ void list_ranks() {
template<typename Selector>
void try_selector( std::string const & title, Selector const & selector ) {
queue q { selector };
sycl::queue q { selector };
std::string device = q.get_device().get_info<info::device::name>();
std::string device = q.get_device().get_info<sycl::info::device::name>();
std::cout << std::setw(12) << title << ' ' << device << std::endl;
}
......@@ -32,13 +32,13 @@ void try_selector( std::string const & title, Selector const & selector ) {
void try_rank( std::size_t required_rank ) {
int rank = 0;
queue q { [&]( device const & d ) {
sycl::queue q { [&]( sycl::device const & d ) {
return (rank++==required_rank) ;
}};
std::string title { "RANK " } ;
title += std::to_string(required_rank) ;
std::string device = q.get_device().get_info<info::device::name>();
std::string device = q.get_device().get_info<sycl::info::device::name>();
std::cout << std::setw(12) << title << ' ' << device << std::endl;
}
......@@ -55,10 +55,10 @@ int main( int argc, char * argv[] ) {
// Try different predefined selector
std::cout << std::endl ;
try_selector( "DEFAULT:", default_selector_v ) ;
try_selector( "CPU:", cpu_selector_v ) ;
try_selector( "GPU:", gpu_selector_v ) ;
try_selector( "ACCELERATOR:", accelerator_selector_v ) ;
try_selector( "DEFAULT:", sycl::default_selector_v ) ;
try_selector( "CPU:", sycl::cpu_selector_v ) ;
try_selector( "GPU:", sycl::gpu_selector_v ) ;
try_selector( "ACCELERATOR:", sycl::accelerator_selector_v ) ;
// Home-made selector based on rank
std::cout << std::endl ;
......
......@@ -4,14 +4,14 @@
constexpr std::size_t SIZE {10};
using namespace cl::sycl;
using namespace cl;
int main() {
// Create SYCL queue
queue q ;
sycl::queue q ;
std::cout << "\nDevice: "
<< q.get_device().get_info<info::device::name>()
<< q.get_device().get_info<sycl::info::device::name>()
<< std::endl;
// Initialize input array
......@@ -22,18 +22,18 @@ int main() {
std::array<float,SIZE> output;
// Create buffers
buffer input_buffer{input.data(), range<1>{SIZE}} ;
buffer output_buffer{output.data(), range<1>{SIZE}} ;
sycl::buffer input_buffer{input.data(), sycl::range<1>{SIZE}} ;
sycl::buffer output_buffer{output.data(), sycl::range<1>{SIZE}} ;
// Submit command group for execution
q.submit([&](handler& cgh) {
q.submit([&](sycl::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);
sycl::accessor input_accessor(input_buffer, cgh, sycl::read_only);
sycl::accessor output_accessor(output_buffer, cgh, sycl::write_only);
// Define the kernel
cgh.parallel_for(range<1>{SIZE}, [=](id<1> idx) {
cgh.parallel_for(sycl::range<1>{SIZE}, [=](sycl::id<1> idx) {
output_accessor[idx] = input_accessor[idx] * input_accessor[idx];
});
......@@ -41,7 +41,7 @@ int main() {
// Print results
std::cout << "\n";
host_accessor output_host_accessor(output_buffer, read_only);
sycl::host_accessor output_host_accessor(output_buffer, sycl::read_only);
for (int i = 0; i < SIZE; i++) {
std::cout << output_host_accessor[i] << " ";
}
......
......@@ -4,14 +4,14 @@
#define SIZE 10
using namespace cl::sycl;
using namespace cl;
int main() {
// Create SYCL queue
queue q ;
sycl::queue q ;
std::cout << "\nDevice: "
<< q.get_device().get_info<info::device::name>()
<< q.get_device().get_info<sycl::info::device::name>()
<< std::endl;
// Initialize input array
......@@ -21,12 +21,12 @@ int main() {
}
// Alloc memory on device
float * dinput = malloc_device<float>(SIZE, q);
float * doutput = malloc_device<float>(SIZE, q);
float * dinput = sycl::malloc_device<float>(SIZE, q);
float * doutput = sycl::malloc_device<float>(SIZE, q);
// Submit command group for execution
q.memcpy(dinput,input.data(),SIZE*sizeof(float)).wait();
q.parallel_for(range<1>{SIZE}, [=](id<1> idx) {
q.parallel_for(sycl::range<1>{SIZE}, [=](sycl::id<1> idx) {
doutput[idx] = dinput[idx] * dinput[idx];
});
q.memcpy(output.data(),doutput,SIZE*sizeof(float)).wait();
......@@ -40,7 +40,7 @@ int main() {
// End
std::cout << std::endl;
free(dinput, q);
free(doutput, q);
sycl::free(dinput, q);
sycl::free(doutput, q);
return 0;
}
......@@ -4,26 +4,26 @@
#define SIZE 10
using namespace cl::sycl;
using namespace cl;
int main() {
// Create SYCL queue
queue q ;
sycl::queue q ;
std::cout << "\nDevice: "
<< q.get_device().get_info<info::device::name>()
<< q.get_device().get_info<sycl::info::device::name>()
<< std::endl;
// Initialize input array
auto * input = malloc_shared<float>(SIZE, q);
auto * output = malloc_shared<float>(SIZE, q);
auto * input = sycl::malloc_shared<float>(SIZE, q);
auto * output = sycl::malloc_shared<float>(SIZE, q);
for (std::size_t i = 0; i < SIZE; i++) {
input[i] = i + 1;
}
// Because I have no need to create some accessors,
// I can use the queue directly to launch the kernel.
q.parallel_for(range<1>{SIZE}, [=](id<1> idx) {
q.parallel_for(sycl::range<1>{SIZE}, [=](sycl::id<1> idx) {
output[idx] = input[idx] * input[idx];
});
q.wait();
......@@ -37,7 +37,7 @@ int main() {
// End
std::cout << std::endl;
free(input, q);
free(output, q);
sycl::free(input, q);
sycl::free(output, q);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment